Beispiel #1
0
 /**
  * Get "double" prices html (block with base and place currency)
  *
  * @param   \Magento\Framework\Object $dataObject
  * @param   float $basePrice
  * @param   float $price
  * @param   bool $strong
  * @param   string $separator
  * @return  string
  */
 public function displayPrices($dataObject, $basePrice, $price, $strong = false, $separator = '<br/>')
 {
     $order = false;
     if ($dataObject instanceof \Magento\Sales\Model\Order) {
         $order = $dataObject;
     } else {
         $order = $dataObject->getOrder();
     }
     if ($order && $order->isCurrencyDifferent()) {
         $res = '<strong>';
         $res .= $order->formatBasePrice($basePrice);
         $res .= '</strong>' . $separator;
         $res .= '[' . $order->formatPrice($price) . ']';
     } elseif ($order) {
         $res = $order->formatPrice($price);
         if ($strong) {
             $res = '<strong>' . $res . '</strong>';
         }
     } else {
         $res = $this->priceCurrency->format($price);
         if ($strong) {
             $res = '<strong>' . $res . '</strong>';
         }
     }
     return $res;
 }
Beispiel #2
0
 /**
  * Prepare order data for refund
  *
  * @param \Magento\Sales\Model\Order\Creditmemo $creditmemo
  * @return void
  */
 protected function prepareOrder(\Magento\Sales\Model\Order\Creditmemo $creditmemo)
 {
     $order = $creditmemo->getOrder();
     $baseOrderRefund = $this->priceCurrency->round($order->getBaseTotalRefunded() + $creditmemo->getBaseGrandTotal());
     $orderRefund = $this->priceCurrency->round($order->getTotalRefunded() + $creditmemo->getGrandTotal());
     $order->setBaseTotalRefunded($baseOrderRefund);
     $order->setTotalRefunded($orderRefund);
     $order->setBaseSubtotalRefunded($order->getBaseSubtotalRefunded() + $creditmemo->getBaseSubtotal());
     $order->setSubtotalRefunded($order->getSubtotalRefunded() + $creditmemo->getSubtotal());
     $order->setBaseTaxRefunded($order->getBaseTaxRefunded() + $creditmemo->getBaseTaxAmount());
     $order->setTaxRefunded($order->getTaxRefunded() + $creditmemo->getTaxAmount());
     $order->setBaseDiscountTaxCompensationRefunded($order->getBaseDiscountTaxCompensationRefunded() + $creditmemo->getBaseDiscountTaxCompensationAmount());
     $order->setDiscountTaxCompensationRefunded($order->getDiscountTaxCompensationRefunded() + $creditmemo->getDiscountTaxCompensationAmount());
     $order->setBaseShippingRefunded($order->getBaseShippingRefunded() + $creditmemo->getBaseShippingAmount());
     $order->setShippingRefunded($order->getShippingRefunded() + $creditmemo->getShippingAmount());
     $order->setBaseShippingTaxRefunded($order->getBaseShippingTaxRefunded() + $creditmemo->getBaseShippingTaxAmount());
     $order->setShippingTaxRefunded($order->getShippingTaxRefunded() + $creditmemo->getShippingTaxAmount());
     $order->setAdjustmentPositive($order->getAdjustmentPositive() + $creditmemo->getAdjustmentPositive());
     $order->setBaseAdjustmentPositive($order->getBaseAdjustmentPositive() + $creditmemo->getBaseAdjustmentPositive());
     $order->setAdjustmentNegative($order->getAdjustmentNegative() + $creditmemo->getAdjustmentNegative());
     $order->setBaseAdjustmentNegative($order->getBaseAdjustmentNegative() + $creditmemo->getBaseAdjustmentNegative());
     $order->setDiscountRefunded($order->getDiscountRefunded() + $creditmemo->getDiscountAmount());
     $order->setBaseDiscountRefunded($order->getBaseDiscountRefunded() + $creditmemo->getBaseDiscountAmount());
     if ($creditmemo->getDoTransaction()) {
         $order->setTotalOnlineRefunded($order->getTotalOnlineRefunded() + $creditmemo->getGrandTotal());
         $order->setBaseTotalOnlineRefunded($order->getBaseTotalOnlineRefunded() + $creditmemo->getBaseGrandTotal());
     } else {
         $order->setTotalOfflineRefunded($order->getTotalOfflineRefunded() + $creditmemo->getGrandTotal());
         $order->setBaseTotalOfflineRefunded($order->getBaseTotalOfflineRefunded() + $creditmemo->getBaseGrandTotal());
     }
     $order->setBaseTotalInvoicedCost($order->getBaseTotalInvoicedCost() - $creditmemo->getBaseCost());
 }
 /**
  * MOBI-486: Add partial payment data to totals are requested with REST API.
  * MOBI-489: Add partial payment configuration to totals extension attributes.
  *
  * @param \Magento\Quote\Model\Cart\CartTotalRepository $subject
  * @param \Closure $proceed
  * @param $cartId
  * @return \Magento\Quote\Api\Data\TotalsInterface
  */
 public function aroundGet(\Magento\Quote\Model\Cart\CartTotalRepository $subject, \Closure $proceed, $cartId)
 {
     /** @var \Magento\Quote\Model\Cart\Totals $result */
     $result = $proceed($cartId);
     /* Get partial method configuration */
     $isPartialEnabled = $this->_hlpCfg->getWalletPartialEnabled();
     if ($isPartialEnabled) {
         //            $partialMaxPercent = $this->_hlpCfg->getWalletPartialPercent();
         //            /** @var \Magento\Quote\Api\Data\TotalExtensionInterface $exts */
         //            $exts = $this->_factTotalExt->create();
         //            /** @var \Praxigento\Wallet\Api\Data\Config\Payment\Method $extData */
         //            $extData = new \Praxigento\Wallet\Api\Data\Config\Payment\Method();
         //            $extData->setPartialMaxPercent($partialMaxPercent);
         //            $extData->setIsPartialEnabled($isPartialEnabled);
         //            $exts->setPraxigentoWalletPaymentConfig($extData);
         //            $result->setExtensionAttributes($exts);
         /* get partial data from repository */
         /** @var \Praxigento\Wallet\Data\Entity\Partial\Quote $found */
         $found = $this->_repoPartialQuote->getById($cartId);
         if ($found) {
             $basePartial = $found->getBasePartialAmount();
             $basePartial = $this->_hlpPriceCurrency->round($basePartial);
             /* add current partial total to segment */
             $segments = $result->getTotalSegments();
             /** @var \Magento\Quote\Api\Data\TotalSegmentInterface $seg */
             $seg = $this->_manObj->create(\Magento\Quote\Api\Data\TotalSegmentInterface::class);
             $seg->setCode(self::TOTAL_SEGMENT);
             $seg->setValue($basePartial);
             $segments[self::TOTAL_SEGMENT] = $seg;
             $result->setTotalSegments($segments);
         }
     }
     return $result;
 }
 /**
  * @param $products
  * @return array
  */
 public function getListValues($ids)
 {
     $values = [];
     $searchCriteria = $this->_criteriaBuilder->addFilter('entity_id', $ids, 'in')->create();
     $products = $this->_productRepository->getList($searchCriteria);
     foreach ($products->getItems() as $product) {
         $image = $this->_imageHelper->init($product, 'product_page_image_small')->getUrl();
         $price = $product->getFinalPrice();
         if ($price == 0 && $product->getTypeId() == 'grouped') {
             $children = $product->getTypeInstance()->getAssociatedProducts($product);
             foreach ($children as $child) {
                 if ($child->getPrice() < $price || $price == 0) {
                     $price = $child->getPrice();
                 }
             }
         }
         $value = array();
         $value['escape_name'] = $this->escapeHtml($product->getName());
         $value['name'] = $product->getName();
         $value['url'] = $product->getProductUrl();
         $value['price'] = $this->_priceCurrency->format($price, false);
         $value['image'] = $image;
         $values[] = $value;
     }
     return $values;
 }
Beispiel #5
0
 /**
  * Initialize required data
  */
 protected function setUp()
 {
     $orderCreateMock = $this->getMock('Magento\\Sales\\Model\\AdminOrder\\Create', ['__wakeup'], [], '', false);
     $taxData = $this->getMockBuilder('Magento\\Tax\\Helper\\Data')->disableOriginalConstructor()->getMock();
     $this->priceCurrency = $this->getMockBuilder('\\Magento\\Framework\\Pricing\\PriceCurrencyInterface')->getMock();
     $coreData = $this->getMockBuilder('Magento\\Core\\Helper\\Data')->disableOriginalConstructor()->getMock();
     $sessionMock = $this->getMockBuilder('Magento\\Backend\\Model\\Session\\Quote')->disableOriginalConstructor()->setMethods(['getQuote', '__wakeup'])->getMock();
     $quoteMock = $this->getMockBuilder('Magento\\Quote\\Model\\Quote')->disableOriginalConstructor()->setMethods(['getStore', '__wakeup'])->getMock();
     $storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->setMethods(['__wakeup'])->getMock();
     $this->priceCurrency->expects($this->any())->method('convertAndFormat')->will($this->returnArgument(0));
     $quoteMock->expects($this->any())->method('getStore')->will($this->returnValue($storeMock));
     $sessionMock->expects($this->any())->method('getQuote')->will($this->returnValue($quoteMock));
     $wishlistFactoryMock = $this->getMockBuilder('Magento\\Wishlist\\Model\\WishlistFactory')->disableOriginalConstructor()->setMethods(['methods', '__wakeup'])->getMock();
     $giftMessageSave = $this->getMockBuilder('Magento\\Giftmessage\\Model\\Save')->setMethods(['__wakeup'])->disableOriginalConstructor()->getMock();
     $taxConfig = $this->getMockBuilder('Magento\\Tax\\Model\\Config')->disableOriginalConstructor()->getMock();
     $this->stockRegistry = $this->getMockBuilder('Magento\\CatalogInventory\\Model\\StockRegistry')->disableOriginalConstructor()->setMethods(['getStockItem', '__wakeup'])->getMock();
     $this->stockItemMock = $this->getMock('Magento\\CatalogInventory\\Model\\Stock\\Item', ['getIsInStock', '__wakeup'], [], '', false);
     $this->stockState = $this->getMock('Magento\\CatalogInventory\\Model\\StockState', ['checkQuoteItemQty', '__wakeup'], [], '', false);
     $this->stockRegistry->expects($this->any())->method('getStockItem')->will($this->returnValue($this->stockItemMock));
     $this->objectManager = new \Magento\TestFramework\Helper\ObjectManager($this);
     $this->block = $this->objectManager->getObject('Magento\\Sales\\Block\\Adminhtml\\Order\\Create\\Items\\Grid', ['wishlistFactory' => $wishlistFactoryMock, 'giftMessageSave' => $giftMessageSave, 'taxConfig' => $taxConfig, 'taxData' => $taxData, 'sessionQuote' => $sessionMock, 'orderCreate' => $orderCreateMock, 'priceCurrency' => $this->priceCurrency, 'coreData' => $coreData, 'stockRegistry' => $this->stockRegistry, 'stockState' => $this->stockState]);
     $this->priceRenderBlock = $this->getMockBuilder('\\Magento\\Backend\\Block\\Template')->disableOriginalConstructor()->setMethods(['setItem', 'toHtml'])->getMock();
     $this->layoutMock = $this->getMockBuilder('\\Magento\\Framework\\View\\Layout')->disableOriginalConstructor()->setMethods(['getBlock'])->getMock();
     $this->itemMock = $this->getMockBuilder('\\Magento\\Quote\\Model\\Quote\\Item')->disableOriginalConstructor()->setMethods(['__wakeup'])->getMock();
 }
Beispiel #6
0
 /**
  * Filter value
  *
  * @param float $value
  * @return string
  */
 public function filter($value)
 {
     $value = $this->_localeFormat->getNumber($value);
     $value = $this->priceCurrency->round($this->_rate * $value);
     $value = sprintf("%f", $value);
     return $this->_currency->toCurrency($value);
 }
Beispiel #7
0
 /**
  * Prepare Data Source
  *
  * @param array $dataSource
  * @return void
  */
 public function prepareDataSource(array &$dataSource)
 {
     if (isset($dataSource['data']['items'])) {
         foreach ($dataSource['data']['items'] as &$item) {
             $item[$this->getData('name')] = $this->priceFormatter->format($item[$this->getData('name')], false);
         }
     }
 }
Beispiel #8
0
 public function testFormatCurrency()
 {
     $amount = '100';
     $includeContainer = true;
     $precision = \Magento\Framework\Pricing\PriceCurrencyInterface::DEFAULT_PRECISION;
     $result = '100.0 grn';
     $this->priceCurrency->expects($this->once())->method('format')->with($amount, $includeContainer, $precision)->will($this->returnValue($result));
     $this->assertEquals($result, $this->model->formatCurrency($amount, $includeContainer, $precision));
 }
Beispiel #9
0
 public function testFormatPrice()
 {
     $amount = '120';
     $includeContainer = false;
     $result = '10grn.';
     $this->priceCurrencyMock->expects($this->once())->method('format')->with($amount, $includeContainer)->will($this->returnValue($result));
     $helper = $this->getHelper(['priceCurrency' => $this->priceCurrencyMock]);
     $this->assertEquals($result, $helper->formatPrice($amount, $includeContainer));
 }
Beispiel #10
0
 /**
  * Convert and format price value for specified store
  *
  * @param   float $value
  * @param   int|\Magento\Store\Model\Store $store
  * @param   bool $format
  * @param   bool $includeContainer
  * @return  float|string
  */
 public function currencyByStore($value, $store = null, $format = true, $includeContainer = true)
 {
     if ($format) {
         $value = $this->priceCurrency->convertAndFormat($value, $includeContainer, PriceCurrencyInterface::DEFAULT_PRECISION, $store);
     } else {
         $value = $this->priceCurrency->convert($value, $store);
     }
     return $value;
 }
Beispiel #11
0
 public function setUp()
 {
     $this->weeeHelper = $this->getMock('Magento\\Weee\\Helper\\Data', [], [], '', false);
     $this->priceCurrencyMock = $this->getMock('\\Magento\\Framework\\Pricing\\PriceCurrencyInterface');
     $this->priceCurrencyMock->expects($this->any())->method('convertAndRound')->will($this->returnCallback(function ($arg) {
         return round($arg * 0.5, 2);
     }));
     $this->adjustment = new Adjustment($this->weeeHelper, $this->priceCurrencyMock, $this->sortOrder);
 }
Beispiel #12
0
 /**
  * @covers Magento\GroupedProduct\Block\Product\Grouped\AssociatedProducts\ListAssociatedProducts
  *     ::getAssociatedProducts
  */
 public function testGetAssociatedProducts()
 {
     $this->priceCurrency->expects($this->any())->method('format')->with('1.00', false)->will($this->returnValue('1'));
     $this->storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($this->storeMock));
     $this->productMock->expects($this->once())->method('getTypeInstance')->will($this->returnValue($this->typeInstanceMock));
     $this->registryMock->expects($this->once())->method('registry')->with('current_product')->will($this->returnValue($this->productMock));
     $this->typeInstanceMock->expects($this->once())->method('getAssociatedProducts')->with($this->productMock)->will($this->returnValue([$this->generateAssociatedProduct(1), $this->generateAssociatedProduct(2)]));
     $expectedResult = ['0' => ['id' => 'id1', 'sku' => 'sku1', 'name' => 'name1', 'qty' => 1, 'position' => 1, 'price' => '1'], '1' => ['id' => 'id2', 'sku' => 'sku2', 'name' => 'name2', 'qty' => 2, 'position' => 2, 'price' => '1']];
     $this->assertEquals($expectedResult, $this->block->getAssociatedProducts());
 }
Beispiel #13
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());
 }
Beispiel #14
0
 /**
  * Prepare Data Source
  *
  * @param array $dataSource
  * @return array
  */
 public function prepareDataSource(array $dataSource)
 {
     if (isset($dataSource['data']['items'])) {
         foreach ($dataSource['data']['items'] as &$item) {
             $currencyCode = isset($item['base_currency_code']) ? $item['base_currency_code'] : null;
             $item[$this->getData('name')] = $this->priceFormatter->format($item[$this->getData('name')], false, null, null, $currencyCode);
         }
     }
     return $dataSource;
 }
Beispiel #15
0
 /**
  * @param string $amount
  * @param string $store
  * @param bool $format
  * @param bool $includeContainer
  * @param string $result
  * @dataProvider currencyByStoreDataProvider
  */
 public function testCurrencyByStore($amount, $store, $format, $includeContainer, $result)
 {
     if ($format) {
         $this->priceCurrencyMock->expects($this->once())->method('convertAndFormat')->with($amount, $includeContainer, PriceCurrencyInterface::DEFAULT_PRECISION, $store)->will($this->returnValue($result));
     } else {
         $this->priceCurrencyMock->expects($this->once())->method('convert')->with($amount, $store)->will($this->returnValue($result));
     }
     $helper = $this->getHelper(['priceCurrency' => $this->priceCurrencyMock]);
     $this->assertEquals($result, $helper->currencyByStore($amount, $store, $format, $includeContainer));
 }
 public function testGetCustomAmount()
 {
     $exclude = false;
     $amount = 21.0;
     $convertedValue = 30.25;
     $customAmount = 42.0;
     $this->priceCurrencyMock->expects($this->any())->method('convertAndRound')->with($amount)->will($this->returnValue($convertedValue));
     $this->calculatorMock->expects($this->once())->method('getAmount')->with($convertedValue, $this->saleableItemMock, $exclude)->will($this->returnValue($customAmount));
     $this->assertEquals($customAmount, $this->price->getCustomAmount($amount, $exclude));
 }
 /**
  * Get credit memo shipping amount depend on configuration settings
  *
  * @return float
  */
 public function getShippingAmount()
 {
     $source = $this->getSource();
     if ($this->_taxConfig->displaySalesShippingInclTax($source->getOrder()->getStoreId())) {
         $shipping = $source->getBaseShippingInclTax();
     } else {
         $shipping = $source->getBaseShippingAmount();
     }
     return $this->priceCurrency->round($shipping) * 1;
 }
Beispiel #18
0
 public function testGetShippingPrice()
 {
     $shippingPrice = 5;
     $convertedPrice = "\$5";
     $shippingRateMock = $this->getMockBuilder('\\Magento\\Quote\\Model\\Quote\\Address\\Rate')->disableOriginalConstructor()->setMethods(['getPrice', '__wakeup'])->getMock();
     $shippingRateMock->expects($this->once())->method('getPrice')->will($this->returnValue($shippingPrice));
     $this->priceCurrency->expects($this->once())->method('convertAndFormat')->with($shippingPrice, true, true)->willReturn($convertedPrice);
     $this->priceObj->setShippingRate($shippingRateMock);
     $this->assertEquals($convertedPrice, $this->priceObj->getShippingPrice());
 }
Beispiel #19
0
 public function testGetShippingPriceInclTax()
 {
     $shippingPrice = 5;
     $shippingPriceInclTax = 5.5;
     $convertedPrice = "\$5.50";
     $shippingRateMock = $this->setupShippingRate($shippingPrice);
     $this->taxHelper->expects($this->once())->method('getShippingPrice')->will($this->returnValue($shippingPriceInclTax));
     $this->priceCurrency->expects($this->once())->method('convertAndFormat')->with($this->logicalOr($shippingPriceInclTax, true, $this->store))->will($this->returnValue($convertedPrice));
     $this->priceObj->setShippingRate($shippingRateMock);
     $this->assertEquals($convertedPrice, $this->priceObj->getShippingPriceExclTax());
 }
 /**
  * @param bool $isValidInterval
  * @param float $specialPrice
  * @param float|bool $specialPriceValue
  *
  * @dataProvider specialPriceDataProvider
  */
 public function testGetValue($isValidInterval, $specialPrice, $specialPriceValue)
 {
     $expected = 56.34;
     $specialPriceModel = $this->objectManager->getObject('Magento\\Catalog\\Pricing\\Price\\SpecialPrice', ['saleableItem' => $this->prepareSaleableItem($specialPrice), 'localeDate' => $this->prepareLocaleDate($isValidInterval), 'priceCurrency' => $this->priceCurrencyMock]);
     if ($isValidInterval) {
         $this->priceCurrencyMock->expects($this->once())->method('convertAndRound')->with($specialPriceValue)->will($this->returnValue($expected));
     } else {
         $expected = $specialPriceValue;
     }
     $this->assertSame($expected, $specialPriceModel->getValue());
 }
 /**
  * Retrieve grouped products
  *
  * @return array
  */
 public function getAssociatedProducts()
 {
     /** @var $product \Magento\Catalog\Model\Product */
     $product = $this->_registry->registry('current_product');
     $associatedProducts = $product->getTypeInstance()->getAssociatedProducts($product);
     $products = [];
     foreach ($associatedProducts as $product) {
         $products[] = ['id' => $product->getId(), 'sku' => $product->getSku(), 'name' => $product->getName(), 'price' => $this->priceCurrency->format($product->getPrice(), false), 'qty' => $product->getQty(), 'position' => $product->getPosition()];
     }
     return $products;
 }
 public function testGetLinkAmount()
 {
     $amount = 100;
     $convertedAmount = 50;
     $this->linkMock->expects($this->once())->method('getPrice')->will($this->returnValue($amount));
     $this->linkMock->expects($this->once())->method('getProduct')->will($this->returnValue($this->saleableItemMock));
     $this->priceCurrencyMock->expects($this->once())->method('convertAndRound')->with($amount)->will($this->returnValue($convertedAmount));
     $this->calculatorMock->expects($this->once())->method('getAmount')->with($convertedAmount, $this->equalTo($this->saleableItemMock))->will($this->returnValue($convertedAmount));
     $result = $this->linkPrice->getLinkAmount($this->linkMock);
     $this->assertEquals($convertedAmount, $result);
 }
Beispiel #23
0
 public function testPrepareDataSource()
 {
     $itemName = 'itemName';
     $oldItemValue = 'oldItemValue';
     $newItemValue = 'newItemValue';
     $dataSource = ['data' => ['items' => [[$itemName => $oldItemValue]]]];
     $this->priceFormatterMock->expects($this->once())->method('format')->with($oldItemValue, false)->willReturn($newItemValue);
     $this->model->setData('name', $itemName);
     $dataSource = $this->model->prepareDataSource($dataSource);
     $this->assertEquals($newItemValue, $dataSource['data']['items'][0][$itemName]);
 }
 public function testGetMinimalPrice()
 {
     $expectedResult = 5;
     $this->saleableInterfaceMock->expects($this->once())->method('getPrice')->will($this->returnValue($expectedResult));
     $this->priceCurrencyMock->expects($this->once())->method('convertAndRound')->will($this->returnArgument(0));
     $this->bundleCalculatorMock->expects($this->once())->method('getMinRegularAmount')->with($expectedResult, $this->saleableInterfaceMock)->will($this->returnValue($expectedResult));
     $result = $this->regularPrice->getMinimalPrice();
     $this->assertEquals($expectedResult, $result, 'Incorrect amount');
     //Calling a second time, should use cached value
     $result = $this->regularPrice->getMinimalPrice();
     $this->assertEquals($expectedResult, $result, 'Incorrect amount the second time');
 }
Beispiel #25
0
 public function setUp()
 {
     $objectManager = new ObjectManager($this);
     $this->coreRegistry = $this->getMockBuilder('\\Magento\\Framework\\Registry')->disableOriginalConstructor()->setMethods(['registry'])->getMock();
     $this->orderTaxService = $this->getMockBuilder('\\Magento\\Tax\\Service\\V1\\OrderTaxService')->disableOriginalConstructor()->setMethods(['getOrderTaxDetails'])->getMock();
     $this->priceCurrency = $this->getMockBuilder('Magento\\Framework\\Pricing\\PriceCurrencyInterface')->getMock();
     $this->priceCurrency->expects($this->any())->method('round')->will($this->returnCallback(function ($argument) {
         return round($argument, 2);
     }));
     $this->taxHelper = $objectManager->getObject('Magento\\Tax\\Helper\\Data', ['coreRegistry' => $this->coreRegistry, 'orderTaxService' => $this->orderTaxService, 'priceCurrency' => $this->priceCurrency]);
     $this->orderTaxDetailsBuilder = $objectManager->getObject('Magento\\Tax\\Service\\V1\\Data\\OrderTaxDetailsBuilder');
 }
Beispiel #26
0
 /**
  * @covers \Magento\Bundle\Pricing\Price\TierPrice::isFirstPriceBetter
  * @dataProvider providerForGetterTierPriceList
  */
 public function testGetterTierPriceList($tierPrices, $basePrice, $expectedResult)
 {
     $this->product->setData(TierPrice::PRICE_CODE, $tierPrices);
     $price = $this->getMock('Magento\\Framework\\Pricing\\Price\\PriceInterface');
     $price->expects($this->any())->method('getValue')->will($this->returnValue($basePrice));
     $this->priceInfo->expects($this->any())->method('getPrice')->will($this->returnValue($price));
     $this->calculator->expects($this->atLeastOnce())->method('getAmount')->will($this->returnArgument(0));
     $this->priceCurrencyMock->expects($this->never())->method('convertAndRound');
     $group = $this->getMock('\\Magento\\Customer\\Model\\Data\\Group', [], [], '', false);
     $group->expects($this->any())->method('getId')->willReturn(\Magento\Customer\Model\GroupManagement::CUST_GROUP_ALL);
     $this->groupManagement->expects($this->any())->method('getAllCustomersGroup')->will($this->returnValue($group));
     $this->assertEquals($expectedResult, $this->model->getTierPriceList());
     $this->assertEquals(count($expectedResult), $this->model->getTierPriceCount());
 }
Beispiel #27
0
 /**
  * @param \Magento\Sales\Model\Order\Creditmemo $creditmemo
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function collect(\Magento\Sales\Model\Order\Creditmemo $creditmemo)
 {
     $order = $creditmemo->getOrder();
     $allowedAmount = $order->getShippingAmount() - $order->getShippingRefunded();
     $baseAllowedAmount = $order->getBaseShippingAmount() - $order->getBaseShippingRefunded();
     $orderShippingAmount = $order->getShippingAmount();
     $orderBaseShippingAmount = $order->getBaseShippingAmount();
     $orderShippingInclTax = $order->getShippingInclTax();
     $orderBaseShippingInclTax = $order->getBaseShippingInclTax();
     $shippingAmount = $baseShippingAmount = $shippingInclTax = $baseShippingInclTax = 0;
     /**
      * Check if shipping amount was specified (from invoice or another source).
      * Using has magic method to allow setting 0 as shipping amount.
      */
     if ($creditmemo->hasBaseShippingAmount()) {
         $baseShippingAmount = $this->priceCurrency->round($creditmemo->getBaseShippingAmount());
         /*
          * Rounded allowed shipping refund amount is the highest acceptable shipping refund amount.
          * Shipping refund amount shouldn't cause errors, if it doesn't exceed that limit.
          * Note: ($x < $y + 0.0001) means ($x <= $y) for floats
          */
         if ($baseShippingAmount < $this->priceCurrency->round($baseAllowedAmount) + 0.0001) {
             $ratio = 0;
             if ($orderBaseShippingAmount > 0) {
                 $ratio = $baseShippingAmount / $orderBaseShippingAmount;
             }
             /*
              * Shipping refund amount should be equated to allowed refund amount,
              * if it exceeds that limit.
              * Note: ($x > $y - 0.0001) means ($x >= $y) for floats
              */
             if ($baseShippingAmount > $baseAllowedAmount - 0.0001) {
                 $shippingAmount = $allowedAmount;
                 $baseShippingAmount = $baseAllowedAmount;
             } else {
                 $shippingAmount = $this->priceCurrency->round($orderShippingAmount * $ratio);
             }
             $shippingInclTax = $this->priceCurrency->round($orderShippingInclTax * $ratio);
             $baseShippingInclTax = $this->priceCurrency->round($orderBaseShippingInclTax * $ratio);
         } else {
             $baseAllowedAmount = $order->getBaseCurrency()->format($baseAllowedAmount, null, false);
             throw new \Magento\Framework\Exception\LocalizedException(__('Maximum shipping amount allowed to refund is: %1', $baseAllowedAmount));
         }
     } else {
         $shippingAmount = $allowedAmount;
         $baseShippingAmount = $baseAllowedAmount;
         $allowedTaxAmount = $order->getShippingTaxAmount() - $order->getShippingTaxRefunded();
         $baseAllowedTaxAmount = $order->getBaseShippingTaxAmount() - $order->getBaseShippingTaxRefunded();
         $shippingInclTax = $this->priceCurrency->round($allowedAmount + $allowedTaxAmount);
         $baseShippingInclTax = $this->priceCurrency->round($baseAllowedAmount + $baseAllowedTaxAmount);
     }
     $creditmemo->setShippingAmount($shippingAmount);
     $creditmemo->setBaseShippingAmount($baseShippingAmount);
     $creditmemo->setShippingInclTax($shippingInclTax);
     $creditmemo->setBaseShippingInclTax($baseShippingInclTax);
     $creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $shippingAmount);
     $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $baseShippingAmount);
     return $this;
 }
Beispiel #28
0
 /**
  * Prepare text of range label
  *
  * @param float|string $fromPrice
  * @param float|string $toPrice
  * @return float|\Magento\Framework\Phrase
  */
 public function renderRangeLabel($fromPrice, $toPrice)
 {
     $formattedFromPrice = $this->priceCurrency->format($fromPrice);
     $priceInterval = $this->scopeConfig->getValue(self::XML_PATH_ONE_PRICE_INTERVAL, ScopeInterface::SCOPE_STORE);
     if ($toPrice === '') {
         return __('%1 and above', $formattedFromPrice);
     } elseif ($fromPrice == $toPrice && $priceInterval) {
         return $formattedFromPrice;
     } else {
         if ($fromPrice != $toPrice) {
             $toPrice -= 0.01;
         }
         return __('%1 - %2', $formattedFromPrice, $this->priceCurrency->format($toPrice));
     }
 }
 public function testGetValue()
 {
     $this->priceInfoMock->expects($this->once())->method('getPrice')->with($this->equalTo('regular_price'))->will($this->returnValue($this->regularPrice));
     $this->regularPrice->expects($this->once())->method('getValue')->will($this->returnValue(100));
     $this->productMock->expects($this->once())->method('getCustomerGroupId')->will($this->returnValue(null));
     $this->customerSessionMock->expects($this->once())->method('getCustomerGroupId')->will($this->returnValue(3));
     $this->productMock->expects($this->once())->method('getResource')->will($this->returnValue($this->productResourceMock));
     $this->productResourceMock->expects($this->once())->method('getAttribute')->with($this->equalTo('group_price'))->will($this->returnValue($this->attributeMock));
     $this->attributeMock->expects($this->once())->method('getBackend')->will($this->returnValue($this->backendMock));
     $this->backendMock->expects($this->once())->method('afterLoad')->with($this->equalTo($this->productMock))->will($this->returnValue($this->backendMock));
     $this->priceCurrencyMock->expects($this->never())->method('convertAndRound');
     $this->productMock->expects($this->once())->method('getData')->with($this->equalTo('group_price'), $this->equalTo(null))->will($this->returnValue([['cust_group' => 3, 'website_price' => 80]]));
     $this->assertEquals(20, $this->groupPrice->getValue());
     $this->assertEquals(20, $this->groupPrice->getValue());
 }
Beispiel #30
0
 /**
  * Test getMinimalPrice()
  */
 public function testGetMinimalPriceWithMinimalPrice()
 {
     $minimalPrice = 5.234;
     $convertedPrice = 3.98;
     $finalPrice = 3.89;
     $this->priceCurrencyMock->expects($this->once())->method('convertAndRound')->with($minimalPrice)->will($this->returnValue($convertedPrice));
     $this->basePriceMock->expects($this->never())->method('getValue');
     $this->calculatorMock->expects($this->once())->method('getAmount')->with($this->equalTo($convertedPrice))->will($this->returnValue($finalPrice));
     $this->saleableMock->expects($this->once())->method('getMinimalPrice')->will($this->returnValue($minimalPrice));
     $result = $this->model->getMinimalPrice();
     $this->assertEquals($finalPrice, $result);
     //The second time will return cached value
     $result = $this->model->getMinimalPrice();
     $this->assertEquals($finalPrice, $result);
 }