-
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.
PISHPS-338: custom product compatibility (#820)
* NTR: PISHPS-338: Add compatiblity with custom products * NTR: stan fix * NTR: fix recursion in sw6.4 * NTR: fix container * NTR: fix container --------- Co-authored-by: Vitalij Mik <[email protected]>
- Loading branch information
1 parent
5436200
commit 719ca14
Showing
10 changed files
with
446 additions
and
318 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,70 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Kiener\MolliePayments\Checkout\Cart; | ||
|
||
use Kiener\MolliePayments\Service\Cart\CartBackupService; | ||
use Kiener\MolliePayments\Service\CartService; | ||
use Psr\Container\ContainerInterface; | ||
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 ContainerInterface | ||
*/ | ||
private $container; | ||
|
||
public function __construct(AbstractCartItemAddRoute $cartItemAddRoute, ContainerInterface $container) | ||
{ | ||
$this->cartItemAddRoute = $cartItemAddRoute; | ||
$this->container = $container; | ||
} | ||
|
||
public function getDecorated(): AbstractCartItemAddRoute | ||
{ | ||
return $this->cartItemAddRoute; | ||
} | ||
|
||
/** | ||
* @param Request $request | ||
* @param Cart $cart | ||
* @param SalesChannelContext $context | ||
* @param ?array<mixed> $items | ||
* @return CartResponse | ||
*/ | ||
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); | ||
} | ||
$cartBackupService = $this->container->get(CartBackupService::class); //Shopware 6.4 have circular injection, we have to use contaier | ||
if (!$cartBackupService->isBackupExisting($context)) { | ||
$cartBackupService->backupCart($context); | ||
} | ||
|
||
$cartService = $this->container->get(CartService::class); | ||
|
||
$cart = $cartService->getCalculatedMainCart($context); | ||
|
||
# clear existing cart and also update it to save it | ||
$cart->setLineItems(new LineItemCollection()); | ||
$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.