[英]How to display price in product page with and without tax in Prestashop 1.7?
[英]How to display product price with and without tax at a time in product list for Prestashop?
在产品清单中,我需要一次显示含税和不含税的产品价格。
我使用的是Prestashop的1.6版本。
现在,包含税的价格显示在产品列表中。 我想显示不含税的价格。
我怎样才能做到这一点? 我搜索过解决方案,但无法为我找到合适的解决方案。
在product-list.tpl
找到以下块:
{foreach from=$products item=product name=products}
将其添加到显示价格不含税:
{convertPrice price=$product.price_tax_exc}
确保在开发期间将Template compilation
设置为Force compilation
并在PrestaShop后台 - > Advanced Parameters
- > Performance
Force compilation
Cache
设置为No
。
在我的情况下,它适用于默认税率:
{convertPrice price=$product->getPrice(false, $smarty.const.NULL)} ({l s='tax excl.'})
我在结账前的订单列表中遇到了类似的问题。 错误消息显示不含税的总金额和产品金额。 所以我修改了控制器>前> OrderController.php(PS 1.6)中的文件在第63行
// Check minimal amount
$currency = Currency::getCurrency((int)$this->context->cart->id_currency);
$orderTotal = $this->context->cart->getOrderTotal();
$minimal_purchase = Tools::convertPrice((float)Configuration::get('PS_PURCHASE_MINIMUM'), $currency);
if ($this->context->cart->getOrderTotal(false, Cart::ONLY_PRODUCTS) < $minimal_purchase && $this->step > 0) {
$_GET['step'] = $this->step = 0;
$this->errors[] = sprintf(
Tools::displayError('A minimum purchase total of %1s (tax excl.) is required to validate your order, current purchase total is %2s (tax excl.).'),
Tools::displayPrice($minimal_purchase_2, $currency), Tools::displayPrice($this->context->cart->getOrderTotal(false, Cart::ONLY_PRODUCTS), $currency)
);
}
使用以下代码
// Check minimal amount
$currency = Currency::getCurrency((int)$this->context->cart->id_currency);
$orderTotal = $this->context->cart->getOrderTotal();
$minimal_purchase = Tools::convertPrice((float)Configuration::get('PS_PURCHASE_MINIMUM'), $currency);
# modified (total amount included tax - only for screen error)
$minimal_purchase_2 = round(Tools::convertPrice((float)Configuration::get('PS_PURCHASE_MINIMUM'), $currency)*1.22,1);
$productTotal = round($this->context->cart->getOrderTotal(false, Cart::ONLY_PRODUCTS)*1.22,1);
if ($this->context->cart->getOrderTotal(false, Cart::ONLY_PRODUCTS) < $minimal_purchase && $this->step > 0) {
$_GET['step'] = $this->step = 0;
$this->errors[] = sprintf(
Tools::displayError('A minimum purchase total of %1s (tax incl.) is required to validate your order, current purchase total is %2s (tax incl.).'),
Tools::displayPrice($minimal_purchase_2, $currency), Tools::displayPrice($productTotal, $currency)
);
}
我必须解决以获得实际税收价值(目前我为意大利税值插入1.22)。
最后,你必须在本地化翻译新句子。 希望有人能够完成或更好地解决这个问题。
我知道已经有一个被接受的答案,但我需要更多关于如何获得产品价格的信息。
Prestashop内置产品类具有getPrice方法。
/**
* Get product price
* Same as static function getPriceStatic, no need to specify product id
*
* @param bool $tax With taxes or not (optional)
* @param int $id_product_attribute Product attribute id (optional)
* @param int $decimals Number of decimals (optional)
* @param int $divisor Util when paying many time without fees (optional)
* @return float Product price in euros
*/
public function getPrice($tax = true, $id_product_attribute = null, $decimals = 6,
$divisor = null, $only_reduc = false, $usereduc = true, $quantity = 1)
{
return Product::getPriceStatic((int)$this->id, $tax, $id_product_attribute, $decimals, $divisor, $only_reduc, $usereduc, $quantity);
}
正如您所看到的,您可以指定是否需要税,结果给出的小数位数和除数。
因此,如果您想通过带税和无税的ID获得产品价格,您可以像这样实现
$product = new Product($id_product, $id_language) // Fill with your info
$price_with_taxes = $product->getPrice(true);
$price_wout_taxes = $product->getPrice(false);
正如其他评论所说,如果您在模板中,则可以根据要修改的视图获取产品ID。
在product.tpl(单个产品视图)中有一个$ product变量。 在product-list.tpl中,您有$ products变量,该数组包含列表中显示的所有产品。
希望这可以帮助。
简单解决方案
转到客户 - >组,然后单击要修改的组上的编辑:
查找价格显示方法选项,然后根据需要选择包含或排除价格,然后保存更改:
按ctrl + f5进行检查。 完成
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.