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 
16 
20 class Button extends Template implements ShortcutInterface
21 {
22  const ALIAS_ELEMENT_INDEX = 'alias';
23 
24  const BUTTON_ELEMENT_INDEX = 'button_id';
25 
29  private $localeResolver;
30 
34  private $checkoutSession;
35 
39  private $config;
40 
44  private $configProvider;
45 
49  private $payment;
50 
62  public function __construct(
63  Context $context,
64  ResolverInterface $localeResolver,
65  Session $checkoutSession,
66  Config $config,
67  ConfigProvider $configProvider,
68  MethodInterface $payment,
69  array $data = []
70  ) {
71  parent::__construct($context, $data);
72 
73  $this->localeResolver = $localeResolver;
74  $this->checkoutSession = $checkoutSession;
75  $this->config = $config;
76  $this->configProvider = $configProvider;
77  $this->payment = $payment;
78  }
79 
83  protected function _toHtml()
84  {
85  if ($this->isActive()) {
86  return parent::_toHtml();
87  }
88 
89  return '';
90  }
91 
95  public function getAlias()
96  {
97  return $this->getData(self::ALIAS_ELEMENT_INDEX);
98  }
99 
103  public function getContainerId()
104  {
105  return $this->getData(self::BUTTON_ELEMENT_INDEX);
106  }
107 
111  public function getLocale()
112  {
113  return $this->localeResolver->getLocale();
114  }
115 
119  public function getCurrency()
120  {
121  return $this->checkoutSession->getQuote()->getCurrency()->getBaseCurrencyCode();
122  }
123 
127  public function getAmount()
128  {
129  return $this->checkoutSession->getQuote()->getBaseGrandTotal();
130  }
131 
135  public function isActive()
136  {
137  return $this->payment->isAvailable($this->checkoutSession->getQuote()) &&
138  $this->config->isDisplayShoppingCart();
139  }
140 
144  public function getMerchantName()
145  {
146  return $this->config->getMerchantName();
147  }
148 
152  public function getClientToken()
153  {
154  return $this->configProvider->getClientToken();
155  }
156 
160  public function getActionSuccess()
161  {
162  return $this->getUrl(ConfigProvider::CODE . '/paypal/review', ['_secure' => true]);
163  }
164 }
getData($key='', $index=null)
Definition: DataObject.php:119
$config
Definition: fraud_order.php:17
__construct(Context $context, ResolverInterface $localeResolver, Session $checkoutSession, Config $config, ConfigProvider $configProvider, MethodInterface $payment, array $data=[])
Definition: Button.php:62
$payment
Definition: order.php:17