From 448276694ace238cb34f5b10975b940e671c1c64 Mon Sep 17 00:00:00 2001 From: Thomas NARES Date: Wed, 2 Nov 2022 18:59:31 +0100 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Pablo Borowicz Co-authored-by: Krystian Podemski --- modules/sample-modules/_index.md | 10 +++---- .../sample-modules/example-hooks/_index.md | 8 ++--- .../example-hooks/actionValidateOrder.md | 30 +++++++++---------- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/modules/sample-modules/_index.md b/modules/sample-modules/_index.md index 647e599668..e43c0eba7a 100644 --- a/modules/sample-modules/_index.md +++ b/modules/sample-modules/_index.md @@ -5,20 +5,20 @@ weight: 80 # Sample modules and how to guides -The PrestaShop Community made some example modules and how to guides to help you understand how to implement hooks, admin grids, manage entities... and a lot more. +The PrestaShop Community has made example modules and how-to guides to help you understand how to implement hooks, admin grids, manage entities... and a lot more. {{% children %}} -## Our example modules repository +## Example modules repository * [See all our example modules (GitHub)](https://github.com/PrestaShop/example-modules) -This repository hosts example modules built and maintained by PrestaShop. -These modules demonstrate useful usecases for developers willing to customize the software. +This repository hosts example modules built and maintained by project members and the community. +These modules demonstrate good use cases for developers willing to customize the software. ### Extending Symfony pages -- [Demo Extending a Symfony Form - 1](https://github.com/PrestaShop/example-modules/tree/master/demoextendsymfonyform1) - how to insert an input inside a Symfony form +- [Extending a Symfony form - how to insert a field inside an existing form](https://github.com/PrestaShop/example-modules/tree/master/demoextendsymfonyform1) - [Demo Extending a Symfony Form - 2](https://github.com/PrestaShop/example-modules/tree/master/demoextendsymfonyform2) - how to insert an input inside a Symfony form - 2 - [Demo Extending a Symfony Form - 3](https://github.com/PrestaShop/example-modules/tree/master/demoextendsymfonyform3) - how to use CQRS in a module - [Demo View Order Hooks](https://github.com/PrestaShop/example-modules/tree/master/demovieworderhooks) diff --git a/modules/sample-modules/example-hooks/_index.md b/modules/sample-modules/example-hooks/_index.md index 1b46a080c1..2cf191db0b 100644 --- a/modules/sample-modules/example-hooks/_index.md +++ b/modules/sample-modules/example-hooks/_index.md @@ -1,12 +1,12 @@ --- -title: Hooks examples +title: Hook examples weight: 2 --- -# Hooks implementation examples +# Hook implementation examples -Hooks is one of the most powerful tools to extend or modify PrestaShop with modules. +Hooks are one of the most powerful tools to extend or modify PrestaShop using modules. -For a complete introduction about hooks, please read [Hooks]({{< relref "/8/modules/concepts/hooks/" >}}) +For a complete introduction to hooks, please read [Hooks]({{< relref "/8/modules/concepts/hooks/" >}}) {{% children %}} \ No newline at end of file diff --git a/modules/sample-modules/example-hooks/actionValidateOrder.md b/modules/sample-modules/example-hooks/actionValidateOrder.md index c2d8130948..1a2cba6b72 100644 --- a/modules/sample-modules/example-hooks/actionValidateOrder.md +++ b/modules/sample-modules/example-hooks/actionValidateOrder.md @@ -3,7 +3,7 @@ title: "actionValidateOrder" weight: 3 --- -# Hook example : actionValidateOrder +# Hook example: actionValidateOrder This hook is triggered when an `order` is validated. @@ -26,9 +26,9 @@ actionValidateOrder ); ``` -A classic use-case for this hook could be : +A classic use case for this hook could be: -> I want to reward my customers on their _n-th_ order +_I want to reward my customers on their n-th order_ ```php customerAlreadyRewarded((int) $customerObject->id)) { $hasConfiguredState = in_array((int) $orderObject->getCurrentState(), $this->getConfuredOrdersStatesIds()); $hasCustomerRequiredNbrOfTheOrderToReward = $this->getCustomerValidOrdersNbr((int) $customerObject->id) == $this->getRequiredNbrOfTheOrderToReward(); - if($hasConfiguredState && $hasCustomerRequiredNbrOfTheOrderToReward) { + if ($hasConfiguredState && $hasCustomerRequiredNbrOfTheOrderToReward) { $customerReward = $this->createCustomerReward($customerObject, $orderObject); - if(Validate::isLoadedObject($customerReward)) { - $this->setAlreadyRewarded($customerObject); - $this->notifyCustomer($customerObject, $customerReward); + if (Validate::isLoadedObject($customerReward)) { + $this->setAlreadyRewarded($customerObject); + $this->notifyCustomer($customerObject, $customerReward); - //TODO : of course don't forget to log if something fails here :) + // of course don't forget to log if something fails here :) } } } @@ -61,37 +61,37 @@ class MyModuleRewardCustomerWhenOrder extends Module protected function customerAlreadyRewarded(int $idCustomer): bool { - //TODO : check if customer already rewarded + // check if customer already rewarded } protected setAlreadyRewarded(): void { - //TODO: set customer was rewarded + // set customer was rewarded } protected function getConfuredOrdersStatesIds(): array { - //TODO : return array with configured states ids in your module + // return array with configured states ids in your module } protected function getCustomerValidOrdersNbr(int $idCustomer): int { - //TODO : return number of total order valid by customer + // return number of total order valid by customer } protected function getRequiredNbrOfTheOrderToReward(): int { - //TODO : return configured number of orders required to reward the customer + // return configured number of orders required to reward the customer } protected function createCustomerReward(Customer $customer, Order $order): ?CartRule { - //TODO: generate customer cart rule (according to the order amount for example) + // generate customer cart rule (according to the order amount for example) } protected function notifyCustomer(Customer $customer, CartRule $cartRule): bool { - //TODO: notify the customer + // notify the customer } } ``` \ No newline at end of file