Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
UpdateProductOptionsObserver.php
Go to the documentation of this file.
1 <?php
7 namespace Magento\Tax\Observer;
8 
10 
12 {
18  protected $taxData;
19 
23  protected $registry;
24 
29  public function __construct(
30  \Magento\Tax\Helper\Data $taxData,
31  \Magento\Framework\Registry $registry
32  ) {
33  $this->taxData = $taxData;
34  $this->registry = $registry;
35  }
36 
43  public function execute(\Magento\Framework\Event\Observer $observer)
44  {
45  $response = $observer->getEvent()->getResponseObject();
46  $options = $response->getAdditionalOptions();
47 
48  $_product = $this->registry->registry('current_product');
49  if (!$_product) {
50  return $this;
51  }
52 
53  $algorithm = $this->taxData->getCalculationAlgorithm();
54  $options['calculationAlgorithm'] = $algorithm;
55  // prepare correct template for options render
56  if ($this->taxData->displayBothPrices()) {
57  $options['optionTemplate'] = sprintf(
58  '<%%= data.label %%>'
59  . '<%% if (data.finalPrice.value) { %%>'
60  . ' +<%%= data.finalPrice.formatted %%> (%1$s <%%= data.basePrice.formatted %%>)'
61  . '<%% } %%>',
62  __('Excl. tax:')
63  );
64  } elseif ($this->taxData->priceIncludesTax() && $this->taxData->displayPriceExcludingTax()) {
65  $options['optionTemplate'] = sprintf(
66  '<%%= data.label %%>'
67  . '<%% if (data.basePrice.value) { %%>'
68  . ' +<%%= data.basePrice.formatted %%>'
69  . '<%% } %%>'
70  );
71  }
72 
73  $response->setAdditionalOptions($options);
74  return $this;
75  }
76 }
$response
Definition: 404.php:11
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
__()
Definition: __.php:13
$_product
Definition: summary.phtml:12
execute(\Magento\Framework\Event\Observer $observer)
__construct(\Magento\Tax\Helper\Data $taxData, \Magento\Framework\Registry $registry)