Magento得到手推车单项目价格含税


Magento get cart single item price incl. tax

我有一个很奇怪的问题,我希望有人能帮助我。

以下是影响我的问题的主要配置设置:

  • 管理面板中的目录价格显示包括税
  • 前端显示目录价格,包括税
  • 购物车中的商品显示不含税(因此它在小计附近单独显示)。

到目前为止一切都很好。问题出现在自定义ajax迷你购物车模块中。我从购物车中获取商品集合,但是,由于我是从购物车中获取商品的价格,所以我获得的是不含税的商品。

下面是一些代码来举例说明我的意思。我将假设20%税和一个管理价格(包括税)设置为120$的产品,该选项的成本60$(还包括税)。不含税,它们将是100$50$。我想要得到价格+期权+税=> 180$
$quote = Mage::getSingleton('checkout/session')->getQuote();
$items = $quote->getAllVisibleItems();
foreach ($items as $item) {
    echo $item->getPrice(); // 150$ - price excluding tax
    echo $item->getPriceInclTax(); // 150$ - price excluding tax
    echo $item->getProduct()->getPrice(); // 120$ price including tax, BUT without the customer selected options.
}

PS:我所说的自定义选项是用户选择的,例如安装复选框,将+50美元添加到产品的价格

- Get products id, name, price, quantity, etc. present in your cart.
- Get number of items in cart and total quantity in cart.
- Get base total price and grand total price of items in cart.
Get all items information in cart
// $items = Mage::getModel('checkout/cart')->getQuote()->getAllItems();
$items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();
foreach($items as $item) {
    echo 'ID: '.$item->getProductId().'<br />';
    echo 'Name: '.$item->getName().'<br />';
    echo 'Sku: '.$item->getSku().'<br />';
    echo 'Quantity: '.$item->getQty().'<br />';
    echo 'Price: '.$item->getPrice().'<br />';
    echo "<br />";           
}
Get total items and total quantity in cart
$totalItems = Mage::getModel('checkout/cart')->getQuote()->getItemsCount();
$totalQuantity = Mage::getModel('checkout/cart')->getQuote()->getItemsQty();
Get subtotal and grand total price of cart
$subTotal = Mage::getModel('checkout/cart')->getQuote()->getSubtotal();
$grandTotal = Mage::getModel('checkout/cart')->getQuote()->getGrandTotal();

你试过了吗:

$product->getFinalPrice();
// or this?
$product->getPriceModel()->getFinalPrice($qty, $product);

$item->getOptions()的输出是什么?你试过$item->getData('price')吗?如何应用自定义选项?$item->debug()的输出是多少?也许你可以在那里找到你需要的东西。

的问候西蒙。

我没有找到解决我的确切问题的方法,但是我改变了设置来模拟这个确切的功能,我遇到的问题不再存在了。

首先,我删除了网站上所有的税,并告诉magento所有的价格都是不含税的(即使它们是含税的)。

减税现在是通过应用于自定义组的促销来实现的,因此对于

$tax = 20; // percent 

我添加了

(1 - (1 / ($tax / 100 + 1)))*100 
// for 20% tax => 16.6667% reduction
// for 24% tax => 19.3548% reduction

带有4个小数(这是magento所能接受的)。它可能偶尔会有1美分的误差——所以如果这不是问题,那就去买吧!

现在,整个网站的价格将准确显示产品(因为促销是针对每个购物车,而不是每个产品)。

你可以试试:

$grandTotal = $this->helper('checkout/cart')->getQuote()->getGrandTotal();
echo $text .= $this->__(' Total: %s', $this->helper('core')->formatPrice($grandTotal, false));

显示购物车的数量

if ($parentBlock = $this->getParentBlock()) {
$count = $this->helper('checkout/cart')->getSummaryCount();
if( $count == 1 ) {
echo $text = $this->__('My Cart (%s item)', $count);
} elseif( $count > 0 ) {
echo $text = $this->__('My Cart (%s items)', $count);
} else {
echo $text = $this->__('My Cart (0 items)');
}
}

显示购物车的总价

$grandTotal = $this->helper('checkout/cart')->getQuote()->getGrandTotal();
echo $text .= $this->__(' Total: %s', $this->helper('core')->formatPrice($grandTotal, false));