/**
  * test method testGetOptionValueModified with option is_percent = false
  */
 public function testGetOptionValueModifiedIsNotPercent()
 {
     $this->saleableItemMock->expects($this->once())->method('setParentId')->with($this->equalTo(true))->will($this->returnValue($this->returnSelf()));
     $this->priceModifier->expects($this->once())->method('modifyPrice')->with($this->equalTo(77.33), $this->equalTo($this->saleableItemMock))->will($this->returnValue(77.67));
     $this->calculatorMock->expects($this->once())->method('getAmount')->with($this->equalTo(77.67), $this->equalTo($this->saleableItemMock), null, [\Magento\Catalog\Pricing\Price\CustomOptionPriceInterface::CONFIGURATION_OPTION_FLAG => true])->will($this->returnValue(80.98999999999999));
     $this->assertEquals(80.98999999999999, $this->attribute->getOptionValueModified(['is_percent' => false, 'pricing_value' => 77.33]));
 }
Example #2
0
 /**
  * test method testGetOptionValueModified with option is_percent = false
  */
 public function testGetOptionValueModifiedIsNotPercent()
 {
     $this->saleableItemMock->expects($this->once())->method('setParentId')->with($this->equalTo(true))->will($this->returnValue($this->returnSelf()));
     $this->priceModifier->expects($this->once())->method('modifyPrice')->with($this->equalTo(77.33), $this->equalTo($this->saleableItemMock))->will($this->returnValue(77.67));
     $this->calculatorMock->expects($this->once())->method('getAmount')->with($this->equalTo(77.67), $this->equalTo($this->saleableItemMock), $this->equalTo(\Magento\Weee\Pricing\Adjustment::ADJUSTMENT_CODE))->will($this->returnValue(80.98999999999999));
     $this->assertEquals(80.98999999999999, $this->attribute->getOptionValueModified(['is_percent' => false, 'pricing_value' => 77.33]));
 }
Example #3
0
 /**
  * Get Total price for configurable items
  *
  * @param \Magento\Catalog\Model\Product $product
  * @param float $finalPrice
  * @return float
  */
 public function getTotalConfigurableItemsPrice($product, $finalPrice)
 {
     $price = 0.0;
     $product->getTypeInstance()->setStoreFilter($product->getStore(), $product);
     $attributes = $product->getTypeInstance()->getConfigurableAttributes($product);
     $selectedAttributes = [];
     if ($product->getCustomOption('attributes')) {
         $selectedAttributes = unserialize($product->getCustomOption('attributes')->getValue());
     }
     foreach ($attributes as $attribute) {
         $attributeId = $attribute->getProductAttribute()->getId();
         $value = $this->_getValueByIndex($attribute->getPrices() ? $attribute->getPrices() : [], isset($selectedAttributes[$attributeId]) ? $selectedAttributes[$attributeId] : null);
         $product->setParentId(true);
         if ($value) {
             if ($value['pricing_value'] != 0) {
                 $product->setConfigurablePrice($this->_calcSelectionPrice($value, $finalPrice));
                 $product->setConfigurablePrice($this->priceModifier->modifyPrice($product->getConfigurablePrice(), $product));
                 $price += $product->getConfigurablePrice();
             }
         }
     }
     return $price;
 }