Example #1
0
 public function testGetAmount()
 {
     $amount = 20.0;
     $priceMock = $this->getMockBuilder('Magento\\Framework\\Pricing\\Price\\PriceInterface')->getMockForAbstractClass();
     $this->priceInfoMock->expects($this->once())->method('getPrices')->willReturn([$priceMock]);
     $this->calculatorMock->expects($this->once())->method('getAmount')->with(false, $this->saleableItemMock)->willReturn($amount);
     $this->assertEquals($amount, $this->basePrice->getAmount());
 }
Example #2
0
 public function testGetLinkAmount()
 {
     $amount = 100;
     $this->linkMock->expects($this->once())->method('getPrice')->will($this->returnValue($amount));
     $this->linkMock->expects($this->once())->method('getProduct')->will($this->returnValue($this->saleableItemMock));
     $this->calculatorMock->expects($this->once())->method('getAmount')->with($amount, $this->equalTo($this->saleableItemMock))->will($this->returnValue($amount));
     $result = $this->linkPrice->getLinkAmount($this->linkMock);
     $this->assertEquals($amount, $result);
 }
Example #3
0
 /**
  * Test method testGetDisplayValue
  */
 public function testGetAmount()
 {
     $priceValue = 77;
     $convertedPrice = 56.32;
     $amountValue = 88;
     $this->saleableItemMock->expects($this->once())->method('getPrice')->will($this->returnValue($priceValue));
     $this->priceCurrencyMock->expects($this->any())->method('convertAndRound')->with($priceValue)->will($this->returnValue($convertedPrice));
     $this->calculatorMock->expects($this->once())->method('getAmount')->with($this->equalTo($convertedPrice))->will($this->returnValue($amountValue));
     $this->assertEquals($amountValue, $this->regularPrice->getAmount());
 }
Example #4
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]));
 }
 public function testGetAmountExclude()
 {
     $amount = 10;
     $fullamount = 10;
     $taxAdjustmentCode = 'tax';
     $weeeAdjustmentCode = 'weee';
     $adjustment = 5;
     $expectedAdjustments = [];
     $productMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->setMethods(['getPriceInfo', '__wakeup'])->getMock();
     $taxAdjustmentMock = $this->getMockBuilder('Magento\\Tax\\Pricing\\Adjustment')->disableOriginalConstructor()->getMock();
     $taxAdjustmentMock->expects($this->once())->method('getAdjustmentCode')->will($this->returnValue($taxAdjustmentCode));
     $taxAdjustmentMock->expects($this->once())->method('isIncludedInBasePrice')->will($this->returnValue(true));
     $taxAdjustmentMock->expects($this->once())->method('extractAdjustment')->with($this->equalTo($amount), $this->equalTo($productMock))->will($this->returnValue($adjustment));
     $taxAdjustmentMock->expects($this->once())->method('applyAdjustment')->with($this->equalTo($fullamount), $this->equalTo($productMock))->will($this->returnValue($amount));
     $weeeAdjustmentMock = $this->getMockBuilder('Magento\\Weee\\Pricing\\Adjustment')->disableOriginalConstructor()->getMock();
     $weeeAdjustmentMock->expects($this->once())->method('getAdjustmentCode')->will($this->returnValue($weeeAdjustmentCode));
     $weeeAdjustmentMock->expects($this->once())->method('isIncludedInBasePrice')->will($this->returnValue(false));
     $weeeAdjustmentMock->expects($this->once())->method('isIncludedInDisplayPrice')->with($this->equalTo($productMock))->will($this->returnValue(true));
     $weeeAdjustmentMock->expects($this->never())->method('applyAdjustment');
     $adjustments = [$taxAdjustmentMock, $weeeAdjustmentMock];
     $priceInfoMock = $this->getMockBuilder('\\Magento\\Framework\\Pricing\\PriceInfo\\Base')->disableOriginalConstructor()->getMock();
     $priceInfoMock->expects($this->any())->method('getAdjustments')->will($this->returnValue($adjustments));
     $productMock->expects($this->any())->method('getPriceInfo')->will($this->returnValue($priceInfoMock));
     $amountBaseMock = $this->getMockBuilder('Magento\\Framework\\Pricing\\Amount\\Base')->disableOriginalConstructor()->getMock();
     $this->amountFactoryMock->expects($this->once())->method('create')->with($this->equalTo($amount), $this->equalTo($expectedAdjustments))->will($this->returnValue($amountBaseMock));
     $result = $this->model->getAmount($amount, $productMock, true);
     $this->assertInstanceOf('Magento\\Framework\\Pricing\\Amount\\AmountInterface', $result);
 }
Example #6
0
 /**
  * Calculate amount for dynamic bundle product
  *
  * @param float $basePriceValue
  * @param Product $bundleProduct
  * @param \Magento\Bundle\Pricing\Price\BundleSelectionPrice[] $selectionPriceList
  * @param null|string $exclude
  * @return \Magento\Framework\Pricing\Amount\AmountInterface
  */
 protected function calculateDynamicBundleAmount($basePriceValue, $bundleProduct, $selectionPriceList, $exclude)
 {
     $fullAmount = 0.0;
     $adjustments = [];
     $amountList = [$this->calculator->getAmount($basePriceValue, $bundleProduct, $exclude)];
     /** @var $option \Magento\Bundle\Model\Option */
     foreach ($selectionPriceList as $selectionPrice) {
         $amountList[] = $selectionPrice->getAmount();
     }
     /** @var  Store $store */
     $store = $bundleProduct->getStore();
     $roundingMethod = $this->taxHelper->getCalculationAgorithm($store);
     /** @var \Magento\Framework\Pricing\Amount\AmountInterface $itemAmount */
     foreach ($amountList as $itemAmount) {
         if ($roundingMethod != TaxCalculationServiceInterface::CALC_TOTAL_BASE) {
             //We need to round the individual selection first
             $fullAmount += $store->roundPrice($itemAmount->getValue());
             foreach ($itemAmount->getAdjustmentAmounts() as $code => $adjustment) {
                 $adjustment = $store->roundPrice($adjustment);
                 $adjustments[$code] = isset($adjustments[$code]) ? $adjustments[$code] + $adjustment : $adjustment;
             }
         } else {
             $fullAmount += $itemAmount->getValue();
             foreach ($itemAmount->getAdjustmentAmounts() as $code => $adjustment) {
                 $adjustments[$code] = isset($adjustments[$code]) ? $adjustments[$code] + $adjustment : $adjustment;
             }
         }
     }
     if ($exclude && isset($adjustments[$exclude])) {
         $fullAmount -= $adjustments[$exclude];
         unset($adjustments[$exclude]);
     }
     return $this->amountFactory->create($fullAmount, $adjustments);
 }
 /**
  * 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 #8
0
 /**
  * Test method testGetDisplayValue
  */
 public function testGetAmount()
 {
     $priceValue = 77;
     $amountValue = 88;
     $this->calculatorMock->expects($this->once())->method('getAmount')->with($this->equalTo($priceValue))->will($this->returnValue($amountValue));
     $this->saleableItemMock->expects($this->once())->method('getPrice')->will($this->returnValue($priceValue));
     $this->assertEquals($amountValue, $this->regularPrice->getAmount());
 }
 /**
  * @param float $amount
  * @param null|bool|string $exclude
  * @param null|array $context
  * @return AmountInterface|bool|float
  */
 public function getCustomAmount($amount = null, $exclude = null, $context = [])
 {
     if (null !== $amount) {
         $amount = $this->priceCurrency->convertAndRound($amount);
     } else {
         $amount = $this->getValue();
     }
     return $this->calculator->getAmount($amount, $this->getProduct(), $exclude, $context);
 }
Example #10
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);
 }
 /**
  * @dataProvider dataProviderForGetterAmount
  */
 public function testGetterAmount($amountForBundle, $optionList, $expectedResult)
 {
     $this->baseCalculator->expects($this->atLeastOnce())->method('getAmount')->with($this->baseAmount, $this->saleableItem)->will($this->returnValue($this->createAmountMock($amountForBundle)));
     $options = [];
     foreach ($optionList as $optionData) {
         $options[] = $this->createOptionMock($optionData);
     }
     $price = $this->getMock('Magento\\Bundle\\Pricing\\Price\\BundleOptionPrice', [], [], '', false);
     $price->expects($this->atLeastOnce())->method('getOptions')->will($this->returnValue($options));
     $this->priceMocks[Price\BundleOptionPrice::PRICE_CODE] = $price;
     // Price type of saleable items
     $this->saleableItem->expects($this->any())->method('getPriceType')->will($this->returnValue(ProductPrice::PRICE_TYPE_DYNAMIC));
     $this->amountFactory->expects($this->atLeastOnce())->method('create')->with($expectedResult['fullAmount'], $expectedResult['adjustments']);
     if ($expectedResult['isMinAmount']) {
         $this->model->getAmount($this->baseAmount, $this->saleableItem);
     } else {
         $this->model->getMaxAmount($this->baseAmount, $this->saleableItem);
     }
 }
Example #12
0
 /**
  * Calculate amount for dynamic bundle product
  *
  * @param float $basePriceValue
  * @param Product $bundleProduct
  * @param \Magento\Bundle\Pricing\Price\BundleSelectionPrice[] $selectionPriceList
  * @param null|bool|string|array $exclude
  * @return \Magento\Framework\Pricing\Amount\AmountInterface
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 protected function calculateDynamicBundleAmount($basePriceValue, $bundleProduct, $selectionPriceList, $exclude)
 {
     $fullAmount = 0.0;
     $adjustments = [];
     $i = 0;
     $amountList[$i]['amount'] = $this->calculator->getAmount($basePriceValue, $bundleProduct, $exclude);
     $amountList[$i]['quantity'] = 1;
     foreach ($selectionPriceList as $selectionPrice) {
         ++$i;
         $amountList[$i]['amount'] = $selectionPrice->getAmount();
         // always honor the quantity given
         $amountList[$i]['quantity'] = $selectionPrice->getQuantity();
     }
     /** @var  Store $store */
     $store = $bundleProduct->getStore();
     $roundingMethod = $this->taxHelper->getCalculationAlgorithm($store);
     foreach ($amountList as $amountInfo) {
         /** @var \Magento\Framework\Pricing\Amount\AmountInterface $itemAmount */
         $itemAmount = $amountInfo['amount'];
         $qty = $amountInfo['quantity'];
         if ($roundingMethod != TaxCalculationInterface::CALC_TOTAL_BASE) {
             //We need to round the individual selection first
             $fullAmount += $this->priceCurrency->round($itemAmount->getValue()) * $qty;
             foreach ($itemAmount->getAdjustmentAmounts() as $code => $adjustment) {
                 $adjustment = $this->priceCurrency->round($adjustment) * $qty;
                 $adjustments[$code] = isset($adjustments[$code]) ? $adjustments[$code] + $adjustment : $adjustment;
             }
         } else {
             $fullAmount += $itemAmount->getValue() * $qty;
             foreach ($itemAmount->getAdjustmentAmounts() as $code => $adjustment) {
                 $adjustment = $adjustment * $qty;
                 $adjustments[$code] = isset($adjustments[$code]) ? $adjustments[$code] + $adjustment : $adjustment;
             }
         }
     }
     if (is_array($exclude) == false) {
         if ($exclude && isset($adjustments[$exclude])) {
             $fullAmount -= $adjustments[$exclude];
             unset($adjustments[$exclude]);
         }
     } else {
         foreach ($exclude as $oneExclusion) {
             if ($oneExclusion && isset($adjustments[$oneExclusion])) {
                 $fullAmount -= $adjustments[$oneExclusion];
                 unset($adjustments[$oneExclusion]);
             }
         }
     }
     return $this->amountFactory->create($fullAmount, $adjustments);
 }
Example #13
0
 /**
  * Test getOptions()
  */
 public function testGetOptions()
 {
     $price = 100;
     $displayValue = 120;
     $id = 1;
     $expected = [$id => [$price => ['base_amount' => $price, 'adjustment' => $displayValue]]];
     $this->amount->expects($this->once())->method('getValue')->will($this->returnValue(120));
     $this->calculator->expects($this->once())->method('getAmount')->will($this->returnValue($this->amount));
     $optionValueMock = $this->getOptionValueMock($price);
     $optionValueMock->expects($this->once())->method('getId')->will($this->returnValue($id));
     $optionItemMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Product\\Option')->disableOriginalConstructor()->setMethods(['getValues', '__wakeup'])->getMock();
     $optionItemMock->expects($this->any())->method('getValues')->will($this->returnValue(array($optionValueMock)));
     $options = [$optionItemMock];
     $this->product->expects($this->once())->method('getOptions')->will($this->returnValue($options));
     $result = $this->object->getOptions();
     $this->assertEquals($expected, $result);
     $result = $this->object->getOptions();
     $this->assertEquals($expected, $result);
 }
Example #14
0
 /**
  * @param float $amount
  * @param null|bool|string $exclude
  * @param null|array $context
  * @return AmountInterface|bool|float
  */
 public function getCustomAmount($amount = null, $exclude = null, $context = [])
 {
     $amount = null === $amount ? $this->getValue() : $amount;
     return $this->calculator->getAmount($amount, $this->product, $exclude, $context);
 }