Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Render.php
Go to the documentation of this file.
1 <?php
8 
14 
24 class Render extends AbstractBlock
25 {
29  const ZONE_ITEM_VIEW = 'item_view';
30  const ZONE_ITEM_LIST = 'item_list';
31  const ZONE_ITEM_OPTION = 'item_option';
32  const ZONE_SALES = 'sales';
33  const ZONE_EMAIL = 'email';
34  const ZONE_CART = 'cart';
35  const ZONE_DEFAULT = null;
39  protected $defaultTypeRender = 'default';
40 
46  protected $priceLayout;
47 
55  public function __construct(
56  Template\Context $context,
58  array $data = []
59  ) {
60  $this->priceLayout = $priceLayout;
61  parent::__construct($context, $data);
62  }
63 
69  protected function _prepareLayout()
70  {
71  $this->priceLayout->addHandle($this->getPriceRenderHandle());
72  $this->priceLayout->loadLayout();
73  return parent::_prepareLayout();
74  }
75 
86  public function render($priceCode, SaleableInterface $saleableItem, array $arguments = [])
87  {
88  $useArguments = array_replace($this->_data, $arguments);
89 
91  $rendererPool = $this->priceLayout->getBlock('render.product.prices');
92  if (!$rendererPool) {
93  throw new \RuntimeException('Wrong Price Rendering layout configuration. Factory block is missed');
94  }
95 
96  // obtain concrete Price Render
97  $priceRender = $rendererPool->createPriceRender($priceCode, $saleableItem, $useArguments);
98  return $priceRender->toHtml();
99  }
100 
111  public function renderAmount(
112  AmountInterface $amount,
113  PriceInterface $price,
114  SaleableInterface $saleableItem = null,
115  array $arguments = []
116  ) {
117  $useArguments = array_replace($this->_data, $arguments);
118 
120  $rendererPool = $this->priceLayout->getBlock('render.product.prices');
121  if (!$rendererPool) {
122  throw new \RuntimeException('Wrong Price Rendering layout configuration. Factory block is missed');
123  }
124 
125  // obtain concrete Amount Render
126  $amountRender = $rendererPool->createAmountRender($amount, $saleableItem, $price, $useArguments);
127  return $amountRender->toHtml();
128  }
129 }
$price
__construct(Template\Context $context, Layout $priceLayout, array $data=[])
Definition: Render.php:55
$amount
Definition: order.php:14
$arguments