Skip to content

Commit

Permalink
feat: Display saved carts for customer from all sales channels
Browse files Browse the repository at this point in the history
  • Loading branch information
J4nk0123 committed Nov 22, 2024
1 parent 3d7564f commit 30311f6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/Resources/config/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,12 @@
<label>Show Saved Carts in Customer Account</label>
<label lang="de-DE">Gespeicherte Warenkörbe im Kundenkonto anzeigen</label>
</input-field>

<input-field type="bool">
<name>showCartsFromAllSalesChannels</name>
<defaultValue>false</defaultValue>
<label>Display saved carts for customers from all sales channels</label>
<label lang="de-DE">Anzeige gespeicherter Warenkörbe für Kunden aus allen Vertriebskanälen</label>
</input-field>
</card>
</config>
7 changes: 6 additions & 1 deletion src/Services/CustomerShareBasketService.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Shopware\Core\System\SystemConfig\SystemConfigService;
use Symfony\Component\DependencyInjection\Attribute\Autowire;

readonly class CustomerShareBasketService implements CustomerShareBasketServiceInterface
Expand All @@ -24,6 +25,7 @@ public function __construct(
private EntityRepository $shareBasketRepository,
#[Autowire(service: 'frosh_share_basket_customer.repository')]
private EntityRepository $shareBasketCustomerRepository,
private readonly SystemConfigService $systemConfigService
) {}

public function loadCustomerCarts(SalesChannelContext $salesChannelContext): ?ShareBasketCollection
Expand All @@ -35,11 +37,14 @@ public function loadCustomerCarts(SalesChannelContext $salesChannelContext): ?Sh

$criteria = new Criteria();
$criteria
->addFilter(new EqualsFilter('salesChannelId', $salesChannelContext->getSalesChannelId()))
->addFilter(new EqualsFilter('customers.id', $customerId))
->addAssociation('lineItems.product.cover')
;

if ($this->systemConfigService->getBool('FroshPlatformShareBasket.config.showCartsFromAllSalesChannels', $salesChannelContext->getSalesChannelId()) === false) {
$criteria->addFilter(new EqualsFilter('salesChannelId', $salesChannelContext->getSalesChannelId()));
}

return $this->shareBasketRepository->search($criteria, $salesChannelContext->getContext())->getEntities();
}

Expand Down

0 comments on commit 30311f6

Please sign in to comment.