Skip to content

Commit

Permalink
Add locale option
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasDaSilva committed May 13, 2024
1 parent 6962beb commit 9b8418d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 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
12 changes: 6 additions & 6 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,7 +69,7 @@ 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 [];
Expand All @@ -91,7 +91,7 @@ private function productToJsonObject(OrderProduct $orderProduct): array
'sku' => null,
'upc' => null,
'url' => URL::getInstance()->absoluteUrl('') .
GuaranteedOpinionOrderQueueQuery::getProductUrl($pse->getProductId())->getUrl(),
GuaranteedOpinionOrderQueueQuery::getProductUrl($pse->getProductId(), $locale)->getUrl(),
];
}

Expand Down

0 comments on commit 9b8418d

Please # to comment.