Esempio n. 1
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;
 }
Esempio n. 2
0
 public function testGetWeeAttributesForBundle()
 {
     $weeObject = new \Magento\Framework\Object(['code' => 'fpt', 'amount' => '15.0000']);
     $testArray = ['fpt' => $weeObject];
     $this->weeeTax->expects($this->any())->method('getProductWeeeAttributes')->will($this->returnValue([$weeObject]));
     $productSimple = $this->getMock('\\Magento\\Catalog\\Model\\Product\\Type\\Simple', [], [], '', false);
     $productInstance = $this->getMock('\\Magento\\Bundle\\Model\\Product\\Type', [], [], '', false);
     $productInstance->expects($this->any())->method('getSelectionsCollection')->will($this->returnValue([$productSimple]));
     $store = $this->getMock('\\Magento\\Store\\Model\\Store', [], [], '', false);
     $product = $this->getMock('\\Magento\\Bundle\\Model\\Product', ['getTypeInstance', 'getStoreId', 'getStore', 'getTypeId'], [], '', false);
     $product->expects($this->any())->method('getTypeInstance')->will($this->returnValue($productInstance));
     $product->expects($this->any())->method('getStoreId')->will($this->returnValue(1));
     $product->expects($this->any())->method('getStore')->will($this->returnValue($store));
     $product->expects($this->any())->method('getTypeId')->will($this->returnValue('bundle'));
     $registry = $this->getMock('Magento\\Framework\\Registry', [], [], '', false);
     $registry->expects($this->any())->method('registry')->with('current_product')->will($this->returnValue($product));
     $this->assertEquals($testArray, $this->_helperData->getWeeAttributesForBundle($product));
 }