QuoteCreation.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\InstantPurchase\Model\QuoteManagement;
  7. use Magento\Customer\Model\Address;
  8. use Magento\Customer\Model\Customer;
  9. use Magento\Framework\Exception\LocalizedException;
  10. use Magento\Quote\Model\Quote;
  11. use Magento\Quote\Model\QuoteFactory;
  12. use Magento\Store\Model\Store;
  13. /**
  14. * Create Quote for instance purchase.
  15. *
  16. * @api May be used for pluginization.
  17. * @since 100.2.0
  18. */
  19. class QuoteCreation
  20. {
  21. /**
  22. * @var QuoteFactory
  23. */
  24. private $quoteFactory;
  25. /**
  26. * QuoteCreation constructor.
  27. * @param QuoteFactory $quoteFactory
  28. */
  29. public function __construct(
  30. QuoteFactory $quoteFactory
  31. ) {
  32. $this->quoteFactory = $quoteFactory;
  33. }
  34. /**
  35. * Creates Quote for instant purchase.
  36. *
  37. * @param Store $store
  38. * @param Customer $customer
  39. * @param Address $shippingAddress
  40. * @param Address $billingAddress
  41. * @return Quote
  42. * @throws LocalizedException if quote can not be created.
  43. * @since 100.2.0
  44. */
  45. public function createQuote(
  46. Store $store,
  47. Customer $customer,
  48. Address $shippingAddress,
  49. Address $billingAddress
  50. ): Quote {
  51. $quote = $this->quoteFactory->create();
  52. $quote->setStoreId($store->getId());
  53. $quote->setCustomer($customer->getDataModel());
  54. $quote->setCustomerIsGuest(0);
  55. $quote->getShippingAddress()
  56. ->importCustomerAddressData($shippingAddress->getDataModel());
  57. $quote->getBillingAddress()
  58. ->importCustomerAddressData($billingAddress->getDataModel());
  59. $quote->setInventoryProcessed(false);
  60. return $quote;
  61. }
  62. }