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

Public Member Functions

 __construct (\Magento\Framework\App\Helper\Context $context, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Sales\Model\Config $salesConfig, \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency, \Magento\Framework\Escaper $escaper)
 
 displayPriceAttribute ($dataObject, $code, $strong=false, $separator='< br/>')
 
 displayPrices ($dataObject, $basePrice, $price, $strong=false, $separator='< br/>')
 
 applySalableProductTypesFilter ($collection)
 
 escapeHtmlWithLinks ($data, $allowedTags=null)
 
- Public Member Functions inherited from AbstractHelper
 __construct (Context $context)
 
 isModuleOutputEnabled ($moduleName=null)
 

Protected Attributes

 $_salesConfig
 
 $_storeManager
 
 $priceCurrency
 
 $escaper
 
- Protected Attributes inherited from AbstractHelper
 $_moduleName
 
 $_request
 
 $_moduleManager
 
 $_logger
 
 $_urlBuilder
 
 $_httpHeader
 
 $_eventManager
 
 $_remoteAddress
 
 $urlEncoder
 
 $urlDecoder
 
 $scopeConfig
 
 $_cacheConfig
 

Additional Inherited Members

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

Detailed Description

Sales admin helper.

Definition at line 13 of file Admin.php.

Constructor & Destructor Documentation

◆ __construct()

Parameters
\Magento\Framework\App\Helper\Context$context
\Magento\Store\Model\StoreManagerInterface$storeManager
\Magento\Sales\Model\Config$salesConfig
\Magento\Framework\Pricing\PriceCurrencyInterface$priceCurrency
\Magento\Framework\Escaper$escaper

Definition at line 42 of file Admin.php.

48  {
49  $this->priceCurrency = $priceCurrency;
50  $this->_storeManager = $storeManager;
51  $this->_salesConfig = $salesConfig;
52  $this->escaper = $escaper;
53  parent::__construct($context);
54  }
$storeManager

Member Function Documentation

◆ applySalableProductTypesFilter()

applySalableProductTypesFilter (   $collection)

Filter collection by removing not available product types

Parameters
\Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection$collection
Returns
\Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection

Definition at line 123 of file Admin.php.

124  {
125  $productTypes = $this->_salesConfig->getAvailableProductTypes();
126  foreach ($collection->getItems() as $key => $item) {
127  if ($item instanceof \Magento\Catalog\Model\Product) {
128  $type = $item->getTypeId();
129  } elseif ($item instanceof \Magento\Sales\Model\Order\Item) {
130  $type = $item->getProductType();
131  } elseif ($item instanceof \Magento\Quote\Model\Quote\Item) {
132  $type = $item->getProductType();
133  } else {
134  $type = '';
135  }
136  if (!in_array($type, $productTypes)) {
137  $collection->removeItemByKey($key);
138  }
139  }
140  return $collection;
141  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$type
Definition: item.phtml:13

◆ displayPriceAttribute()

displayPriceAttribute (   $dataObject,
  $code,
  $strong = false,
  $separator = '<br/>' 
)

Display price attribute value in base order currency and in place order currency

Parameters
\Magento\Framework\DataObject$dataObject
string$code
bool$strong
string$separator
Returns
string

Definition at line 65 of file Admin.php.

66  {
67  // Fix for 'bs_customer_bal_total_refunded' attribute
68  $baseValue = $dataObject->hasData('bs_' . $code)
69  ? $dataObject->getData('bs_' . $code)
70  : $dataObject->getData('base_' . $code);
71  return $this->displayPrices(
72  $dataObject,
73  $baseValue,
74  $dataObject->getData($code),
75  $strong,
76  $separator
77  );
78  }
displayPrices($dataObject, $basePrice, $price, $strong=false, $separator='< br/>')
Definition: Admin.php:90
$code
Definition: info.phtml:12

◆ displayPrices()

displayPrices (   $dataObject,
  $basePrice,
  $price,
  $strong = false,
  $separator = '<br/>' 
)

Get "double" prices html (block with base and place currency)

Parameters
\Magento\Framework\DataObject$dataObject
float$basePrice
float$price
bool$strong
string$separator
Returns
string

Definition at line 90 of file Admin.php.

91  {
92  if ($dataObject instanceof \Magento\Sales\Model\Order) {
93  $order = $dataObject;
94  } else {
95  $order = $dataObject->getOrder();
96  }
97 
98  if ($order && $order->isCurrencyDifferent()) {
99  $res = '<strong>';
100  $res .= $order->formatBasePrice($basePrice);
101  $res .= '</strong>' . $separator;
102  $res .= '[' . $order->formatPrice($price) . ']';
103  } elseif ($order) {
104  $res = $order->formatPrice($price);
105  if ($strong) {
106  $res = '<strong>' . $res . '</strong>';
107  }
108  } else {
109  $res = $this->priceCurrency->format($price);
110  if ($strong) {
111  $res = '<strong>' . $res . '</strong>';
112  }
113  }
114  return $res;
115  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$order
Definition: order.php:55
$price

◆ escapeHtmlWithLinks()

escapeHtmlWithLinks (   $data,
  $allowedTags = null 
)

Escape string preserving links

Parameters
string$data
null | array$allowedTags
Returns
string

Definition at line 150 of file Admin.php.

151  {
152  if (!empty($data) && is_array($allowedTags) && in_array('a', $allowedTags)) {
153  $links = [];
154  $i = 1;
155  $data = str_replace('%', '%%', $data);
156  $regexp = "#(?J)<a"
157  ."(?:(?:\s+(?:(?:href\s*=\s*(['\"])(?<link>.*?)\\1\s*)|(?:\S+\s*=\s*(['\"])(.*?)\\3)\s*)*)|>)"
158  .">?(?:(?:(?<text>.*?)(?:<\/a\s*>?|(?=<\w))|(?<text>.*)))#si";
159  while (preg_match($regexp, $data, $matches)) {
160  $text = '';
161  if (!empty($matches['text'])) {
162  $text = str_replace('%%', '%', $matches['text']);
163  }
164  $url = $this->filterUrl($matches['link'] ?? '');
165  //Recreate a minimalistic secure a tag
166  $links[] = sprintf(
167  '<a href="%s">%s</a>',
168  htmlspecialchars($url, ENT_QUOTES, 'UTF-8', false),
169  $this->escaper->escapeHtml($text)
170  );
171  $data = str_replace($matches[0], '%' . $i . '$s', $data);
172  ++$i;
173  }
174  $data = $this->escaper->escapeHtml($data, $allowedTags);
175  return vsprintf($data, $links);
176  }
177  return $this->escaper->escapeHtml($data, $allowedTags);
178  }
endifif( $block->getLastPageNum()>1)( 'Page') ?></strong >< ul class $text
Definition: pager.phtml:43
$i
Definition: gallery.phtml:31

Field Documentation

◆ $_salesConfig

$_salesConfig
protected

Definition at line 18 of file Admin.php.

◆ $_storeManager

$_storeManager
protected

Definition at line 23 of file Admin.php.

◆ $escaper

$escaper
protected

Definition at line 33 of file Admin.php.

◆ $priceCurrency

$priceCurrency
protected

Definition at line 28 of file Admin.php.


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