Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Button.php
Go to the documentation of this file.
1 <?php
7 
11 
18 class Button extends Template
19 {
23  private $instantPurchaseConfig;
24 
31  public function __construct(
32  Context $context,
33  Config $instantPurchaseConfig,
34  array $data = []
35  ) {
36  parent::__construct($context, $data);
37  $this->instantPurchaseConfig = $instantPurchaseConfig;
38  }
39 
46  public function isEnabled(): bool
47  {
48  return $this->instantPurchaseConfig->isModuleEnabled($this->getCurrentStoreId());
49  }
50 
55  public function getJsLayout(): string
56  {
57  $buttonText = $this->instantPurchaseConfig->getButtonText($this->getCurrentStoreId());
58  $purchaseUrl = $this->getUrl('instantpurchase/button/placeOrder', ['_secure' => true]);
59 
60  // String data does not require escaping here and handled on transport level and on client side
61  $this->jsLayout['components']['instant-purchase']['config']['buttonText'] = $buttonText;
62  $this->jsLayout['components']['instant-purchase']['config']['purchaseUrl'] = $purchaseUrl;
63  return parent::getJsLayout();
64  }
65 
71  private function getCurrentStoreId(): int
72  {
73  return $this->_storeManager->getStore()->getId();
74  }
75 }
__construct(Context $context, Config $instantPurchaseConfig, array $data=[])
Definition: Button.php:31