Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
GuestCartManagement.php
Go to the documentation of this file.
1 <?php
8 
12 use Magento\Quote\Model\QuoteIdMaskFactory;
15 
22 {
26  protected $quoteManagement;
27 
32 
36  protected $cartRepository;
37 
46  public function __construct(
48  QuoteIdMaskFactory $quoteIdMaskFactory,
50  ) {
51  $this->quoteManagement = $quoteManagement;
52  $this->quoteIdMaskFactory = $quoteIdMaskFactory;
53  $this->cartRepository = $cartRepository;
54  }
55 
59  public function createEmptyCart()
60  {
62  $quoteIdMask = $this->quoteIdMaskFactory->create();
63  $cartId = $this->quoteManagement->createEmptyCart();
64  $quoteIdMask->setQuoteId($cartId)->save();
65  return $quoteIdMask->getMaskedId();
66  }
67 
71  public function assignCustomer($cartId, $customerId, $storeId)
72  {
74  $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
75  return $this->quoteManagement->assignCustomer($quoteIdMask->getQuoteId(), $customerId, $storeId);
76  }
77 
81  public function placeOrder($cartId, PaymentInterface $paymentMethod = null)
82  {
84  $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
85  $this->cartRepository->get($quoteIdMask->getQuoteId())
86  ->setCheckoutMethod(CartManagementInterface::METHOD_GUEST);
87  return $this->quoteManagement->placeOrder($quoteIdMask->getQuoteId(), $paymentMethod);
88  }
89 }
$cartId
Definition: quote.php:22
__construct(CartManagementInterface $quoteManagement, QuoteIdMaskFactory $quoteIdMaskFactory, CartRepositoryInterface $cartRepository)
placeOrder($cartId, PaymentInterface $paymentMethod=null)
assignCustomer($cartId, $customerId, $storeId)