Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSP-60 Sales is not tracked in Nosto-Backend anymore v4 #86

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading