Skip to content

Commit

Permalink
Merge pull request #86 from Nosto/SSP-60_sales_is_not_tracked_in_nost…
Browse files Browse the repository at this point in the history
…o_backend_anymore_v4

SSP-60 Sales is not tracked in Nosto-Backend anymore v4
  • Loading branch information
Bibarella authored Oct 14, 2024
2 parents d2ad3d3 + 269b03f commit 095e498
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/Model/Operation/OrderSyncHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsAnyFilter;
use Shopware\Core\Framework\DataAbstractionLayer\{EntityCollection, EntityRepository};
use Shopware\Core\Framework\DataAbstractionLayer\{EntityCollection, EntityRepository, Search\Filter\EqualsFilter};
use Shopware\Core\Framework\Uuid\Uuid;
use Shopware\Core\System\SalesChannel\Context\AbstractSalesChannelContextFactory;
use Shopware\Core\System\SalesChannel\Context\SalesChannelContextService;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Throwable;

Expand All @@ -26,6 +29,7 @@ class OrderSyncHandler implements JobHandlerInterface
public const HANDLER_CODE = 'nosto-integration-order-sync';

public function __construct(
private readonly AbstractSalesChannelContextFactory $channelContextFactory,
private readonly EntityRepository $orderRepository,
private readonly Account\Provider $accountProvider,
private readonly OrderBuilder $nostoOrderbuilder,
Expand All @@ -41,7 +45,14 @@ public function execute(object $message): JobResult
{
$operationResult = new JobResult();
foreach ($this->accountProvider->all($message->getContext()) as $account) {
$accountOperationResult = $this->doOperation($account, $message->getContext(), $message);
$channelContext = $this->channelContextFactory->create(
Uuid::randomHex(),
$account->getChannelId(),
[
SalesChannelContextService::LANGUAGE_ID => $account->getLanguageId(),
],
);
$accountOperationResult = $this->doOperation($account, $channelContext->getContext(), $message);
foreach ($accountOperationResult->getErrors() as $error) {
$operationResult->addError($error);
}
Expand Down Expand Up @@ -82,6 +93,7 @@ private function getOrders(Context $context, array $orderIds): EntityCollection
$criteria->addAssociation('transactions.paymentMethod');
$criteria->addAssociation('lineItems.orderLineItem.product');
$criteria->addFilter(new EqualsAnyFilter('id', $orderIds));
$criteria->addFilter(new EqualsFilter('languageId', $context->getLanguageId()));
$this->eventDispatcher->dispatch(new NostoOrderCriteriaEvent($criteria, $context));
return $this->orderRepository->search($criteria, $context)->getEntities();
}
Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<service id="Nosto\NostoIntegration\Model\Operation\OrderSyncHandler">
<tag name="nosto.job_handler" code="nosto-integration-order-sync" />

<argument key="$channelContextFactory" type="service" id="Shopware\Core\System\SalesChannel\Context\SalesChannelContextFactory" />
<argument key="$orderRepository" type="service" id="order.repository" />
</service>

Expand Down

0 comments on commit 095e498

Please sign in to comment.