Skip to content

Commit

Permalink
Merge pull request #16 from ThomasDaSilva/fix_1.0.15
Browse files Browse the repository at this point in the history
Remove Useless Field + Fix Url Send
  • Loading branch information
ThomasDaSilva authored May 13, 2024
2 parents de53177 + 9b8418d commit 50a6958
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 26 deletions.
7 changes: 5 additions & 2 deletions Command/SendOrderCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use GuaranteedOpinion\Api\GuaranteedOpinionClient;
use GuaranteedOpinion\Service\OrderService;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Thelia\Command\ContainerAwareCommand;

Expand All @@ -22,15 +23,17 @@ public function configure(): void
{
$this
->setName('module:GuaranteedOpinion:SendOrder')
->setDescription('Send orders to API Avis-Garantis');
->setDescription('Send orders to API Avis-Garantis')
->addOption('locale', 'l', InputOption::VALUE_OPTIONAL, 'locale', 'fr_FR')
;
}

public function execute(InputInterface $input, OutputInterface $output): int
{
$this->initRequest();

try {
$order = $this->orderService->prepareOrderRequest();
$order = $this->orderService->prepareOrderRequest($input->getOption('locale'));

$response = $this->client->sendOrder($order);

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.14</version>
<version>1.0.15</version>
<authors>
<author>
<name>Chabreuil Antoine</name>
Expand Down
1 change: 0 additions & 1 deletion Controller/GuaranteedOpinionConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public function saveConfiguration(ParserContext $parserContext) : RedirectRespon
GuaranteedOpinion::setConfigValue(GuaranteedOpinion::SHOW_RATING_URL_CONFIG_KEY, $data["show_rating_url"]);

GuaranteedOpinion::setConfigValue(GuaranteedOpinion::STATUS_TO_EXPORT_CONFIG_KEY, implode(',', $data["status_to_export"]));
GuaranteedOpinion::setConfigValue(GuaranteedOpinion::EMAIL_DELAY_CONFIG_KEY, $data["email_delay"]);

GuaranteedOpinion::setConfigValue(GuaranteedOpinion::SITE_REVIEW_HOOK_DISPLAY_CONFIG_KEY, $data["site_review_hook_display"]);
GuaranteedOpinion::setConfigValue(GuaranteedOpinion::SITE_REVIEW_DISPLAY_CONFIG_KEY, (bool)$data["site_review_display"]);
Expand Down
9 changes: 0 additions & 9 deletions Form/ConfigurationForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,6 @@ protected function buildForm(): void
),
"data" => GuaranteedOpinion::getConfigValue(GuaranteedOpinion::API_ORDER_CONFIG_KEY)
))
->add(
'email_delay',
TextType::class,
[
"data" => GuaranteedOpinion::getConfigValue(GuaranteedOpinion::EMAIL_DELAY_CONFIG_KEY, 10),
"label"=>$translator?->trans("Reviews email delay (in days):", array(), GuaranteedOpinion::DOMAIN_NAME),
"required" => false
]
)
->add(
'show_rating_url',
TextType::class,
Expand Down
1 change: 0 additions & 1 deletion GuaranteedOpinion.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class GuaranteedOpinion extends BaseModule
public const API_ORDER_CONFIG_KEY = "guaranteedopinion.api.order";

public const STATUS_TO_EXPORT_CONFIG_KEY = "guaranteedopinion.status_to_export";
public const EMAIL_DELAY_CONFIG_KEY = "guaranteedopinion.email_delay";

public const SHOW_RATING_URL_CONFIG_KEY = "guaranteedopinion.show_rating_url";

Expand Down
1 change: 0 additions & 1 deletion I18n/fr_FR.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
'Api key review' => 'Clé API publique des avis',
'Order status to export' => 'Statut des commandes à envoyer',
'Product review hook display' => 'Lien du hook des avis des produits',
'Reviews email delay (in days):' => 'Delai de l\'envoi du mail (en jours)',
'Show all opinions url' => 'Url des avis vérifiés du sites',
'Show product review' => 'Montrer les avis des produits',
'Show product review tab' => 'Montrer le tableau des avis des produits',
Expand Down
4 changes: 3 additions & 1 deletion Model/GuaranteedOpinionOrderQueueQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ public static function getCategoryByProductSaleElements(ProductSaleElements $pro
->findOne();
}

public static function getProductUrl(int $id): RewritingUrl
public static function getProductUrl(int $id, string $locale = 'fr_FR'): RewritingUrl
{
return RewritingUrlQuery::create()
->filterByView('product')
->filterByViewId($id)
->filterByViewLocale($locale)
->filterByRedirected()
->findOne();
}
}
18 changes: 9 additions & 9 deletions Service/OrderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ public function __construct(
/**
* @throws JsonException|RuntimeException|PropelException
*/
public function prepareOrderRequest(): string
public function prepareOrderRequest(string $locale): string
{
$jsonOrder = [];

$guaranteedOpinionOrders = GuaranteedOpinionOrderQueueQuery::create()->filterByTreatedAt(null)->findByStatus(0);

foreach ($guaranteedOpinionOrders as $guaranteedOpinionOrder) {
$jsonOrder[] = $this->orderToJsonObject($guaranteedOpinionOrder);
$jsonOrder[] = $this->orderToJsonObject($guaranteedOpinionOrder, $locale);
}

if (empty($jsonOrder)) {
Expand All @@ -45,14 +45,14 @@ public function prepareOrderRequest(): string
/**
* @throws PropelException
*/
private function orderToJsonObject(GuaranteedOpinionOrderQueue $guaranteedOpinionOrder): array
private function orderToJsonObject(GuaranteedOpinionOrderQueue $guaranteedOpinionOrder, string $locale): array
{
$order = OrderQuery::create()->findOneById($guaranteedOpinionOrder->getOrderId());

$jsonProduct = [];

foreach ($order?->getOrderProducts() as $orderProduct) {
$jsonProduct[] = $this->productToJsonObject($orderProduct);
$jsonProduct[] = $this->productToJsonObject($orderProduct, $locale);
}

return [
Expand All @@ -69,29 +69,29 @@ private function orderToJsonObject(GuaranteedOpinionOrderQueue $guaranteedOpinio
/**
* @throws PropelException
*/
private function productToJsonObject(OrderProduct $orderProduct): array
private function productToJsonObject(OrderProduct $orderProduct, string $locale): array
{
if (null === $pse = ProductSaleElementsQuery::create()->findOneById($orderProduct->getProductSaleElementsId())) {
return [];
}

$category = GuaranteedOpinionOrderQueueQuery::getCategoryByProductSaleElements($pse);
$productReviewEvent = new ProductReviewEvent($pse?->getProduct());
$productReviewEvent = new ProductReviewEvent($pse->getProduct());
$this->eventDispatcher->dispatch($productReviewEvent, GuaranteedOpinionEvents::SEND_ORDER_PRODUCT_EVENT);

return [
'id' => $productReviewEvent->getGuaranteedOpinionProductId(),
'name' => $pse?->getProduct()->getRef(),
'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' => URL::getInstance()->absoluteUrl('') .
GuaranteedOpinionOrderQueueQuery::getProductUrl($pse?->getProductId())->getUrl(),
GuaranteedOpinionOrderQueueQuery::getProductUrl($pse->getProductId(), $locale)->getUrl(),
];
}

Expand Down
1 change: 0 additions & 1 deletion templates/backOffice/default/module_configuration.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ <h2 class="title title-without-tabs">{intl l="Guaranteed Opinion Order access" d
</div>

<div class="form-group">
{render_form_field form=$form field="email_delay"}
{render_form_field form=$form field="status_to_export"}
</div>
</div>
Expand Down

0 comments on commit 50a6958

Please # to comment.