Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
All Data Structures Namespaces Files Functions Variables Pages
InstantPurchaseOptionLoadingFactory.php
Go to the documentation of this file.
1 <?php
7 
10 use Magento\Customer\Model\AddressFactory;
11 use Magento\Quote\Api\Data\ShippingMethodInterfaceFactory;
13 
18 {
22  private $instantPurchaseOptionFactory;
23 
27  private $paymentTokenManagement;
28 
32  private $addressRepository;
33 
37  private $addressFactory;
38 
42  private $shippingMethodFactory;
43 
52  public function __construct(
53  InstantPurchaseOptionFactory $instantPurchaseOptionFactory,
54  PaymentTokenManagementInterface $paymentTokenManagement,
55  AddressRepositoryInterface $addressRepository,
56  AddressFactory $addressFactory,
57  ShippingMethodInterfaceFactory $shippingMethodFactory
58  ) {
59  $this->instantPurchaseOptionFactory = $instantPurchaseOptionFactory;
60  $this->paymentTokenManagement = $paymentTokenManagement;
61  $this->addressRepository = $addressRepository;
62  $this->addressFactory = $addressFactory;
63  $this->shippingMethodFactory = $shippingMethodFactory;
64  }
65 
77  public function create(
78  int $customerId,
79  string $paymentTokenPublicHash,
80  int $shippingAddressId,
81  int $billingAddressId,
82  string $carrierCode,
83  string $shippingMethodCode
85  $paymentToken = $this->paymentTokenManagement->getByPublicHash($paymentTokenPublicHash, $customerId);
86  $shippingAddress = $this->getAddress($shippingAddressId);
87  $billingAddress = $this->getAddress($billingAddressId);
88  $shippingMethod = $this->shippingMethodFactory->create()
89  ->setCarrierCode($carrierCode)
90  ->setMethodCode($shippingMethodCode);
91 
92  return $this->instantPurchaseOptionFactory->create(
97  );
98  }
99 
106  private function getAddress($addressId): Address
107  {
108  $addressDataModel = $this->addressRepository->getById($addressId);
109  $address = $this->addressFactory->create();
110  $address->updateData($addressDataModel);
111  return $address;
112  }
113 }
$addressRepository
__construct(InstantPurchaseOptionFactory $instantPurchaseOptionFactory, PaymentTokenManagementInterface $paymentTokenManagement, AddressRepositoryInterface $addressRepository, AddressFactory $addressFactory, ShippingMethodInterfaceFactory $shippingMethodFactory)
$billingAddress
Definition: order.php:25
$shippingAddress
Definition: order.php:40
$address
Definition: customer.php:38
create(int $customerId, string $paymentTokenPublicHash, int $shippingAddressId, int $billingAddressId, string $carrierCode, string $shippingMethodCode)
$addressFactory
Definition: quote.php:20
$shippingMethod
Definition: popup.phtml:12