Skip to content

Commit

Permalink
Merge pull request #2 from ThomasDaSilva/main
Browse files Browse the repository at this point in the history
Update Read.me & Fix module & Add a Product Review Loop
  • Loading branch information
zawaze authored Feb 15, 2024
2 parents c67dcc0 + fcb6f61 commit 57c3538
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 25 deletions.
1 change: 0 additions & 1 deletion Api/GuaranteedOpinionClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
namespace GuaranteedOpinion\Api;

use GuaranteedOpinion\GuaranteedOpinion;
use Thelia\Model\Order;

/**
* Class GuaranteedOpinionClient
Expand Down
2 changes: 1 addition & 1 deletion Config/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<language>en_US</language>
<language>fr_FR</language>
</languages>
<version>1.0.0</version>
<version>1.0.1</version>
<authors>
<author>
<name>Chabreuil Antoine</name>
Expand Down
2 changes: 0 additions & 2 deletions Controller/GuaranteedOpinionConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"]);

Expand Down
1 change: 0 additions & 1 deletion Hook/FrontHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
70 changes: 70 additions & 0 deletions Loop/GuaranteedProductLoop.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

namespace GuaranteedOpinion\Loop;

use GuaranteedOpinion\Model\GuaranteedOpinionProductReviewQuery;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\ActiveQuery\ModelCriteria;
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;

/**
* @method getMinRate()
* @method getProduct()
*/
class GuaranteedProductLoop extends BaseLoop implements PropelSearchLoopInterface
{

public function parseResults(LoopResult $loopResult): LoopResult
{
foreach ($loopResult->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')
);
}
}
38 changes: 34 additions & 4 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
```
Expand All @@ -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
26 changes: 15 additions & 11 deletions Service/OrderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
];
}
Expand All @@ -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();
Expand Down
5 changes: 0 additions & 5 deletions Service/ProductReviewService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -57,8 +54,6 @@ public function addGuaranteedOpinionProductRow($row, int $productId): void
}
}



/**
* @throws PropelException
*/
Expand Down

0 comments on commit 57c3538

Please # to comment.