Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
PriceBox Class Reference
Inheritance diagram for PriceBox:
Template PriceBoxRenderInterface IdentityInterface AbstractBlock DataObject BlockInterface FinalPriceBox PriceBox FinalPriceBox ConfiguredPriceBox FinalPriceBox ConfiguredPriceBox TierPriceBox

Public Member Functions

 __construct (Template\Context $context, SaleableInterface $saleableItem, PriceInterface $price, RendererPool $rendererPool, array $data=[])
 
 getCacheKey ()
 
 getSaleableItem ()
 
 getPrice ()
 
 getPriceId ($defaultPrefix=null, $defaultSuffix=null)
 
 getPriceType ($priceCode)
 
 renderAmount (AmountInterface $amount, array $arguments=[])
 
 getRendererPool ()
 
 getIdentities ()
 
- Public Member Functions inherited from Template
 __construct (Template\Context $context, array $data=[])
 
 setTemplateContext ($templateContext)
 
 getTemplate ()
 
 setTemplate ($template)
 
 getTemplateFile ($template=null)
 
 getArea ()
 
 assign ($key, $value=null)
 
 fetchView ($fileName)
 
 getBaseUrl ()
 
 getObjectData (\Magento\Framework\DataObject $object, $key)
 
 getCacheKeyInfo ()
 
- Public Member Functions inherited from AbstractBlock
 __construct (\Magento\Framework\View\Element\Context $context, array $data=[])
 
 getJsLayout ()
 
 getRequest ()
 
 getParentBlock ()
 
 setLayout (\Magento\Framework\View\LayoutInterface $layout)
 
 getLayout ()
 
 setNameInLayout ($name)
 
 getChildNames ()
 
 setAttribute ($name, $value=null)
 
 setChild ($alias, $block)
 
 addChild ($alias, $block, $data=[])
 
 unsetChild ($alias)
 
 unsetCallChild ($alias, $callback, $result, $params)
 
 unsetChildren ()
 
 getChildBlock ($alias)
 
 getChildHtml ($alias='', $useCache=true)
 
 getChildChildHtml ($alias, $childChildAlias='', $useCache=true)
 
 getBlockHtml ($name)
 
 insert ($element, $siblingName=0, $after=true, $alias='')
 
 append ($element, $alias='')
 
 getGroupChildNames ($groupName)
 
 getChildData ($alias, $key='')
 
 getUiId ($arg1=null, $arg2=null, $arg3=null, $arg4=null, $arg5=null)
 
 getJsId ($arg1=null, $arg2=null, $arg3=null, $arg4=null, $arg5=null)
 
 getUrl ($route='', $params=[])
 
 getViewFileUrl ($fileId, array $params=[])
 
 formatDate ( $date=null, $format=\IntlDateFormatter::SHORT, $showTime=false, $timezone=null)
 
 formatTime ( $time=null, $format=\IntlDateFormatter::SHORT, $showDate=false)
 
 getModuleName ()
 
 escapeHtml ($data, $allowedTags=null)
 
 escapeJs ($string)
 
 escapeHtmlAttr ($string, $escapeSingleQuote=true)
 
 escapeCss ($string)
 
 stripTags ($data, $allowableTags=null, $allowHtmlEntities=false)
 
 escapeUrl ($string)
 
 escapeXssInUrl ($data)
 
 escapeQuote ($data, $addSlashes=false)
 
 escapeJsQuote ($data, $quote='\'')
 
 getNameInLayout ()
 
 getCacheKeyInfo ()
 
 getCacheKey ()
 
 getVar ($name, $module=null)
 
 isScopePrivate ()
 
- Public Member Functions inherited from DataObject
 __construct (array $data=[])
 
 addData (array $arr)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 getDataByPath ($path)
 
 getDataByKey ($key)
 
 setDataUsingMethod ($key, $args=[])
 
 getDataUsingMethod ($key, $args=null)
 
 hasData ($key='')
 
 toArray (array $keys=[])
 
 convertToArray (array $keys=[])
 
 toXml (array $keys=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 convertToXml (array $arrAttributes=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 toJson (array $keys=[])
 
 convertToJson (array $keys=[])
 
 toString ($format='')
 
 __call ($method, $args)
 
 isEmpty ()
 
 serialize ($keys=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
 
 debug ($data=null, &$objects=[])
 
 offsetSet ($offset, $value)
 
 offsetExists ($offset)
 
 offsetUnset ($offset)
 
 offsetGet ($offset)
 
- Public Member Functions inherited from BlockInterface
 toHtml ()
 

Data Fields

const DEFAULT_LIFETIME = 3600
 
- Data Fields inherited from Template
const XML_PATH_TEMPLATE_ALLOW_SYMLINK = 'dev/template/allow_symlink'
 
- Data Fields inherited from AbstractBlock
const CACHE_GROUP = \Magento\Framework\App\Cache\Type\Block::TYPE_IDENTIFIER
 
const CACHE_KEY_PREFIX = 'BLOCK_'
 

Protected Member Functions

 _toHtml ()
 
 getCacheLifetime ()
 
 getAmountRender (AmountInterface $amount, array $arguments=[])
 
- Protected Member Functions inherited from Template
 _construct ()
 
 _toHtml ()
 
 getRootDirectory ()
 
 getMediaDirectory ()
 
- Protected Member Functions inherited from AbstractBlock
 _construct ()
 
 _prepareLayout ()
 
 _beforeToHtml ()
 
 _afterToHtml ($html)
 
 _toHtml ()
 
 _getNotFoundUrl ($route='', $params=['_direct'=> 'core/index/notFound'])
 
 getCacheTags ()
 
 getCacheLifetime ()
 
 _loadCache ()
 
 _saveCache ($data)
 
 _getSidPlaceholder ($cacheKey=null)
 
- Protected Member Functions inherited from DataObject
 _getData ($key)
 
 _underscore ($name)
 

Protected Attributes

 $saleableItem
 
 $price
 
 $rendererPool
 
- Protected Attributes inherited from Template
 $_viewVars = []
 
 $_baseUrl
 
 $_jsUrl
 
 $_allowSymlinks
 
 $_filesystem
 
 $_template
 
 $templateEnginePool
 
 $_storeManager
 
 $_appState
 
 $directory
 
 $templateContext
 
 $pageConfig
 
 $resolver
 
 $validator
 
- Protected Attributes inherited from AbstractBlock
 $_design
 
 $_session
 
 $_sidResolver
 
 $_nameInLayout
 
 $_layout
 
 $jsLayout = []
 
 $_request
 
 $_urlBuilder
 
 $_eventManager
 
 $_frontController
 
 $_assetRepo
 
 $_viewConfig
 
 $_cacheState
 
 $_logger
 
 $_escaper
 
 $filterManager
 
 $_localeDate
 
 $inlineTranslation
 
 $_isScopePrivate = false
 
 $_scopeConfig
 
 $_cache
 
- Protected Attributes inherited from DataObject
 $_data = []
 

Additional Inherited Members

- Static Public Member Functions inherited from AbstractBlock
static extractModuleName ($className)
 
- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

Default price box renderer

@method bool hasListClass() @method string getListClass()

Definition at line 21 of file PriceBox.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( Template\Context  $context,
SaleableInterface  $saleableItem,
PriceInterface  $price,
RendererPool  $rendererPool,
array  $data = [] 
)
Parameters
Template\Context$context
SaleableInterface$saleableItem
PriceInterface$price
RendererPool$rendererPool
array$data

Definition at line 48 of file PriceBox.php.

54  {
55  $this->saleableItem = $saleableItem;
56  $this->price = $price;
57  $this->rendererPool = $rendererPool;
58  parent::__construct($context, $data);
59  }

Member Function Documentation

◆ _toHtml()

_toHtml ( )
protected
Returns
string

Definition at line 64 of file PriceBox.php.

65  {
66  $cssClasses = $this->hasData('css_classes') ? explode(' ', $this->getData('css_classes')) : [];
67  $cssClasses[] = 'price-' . $this->getPrice()->getPriceCode();
68  $this->setData('css_classes', implode(' ', $cssClasses));
69  return parent::_toHtml();
70  }
getData($key='', $index=null)
Definition: DataObject.php:119
setData($key, $value=null)
Definition: DataObject.php:72

◆ getAmountRender()

getAmountRender ( AmountInterface  $amount,
array  $arguments = [] 
)
protected
Parameters
AmountInterface$amount
array$arguments
Returns
AmountRenderInterface

Definition at line 156 of file PriceBox.php.

157  {
158  return $this->rendererPool->createAmountRender(
159  $amount,
160  $this->getSaleableItem(),
161  $this->getPrice(),
162  $arguments
163  );
164  }
$amount
Definition: order.php:14
$arguments

◆ getCacheKey()

getCacheKey ( )

Get Key for caching block content

Returns
string

Definition at line 77 of file PriceBox.php.

78  {
79  return parent::getCacheKey() . '-' . $this->getPriceId() . '-' . $this->getPrice()->getPriceCode();
80  }
getPriceId($defaultPrefix=null, $defaultSuffix=null)
Definition: PriceBox.php:115

◆ getCacheLifetime()

getCacheLifetime ( )
protected

Get block cache life time

Returns
int

Definition at line 87 of file PriceBox.php.

88  {
89  return parent::hasCacheLifetime() ? parent::getCacheLifetime() : null;
90  }

◆ getIdentities()

getIdentities ( )

Return unique ID(s) for each object in system

Returns
array

Implements IdentityInterface.

Definition at line 179 of file PriceBox.php.

180  {
181  $item = $this->getSaleableItem();
182  if ($item instanceof IdentityInterface) {
183  return $item->getIdentities();
184  } else {
185  return [];
186  }
187  }

◆ getPrice()

getPrice ( )
Returns
PriceInterface

Implements PriceBoxRenderInterface.

Definition at line 103 of file PriceBox.php.

104  {
105  return $this->price;
106  }

◆ getPriceId()

getPriceId (   $defaultPrefix = null,
  $defaultSuffix = null 
)

Get price id

Parameters
null | string$defaultPrefix
null | string$defaultSuffix
Returns
string

Definition at line 115 of file PriceBox.php.

116  {
117  if ($this->hasData('price_id')) {
118  return $this->getData('price_id');
119  }
120  $priceId = $this->saleableItem->getId();
121  $prefix = $this->hasData('price_id_prefix') ? $this->getData('price_id_prefix') : $defaultPrefix;
122  $suffix = $this->hasData('price_id_suffix') ? $this->getData('price_id_suffix') : $defaultSuffix;
123  $priceId = $prefix . $priceId . $suffix;
124  return $priceId;
125  }
$suffix
Definition: name.phtml:27
getData($key='', $index=null)
Definition: DataObject.php:119
$prefix
Definition: name.phtml:25

◆ getPriceType()

getPriceType (   $priceCode)

Retrieve price object of given type and quantity

Parameters
string$priceCode
Returns
PriceInterface

Definition at line 133 of file PriceBox.php.

134  {
135  return $this->saleableItem->getPriceInfo()->getPrice($priceCode);
136  }

◆ getRendererPool()

getRendererPool ( )
Returns
RendererPool

Definition at line 169 of file PriceBox.php.

◆ getSaleableItem()

getSaleableItem ( )
Returns
SaleableInterface

Implements PriceBoxRenderInterface.

Definition at line 95 of file PriceBox.php.

◆ renderAmount()

renderAmount ( AmountInterface  $amount,
array  $arguments = [] 
)
Parameters
AmountInterface$amount
array$arguments
Returns
string

Implements PriceBoxRenderInterface.

Definition at line 143 of file PriceBox.php.

144  {
145  $arguments = array_replace($this->getData(), $arguments);
146 
147  //@TODO AmountInterface does not contain toHtml() method
148  return $this->getAmountRender($amount, $arguments)->toHtml();
149  }
getData($key='', $index=null)
Definition: DataObject.php:119
$amount
Definition: order.php:14
getAmountRender(AmountInterface $amount, array $arguments=[])
Definition: PriceBox.php:156
$arguments

Field Documentation

◆ $price

$price
protected

Definition at line 34 of file PriceBox.php.

◆ $rendererPool

$rendererPool
protected

Definition at line 39 of file PriceBox.php.

◆ $saleableItem

$saleableItem
protected

Definition at line 29 of file PriceBox.php.

◆ DEFAULT_LIFETIME

const DEFAULT_LIFETIME = 3600

Default block lifetime

Definition at line 24 of file PriceBox.php.


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