From fcb6f6101aca03b73fb22e69e4f2d1afa41929c7 Mon Sep 17 00:00:00 2001 From: Da Silva Mendonca Thomas Date: Mon, 29 Jan 2024 11:08:23 +0100 Subject: [PATCH] Update Read.me & Fix module & Add a Product Review Loop --- Api/GuaranteedOpinionClient.php | 1 - Config/module.xml | 2 +- .../GuaranteedOpinionConfigController.php | 2 - Hook/FrontHook.php | 1 - Loop/GuaranteedProductLoop.php | 70 +++++++++++++++++++ Readme.md | 38 ++++++++-- Service/OrderService.php | 26 ++++--- Service/ProductReviewService.php | 5 -- 8 files changed, 120 insertions(+), 25 deletions(-) create mode 100644 Loop/GuaranteedProductLoop.php diff --git a/Api/GuaranteedOpinionClient.php b/Api/GuaranteedOpinionClient.php index 1904154..70250cf 100644 --- a/Api/GuaranteedOpinionClient.php +++ b/Api/GuaranteedOpinionClient.php @@ -13,7 +13,6 @@ namespace GuaranteedOpinion\Api; use GuaranteedOpinion\GuaranteedOpinion; -use Thelia\Model\Order; /** * Class GuaranteedOpinionClient diff --git a/Config/module.xml b/Config/module.xml index 6f5a15d..564c6bd 100644 --- a/Config/module.xml +++ b/Config/module.xml @@ -13,7 +13,7 @@ en_US fr_FR - 1.0.0 + 1.0.1 Chabreuil Antoine diff --git a/Controller/GuaranteedOpinionConfigController.php b/Controller/GuaranteedOpinionConfigController.php index c5ac816..43ef102 100644 --- a/Controller/GuaranteedOpinionConfigController.php +++ b/Controller/GuaranteedOpinionConfigController.php @@ -30,8 +30,6 @@ public function saveConfiguration(ParserContext $parserContext) : RedirectRespon GuaranteedOpinion::setConfigValue(GuaranteedOpinion::STATUS_TO_EXPORT, implode(',', $data["status_to_export"])); GuaranteedOpinion::setConfigValue(GuaranteedOpinion::EMAIL_DELAY, $data["email_delay"]); - GuaranteedOpinion::setConfigValue(GuaranteedOpinion::FOOTER_LINK_TITLE, $data["footer_link_title"]); - GuaranteedOpinion::setConfigValue(GuaranteedOpinion::SITE_REVIEW_HOOK_DISPLAY, $data["site_review_hook_display"]); GuaranteedOpinion::setConfigValue(GuaranteedOpinion::SITE_REVIEW_DISPLAY, (bool)$data["site_review_display"]); diff --git a/Hook/FrontHook.php b/Hook/FrontHook.php index c1d3737..489ef34 100644 --- a/Hook/FrontHook.php +++ b/Hook/FrontHook.php @@ -4,7 +4,6 @@ use GuaranteedOpinion\GuaranteedOpinion; use GuaranteedOpinion\Model\GuaranteedOpinionProductReviewQuery; -use GuaranteedOpinion\Model\GuaranteedOpinionSiteReviewQuery; use Propel\Runtime\ActiveQuery\Criteria; use Thelia\Core\Event\Hook\HookRenderBlockEvent; use Thelia\Core\Event\Hook\HookRenderEvent; diff --git a/Loop/GuaranteedProductLoop.php b/Loop/GuaranteedProductLoop.php new file mode 100644 index 0000000..b122366 --- /dev/null +++ b/Loop/GuaranteedProductLoop.php @@ -0,0 +1,70 @@ +getResultDataCollection() as $review) { + $loopResultRow = new LoopResultRow($review); + + $loopResultRow + ->set('ID', $review->getId()) + ->set('PRODUCT_REVIEW_ID', $review->getProductReviewId()) + ->set('NAME', $review->getName()) + ->set('RATE', $review->getRate()) + ->set('REVIEW', $review->getReview()) + ->set('REVIEW_DATE', $review->getReviewDate()?->format('Y-m-d')) + ->set('PRODUCT_ID', $review->getProductId()) + ->set('ORDER_ID', $review->getOrderId()) + ->set('ORDER_DATE', $review->getOrderDate()?->format('Y-m-d')) + ->set('REPLY', $review->getReply()) + ->set('REPLY_DATE', $review->getReplyDate()?->format('Y-m-d')) + ; + $this->addOutputFields($loopResultRow, $review); + + $loopResult->addRow($loopResultRow); + } + + return $loopResult; + } + + public function buildModelCriteria(): GuaranteedOpinionProductReviewQuery|ModelCriteria + { + $search = GuaranteedOpinionProductReviewQuery::create(); + + if (null !== $productId = $this->getProduct()) { + $search->filterByProductId($productId, Criteria::IN); + } + + if (null !== $minRate = $this->getMinRate()) { + $search->filterByRate($minRate, Criteria::GREATER_EQUAL); + } + + return $search; + } + + protected function getArgDefinitions(): ArgumentCollection + { + return new ArgumentCollection( + Argument::createIntListTypeArgument('product'), + Argument::createIntListTypeArgument('min_rate') + ); + } +} \ No newline at end of file diff --git a/Readme.md b/Readme.md index 6b42c43..e5b8b23 100644 --- a/Readme.md +++ b/Readme.md @@ -9,14 +9,14 @@ This module allows you to import your opinion on your Thelia website and export Add it in your main thelia composer.json file ``` -composer require theloa/guaranteed-opinion-module:~1.0 +composer require thelia/guaranteed-opinion-module:~1.0 ``` ## Usage Configure the module backoffice with your api keys -Then, add a crong : +Then, add a cron : To import your product opinion : ``` @@ -30,6 +30,36 @@ php Thelia module:GuaranteedOpinion:SendOrder No need to import your site opinion, you only need to use the widget and widget iframe -## Hook +## Loop -Configure your hook in the backOffice +[google_reviews_loop] + +### Input arguments + +| Argument | Description | +|--------------|--------------------------------| +| **min_rate** | minimum score allowed. (min 0) | +| **product** | id of your product | + +### Output arguments + +| Variable | Description | +|--------------------|------------------------------| +| $ID | id of your review | +| $PRODUCT_REVIEW_ID | guaranteed opinion review id | +| $NAME | name of the reviewer | +| $RATE | score | +| $REVIEW | review message | +| $REVIEW_DATE | date of review | +| $PRODUCT_ID | id of the product | +| $ORDER_ID | order related to the review | +| $ORDER_DATE | date of the order | +| $REPLY | reply of the review | +| $REPLY_DATE | reply date | + +## Documentations + +Societe-des-avis-garantis API documentation is available at https://www.societe-des-avis-garantis.fr/configuration + +API PUBLIC OPINIONS : https://www.societe-des-avis-garantis.fr/configuration/api-publique +API PRIVATE ORDERS : https://www.societe-des-avis-garantis.fr/configuration/api-orders \ No newline at end of file diff --git a/Service/OrderService.php b/Service/OrderService.php index bd61a61..6538d51 100644 --- a/Service/OrderService.php +++ b/Service/OrderService.php @@ -5,6 +5,7 @@ use GuaranteedOpinion\GuaranteedOpinion; use GuaranteedOpinion\Model\GuaranteedOpinionOrderQueue; use GuaranteedOpinion\Model\GuaranteedOpinionOrderQueueQuery; +use Propel\Runtime\Exception\PropelException; use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; use Thelia\Model\OrderProduct; use Thelia\Model\OrderQuery; @@ -43,17 +44,17 @@ private function orderToJsonObject(GuaranteedOpinionOrderQueue $guaranteedOpinio $jsonProduct = []; - foreach ($order->getOrderProducts() as $orderProduct) { + foreach ($order?->getOrderProducts() as $orderProduct) { $jsonProduct[] = $this->productToJsonObject($orderProduct); } return [ - 'id_order' => $order->getId(), - 'order_date' => $order->getCreatedAt()->format('Y-m-d H:i:s'), - 'firstname' => $order->getCustomer()->getFirstname(), - 'lastname' => $order->getCustomer()->getLastname(), - 'email' => $order->getCustomer()->getEmail(), - 'reference' => $order->getRef(), + 'id_order' => $order?->getId(), + 'order_date' => $order?->getCreatedAt()->format('Y-m-d H:i:s'), + 'firstname' => $order?->getCustomer()->getFirstname(), + 'lastname' => $order?->getCustomer()->getLastname(), + 'email' => $order?->getCustomer()->getEmail(), + 'reference' => $order?->getRef(), 'products' => $jsonProduct ]; } @@ -65,21 +66,24 @@ private function productToJsonObject(OrderProduct $orderProduct): array $category = GuaranteedOpinionOrderQueueQuery::getCategoryByProductSaleElements($pse); return [ - 'id' => $pse->getProductId(), - 'name' => $pse->getProduct()->getRef(), + 'id' => $pse?->getProductId(), + 'name' => $pse?->getProduct()->getRef(), 'category_id' => $category->getId(), 'category_name' => $category->getTitle(), 'qty' => $orderProduct->getQuantity(), 'unit_price' => $orderProduct->getPrice(), 'mpn' => null, - 'ean13' => $pse->getEanCode(), + 'ean13' => $pse?->getEanCode(), 'sku' => null, 'upc' => null, 'url' => GuaranteedOpinion::STORE_URL . '/'. - GuaranteedOpinionOrderQueueQuery::getProductUrl($pse->getProductId())->getUrl(), + GuaranteedOpinionOrderQueueQuery::getProductUrl($pse?->getProductId())->getUrl(), ]; } + /** + * @throws PropelException + */ public function clearOrderQueueTable(): void { $orders = GuaranteedOpinionOrderQueueQuery::create()->find(); diff --git a/Service/ProductReviewService.php b/Service/ProductReviewService.php index 73e57c6..25e5cc3 100644 --- a/Service/ProductReviewService.php +++ b/Service/ProductReviewService.php @@ -5,10 +5,7 @@ use GuaranteedOpinion\GuaranteedOpinion; use GuaranteedOpinion\Model\GuaranteedOpinionProductReview; use GuaranteedOpinion\Model\GuaranteedOpinionProductReviewQuery; -use PDO; use Propel\Runtime\Exception\PropelException; -use Propel\Runtime\Propel; -use Thelia\Model\ProductQuery; class ProductReviewService { @@ -57,8 +54,6 @@ public function addGuaranteedOpinionProductRow($row, int $productId): void } } - - /** * @throws PropelException */