Skip to content

Cart rules optimizer - #110

Draft
TheoAlloin wants to merge 3 commits into
friends-of-presta:devfrom
TheoAlloin:clean-my-prestashop-cart-rule
Draft

Cart rules optimizer#110
TheoAlloin wants to merge 3 commits into
friends-of-presta:devfrom
TheoAlloin:clean-my-prestashop-cart-rule

Conversation

@TheoAlloin

Copy link
Copy Markdown

Related to this prestashop issue

Not a solution but a patch to remove deprecated cart rules when we have a lot of cart rules in database like :

image

@SebSept

SebSept commented Apr 5, 2021

Copy link
Copy Markdown
Contributor

Thanks for contributing :)
You are welcome.
We'll review your PR as soon as possible ... (in a few, days or weeks...)

@SebSept SebSept left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Une première lecture du code avec quelques demandes et questions.
Je n'ai pas encore testé le code.

Si tu veux l'améliorer simplement, tu peux lancer ./vendor/bin/phpstan analyse src/Commands/Optimize/CartRulesOptimizer.php dans le dossier du module.
Et augmenter progressivement le niveau de test de phpstan (fichier .phpstan.neon)

Comment thread config/services.yml Outdated
- { name: console.command }

fop.console.optimize_cart_rules.command:
class: FOP\Console\Commands\Optimize\CartRulesOptimizer

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Optimize" c'est très générique, plus on précis mieux c'est.
Là, pour le coup, on ne sait pas vraiment ce que va faire la commande.
Avec un truc du genre cartrules.remove_outdated / CartRulesCleanOutdated par exemple, c'est plus parlant.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bonjour @SebSept, modification effectuée

/**
* {@inheritdoc}
*/
protected function configure()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Si tu peux spécifier le type retourné par les fonctions, ça serait top.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SebSept c'est fait

/**
* {@inheritdoc}
*/
public function execute(InputInterface $input, OutputInterface $output)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cette fonction doit retourner une valeur : 0 en cas de succes 1 en cas d'echec.
Tu peux aussi spécifier ça dans la signature de la fonction.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SebSept c'est fait


$this->clearCartRules();

if ($this->logs['cart_rules'] === 0) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Le mieux ça serait que clearCartRules() renvoit le nombre de règles.
Si on peut éviter de trimbaler une variables pour stocker la valeur, c'est plus fiable et plus économe en code.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SebSept, c'est fait


if (!$this->checkDate($from_date)) {
$io->error('Incorrect date parameter. Please type a date from format Y-m-d. Date given : ' . $from_date);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Le mieux, c'est surement d'interrompre le traitement ici.
Plutot que de continuer l'execution du script alors que le paramètre de date est incorrect.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SebSept c'est fait sauf que je traite des jours plutôt qu'une date maintenant

->setDescription('Clear and optimize your Prestashop Cart rules')
->setHelp('Clear your Prestashop from useless row in cart rules table');

$this->addUsage('--from=[from-date] (format: Y-m-d, default: 1 month)');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ça serait pas mieux d'avoir comme paramètre une durée ?
Une durée qui corresponde aux nombre de jours depuis lequel les cartRules sont périmé.
Si j'écris un script avec cette commande, dans 6 mois, il faudra réécrire la commande pour changer la date.
Alors que je l'utilse sans paramètre ou avec un paramètre qui serait le nombre de jours, ça serait déjà ok.
Qu'en penses-tu ?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SebSept, c'est effectivement plus logique avec des jours que une date.
J'ai fait un refactoring

{
$instance = Db::getInstance();

$instance->delete('cart_rule_combination', 'id_cart_rule_1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tu peux mettres un petit commentaire (en anglais) pour indiquer ce que fais chaque requete, s'il te plait ?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SebSept, non traité pour l'instant

$instance->delete('cart_rule_product_rule_group', 'id_cart_rule IN (SELECT id_cart_rule FROM `ps_cart_rule` WHERE `date_to` < "' . $this->from_date . '" OR active = 0 OR quantity = 0)');
$instance->delete('cart_rule_product_rule', 'NOT EXISTS (SELECT 1 FROM `' . _DB_PREFIX_ . 'cart_rule_product_rule_group` WHERE `' . _DB_PREFIX_ . 'cart_rule_product_rule`.`id_product_rule_group` = `' . _DB_PREFIX_ . 'cart_rule_product_rule_group`.`id_product_rule_group`)');
$instance->delete('cart_rule_product_rule_value', 'NOT EXISTS (SELECT 1 FROM `' . _DB_PREFIX_ . 'cart_rule_product_rule` WHERE `' . _DB_PREFIX_ . 'cart_rule_product_rule_value`.`id_product_rule` = `' . _DB_PREFIX_ . 'cart_rule_product_rule`.`id_product_rule`)');
$instance->delete('cart_rule', '`date_to` < "' . $this->from_date . '" OR active = 0 OR quantity = 0');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

En fait, ça ne fait pas que supprimer les cartRule périmés comme je le pensais au début. D'où l'intéret de faire une description claire :D dans la commande et dans le message de PR.
Il vaut mieux être trop verbeux dans les explications que pas assez.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Du coup, ça aurait du sens de proposer une option pour supprimer ou pas les régles inactives ? et une pour celle avec une quantité nulle ?

@SebSept SebSept added the feature a new feature to implement label Apr 5, 2021
@SebSept

SebSept commented Jun 15, 2021

Copy link
Copy Markdown
Contributor

ping @TheoAlloin .
J'ai fais pas mal de remarques, qu'en penses-tu ?

@SebSept
SebSept marked this pull request as draft June 15, 2021 10:37
@SebSept SebSept added the help wanted Extra attention is needed label Oct 1, 2021
@SebSept

SebSept commented Oct 1, 2021

Copy link
Copy Markdown
Contributor

Tu sais, j'ai donné de mon temps pour faire cette review @TheoAlloin
ça serait gentil de donner un signe de vie ...

@jf-viguier

Copy link
Copy Markdown
Member

@TheoAlloin ? des nouvelles ?

@matthieu2607

Copy link
Copy Markdown

Bonjour,
@SebSept, on propose de reprendre la pull request en prenant en compte tes retours qui sont pertinents.
Cordialement

@jf-viguier

jf-viguier commented Oct 10, 2022

Copy link
Copy Markdown
Member

Merci @matthieu2607 avec plaisir. Êtes-vous sur le slack Friends of Presta pour en discuter ? Invitation sur https://friendsofpresta.org/

@matthieu2607

Copy link
Copy Markdown

Bonjour @jf-viguier,
Non, je ne suis pas sur le slack mais je vais le faire ;)
Nous souhaitons proposer d'autres commandes également, on pourra faire le point sur slack.
Cordialement

@matthieu2607
matthieu2607 force-pushed the clean-my-prestashop-cart-rule branch from 2d58927 to 73e57c9 Compare October 14, 2022 14:31
@SebSept SebSept removed their assignment Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature a new feature to implement help wanted Extra attention is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants