-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NTR: PISHPS-338: Add compatiblity with custom products
- Loading branch information
Vitalij Mik
committed
Sep 2, 2024
1 parent
5436200
commit 6338971
Showing
10 changed files
with
443 additions
and
299 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Kiener\MolliePayments\Checkout\Cart; | ||
|
||
use Kiener\MolliePayments\Service\Cart\CartBackupService; | ||
use Kiener\MolliePayments\Service\CartServiceInterface; | ||
use Shopware\Core\Checkout\Cart\Cart; | ||
use Shopware\Core\Checkout\Cart\LineItem\LineItemCollection; | ||
use Shopware\Core\Checkout\Cart\SalesChannel\AbstractCartItemAddRoute; | ||
use Shopware\Core\Checkout\Cart\SalesChannel\CartResponse; | ||
use Shopware\Core\System\SalesChannel\SalesChannelContext; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
class ExpressCartItemAddRoute extends AbstractCartItemAddRoute | ||
{ | ||
/** | ||
* @var AbstractCartItemAddRoute | ||
*/ | ||
private $cartItemAddRoute; | ||
|
||
/** | ||
* @var CartBackupService | ||
*/ | ||
|
||
private $cartBackupService; | ||
/** | ||
* @var CartServiceInterface | ||
*/ | ||
private $cartService; | ||
|
||
public function __construct(AbstractCartItemAddRoute $cartItemAddRoute, CartBackupService $cartBackupService, CartServiceInterface $cartService) | ||
{ | ||
$this->cartItemAddRoute = $cartItemAddRoute; | ||
$this->cartBackupService = $cartBackupService; | ||
$this->cartService = $cartService; | ||
} | ||
|
||
public function getDecorated(): AbstractCartItemAddRoute | ||
{ | ||
return $this->cartItemAddRoute; | ||
} | ||
|
||
public function add(Request $request, Cart $cart, SalesChannelContext $context, ?array $items): CartResponse | ||
{ | ||
//we have to create a new request from global variables, because the request is not set here in the route | ||
$request = Request::createFromGlobals(); | ||
|
||
$isExpressCheckout = (bool)$request->get('isExpressCheckout', false); | ||
if ($isExpressCheckout === false) { | ||
return $this->getDecorated()->add($request, $cart, $context, $items); | ||
} | ||
|
||
if (!$this->cartBackupService->isBackupExisting($context)) { | ||
$this->cartBackupService->backupCart($context); | ||
} | ||
|
||
$cart = $this->cartService->getCalculatedMainCart($context); | ||
|
||
# clear existing cart and also update it to save it | ||
$cart->setLineItems(new LineItemCollection()); | ||
$this->cartService->updateCart($cart); | ||
|
||
return $this->getDecorated()->add($request, $cart, $context, $items); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.