/**
  * Returns which product price to use as a basis for the Weee's final price
  *
  * @param  int|null $storeId
  * @return string
  */
 protected function getWhichCalcPriceToUse($storeId = null)
 {
     $calcPrice = 'finalPrice';
     if ($this->weeeData->geDisplayExcl($storeId) || $this->weeeData->geDisplayExlDescIncl($storeId) || $this->taxData->priceIncludesTax() && $this->taxData->displayPriceExcludingTax()) {
         $calcPrice = 'basePrice';
     }
     return $calcPrice;
 }
Esempio n. 2
0
 /**
  * Change default JavaScript templates for options rendering
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return $this
  */
 public function updateProductOptions(\Magento\Framework\Event\Observer $observer)
 {
     $response = $observer->getEvent()->getResponseObject();
     $options = $response->getAdditionalOptions();
     /** @var \Magento\Catalog\Model\Product $product */
     $product = $this->_registry->registry('current_product');
     if (!$product) {
         return $this;
     }
     if ($this->_weeeData->isEnabled() && !$this->_weeeData->geDisplayIncl($product->getStoreId()) && !$this->_weeeData->geDisplayExcl($product->getStoreId())) {
         // only do processing on bundle product
         if ($product->getTypeId() == \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE) {
             if (!array_key_exists('optionTemplate', $options)) {
                 $options['optionTemplate'] = '<%- data.label %>' . '<% if (data.finalPrice.value) { %>' . ' +<%- data.finalPrice.formatted %>' . '<% } %>';
             }
             foreach ($this->_weeeData->getWeeAttributesForBundle($product) as $weeAttribute) {
                 $options['optionTemplate'] .= sprintf(' <%% if (data.weeePrice' . $weeAttribute->getCode() . ') { %%>' . '  (' . $weeAttribute->getName() . ':<%%= data.weeePrice' . $weeAttribute->getCode() . '.formatted %%>)' . '<%% } %%>');
             }
             if ($this->_weeeData->geDisplayExlDescIncl($product->getStoreId())) {
                 $options['optionTemplate'] .= sprintf(' <%% if (data.weeePrice) { %%>' . '<%%= data.weeePrice.formatted %%>' . '<%% } %%>');
             }
         }
     }
     $response->setAdditionalOptions($options);
     return $this;
 }