Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Shortcut.php
Go to the documentation of this file.
1 <?php
8 
11 
13 {
19  protected $_shouldRender = true;
20 
26  private $_paymentMethodCode = '';
27 
33  private $_alias = '';
34 
40  private $_startAction = '';
41 
45  private $_paymentData;
46 
50  private $_mathRandom;
51 
57  private $_bmlMethodCode = '';
58 
62  const SHORTCUT_IMAGE = 'https://www.paypalobjects.com/webstatic/en_US/i/buttons/ppcredit-logo-medium.png';
63 
67  private $_shortcutValidator;
68 
82  public function __construct(
83  \Magento\Framework\View\Element\Template\Context $context,
84  \Magento\Payment\Helper\Data $paymentData,
85  \Magento\Framework\Math\Random $mathRandom,
86  ValidatorInterface $shortcutValidator,
87  $paymentMethodCode,
88  $startAction,
89  $alias,
90  $bmlMethodCode,
91  $shortcutTemplate,
92  array $data = []
93  ) {
94  $this->_paymentData = $paymentData;
95  $this->_mathRandom = $mathRandom;
96  $this->_shortcutValidator = $shortcutValidator;
97 
98  $this->_paymentMethodCode = $paymentMethodCode;
99  $this->_startAction = $startAction;
100  $this->_alias = $alias;
101  $this->setTemplate($shortcutTemplate);
102  $this->_bmlMethodCode = $bmlMethodCode;
103  parent::__construct($context, $data);
104  }
105 
109  protected function _beforeToHtml()
110  {
111  $result = parent::_beforeToHtml();
112  $isInCatalog = $this->getIsInCatalogProduct();
113  if (!$this->_shortcutValidator->validate($this->_paymentMethodCode, $isInCatalog)) {
114  $this->_shouldRender = false;
115  return $result;
116  }
117 
119  $method = $this->_paymentData->getMethodInstance($this->_bmlMethodCode);
120  if (!$method->isAvailable()) {
121  $this->_shouldRender = false;
122  return $result;
123  }
124 
125  $this->setShortcutHtmlId($this->_mathRandom->getUniqueHash('ec_shortcut_bml_'))
126  ->setCheckoutUrl($this->getUrl($this->_startAction))
127  ->setImageUrl(self::SHORTCUT_IMAGE)
128  ->setAdditionalLinkImage(
129  [
130  'href' => 'https://www.securecheckout.billmelater.com/paycapture-content/'
131  . 'fetch?hash=AU826TU8&content=/bmlweb/ppwpsiw.html',
132  'src' => 'https://www.paypalobjects.com/webstatic/en_US/btn/btn_bml_text.png',
133  ]
134  );
135 
136  return $result;
137  }
138 
144  protected function _toHtml()
145  {
146  if (!$this->_shouldRender) {
147  return '';
148  }
149  return parent::_toHtml();
150  }
151 
157  public function isOrPositionBefore()
158  {
159  return $this->getShowOrPosition() == CatalogBlock\ShortcutButtons::POSITION_BEFORE;
160  }
161 
167  public function isOrPositionAfter()
168  {
169  return $this->getShowOrPosition() == CatalogBlock\ShortcutButtons::POSITION_AFTER;
170  }
171 
177  public function getAlias()
178  {
179  return $this->_alias;
180  }
181 }
__construct(\Magento\Framework\View\Element\Template\Context $context, \Magento\Payment\Helper\Data $paymentData, \Magento\Framework\Math\Random $mathRandom, ValidatorInterface $shortcutValidator, $paymentMethodCode, $startAction, $alias, $bmlMethodCode, $shortcutTemplate, array $data=[])
Definition: Shortcut.php:82
$method
Definition: info.phtml:13
if(!trim($html)) $alias
Definition: details.phtml:20