10

我有一个非常奇怪的问题,我希望有人能帮助我解决这个问题。

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

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

到目前为止一切正常。问题出现在自定义 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 美元。

4

6 回答 6

2
- 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();
于 2013-03-12T10:23:00.920 回答
1

你有没有尝试过:

$product->getFinalPrice();

// or this?
$product->getPriceModel()->getFinalPrice($qty, $product);
于 2013-03-01T13:33:13.200 回答
1

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

问候西蒙

于 2013-03-09T12:32:32.550 回答
1

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

首先,我删除了网站上的所有税费,并告诉 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 美分的误差 - 所以如果这不是问题,那就去做吧!

现在,整个网站的价格都将准确地显示为产品(因为促销是按购物车应用的,而不是按产品应用的)。

于 2013-03-11T08:18:01.683 回答
0

你可以试试这个:

$grandTotal = $this->helper('checkout/cart')->getQuote()->getGrandTotal();
echo $text .= $this->__(' Total: %s', $this->helper('core')->formatPrice($grandTotal, false));
于 2013-03-11T06:25:38.727 回答
0

在我的标题中显示购物车的数量

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));
于 2013-03-12T10:28:25.143 回答