1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Quote\Model\GuestCart;
- use Magento\Quote\Api\GuestCartManagementInterface;
- use Magento\Quote\Api\CartManagementInterface;
- use Magento\Quote\Model\QuoteIdMask;
- use Magento\Quote\Model\QuoteIdMaskFactory;
- use Magento\Quote\Api\Data\PaymentInterface;
- use Magento\Quote\Api\CartRepositoryInterface;
- /**
- * Cart Management class for guest carts.
- *
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
- class GuestCartManagement implements GuestCartManagementInterface
- {
- /**
- * @var CartManagementInterface
- */
- protected $quoteManagement;
- /**
- * @var QuoteIdMaskFactory
- */
- protected $quoteIdMaskFactory;
- /**
- * @var CartRepositoryInterface
- */
- protected $cartRepository;
- /**
- * Initialize dependencies.
- *
- * @param CartManagementInterface $quoteManagement
- * @param QuoteIdMaskFactory $quoteIdMaskFactory
- * @param CartRepositoryInterface $cartRepository
- * @SuppressWarnings(PHPMD.ExcessiveParameterList)
- */
- public function __construct(
- CartManagementInterface $quoteManagement,
- QuoteIdMaskFactory $quoteIdMaskFactory,
- CartRepositoryInterface $cartRepository
- ) {
- $this->quoteManagement = $quoteManagement;
- $this->quoteIdMaskFactory = $quoteIdMaskFactory;
- $this->cartRepository = $cartRepository;
- }
- /**
- * {@inheritdoc}
- */
- public function createEmptyCart()
- {
- /** @var $quoteIdMask \Magento\Quote\Model\QuoteIdMask */
- $quoteIdMask = $this->quoteIdMaskFactory->create();
- $cartId = $this->quoteManagement->createEmptyCart();
- $quoteIdMask->setQuoteId($cartId)->save();
- return $quoteIdMask->getMaskedId();
- }
- /**
- * {@inheritdoc}
- */
- public function assignCustomer($cartId, $customerId, $storeId)
- {
- /** @var $quoteIdMask QuoteIdMask */
- $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
- return $this->quoteManagement->assignCustomer($quoteIdMask->getQuoteId(), $customerId, $storeId);
- }
- /**
- * {@inheritdoc}
- */
- public function placeOrder($cartId, PaymentInterface $paymentMethod = null)
- {
- /** @var $quoteIdMask QuoteIdMask */
- $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
- $this->cartRepository->get($quoteIdMask->getQuoteId())
- ->setCheckoutMethod(CartManagementInterface::METHOD_GUEST);
- return $this->quoteManagement->placeOrder($quoteIdMask->getQuoteId(), $paymentMethod);
- }
- }
|