/**
  * Get the price value for one of selection product
  *
  * @return bool|float
  */
 public function getValue()
 {
     if (null !== $this->value) {
         return $this->value;
     }
     $priceCode = $this->useRegularPrice ? BundleRegularPrice::PRICE_CODE : FinalPrice::PRICE_CODE;
     if ($this->bundleProduct->getPriceType() == Price::PRICE_TYPE_DYNAMIC) {
         // just return whatever the product's value is
         $value = $this->priceInfo->getPrice($priceCode)->getValue();
     } else {
         // don't multiply by quantity.  Instead just keep as quantity = 1
         $selectionPriceValue = $this->selection->getSelectionPriceValue();
         if ($this->product->getSelectionPriceType()) {
             // calculate price for selection type percent
             $price = $this->bundleProduct->getPriceInfo()->getPrice(CatalogPrice\RegularPrice::PRICE_CODE)->getValue();
             $product = clone $this->bundleProduct;
             $product->setFinalPrice($price);
             $this->eventManager->dispatch('catalog_product_get_final_price', ['product' => $product, 'qty' => $this->bundleProduct->getQty()]);
             $value = $product->getData('final_price') * ($selectionPriceValue / 100);
         } else {
             // calculate price for selection type fixed
             $value = $this->priceCurrency->convert($selectionPriceValue) * $this->quantity;
         }
     }
     if (!$this->useRegularPrice) {
         $value = $this->discountCalculator->calculateDiscount($this->bundleProduct, $value);
     }
     $this->value = $this->priceCurrency->round($value);
     return $this->value;
 }
Exemplo n.º 2
0
 /**
  * Get the price value for one of selection product
  *
  * @return bool|float
  */
 public function getValue()
 {
     if (null !== $this->value) {
         return $this->value;
     }
     if ($this->bundleProduct->getPriceType() == Price::PRICE_TYPE_DYNAMIC) {
         $value = $this->priceInfo->getPrice(FinalPrice::PRICE_CODE)->getValue();
     } else {
         if ($this->product->getSelectionPriceType()) {
             // calculate price for selection type percent
             $price = $this->bundleProduct->getPriceInfo()->getPrice(CatalogPrice\RegularPrice::PRICE_CODE)->getValue();
             $product = clone $this->bundleProduct;
             $product->setFinalPrice($price);
             $this->eventManager->dispatch('catalog_product_get_final_price', array('product' => $product, 'qty' => $this->bundleProduct->getQty()));
             $value = $product->getData('final_price') * ($this->product->getSelectionPriceValue() / 100);
         } else {
             // calculate price for selection type fixed
             $value = $this->product->getSelectionPriceValue() * $this->quantity;
         }
     }
     $this->value = $this->discountCalculator->calculateDiscount($this->bundleProduct, $value);
     return $this->value;
 }
 /**
  * test method calculateDiscount with custom price amount
  */
 public function testCalculateDiscountWithCustomAmount()
 {
     $this->productMock->expects($this->once())->method('getPriceInfo')->will($this->returnValue($this->priceInfoMock));
     $this->priceInfoMock->expects($this->once())->method('getPrices')->will($this->returnValue([$this->getPriceMock(30), $this->getPriceMock(20), $this->getPriceMock(40)]));
     $this->assertEquals(10, $this->calculator->calculateDiscount($this->productMock, 50));
 }