Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
All Data Structures Namespaces Files Functions Variables Pages
InstantPurchaseChooser.php
Go to the documentation of this file.
1 <?php
7 
9 
15 
22 {
26  private $instantPurchaseOptionFactory;
27 
31  private $config;
32 
36  private $paymentTokenChooser;
37 
41  private $shippingAddressChooser;
42 
46  private $billingAddressChooser;
47 
51  private $shippingMethodChooser;
52 
62  public function __construct(
63  InstantPurchaseOptionFactory $instantPurchaseOptionFactory,
64  Config $config,
65  PaymentTokenChooserInterface $paymentTokenChooser,
66  ShippingAddressChooserInterface $shippingAddressChooser,
67  BillingAddressChooserInterface $billingAddressChooser,
68  ShippingMethodChooserInterface $shippingMethodChooser
69  ) {
70  $this->instantPurchaseOptionFactory = $instantPurchaseOptionFactory;
71  $this->config = $config;
72  $this->paymentTokenChooser = $paymentTokenChooser;
73  $this->shippingAddressChooser = $shippingAddressChooser;
74  $this->billingAddressChooser = $billingAddressChooser;
75  $this->shippingMethodChooser = $shippingMethodChooser;
76  }
77 
81  public function getOption(
82  Store $store,
85  if (!$this->isInstantPurchaseButtonEnabled($store)) {
86  return $this->instantPurchaseOptionFactory->createDisabledOption();
87  }
88 
89  $paymentToken = $this->paymentTokenChooser->choose($store, $customer);
90  $shippingAddress = $this->shippingAddressChooser->choose($customer);
91  $billingAddress = $this->billingAddressChooser->choose($customer);
92  if ($shippingAddress) {
93  $shippingMethod = $this->shippingMethodChooser->choose($shippingAddress);
94  } else {
95  $shippingMethod = null;
96  }
97 
98  $option = $this->instantPurchaseOptionFactory->create(
103  );
104 
105  return $option;
106  }
107 
114  private function isInstantPurchaseButtonEnabled(Store $store): bool
115  {
116  return $this->config->isModuleEnabled($store->getId());
117  }
118 }
$billingAddress
Definition: order.php:25
$customer
Definition: customers.php:11
$config
Definition: fraud_order.php:17
$shippingAddress
Definition: order.php:40
__construct(InstantPurchaseOptionFactory $instantPurchaseOptionFactory, Config $config, PaymentTokenChooserInterface $paymentTokenChooser, ShippingAddressChooserInterface $shippingAddressChooser, BillingAddressChooserInterface $billingAddressChooser, ShippingMethodChooserInterface $shippingMethodChooser)
$shippingMethod
Definition: popup.phtml:12