/**
  * test method calculateDiscount with default price amount
  */
 public function testCalculateDiscountWithDefaultAmount()
 {
     $this->productMock->expects($this->exactly(2))->method('getPriceInfo')->will($this->returnValue($this->priceInfoMock));
     $this->priceInfoMock->expects($this->once())->method('getPrice')->with($this->equalTo(\Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE))->will($this->returnValue($this->finalPriceMock));
     $this->finalPriceMock->expects($this->once())->method('getValue')->will($this->returnValue(100));
     $this->priceInfoMock->expects($this->once())->method('getPrices')->will($this->returnValue([$this->getPriceMock(30), $this->getPriceMock(20), $this->getPriceMock(40)]));
     $this->assertEquals(20, $this->calculator->calculateDiscount($this->productMock));
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function getAmount()
 {
     if ($this->product->getSelectedConfigurableOption()) {
         $this->amount = null;
     }
     return parent::getAmount();
 }
Example #3
0
 /**
  * Test getMaximalPrice()
  */
 public function testGetMaximalPrice()
 {
     $basePrice = 10;
     $minimalPrice = 5;
     $this->basePriceMock->expects($this->once())->method('getValue')->will($this->returnValue($basePrice));
     $this->calculatorMock->expects($this->once())->method('getAmount')->with($this->equalTo($basePrice))->will($this->returnValue($minimalPrice));
     $result = $this->model->getMaximalPrice();
     $this->assertEquals($minimalPrice, $result);
 }
Example #4
0
 /**
  *  test fro method getValue with dynamic productType
  */
 public function testGetValueTypeDynamic()
 {
     $this->bundleMock->expects($this->once())->method('getPriceType')->will($this->returnValue(\Magento\Bundle\Model\Product\Price::PRICE_TYPE_DYNAMIC));
     $this->priceInfoMock->expects($this->once())->method('getPrice')->with($this->equalTo(FinalPrice::PRICE_CODE))->will($this->returnValue($this->finalPriceMock));
     $this->finalPriceMock->expects($this->once())->method('getValue')->will($this->returnValue(100));
     $this->discountCalculatorMock->expects($this->once())->method('calculateDiscount')->with($this->equalTo($this->bundleMock), $this->equalTo(100))->will($this->returnValue(70));
     $this->assertEquals(70, $this->selectionPrice->getValue());
     $this->assertEquals(70, $this->selectionPrice->getValue());
 }
 public function testGetAmount()
 {
     $this->setupSelectionPrice();
     $price = 10.0;
     $amount = 20.0;
     $this->priceInfoMock->expects($this->once())->method('getPrice')->with(\Magento\Bundle\Pricing\Price\FinalPrice::PRICE_CODE)->willReturn($this->finalPriceMock);
     $this->finalPriceMock->expects($this->once())->method('getValue')->willReturn($price);
     $this->discountCalculatorMock->expects($this->once())->method('calculateDiscount')->with($this->bundleMock, $price)->willReturn($price);
     $this->priceCurrencyMock->expects($this->once())->method('round')->with($price)->willReturn($price);
     $this->bundleMock->expects($this->any())->method('getPriceType')->willReturn(\Magento\Bundle\Model\Product\Price::PRICE_TYPE_DYNAMIC);
     $this->calculatorMock->expects($this->once())->method('getAmount')->with($price, $this->productMock, null)->willReturn($amount);
     $this->assertEquals($amount, $this->selectionPrice->getAmount());
 }
 /**
  *  test fro method getValue with dynamic productType
  *
  * @param bool $useRegularPrice
  * @dataProvider useRegularPriceDataProvider
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function testGetValueTypeDynamic($useRegularPrice)
 {
     $this->setupSelectionPrice($useRegularPrice);
     $priceCode = $useRegularPrice ? RegularPrice::PRICE_CODE : FinalPrice::PRICE_CODE;
     $regularPrice = 100.125;
     $discountedPrice = 70.453;
     $actualPrice = $useRegularPrice ? $regularPrice : $discountedPrice;
     $expectedPrice = $useRegularPrice ? round($regularPrice, 2) : round($discountedPrice, 2);
     $this->bundleMock->expects($this->once())->method('getPriceType')->will($this->returnValue(\Magento\Bundle\Model\Product\Price::PRICE_TYPE_DYNAMIC));
     $this->priceInfoMock->expects($this->once())->method('getPrice')->with($this->equalTo($priceCode))->will($this->returnValue($this->finalPriceMock));
     $this->finalPriceMock->expects($this->once())->method('getValue')->will($this->returnValue($actualPrice));
     if (!$useRegularPrice) {
         $this->discountCalculatorMock->expects($this->once())->method('calculateDiscount')->with($this->equalTo($this->bundleMock), $this->equalTo($actualPrice))->will($this->returnValue($discountedPrice));
     }
     $this->priceCurrencyMock->expects($this->once())->method('round')->with($actualPrice)->will($this->returnValue($expectedPrice));
     $this->assertEquals($expectedPrice, $this->selectionPrice->getValue());
 }
 /**
  * Get Amount for configured price which is included amount for all selected options
  *
  * @return \Magento\Framework\Pricing\Amount\AmountInterface
  */
 public function getAmount()
 {
     return $this->item ? $this->getConfiguredAmount($this->getBasePrice()->getValue()) : parent::getAmount();
 }
Example #8
0
 /**
  * @param \Magento\Framework\Pricing\SaleableInterface $saleableItem
  * @param float $quantity
  * @param \Magento\Framework\Pricing\Adjustment\CalculatorInterface $calculator
  * @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency
  * @param PriceResolverInterface $priceResolver
  */
 public function __construct(\Magento\Framework\Pricing\SaleableInterface $saleableItem, $quantity, \Magento\Framework\Pricing\Adjustment\CalculatorInterface $calculator, \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency, PriceResolverInterface $priceResolver)
 {
     parent::__construct($saleableItem, $quantity, $calculator, $priceCurrency);
     $this->priceResolver = $priceResolver;
 }
Example #9
0
 /**
  * get bundle product price without any option
  *
  * @return \Magento\Framework\Pricing\Amount\AmountInterface
  */
 public function getPriceWithoutOption()
 {
     if (!$this->priceWithoutOption) {
         $this->priceWithoutOption = $this->calculator->getAmountWithoutOption(parent::getValue(), $this->product);
     }
     return $this->priceWithoutOption;
 }
Example #10
0
 /**
  * @param Product $saleableItem
  * @param float $quantity
  * @param CalculatorInterface $calculator
  * @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency
  * @param \Magento\Msrp\Helper\Data $msrpData
  * @param \Magento\Msrp\Model\Config $config
  */
 public function __construct(Product $saleableItem, $quantity, CalculatorInterface $calculator, \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency, \Magento\Msrp\Helper\Data $msrpData, \Magento\Msrp\Model\Config $config)
 {
     parent::__construct($saleableItem, $quantity, $calculator, $priceCurrency);
     $this->msrpData = $msrpData;
     $this->config = $config;
 }
Example #11
0
 /**
  * @inheritdoc
  */
 public function getValue()
 {
     return max(0, parent::getValue() + $this->getLinkPrice());
 }
Example #12
0
 /**
  * Returns price amount
  *
  * @return \Magento\Framework\Pricing\Amount\AmountInterface
  */
 public function getAmount()
 {
     return $this->calculator->getAmount(parent::getValue(), $this->product);
 }
Example #13
0
 /**
  * Price value of product with configured options
  *
  * @return bool|float
  */
 public function getValue()
 {
     return $this->item ? $this->calculatePrice() : parent::getValue();
 }
Example #14
0
 /**
  * @param Product $saleableItem
  * @param float $quantity
  * @param CalculatorInterface $calculator
  * @param Data $catalogDataHelper
  */
 public function __construct(Product $saleableItem, $quantity, CalculatorInterface $calculator, Data $catalogDataHelper)
 {
     parent::__construct($saleableItem, $quantity, $calculator);
     $this->catalogDataHelper = $catalogDataHelper;
 }
 /**
  * Price value of product with configured options
  *
  * @return bool|float
  */
 public function getValue()
 {
     return $this->item ? parent::getValue() + $this->getOptionsValue() : parent::getValue();
 }