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

use more specific way to check if a backup cart is existing #868

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@

<service id="Kiener\MolliePayments\Service\Cart\CartBackupService" class="Kiener\MolliePayments\Service\Cart\CartBackupService" public="true">
<argument type="service" id="Shopware\Core\Checkout\Cart\SalesChannel\CartService"/>
<argument type="service" id="Shopware\Core\Checkout\Cart\CartPersister"/>
</service>

<service id="Kiener\MolliePayments\Service\Mollie\OrderStatusConverter" public="false">
Expand Down
16 changes: 12 additions & 4 deletions src/Service/Cart/CartBackupService.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@ class CartBackupService
*/
private $cartService;

/**
* @var AbstractCartPerister
*/
private $cartPersister;

/**
* @param CartService $cartService
*/
public function __construct(CartService $cartService)
public function __construct(CartService $cartService, AbstractCartPerister $cartPersister)
{
$this->cartService = $cartService;
$this->cartPersister = $cartPersister;
}


Expand All @@ -35,9 +40,12 @@ public function __construct(CartService $cartService)
*/
public function isBackupExisting(SalesChannelContext $context): bool
{
$backupCart = $this->cartService->getCart(self::BACKUP_TOKEN, $context);

return ($backupCart->getLineItems()->count() > 0);
try {
$backupCart = $this->cartPersister->load(self::BACKUP_TOKEN, $context);
return true;
} catch (\Exception $e) {
return false;
}
}

/**
Expand Down