Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Data Class Reference
Inheritance diagram for Data:
AbstractHelper

Public Member Functions

 __construct (\Magento\Framework\App\Helper\Context $context, LayoutFactory $layoutFactory, \Magento\Payment\Model\Method\Factory $paymentMethodFactory, \Magento\Store\Model\App\Emulation $appEmulation, \Magento\Payment\Model\Config $paymentConfig, \Magento\Framework\App\Config\Initial $initialConfig)
 
 getMethodInstance ($code)
 
 getMethodFormBlock (MethodInterface $method, LayoutInterface $layout)
 
 getInfoBlock (InfoInterface $info, LayoutInterface $layout=null)
 
 getInfoBlockHtml (InfoInterface $info, $storeId)
 
 getPaymentMethods ()
 
 getPaymentMethodList ($sorted=true, $asLabelValue=false, $withGroups=false, $store=null)
 
 isZeroSubTotal ($store=null)
 
 getZeroSubTotalOrderStatus ($store=null)
 
 getZeroSubTotalPaymentAutomaticInvoice ($store=null)
 
- Public Member Functions inherited from AbstractHelper
 __construct (Context $context)
 
 isModuleOutputEnabled ($moduleName=null)
 

Data Fields

const XML_PATH_PAYMENT_METHODS = 'payment'
 

Protected Member Functions

 getMethodModelConfigName ($code)
 
- Protected Member Functions inherited from AbstractHelper
 _getRequest ()
 
 _getModuleName ()
 
 _getUrl ($route, $params=[])
 

Protected Attributes

 $_paymentConfig
 
 $_layout
 
 $_methodFactory
 
 $_appEmulation
 
 $_initialConfig
 
- Protected Attributes inherited from AbstractHelper
 $_moduleName
 
 $_request
 
 $_moduleManager
 
 $_logger
 
 $_urlBuilder
 
 $_httpHeader
 
 $_eventManager
 
 $_remoteAddress
 
 $urlEncoder
 
 $urlDecoder
 
 $scopeConfig
 
 $_cacheConfig
 

Detailed Description

Payment module base helper @SuppressWarnings(PHPMD.CouplingBetweenObjects)

@api

Since
100.0.2

Definition at line 25 of file Data.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\App\Helper\Context  $context,
LayoutFactory  $layoutFactory,
\Magento\Payment\Model\Method\Factory  $paymentMethodFactory,
\Magento\Store\Model\App\Emulation  $appEmulation,
\Magento\Payment\Model\Config  $paymentConfig,
\Magento\Framework\App\Config\Initial  $initialConfig 
)

Construct

Parameters
\Magento\Framework\App\Helper\Context$context
LayoutFactory$layoutFactory
\Magento\Payment\Model\Method\Factory$paymentMethodFactory
\Magento\Store\Model\App\Emulation$appEmulation
\Magento\Payment\Model\Config$paymentConfig
\Magento\Framework\App\Config\Initial$initialConfig

Definition at line 70 of file Data.php.

77  {
78  parent::__construct($context);
79  $this->_layout = $layoutFactory->create();
80  $this->_methodFactory = $paymentMethodFactory;
81  $this->_appEmulation = $appEmulation;
82  $this->_paymentConfig = $paymentConfig;
83  $this->_initialConfig = $initialConfig;
84  }

Member Function Documentation

◆ getInfoBlock()

getInfoBlock ( InfoInterface  $info,
LayoutInterface  $layout = null 
)

Retrieve payment information block

Parameters
InfoInterface$info
\Magento\Framework\View\LayoutInterface$layout
Returns
Template

Definition at line 182 of file Data.php.

183  {
184  $layout = $layout ?: $this->_layout;
185  $blockType = $info->getMethodInstance()->getInfoBlockType();
186  $block = $layout->createBlock($blockType);
187  $block->setInfo($info);
188  return $block;
189  }
$block
Definition: block.php:8
foreach( $_productCollection as $_product)() ?>" class $info
Definition: listing.phtml:52

◆ getInfoBlockHtml()

getInfoBlockHtml ( InfoInterface  $info,
  $storeId 
)

Render payment information block

Parameters
InfoInterface$info
int$storeId
Returns
string
Exceptions

Definition at line 199 of file Data.php.

200  {
201  $this->_appEmulation->startEnvironmentEmulation($storeId);
202 
203  try {
204  // Retrieve specified view block from appropriate design package (depends on emulated store)
205  $paymentBlock = $this->getInfoBlock($info);
206  $paymentBlock->setArea(\Magento\Framework\App\Area::AREA_FRONTEND)
207  ->setIsSecureMode(true);
208  $paymentBlock->getMethod()
209  ->setStore($storeId);
210  $paymentBlockHtml = $paymentBlock->toHtml();
211  } catch (\Exception $exception) {
212  $this->_appEmulation->stopEnvironmentEmulation();
213  throw $exception;
214  }
215 
216  $this->_appEmulation->stopEnvironmentEmulation();
217 
218  return $paymentBlockHtml;
219  }
getInfoBlock(InfoInterface $info, LayoutInterface $layout=null)
Definition: Data.php:182
foreach( $_productCollection as $_product)() ?>" class $info
Definition: listing.phtml:52

◆ getMethodFormBlock()

getMethodFormBlock ( MethodInterface  $method,
LayoutInterface  $layout 
)

Retrieve payment method form html

Parameters
MethodInterface$method
LayoutInterface$layout
Returns
Form

Definition at line 168 of file Data.php.

169  {
170  $block = $layout->createBlock($method->getFormBlockType(), $method->getCode());
171  $block->setMethod($method);
172  return $block;
173  }
$block
Definition: block.php:8
$method
Definition: info.phtml:13

◆ getMethodInstance()

getMethodInstance (   $code)

Retrieve method model object

Parameters
string$code
Exceptions

Definition at line 103 of file Data.php.

104  {
105  $class = $this->scopeConfig->getValue(
108  );
109 
110  if (!$class) {
111  throw new \UnexpectedValueException('Payment model name is not provided in config!');
112  }
113 
114  return $this->_methodFactory->create($class);
115  }
$_option $_optionId $class
Definition: date.phtml:13
getMethodModelConfigName($code)
Definition: Data.php:90
$code
Definition: info.phtml:12

◆ getMethodModelConfigName()

getMethodModelConfigName (   $code)
protected
Parameters
string$code
Returns
string

Definition at line 90 of file Data.php.

91  {
92  return sprintf('%s/%s/model', self::XML_PATH_PAYMENT_METHODS, $code);
93  }
$code
Definition: info.phtml:12

◆ getPaymentMethodList()

getPaymentMethodList (   $sorted = true,
  $asLabelValue = false,
  $withGroups = false,
  $store = null 
)

Retrieve all payment methods list as an array

Possible output: 1) assoc array as => <title> 2) array of array('label' => <title>, 'value' => ) 3) array of array( array('value' => , 'label' => <title>), array('value' => array( 'value' => array(array(<code1> => <title1>, <code2> =>...), 'label' => <group name>=""> )), array('value' => , 'label' => <title>), ... )

Parameters
bool$sorted
bool$asLabelValue
bool$withGroups
Store | null$store
Returns
array @SuppressWarnings(PHPMD.CyclomaticComplexity) @SuppressWarnings(PHPMD.NPathComplexity)

Definition at line 255 of file Data.php.

256  {
257  $methods = [];
258  $groups = [];
259  $groupRelations = [];
260 
261  foreach ($this->getPaymentMethods() as $code => $data) {
262  if (isset($data['title'])) {
263  $methods[$code] = $data['title'];
264  } else {
265  $methods[$code] = $this->getMethodInstance($code)->getConfigData('title', $store);
266  }
267  if ($asLabelValue && $withGroups && isset($data['group'])) {
268  $groupRelations[$code] = $data['group'];
269  }
270  }
271  if ($asLabelValue && $withGroups) {
272  $groups = $this->_paymentConfig->getGroups();
273  foreach ($groups as $code => $title) {
274  $methods[$code] = $title;
275  }
276  }
277  if ($sorted) {
278  asort($methods);
279  }
280  if ($asLabelValue) {
281  $labelValues = [];
282  foreach ($methods as $code => $title) {
283  $labelValues[$code] = [];
284  }
285  foreach ($methods as $code => $title) {
286  if (isset($groups[$code])) {
287  $labelValues[$code]['label'] = $title;
288  if (!isset($labelValues[$code]['value'])) {
289  $labelValues[$code]['value'] = null;
290  }
291  } elseif (isset($groupRelations[$code])) {
292  unset($labelValues[$code]);
293  $labelValues[$groupRelations[$code]]['value'][$code] = ['value' => $code, 'label' => $title];
294  } else {
295  $labelValues[$code] = ['value' => $code, 'label' => $title];
296  }
297  }
298  return $labelValues;
299  }
300 
301  return $methods;
302  }
$title
Definition: default.phtml:14
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$methods
Definition: billing.phtml:71
$code
Definition: info.phtml:12

◆ getPaymentMethods()

getPaymentMethods ( )

Retrieve all payment methods

Returns
array

Definition at line 226 of file Data.php.

227  {
228  return $this->_initialConfig->getData('default')[self::XML_PATH_PAYMENT_METHODS];
229  }
const XML_PATH_PAYMENT_METHODS
Definition: Data.php:27

◆ getZeroSubTotalOrderStatus()

getZeroSubTotalOrderStatus (   $store = null)

Returns value of Zero Subtotal Checkout / New Order Status

Parameters
null | string | bool | int | Store$store
Returns
string

Definition at line 325 of file Data.php.

326  {
327  return $this->scopeConfig->getValue(
328  \Magento\Payment\Model\Method\Free::XML_PATH_PAYMENT_FREE_ORDER_STATUS,
330  $store
331  );
332  }

◆ getZeroSubTotalPaymentAutomaticInvoice()

getZeroSubTotalPaymentAutomaticInvoice (   $store = null)

Returns value of Zero Subtotal Checkout / Automatically Invoice All Items

Parameters
null | string | bool | int | Store$store
Returns
string

Definition at line 340 of file Data.php.

341  {
342  return $this->scopeConfig->getValue(
343  \Magento\Payment\Model\Method\Free::XML_PATH_PAYMENT_FREE_PAYMENT_ACTION,
345  $store
346  );
347  }

◆ isZeroSubTotal()

isZeroSubTotal (   $store = null)

Returns value of Zero Subtotal Checkout / Enabled

Parameters
null | string | bool | int | Store$store
Returns
bool

Definition at line 310 of file Data.php.

311  {
312  return $this->scopeConfig->getValue(
313  \Magento\Payment\Model\Method\Free::XML_PATH_PAYMENT_FREE_ACTIVE,
315  $store
316  );
317  }

Field Documentation

◆ $_appEmulation

$_appEmulation
protected

Definition at line 53 of file Data.php.

◆ $_initialConfig

$_initialConfig
protected

Definition at line 58 of file Data.php.

◆ $_layout

$_layout
protected

Definition at line 39 of file Data.php.

◆ $_methodFactory

$_methodFactory
protected

Definition at line 46 of file Data.php.

◆ $_paymentConfig

$_paymentConfig
protected

Definition at line 32 of file Data.php.

◆ XML_PATH_PAYMENT_METHODS

const XML_PATH_PAYMENT_METHODS = 'payment'

Definition at line 27 of file Data.php.


The documentation for this class was generated from the following file: