![]() 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/Cart/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ declare(strict_types=1); namespace Magento\QuoteGraphQl\Model\Cart; use Magento\Framework\GraphQl\Exception\GraphQlInputException; use Magento\Framework\GraphQl\Query\Resolver\ContextInterface; use Magento\Quote\Api\Data\CartInterface; /** * Set single shipping method for a specified shopping cart */ class SetShippingMethodsOnCart implements SetShippingMethodsOnCartInterface { /** * @var AssignShippingMethodToCart */ private $assignShippingMethodToCart; /** * @param AssignShippingMethodToCart $assignShippingMethodToCart */ public function __construct( AssignShippingMethodToCart $assignShippingMethodToCart ) { $this->assignShippingMethodToCart = $assignShippingMethodToCart; } /** * @inheritdoc */ public function execute(ContextInterface $context, CartInterface $cart, array $shippingMethodsInput): void { if (count($shippingMethodsInput) > 1) { throw new GraphQlInputException( __('You cannot specify multiple shipping methods.') ); } $shippingMethodInput = current($shippingMethodsInput); if (empty($shippingMethodInput['carrier_code'])) { throw new GraphQlInputException(__('Required parameter "carrier_code" is missing.')); } $carrierCode = $shippingMethodInput['carrier_code']; if (empty($shippingMethodInput['method_code'])) { throw new GraphQlInputException(__('Required parameter "method_code" is missing.')); } $methodCode = $shippingMethodInput['method_code']; $shippingAddress = $cart->getShippingAddress(); $this->assignShippingMethodToCart->execute($cart, $shippingAddress, $carrierCode, $methodCode); } }