Magento获得购物车单件价格,含增值税.税 [英] Magento get cart single item price incl. tax

查看:124
本文介绍了Magento获得购物车单件价格,含增值税.税的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很奇怪的问题,希望有人可以帮我解决这个问题.

I have a pretty weird issue, I hope someone can help me with this.

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

Here are the major config settings that influence my problem:

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

到目前为止,一切正常.问题来自自定义的ajax迷你购物车模块.我从购物车中抓取商品集合,但是,由于我从购物车中获取价格,所以我免税了.

Everything is working fine so far. The problem comes in a custom ajax mini cart module. I grab the collection of items from the cart, but, since I'm getting the price from the shopping cart item, I get it without tax.

这里有一些代码可以例证我的意思.我将假设收取 20%税,并且将管理价格(含税)设置为 120 $ 的产品,该选项的价格为 60 $ (还包括税).不含税,它们分别为 100 $ 50 $ .我想获取价格+选项+税=> 180 $

Here is some code to exemplify what I mean. I will assume a 20% tax and a product that has the admin price (including tax) set to 120$, an option that costs 60$ (also including tax). Excluding tax these would be 100$ and 50$. I want to get the price + option + tax => 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 $.

PS: The custom option I am talking about is user selected, for example an install checkbox that adds +50$ to the price of the product.

推荐答案

我没有找到确切问题的解决方案,但是我更改了设置以模仿此确切功能,而我遇到的问题不再存在.

I didn't find a solution to my exact problem, but I changed the settings to mimic this exact functionality, and the problem I encountered was no longer there.

首先,我删除了网站上的所有税金,并告诉magento所有价格均不含税(即使其中包括税金).

First of all, I removed all the taxes on the site, and told magento all the prices are excluding tax (even though they are including tax).

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

The tax reduction is now made through a promotion applied on a custom group, so for

$tax = 20; // percent 

我减少了

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

带有4个小数(这是magento接受的数量).它可能会不时出现1美分的误差-因此,如果这不是问题,那就去解决吧!

with 4 decimals (that's as much as magento accepts). It may have an error of 1 cent from time to time - so if this is not an issue, go for it!

现在,整个网站上的价格都将准确显示该产品的价格(因为促销适用于每个购物车,而不是每个产品).

Now the prices all over the website will be shown exactly for the product (because the promotion is applied per cart, not per product).

这篇关于Magento获得购物车单件价格,含增值税.税的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆