public function testGetAllItems() { $totals = $this->_prepareValidModelData(); $this->assertEquals([new \Magento\Framework\Object(['name' => $this->_validItem->getName(), 'qty' => $this->_validItem->getQty(), 'amount' => $this->_validItem->getPrice()])], $this->_model->getAllItems()); $this->assertEquals($totals['subtotal'], $this->_model->getSubtotal()); $this->assertEquals($totals['tax'], $this->_model->getTax()); $this->assertEquals($totals['shipping'], $this->_model->getShipping()); $this->assertEquals($totals['discount'], $this->_model->getDiscount()); }
/** * Render minimal price for downloadable products * * @param \Magento\Framework\Object $row * @return string */ public function render(\Magento\Framework\Object $row) { if ($row->getTypeId() == 'downloadable') { $row->setPrice($row->getPrice()); } return parent::render($row); }
/** * Validate Product Rule Condition * * @param \Magento\Framework\Object $object * @return bool */ public function validate(\Magento\Framework\Object $object) { //@todo reimplement this method when is fixed MAGETWO-5713 /** @var \Magento\Catalog\Model\Product $product */ $product = $object->getProduct(); if (!$product instanceof \Magento\Catalog\Model\Product) { $product = $this->_productFactory->create()->load($object->getProductId()); } $product->setQuoteItemQty($object->getQty())->setQuoteItemPrice($object->getPrice())->setQuoteItemRowTotal($object->getBaseRowTotal()); return parent::validate($product); }
/** * @param \Magento\Framework\Object $input * @param float $expectOutputPrice * @param string[] $configs * @param string $productClassName * * @magentoDataFixture Magento/Catalog/_files/products.php * @magentoDataFixture Magento/Customer/_files/customer.php * @magentoDataFixture Magento/Customer/_files/customer_address.php * @magentoDbIsolation enabled * @dataProvider getPriceDataProvider */ public function testGetPrice($input, $expectOutputPrice, $configs = [], $productClassName = 'DefaultProductClass') { $this->setUpDefaultRules(); $fixtureProductId = 1; /** @var \Magento\Catalog\Model\Product $product */ $product = $this->objectManager->create('Magento\\Catalog\\Model\\Product')->load($fixtureProductId); $product->setTaxClassId($this->taxClasses[$productClassName]); $shippingAddress = $this->getCustomerAddress(); $billingAddress = $shippingAddress; foreach ($configs as $config) { $this->scopeConfig->setValue($config['path'], $config['value'], ScopeInterface::SCOPE_STORE, 'default'); } $price = $this->helper->getPrice($product, $input->getPrice(), $input->getIncludingTax(), $shippingAddress, $billingAddress, $this->taxClasses['DefaultCustomerClass'], $input->getStore(), $input->getPriceIncludesTax(), $input->getRoundPrice()); $this->assertEquals($expectOutputPrice, $price); }
/** * Get shipping rate code title and its price or error message * * @param \Magento\Framework\Object $rate * @param string $format * @param string $inclTaxFormat * @return string */ public function renderShippingRateOption($rate, $format = '%s - %s%s', $inclTaxFormat = ' (%s %s)') { $renderedInclTax = ''; if ($rate->getErrorMessage()) { $price = $rate->getErrorMessage(); } else { $price = $this->_getShippingPrice($rate->getPrice(), $this->_taxHelper->displayShippingPriceIncludingTax()); $incl = $this->_getShippingPrice($rate->getPrice(), true); if ($incl != $price && $this->_taxHelper->displayShippingBothPrices()) { $renderedInclTax = sprintf($inclTaxFormat, __('Incl. Tax'), $incl); } } return sprintf($format, $this->escapeHtml($rate->getMethodTitle()), $price, $renderedInclTax); }
/** * Retrieve include tax html formatted content * * @param \Magento\Framework\Object $item * @return string */ public function displayPriceInclTax(\Magento\Framework\Object $item) { $qty = $item->getQtyOrdered() ? $item->getQtyOrdered() : ($item->getQty() ? $item->getQty() : 1); $baseTax = $item->getTaxBeforeDiscount() ? $item->getTaxBeforeDiscount() : ($item->getTaxAmount() ? $item->getTaxAmount() : 0); $tax = $item->getBaseTaxBeforeDiscount() ? $item->getBaseTaxBeforeDiscount() : ($item->getBaseTaxAmount() ? $item->getBaseTaxAmount() : 0); $basePriceTax = 0; $priceTax = 0; if (floatval($qty)) { $basePriceTax = $item->getBasePrice() + $baseTax / $qty; $priceTax = $item->getPrice() + $tax / $qty; } return $this->displayPrices($this->getOrder()->getStore()->roundPrice($basePriceTax), $this->getOrder()->getStore()->roundPrice($priceTax)); }
/** * Create and return new order item based on payment item data and $itemInfo * for initial payment * * @param \Magento\Framework\Object $itemInfo * @return \Magento\Sales\Model\Order\Item */ protected function _getInitialItem($itemInfo) { $price = $itemInfo->getPrice() ? $itemInfo->getPrice() : $this->getInitAmount(); $shippingAmount = $itemInfo->getShippingAmount() ? $itemInfo->getShippingAmount() : 0; $taxAmount = $itemInfo->getTaxAmount() ? $itemInfo->getTaxAmount() : 0; $item = $this->_orderItemFactory->create()->setStoreId($this->getStoreId())->setProductType(\Magento\Catalog\Model\Product\Type::TYPE_VIRTUAL)->setIsVirtual(1)->setSku('initial_fee')->setName(__('Recurring Payment Initial Fee'))->setDescription('')->setWeight(0)->setQtyOrdered(1)->setPrice($price)->setOriginalPrice($price)->setBasePrice($price)->setBaseOriginalPrice($price)->setRowTotal($price)->setBaseRowTotal($price)->setTaxAmount($taxAmount)->setShippingAmount($shippingAmount); $option = array('label' => __('Payment type'), 'value' => __('Initial period payment')); $this->_addAdditionalOptionToItem($item, $option); return $item; }