![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/magento/module-quote-graph-ql/Model/Resolver/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ declare(strict_types=1); namespace Magento\QuoteGraphQl\Model\Resolver; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\GraphQl\Config\Element\Field; use Magento\Framework\GraphQl\Exception\GraphQlInputException; use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException; use Magento\Framework\GraphQl\Query\ResolverInterface; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; use Magento\Quote\Api\CartItemRepositoryInterface; use Magento\Quote\Model\MaskedQuoteIdToQuoteId; use Magento\QuoteGraphQl\Model\Cart\GetCartForUser; use Magento\Framework\GraphQl\Query\Resolver\ArgumentsProcessorInterface; /** * @inheritdoc */ class RemoveItemFromCart implements ResolverInterface { /** * @var GetCartForUser */ private $getCartForUser; /** * @var CartItemRepositoryInterface */ private $cartItemRepository; /** * @var MaskedQuoteIdToQuoteId */ private $maskedQuoteIdToQuoteId; /** * @var ArgumentsProcessorInterface */ private $argsSelection; /** * @param GetCartForUser $getCartForUser * @param CartItemRepositoryInterface $cartItemRepository * @param MaskedQuoteIdToQuoteId $maskedQuoteIdToQuoteId * @param ArgumentsProcessorInterface $argsSelection */ public function __construct( GetCartForUser $getCartForUser, CartItemRepositoryInterface $cartItemRepository, MaskedQuoteIdToQuoteId $maskedQuoteIdToQuoteId, ArgumentsProcessorInterface $argsSelection ) { $this->getCartForUser = $getCartForUser; $this->cartItemRepository = $cartItemRepository; $this->maskedQuoteIdToQuoteId = $maskedQuoteIdToQuoteId; $this->argsSelection = $argsSelection; } /** * @inheritdoc */ public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) { $processedArgs = $this->argsSelection->process($info->fieldName, $args); if (empty($processedArgs['input']['cart_id'])) { throw new GraphQlInputException(__('Required parameter "cart_id" is missing.')); } $maskedCartId = $processedArgs['input']['cart_id']; try { $cartId = $this->maskedQuoteIdToQuoteId->execute($maskedCartId); } catch (NoSuchEntityException $exception) { throw new GraphQlNoSuchEntityException( __('Could not find a cart with ID "%masked_cart_id"', ['masked_cart_id' => $maskedCartId]) ); } if (empty($processedArgs['input']['cart_item_id'])) { throw new GraphQlInputException(__('Required parameter "cart_item_id" is missing.')); } $itemId = $processedArgs['input']['cart_item_id']; $storeId = (int)$context->getExtensionAttributes()->getStore()->getId(); /** Check if the current user is allowed to perform actions with the cart */ $cart = $this->getCartForUser->execute($maskedCartId, $context->getUserId(), $storeId); try { $this->cartItemRepository->deleteById($cartId, $itemId); } catch (NoSuchEntityException $e) { throw new GraphQlNoSuchEntityException(__('The cart doesn\'t contain the item')); } catch (LocalizedException $e) { throw new GraphQlInputException(__($e->getMessage()), $e); } return [ 'cart' => [ 'model' => $cart, ], ]; } }