diff --git a/Config/config.xml b/Config/config.xml index 3ba53ff..42d3733 100644 --- a/Config/config.xml +++ b/Config/config.xml @@ -3,10 +3,4 @@ - - - - - - diff --git a/Config/module.xml b/Config/module.xml index 917b988..78d6305 100644 --- a/Config/module.xml +++ b/Config/module.xml @@ -7,7 +7,7 @@ Permet au client d'ajouter un commentaire à sa commande - 3.0.1 + 3.1.0 Vincent Lopes-Vicente vlopes@openstudio.fr diff --git a/Controller/OrderCommentController.php b/Controller/OrderCommentController.php index f80d654..a66bb2b 100644 --- a/Controller/OrderCommentController.php +++ b/Controller/OrderCommentController.php @@ -12,8 +12,8 @@ namespace OrderComment\Controller; -use Front\Front; use OrderComment\Form\CommentForm; +use OrderComment\OrderComment; use Propel\Runtime\Exception\PropelException; use Thelia\Controller\Front\BaseFrontController; use Thelia\Core\HttpFoundation\Request; @@ -41,12 +41,12 @@ public function setComment(Request $request) return $this->generateRedirectFromRoute('order.delivery'); } catch (FormValidationException $e) { - $message = Translator::getInstance()->trans('Please check your input: %s', ['%s' => $e->getMessage()], Front::MESSAGE_DOMAIN); + $message = Translator::getInstance()->trans('Please check your input: %s', ['%s' => $e->getMessage()], OrderComment::MESSAGE_DOMAIN); } catch (PropelException $e) { $this->getParserContext()->setGeneralError($e->getMessage()); - $message = Translator::getInstance()->trans('Sorry, a database error occurred: %s', ['%s' => $e->getMessage()], Front::MESSAGE_DOMAIN); + $message = Translator::getInstance()->trans('Sorry, a database error occurred: %s', ['%s' => $e->getMessage()], OrderComment::MESSAGE_DOMAIN); } catch (\Exception $e) { - $message = Translator::getInstance()->trans('Sorry, an error occurred: %s', ['%s' => $e->getMessage()], Front::MESSAGE_DOMAIN); + $message = Translator::getInstance()->trans('Sorry, an error occurred: %s', ['%s' => $e->getMessage()], OrderComment::MESSAGE_DOMAIN); } if ($message !== false) { diff --git a/Hook/FrontHook.php b/Hook/FrontHook.php deleted file mode 100644 index 00e9e83..0000000 --- a/Hook/FrontHook.php +++ /dev/null @@ -1,54 +0,0 @@ - - */ -class FrontHook extends BaseHook -{ - public static function getSubscribedHooks(): array - { - return [ - 'cart.bottom' => [ - ['type' => 'front', 'method' => 'onCartBottom'], - ], - 'cart.after-javascript-include' => [ - ['type' => 'front', 'method' => 'onCartIncludeJs'], - ], - 'order-delivery.form-bottom' => [ - ['type' => 'front', 'method' => 'onDeliveryFormBottom'], - ], - ]; - } - - public function onCartBottom(HookRenderEvent $event) - { - $event->add($this->render("OrderComment/cart-comment.html")); - } - - public function onCartIncludeJs(HookRenderEvent $event) - { - $event->add(($this->addJS("OrderComment/assets/js/cart-comment-js.js"))); - } - - public function onDeliveryFormBottom(HookRenderEvent $event) - { - $event->add($this->render("OrderComment/comment-input.html")); - } -} \ No newline at end of file diff --git a/Loop/OrderCommentLoop.php b/Loop/OrderCommentLoop.php deleted file mode 100644 index becac31..0000000 --- a/Loop/OrderCommentLoop.php +++ /dev/null @@ -1,50 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace OrderComment\Loop; - -use OrderComment\Model\OrderCommentQuery; -use Thelia\Core\Template\Element\BaseLoop; -use Thelia\Core\Template\Element\LoopResult; -use Thelia\Core\Template\Element\LoopResultRow; -use Thelia\Core\Template\Element\PropelSearchLoopInterface; -use Thelia\Core\Template\Loop\Argument\Argument; -use Thelia\Core\Template\Loop\Argument\ArgumentCollection; -use Propel\Runtime\ActiveQuery\ModelCriteria; - -class OrderCommentLoop extends BaseLoop implements PropelSearchLoopInterface -{ - protected function getArgDefinitions(): ArgumentCollection - { - return new ArgumentCollection( - Argument::createIntTypeArgument('order_id', null, true) - ); - } - - public function buildModelCriteria(): ModelCriteria - { - return OrderCommentQuery::create()->filterByOrderId($this->getOrderId()); - } - - public function parseResults(LoopResult $loopResult): LoopResult - { - /** @var \OrderComment\Model\OrderComment $orderComment */ - foreach ($loopResult->getResultDataCollection() as $orderComment) { - $loopResultRow = new LoopResultRow($orderComment); - - $loopResultRow->set('ORDER_COMMENT', $orderComment->getComment()); - $loopResult->addRow($loopResultRow); - } - - return $loopResult; - } -} diff --git a/Loop/SessionOrderCommentLoop.php b/Loop/SessionOrderCommentLoop.php deleted file mode 100644 index ec29f09..0000000 --- a/Loop/SessionOrderCommentLoop.php +++ /dev/null @@ -1,39 +0,0 @@ -requestStack->getCurrentRequest(); - $comment = (null !== $request && $request->hasSession()) - ? $request->getSession()->get('order_comment') - : null; - - return ['comment' => $comment]; - } - - public function parseResults(LoopResult $loopResult): LoopResult - { - $item = $loopResult->getResultDataCollection(); - - $loopResultRow = new LoopResultRow(); - $loopResultRow->set('ORDER_COMMENT', $item['comment']); - - $loopResult->addRow($loopResultRow); - - return $loopResult; - } - - public function getArgDefinitions(): ArgumentCollection - { - return new ArgumentCollection(); - } -} diff --git a/OrderComment.php b/OrderComment.php index c7408c5..f827178 100644 --- a/OrderComment.php +++ b/OrderComment.php @@ -27,7 +27,9 @@ class OrderComment extends BaseModule { - public function postActivation(ConnectionInterface $con = null): void + public const MESSAGE_DOMAIN = 'ordercomment'; + + public function postActivation(?ConnectionInterface $con = null): void { $wrapped = $con->getWrappedConnection(); $stmt = $wrapped->query("SHOW TABLES LIKE 'order_comment'"); diff --git a/Readme.md b/Readme.md index af1e66e..68a2da0 100644 --- a/Readme.md +++ b/Readme.md @@ -19,40 +19,6 @@ Add it in your main thelia composer.json file composer require thelia/order-comment-module:~2.0 ``` -## Loop +## Usage -OrderCommentLoop : order.comment.comment - -This loop return the comment of an order. - -### Input arguments - -|Argument |Description | -|--- |--- | -|**order_id** | Unique ID of the order (eg. order_id=5) | - -### Output arguments - -|Variable |Description | -|--- |--- | -|$ORDER_COMMENT | Content of the comment | - -### Example - -``` -{ifloop rel="order_comment_loop"} - {loop name="order_comment_loop" type="order.comment.comment" order_id="$order_id" } - {$ORDER_COMMENT} - {/loop} -{/ifloop} -{elseloop rel="order_comment_loop"} -

- {intl l="No comment for this order was defined." d="ordercomment"} -

-{/elseloop} -``` - -## Other ? - -It may be convenient to display the comment on the detail page of the customer's order. -To do that, uses the loop described previously. +On the checkout delivery step, the customer comment is entered with the `AddOrderComment` live component. The comment is saved with the order and shown in the order detail page of the back office. diff --git a/templates/backOffice/default/order-edit.html b/templates/backOffice/default/order-edit.html deleted file mode 100755 index b313fd6..0000000 --- a/templates/backOffice/default/order-edit.html +++ /dev/null @@ -1,19 +0,0 @@ -
-
-

- {intl l="Customer comment" d="ordercomment.bo.default"} -

-
-
- {$comment = ''} - {loop name="order.comment.comment" type="order_comment_loop" order_id=$order_id} - {$comment = $ORDER_COMMENT} - {/loop} - - {if $comment} - {$comment|nl2br nofilter} - {else} - {intl l="No comment for this order was defined." d="ordercomment.bo.default"} - {/if} -
-
diff --git a/templates/frontOffice/default/OrderComment/assets/js/cart-comment-js.js b/templates/frontOffice/default/OrderComment/assets/js/cart-comment-js.js deleted file mode 100644 index 0966291..0000000 --- a/templates/frontOffice/default/OrderComment/assets/js/cart-comment-js.js +++ /dev/null @@ -1 +0,0 @@ -$('#cart > a').slice(-2).remove(); \ No newline at end of file diff --git a/templates/frontOffice/default/OrderComment/cart-comment.html b/templates/frontOffice/default/OrderComment/cart-comment.html deleted file mode 100644 index 364d60c..0000000 --- a/templates/frontOffice/default/OrderComment/cart-comment.html +++ /dev/null @@ -1,10 +0,0 @@ -{form name="order_comment_form"} -
- {form_hidden_fields form=$form} - - {include file="OrderComment/comment-input.html"} - - {intl l="Continue Shopping"} - -
-{/form} diff --git a/templates/frontOffice/default/OrderComment/comment-input.html b/templates/frontOffice/default/OrderComment/comment-input.html deleted file mode 100644 index f79583c..0000000 --- a/templates/frontOffice/default/OrderComment/comment-input.html +++ /dev/null @@ -1,13 +0,0 @@ -
-
- {intl l="Add your comment" d="ordercomment.fo.default"} -
-
- {if $form_error|default:null}
{$form_error_message|default:null}
{/if} - -
- {form_field form=$form|default:null field='comment'} - - {/form_field} -
-