php Magento 在非模板文件中获取含税价格

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13287820/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 05:06:31  来源:igfitidea点击:

Magento get price including tax in a none-template file

phpmagentoget

提问by Weszzz7

At the moment i am trying to get the product price including tax in a php file for my product feed. I have this code at the moment:

目前,我正在尝试在我的产品 Feed 的 php 文件中获取产品价格(含税)。我现在有这个代码:

$_product = Mage::getModel('catalog/product')->load($productId);
$_priceIncludingTax = $this->helper('tax')
                               ->getPrice($_product, $_product->getFinalPrice());

Problem is that since that of course the '$this->' part doesn't work so well from the file. Anyone know how i can still get the price including tax in this file?

问题是,因为当然'$this->' 部分在文件中不能很好地工作。任何人都知道我如何仍然可以获得此文件中的含税价格?

回答by Alex

You can get a helper-instance in any file using:

您可以使用以下命令在任何文件中获取帮助程序实例:

Mage::helper('tax')

Your full code is:

你的完整代码是:

$_product = Mage::getModel('catalog/product')->load($productId);
$_priceIncludingTax = Mage::helper('tax')
    ->getPrice($_product, $_product->getFinalPrice());

回答by jruzafa

Thanks @Alex:

谢谢@亚历克斯:

If the product has FinalPrice special price is the final price of the product to access the most serious tax base price:

如果产品有FinalPrice特价是产品的最终价格接入最严重的税基价:

    $_product = Mage::getModel('catalog/product')->load($p->getId());

    $_specialPriceIncTax = Mage::helper('tax')
        ->getPrice($_product, $_product->getFinalPrice());

    $_priceTax = Mage::helper('tax')
        ->getPrice($_product, $_product->getPrice());