diff --git a/vendor/magento/module-quote/Model/GuestCart/GetGuestCart.php b/vendor/magento/module-quote/Model/GuestCart/GetGuestCart.php new file mode 100644 index 0000000000000..270bcb2ca3dc1 --- /dev/null +++ b/vendor/magento/module-quote/Model/GuestCart/GetGuestCart.php @@ -0,0 +1,61 @@ +cartRepository->get($quoteId); + $this->checkIsGuestCart((int) $quote->getCustomerId(), $maskedCartId); + + return $quote; + } + + /** + * Check if the cart is a guest cart. + * + * @param int $customerId + * @param string $maskedCartId + * @throws NoSuchEntityException + */ + public function checkIsGuestCart(int $customerId, string $maskedCartId): void + { + if ($customerId !== 0) { + throw new NoSuchEntityException( + __("Could not find a cart with ID '%masked_cart_id'", ['masked_cart_id' => $maskedCartId]) + ); + } + } +} diff --git a/vendor/magento/module-quote/Model/GuestCart/GuestBillingAddressManagement.php b/vendor/magento/module-quote/Model/GuestCart/GuestBillingAddressManagement.php index 3e491e0b1a24d..492a5d66166e6 100644 --- a/vendor/magento/module-quote/Model/GuestCart/GuestBillingAddressManagement.php +++ b/vendor/magento/module-quote/Model/GuestCart/GuestBillingAddressManagement.php @@ -6,9 +6,12 @@ + namespace Magento\Quote\Model\GuestCart; use Magento\Quote\Api\GuestBillingAddressManagementInterface; use Magento\Quote\Api\BillingAddressManagementInterface; use Magento\Quote\Model\QuoteIdMask; use Magento\Quote\Model\QuoteIdMaskFactory; +use Magento\Quote\Model\GuestCart\GetGuestCart; +use Magento\Framework\App\ObjectManager; /** * Billing address management service for guest carts. @@ -26,36 +30,46 @@ class GuestBillingAddressManagement implements GuestBillingAddressManagementInte private $billingAddressManagement; + /** + * @var GetGuestCart|null + */ + private $getGuestCart; + /** * Constructs a quote billing address service object. * * @param BillingAddressManagementInterface $billingAddressManagement * @param QuoteIdMaskFactory $quoteIdMaskFactory + * @param GetGuestCart|null $getGuestCart */ public function __construct( BillingAddressManagementInterface $billingAddressManagement, - QuoteIdMaskFactory $quoteIdMaskFactory + QuoteIdMaskFactory $quoteIdMaskFactory, + ?GetGuestCart $getGuestCart = null ) { $this->quoteIdMaskFactory = $quoteIdMaskFactory; $this->billingAddressManagement = $billingAddressManagement; + $this->getGuestCart = $getGuestCart ?? ObjectManager::getInstance()->get(GetGuestCart::class); } /** - * {@inheritDoc} + * @inheritDoc */ public function assign($cartId, \Magento\Quote\Api\Data\AddressInterface $address, $useForShipping = false) { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + $this->getGuestCart->execute($cartId, (int) $quoteIdMask->getQuoteId()); return (int)$this->billingAddressManagement->assign($quoteIdMask->getQuoteId(), $address, $useForShipping); } /** - * {@inheritDoc} + * @inheritDoc */ public function get($cartId) { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + $this->getGuestCart->execute($cartId, (int) $quoteIdMask->getQuoteId()); return $this->billingAddressManagement->get($quoteIdMask->getQuoteId()); } } diff --git a/vendor/magento/module-quote/Model/GuestCart/GuestCartItemRepository.php b/vendor/magento/module-quote/Model/GuestCart/GuestCartItemRepository.php index 46c3b9b7a8fdf..a1b831740f67d 100644 --- a/vendor/magento/module-quote/Model/GuestCart/GuestCartItemRepository.php +++ b/vendor/magento/module-quote/Model/GuestCart/GuestCartItemRepository.php @@ -7,9 +6,12 @@ + namespace Magento\Quote\Model\GuestCart; use Magento\Quote\Api\Data\CartItemInterface; use Magento\Quote\Api\CartItemRepositoryInterface; use Magento\Quote\Model\QuoteIdMask; use Magento\Quote\Model\QuoteIdMaskFactory; +use Magento\Quote\Model\GuestCart\GetGuestCart; +use Magento\Framework\App\ObjectManager; /** * Cart Item repository class for guest carts. @@ -17,7 +20,7 @@ class GuestCartItemRepository implements \Magento\Quote\Api\GuestCartItemRepositoryInterface { /** - * @var \Magento\Quote\Api\CartItemRepositoryInterface + * @var CartItemRepositoryInterface */ protected $repository; @@ -27,26 +30,35 @@ class GuestCartItemRepository implements \Magento\Quote\Api\GuestCartItemReposit protected $quoteIdMaskFactory; + /** + * @var GetGuestCart|null + */ + private $getGuestCart; + /** * Constructs a read service object. * - * @param \Magento\Quote\Api\CartItemRepositoryInterface $repository + * @param CartItemRepositoryInterface $repository * @param QuoteIdMaskFactory $quoteIdMaskFactory + * @param GetGuestCart|null $getGuestCart */ public function __construct( - \Magento\Quote\Api\CartItemRepositoryInterface $repository, - QuoteIdMaskFactory $quoteIdMaskFactory + CartItemRepositoryInterface $repository, + QuoteIdMaskFactory $quoteIdMaskFactory, + ?GetGuestCart $getGuestCart = null ) { $this->quoteIdMaskFactory = $quoteIdMaskFactory; $this->repository = $repository; + $this->getGuestCart = $getGuestCart ?? ObjectManager::getInstance()->get(GetGuestCart::class); } /** - * {@inheritdoc} + * @inheritDoc */ public function getList($cartId) { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + $this->getGuestCart->execute($cartId, (int) $quoteIdMask->getQuoteId()); $cartItemList = $this->repository->getList($quoteIdMask->getQuoteId()); /** @var $item CartItemInterface */ foreach ($cartItemList as $item) { @@ -56,23 +68,25 @@ public function getList($cartId) } /** - * {@inheritdoc} + * @inheritDoc */ - public function save(\Magento\Quote\Api\Data\CartItemInterface $cartItem) + public function save(CartItemInterface $cartItem) { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartItem->getQuoteId(), 'masked_id'); + $this->getGuestCart->execute($cartItem->getQuoteId(), (int) $quoteIdMask->getQuoteId()); $cartItem->setQuoteId($quoteIdMask->getQuoteId()); return $this->repository->save($cartItem); } /** - * {@inheritdoc} + * @inheritdoc */ public function deleteById($cartId, $itemId) { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + $this->getGuestCart->execute($cartId, (int) $quoteIdMask->getQuoteId()); return $this->repository->deleteById($quoteIdMask->getQuoteId(), $itemId); } } diff --git a/vendor/magento/module-quote/Model/GuestCart/GuestCartManagement.php b/vendor/magento/module-quote/Model/GuestCart/GuestCartManagement.php index 0236cb583dac1..eeb1b01af50a8 100644 --- a/vendor/magento/module-quote/Model/GuestCart/GuestCartManagement.php +++ b/vendor/magento/module-quote/Model/GuestCart/GuestCartManagement.php @@ -12,6 +13,8 @@ use Magento\Quote\Model\QuoteIdMaskFactory; use Magento\Quote\Api\Data\PaymentInterface; use Magento\Quote\Api\CartRepositoryInterface; +use Magento\Quote\Model\GuestCart\GetGuestCart; +use Magento\Framework\App\ObjectManager; /** * Cart Management class for guest carts. @@ -36,25 +39,33 @@ class GuestCartManagement implements GuestCartManagementInterface protected $cartRepository; + /** + * @var GetGuestCart|null + */ + private $getGuestCart; + /** * Initialize dependencies. * * @param CartManagementInterface $quoteManagement * @param QuoteIdMaskFactory $quoteIdMaskFactory * @param CartRepositoryInterface $cartRepository + * @param GetGuestCart|null $getGuestCart * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( CartManagementInterface $quoteManagement, QuoteIdMaskFactory $quoteIdMaskFactory, - CartRepositoryInterface $cartRepository + CartRepositoryInterface $cartRepository, + ?GetGuestCart $getGuestCart = null ) { $this->quoteManagement = $quoteManagement; $this->quoteIdMaskFactory = $quoteIdMaskFactory; $this->cartRepository = $cartRepository; + $this->getGuestCart = $getGuestCart ?? ObjectManager::getInstance()->get(GetGuestCart::class); } /** - * {@inheritdoc} + * @inheritDoc */ public function createEmptyCart() { @@ -66,22 +77,24 @@ public function createEmptyCart() } /** - * {@inheritdoc} + * @inheritDoc */ public function assignCustomer($cartId, $customerId, $storeId) { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + $this->getGuestCart->execute($cartId, (int) $quoteIdMask->getQuoteId()); return $this->quoteManagement->assignCustomer($quoteIdMask->getQuoteId(), $customerId, $storeId); } /** - * {@inheritdoc} + * @inheritdoc */ public function placeOrder($cartId, PaymentInterface $paymentMethod = null) { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + $this->getGuestCart->execute($cartId, (int) $quoteIdMask->getQuoteId()); $this->cartRepository->get($quoteIdMask->getQuoteId()) ->setCheckoutMethod(CartManagementInterface::METHOD_GUEST); return $this->quoteManagement->placeOrder($quoteIdMask->getQuoteId(), $paymentMethod); diff --git a/vendor/magento/module-quote/Model/GuestCart/GuestCartRepository.php b/vendor/magento/module-quote/Model/GuestCart/GuestCartRepository.php index 665dc0a87c97b..7c8cca1086f9e 100644 --- a/vendor/magento/module-quote/Model/GuestCart/GuestCartRepository.php +++ b/vendor/magento/module-quote/Model/GuestCart/GuestCartRepository.php @@ -6,9 +6,12 @@ + namespace Magento\Quote\Model\GuestCart; use Magento\Quote\Api\GuestCartRepositoryInterface; use Magento\Quote\Model\QuoteIdMask; use Magento\Quote\Api\CartRepositoryInterface; use Magento\Quote\Model\QuoteIdMaskFactory; +use Magento\Quote\Model\GuestCart\GetGuestCart; +use Magento\Framework\App\ObjectManager; /** * Cart Repository class for guest carts. @@ -26,26 +30,36 @@ class GuestCartRepository implements GuestCartRepositoryInterface protected $quoteRepository; + /** + * @var GetGuestCart|null + */ + private $getGuestCart; + /** * Initialize dependencies. * * @param CartRepositoryInterface $quoteRepository * @param QuoteIdMaskFactory $quoteIdMaskFactory + * @param GetGuestCart|null $getGuestCart */ public function __construct( CartRepositoryInterface $quoteRepository, - QuoteIdMaskFactory $quoteIdMaskFactory + QuoteIdMaskFactory $quoteIdMaskFactory, + ?GetGuestCart $getGuestCart = null ) { $this->quoteIdMaskFactory = $quoteIdMaskFactory; $this->quoteRepository = $quoteRepository; + $this->getGuestCart = $getGuestCart ?? ObjectManager::getInstance()->get(GetGuestCart::class); } /** - * {@inheritdoc} + * @inheritDoc */ public function get($cartId) { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); - return $this->quoteRepository->get($quoteIdMask->getQuoteId()); + $quote = $this->quoteRepository->get($quoteIdMask->getQuoteId()); + $this->getGuestCart->checkIsGuestCart((int)$quote->getCustomerId(), $cartId); + return $quote; } } diff --git a/vendor/magento/module-quote/Model/GuestCart/GuestCartTotalManagement.php b/vendor/magento/module-quote/Model/GuestCart/GuestCartTotalManagement.php index 33cb83fa5fbcb..d5c457d645ff2 100644 --- a/vendor/magento/module-quote/Model/GuestCart/GuestCartTotalManagement.php +++ b/vendor/magento/module-quote/Model/GuestCart/GuestCartTotalManagement.php @@ -6,7 +6,11 @@ + namespace Magento\Quote\Model\GuestCart; use Magento\Quote\Model\QuoteIdMaskFactory; use Magento\Quote\Api\GuestCartTotalManagementInterface; +use Magento\Framework\App\ObjectManager; +use Magento\Quote\Model\GuestCart\GetGuestCart; +use Magento\Quote\Api\CartTotalManagementInterface; /** * @inheritDoc @@ -14,7 +19,7 @@ class GuestCartTotalManagement implements GuestCartTotalManagementInterface { /** - * @var \Magento\Quote\Api\CartTotalManagementInterface + * @var CartTotalManagementInterface */ protected $cartTotalManagement; @@ -24,19 +29,27 @@ class GuestCartTotalManagement implements GuestCartTotalManagementInterface protected $quoteIdMaskFactory; /** - * @param \Magento\Quote\Api\CartTotalManagementInterface $cartTotalManagement + * @var GetGuestCart|null + */ + private $getGuestCart; + + /** + * @param CartTotalManagementInterface $cartTotalManagement * @param QuoteIdMaskFactory $quoteIdMaskFactory + * @param GetGuestCart|null $getGuestCart */ public function __construct( - \Magento\Quote\Api\CartTotalManagementInterface $cartTotalManagement, - QuoteIdMaskFactory $quoteIdMaskFactory + CartTotalManagementInterface $cartTotalManagement, + QuoteIdMaskFactory $quoteIdMaskFactory, + ?GetGuestCart $getGuestCart = null ) { $this->cartTotalManagement = $cartTotalManagement; $this->quoteIdMaskFactory = $quoteIdMaskFactory; + $this->getGuestCart = $getGuestCart ?? ObjectManager::getInstance()->get(GetGuestCart::class); } /** - * {@inheritDoc} + * @inheritDoc */ public function collectTotals( $cartId, @@ -46,6 +59,7 @@ public function collectTotals( \Magento\Quote\Api\Data\TotalsAdditionalDataInterface $additionalData = null ) { $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + $this->getGuestCart->execute($cartId, (int) $quoteIdMask->getQuoteId()); return $this->cartTotalManagement->collectTotals( $quoteIdMask->getQuoteId(), $paymentMethod, diff --git a/vendor/magento/module-quote/Model/GuestCart/GuestCartTotalRepository.php b/vendor/magento/module-quote/Model/GuestCart/GuestCartTotalRepository.php index 9e384671cf6bd..66540578c6526 100644 --- a/vendor/magento/module-quote/Model/GuestCart/GuestCartTotalRepository.php +++ b/vendor/magento/module-quote/Model/GuestCart/GuestCartTotalRepository.php @@ -10,6 +11,8 @@ use Magento\Quote\Api\GuestCartTotalRepositoryInterface; use Magento\Quote\Model\QuoteIdMask; use Magento\Quote\Model\QuoteIdMaskFactory; +use Magento\Quote\Model\GuestCart\GetGuestCart; +use Magento\Framework\App\ObjectManager; /** * Cart totals repository class for guest carts. @@ -27,26 +30,35 @@ class GuestCartTotalRepository implements GuestCartTotalRepositoryInterface private $cartTotalRepository; + /** + * @var GetGuestCart|null + */ + private $getGuestCart; + /** * Constructs a cart totals data object. * * @param CartTotalRepositoryInterface $cartTotalRepository * @param QuoteIdMaskFactory $quoteIdMaskFactory + * @param GetGuestCart|null $getGuestCart */ public function __construct( CartTotalRepositoryInterface $cartTotalRepository, - QuoteIdMaskFactory $quoteIdMaskFactory + QuoteIdMaskFactory $quoteIdMaskFactory, + ?GetGuestCart $getGuestCart = null ) { $this->cartTotalRepository = $cartTotalRepository; $this->quoteIdMaskFactory = $quoteIdMaskFactory; + $this->getGuestCart = $getGuestCart ?? ObjectManager::getInstance()->get(GetGuestCart::class); } /** - * {@inheritDoc} + * @inheritDoc */ public function get($cartId) { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + $this->getGuestCart->execute($cartId, (int) $quoteIdMask->getQuoteId()); return $this->cartTotalRepository->get($quoteIdMask->getQuoteId()); } } diff --git a/vendor/magento/module-quote/Model/GuestCart/GuestCouponManagement.php b/vendor/magento/module-quote/Model/GuestCart/GuestCouponManagement.php index a000d44be9eba..c585c29dc071b 100644 --- a/vendor/magento/module-quote/Model/GuestCart/GuestCouponManagement.php +++ b/vendor/magento/module-quote/Model/GuestCart/GuestCouponManagement.php @@ -7,9 +6,12 @@ + namespace Magento\Quote\Model\GuestCart; use Magento\Quote\Api\GuestCouponManagementInterface; use Magento\Quote\Api\CouponManagementInterface; use Magento\Quote\Model\QuoteIdMask; use Magento\Quote\Model\QuoteIdMaskFactory; +use Magento\Quote\Model\GuestCart\GetGuestCart; +use Magento\Framework\App\ObjectManager; /** * Coupon management class for guest carts. @@ -27,17 +30,25 @@ class GuestCouponManagement implements GuestCouponManagementInterface private $couponManagement; + /** + * @var GetGuestCart|null + */ + private $getGuestCart; + /** * Constructs a coupon read service object. * * @param CouponManagementInterface $couponManagement * @param QuoteIdMaskFactory $quoteIdMaskFactory + * @param GetGuestCart|null $getGuestCart */ public function __construct( CouponManagementInterface $couponManagement, - QuoteIdMaskFactory $quoteIdMaskFactory + QuoteIdMaskFactory $quoteIdMaskFactory, + ?GetGuestCart $getGuestCart = null ) { $this->quoteIdMaskFactory = $quoteIdMaskFactory; $this->couponManagement = $couponManagement; + $this->getGuestCart = $getGuestCart ?? ObjectManager::getInstance()->get(GetGuestCart::class); } /** @@ -47,6 +58,7 @@ public function get($cartId) { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + $this->getGuestCart->execute($cartId, (int) $quoteIdMask->getQuoteId()); return $this->couponManagement->get($quoteIdMask->getQuoteId()); } @@ -57,6 +69,7 @@ public function set($cartId, $couponCode) { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + $this->getGuestCart->execute($cartId, (int) $quoteIdMask->getQuoteId()); return $this->couponManagement->set($quoteIdMask->getQuoteId(), trim($couponCode)); } @@ -67,6 +80,7 @@ public function remove($cartId) { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + $this->getGuestCart->execute($cartId, (int) $quoteIdMask->getQuoteId()); return $this->couponManagement->remove($quoteIdMask->getQuoteId()); } } diff --git a/vendor/magento/module-quote/Model/GuestCart/GuestPaymentMethodManagement.php b/vendor/magento/module-quote/Model/GuestCart/GuestPaymentMethodManagement.php index f57a7d2e0ba6e..d42518fcf6d88 100644 --- a/vendor/magento/module-quote/Model/GuestCart/GuestPaymentMethodManagement.php +++ b/vendor/magento/module-quote/Model/GuestCart/GuestPaymentMethodManagement.php @@ -6,9 +6,12 @@ + namespace Magento\Quote\Model\GuestCart; use Magento\Quote\Api\PaymentMethodManagementInterface; use Magento\Quote\Api\GuestPaymentMethodManagementInterface; use Magento\Quote\Model\QuoteIdMask; use Magento\Quote\Model\QuoteIdMaskFactory; +use Magento\Quote\Model\GuestCart\GetGuestCart; +use Magento\Framework\App\ObjectManager; /** * Payment method management class for guest carts. @@ -26,46 +30,57 @@ class GuestPaymentMethodManagement implements GuestPaymentMethodManagementInterf protected $paymentMethodManagement; + /** + * @var GetGuestCart|null + */ + private $getGuestCart; + /** * Initialize dependencies. * * @param PaymentMethodManagementInterface $paymentMethodManagement * @param QuoteIdMaskFactory $quoteIdMaskFactory + * @param GetGuestCart|null $getGuestCart */ public function __construct( PaymentMethodManagementInterface $paymentMethodManagement, - QuoteIdMaskFactory $quoteIdMaskFactory + QuoteIdMaskFactory $quoteIdMaskFactory, + ?GetGuestCart $getGuestCart = null ) { $this->quoteIdMaskFactory = $quoteIdMaskFactory; $this->paymentMethodManagement = $paymentMethodManagement; + $this->getGuestCart = $getGuestCart ?? ObjectManager::getInstance()->get(GetGuestCart::class); } /** - * {@inheritdoc} + * @inheritDoc */ public function set($cartId, \Magento\Quote\Api\Data\PaymentInterface $method) { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + $this->getGuestCart->execute($cartId, (int) $quoteIdMask->getQuoteId()); return $this->paymentMethodManagement->set($quoteIdMask->getQuoteId(), $method); } /** - * {@inheritdoc} + * @inheritDoc */ public function get($cartId) { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + $this->getGuestCart->execute($cartId, (int) $quoteIdMask->getQuoteId()); return $this->paymentMethodManagement->get($quoteIdMask->getQuoteId()); } /** - * {@inheritdoc} + * @inheritDoc */ public function getList($cartId) { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + $this->getGuestCart->execute($cartId, (int) $quoteIdMask->getQuoteId()); return $this->paymentMethodManagement->getList($quoteIdMask->getQuoteId()); } } diff --git a/vendor/magento/module-quote/Model/GuestCart/GuestShippingAddressManagement.php b/vendor/magento/module-quote/Model/GuestCart/GuestShippingAddressManagement.php index e2f31406cfe7e..6343a94df5787 100644 --- a/vendor/magento/module-quote/Model/GuestCart/GuestShippingAddressManagement.php +++ b/vendor/magento/module-quote/Model/GuestCart/GuestShippingAddressManagement.php @@ -6,9 +6,12 @@ + namespace Magento\Quote\Model\GuestCart; use Magento\Quote\Model\GuestCart\GuestShippingAddressManagementInterface; use Magento\Quote\Model\QuoteIdMask; use Magento\Quote\Model\QuoteIdMaskFactory; use Magento\Quote\Model\ShippingAddressManagementInterface; +use Magento\Framework\App\ObjectManager; +use Magento\Quote\Model\GuestCart\GetGuestCart; /** * Shipping address management class for guest carts. @@ -26,36 +30,46 @@ class GuestShippingAddressManagement implements GuestShippingAddressManagementIn protected $shippingAddressManagement; + /** + * @var GetGuestCart|null + */ + private $getGuestCart; + /** * Constructs a quote shipping address write service object. * * @param ShippingAddressManagementInterface $shippingAddressManagement * @param QuoteIdMaskFactory $quoteIdMaskFactory + * @param GetGuestCart|null $getGuestCart */ public function __construct( ShippingAddressManagementInterface $shippingAddressManagement, - QuoteIdMaskFactory $quoteIdMaskFactory + QuoteIdMaskFactory $quoteIdMaskFactory, + ?GetGuestCart $getGuestCart = null ) { $this->shippingAddressManagement = $shippingAddressManagement; $this->quoteIdMaskFactory = $quoteIdMaskFactory; + $this->getGuestCart = $getGuestCart ?? ObjectManager::getInstance()->get(GetGuestCart::class); } /** - * {@inheritDoc} + * @inheritDoc */ public function assign($cartId, \Magento\Quote\Api\Data\AddressInterface $address) { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + $this->getGuestCart->execute($cartId, (int) $quoteIdMask->getQuoteId()); return $this->shippingAddressManagement->assign($quoteIdMask->getQuoteId(), $address); } /** - * {@inheritDoc} + * @inheritDoc */ public function get($cartId) { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + $this->getGuestCart->execute($cartId, (int) $quoteIdMask->getQuoteId()); return $this->shippingAddressManagement->get($quoteIdMask->getQuoteId()); } } diff --git a/vendor/magento/module-quote/Model/GuestCart/GuestShippingMethodManagement.php b/vendor/magento/module-quote/Model/GuestCart/GuestShippingMethodManagement.php index 88c4e10d17053..61f4d270f5ffc 100644 --- a/vendor/magento/module-quote/Model/GuestCart/GuestShippingMethodManagement.php +++ b/vendor/magento/module-quote/Model/GuestCart/GuestShippingMethodManagement.php @@ -13,6 +14,7 @@ use Magento\Quote\Api\ShippingMethodManagementInterface; use Magento\Quote\Model\QuoteIdMask; use Magento\Quote\Model\QuoteIdMaskFactory; +use Magento\Quote\Model\GuestCart\GetGuestCart; /** * Shipping method management class for guest carts. @@ -38,56 +40,68 @@ class GuestShippingMethodManagement implements private $shipmentEstimationManagement; + /** + * @var GetGuestCart|null + */ + private $getGuestCart; + /** * Constructs a shipping method read service object. * * @param ShippingMethodManagementInterface $shippingMethodManagement * @param QuoteIdMaskFactory $quoteIdMaskFactory + * @param GetGuestCart|null $getGuestCart */ public function __construct( ShippingMethodManagementInterface $shippingMethodManagement, - QuoteIdMaskFactory $quoteIdMaskFactory + QuoteIdMaskFactory $quoteIdMaskFactory, + ?GetGuestCart $getGuestCart = null ) { $this->shippingMethodManagement = $shippingMethodManagement; $this->quoteIdMaskFactory = $quoteIdMaskFactory; + $this->getGuestCart = $getGuestCart ?? ObjectManager::getInstance()->get(GetGuestCart::class); } /** - * {@inheritDoc} + * @inheritDoc */ public function get($cartId) { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + $this->getGuestCart->execute($cartId, (int) $quoteIdMask->getQuoteId()); return $this->shippingMethodManagement->get($quoteIdMask->getQuoteId()); } /** - * {@inheritDoc} + * @inheritDoc */ public function getList($cartId) { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + $this->getGuestCart->execute($cartId, (int) $quoteIdMask->getQuoteId()); return $this->shippingMethodManagement->getList($quoteIdMask->getQuoteId()); } /** - * {@inheritDoc} + * @inheritDoc */ public function set($cartId, $carrierCode, $methodCode) { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + $this->getGuestCart->execute($cartId, (int) $quoteIdMask->getQuoteId()); return $this->shippingMethodManagement->set($quoteIdMask->getQuoteId(), $carrierCode, $methodCode); } /** - * {@inheritDoc} + * @inheritDoc */ public function estimateByAddress($cartId, \Magento\Quote\Api\Data\EstimateAddressInterface $address) { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + $this->getGuestCart->execute($cartId, (int) $quoteIdMask->getQuoteId()); return $this->shippingMethodManagement->estimateByAddress($quoteIdMask->getQuoteId(), $address); } @@ -98,6 +112,7 @@ public function estimateByExtendedAddress($cartId, AddressInterface $address) { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + $this->getGuestCart->execute($cartId, (int) $quoteIdMask->getQuoteId()); return $this->getShipmentEstimationManagement() ->estimateByExtendedAddress((int) $quoteIdMask->getQuoteId(), $address); @@ -105,8 +120,10 @@ public function estimateByExtendedAddress($cartId, AddressInterface $address) /** * Get shipment estimation management service + * * @return ShipmentEstimationInterface * @deprecated 100.0.7 + * @see getShipmentEstimationManagement */ private function getShipmentEstimationManagement() { diff --git a/vendor/magento/module-quote/etc/di.xml b/vendor/magento/module-quote/etc/di.xml index cd46d9e6314c5..e5590ced9c19a 100644 --- a/vendor/magento/module-quote/etc/di.xml +++ b/vendor/magento/module-quote/etc/di.xml @@ -165,4 +165,7 @@ + + + diff --git a/vendor/magento/module-quote/etc/webapi_rest/di.xml b/vendor/magento/module-quote/etc/webapi_rest/di.xml index 85d8bafc23da7..6ed9909f04eb9 100644 --- a/vendor/magento/module-quote/etc/webapi_rest/di.xml +++ b/vendor/magento/module-quote/etc/webapi_rest/di.xml @@ -18,6 +18,5 @@ - diff --git a/vendor/magento/module-quote/i18n/en_US.csv b/vendor/magento/module-quote/i18n/en_US.csv index 6563651ba5acd..248c35de54b24 100644 --- a/vendor/magento/module-quote/i18n/en_US.csv +++ b/vendor/magento/module-quote/i18n/en_US.csv @@ -75,3 +75,4 @@ Carts,Carts "Identity type not found","Identity type not found" "Invalid order backpressure limit config","Invalid order backpressure limit config" "Please check input parameters.","Please check input parameters." +"Could not find a cart with ID '%masked_cart_id'","Could not find a cart with ID '%masked_cart_id'"