簡體   English   中英

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));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM