如何在Prestashop的产品列表中一次显示有税和无税的产品价格?

时间:2014-04-23 07:42:14

标签: php prestashop prestashop-1.6

在产品清单中,我需要一次显示含税和不含税的产品价格。

我正在使用Prestashop的1.6版本。

现在包含税的价格显示在产品列表中。我想显示不含税的价格。

我该怎么做?我搜索过解决方案,但无法为我找到合适的解决方案。

5 个答案:

答案 0 :(得分:9)

product-list.tpl中找到以下块:

{foreach from=$products item=product name=products}

将此添加到不含税的显示价格:

{convertPrice price=$product.price_tax_exc}

确保在开发过程中Template compilation设置为Force compilation且{1}}在PrestaShop后台设置为Cache - > No - > Advanced Parameters

答案 1 :(得分:2)

在我的情况下,它适用于默认税除外:

{convertPrice price=$product->getPrice(false, $smarty.const.NULL)} ({l s='tax excl.'})

答案 2 :(得分:0)

我在结账前的订单列表中遇到了类似的问题。 错误消息显示不含税的总金额和产品金额。 所以我修改了控制器中的文件>前面> 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)。

最后,您必须在本地化中翻译新句子。 希望有人能够完成或更好地解决这个问题。

答案 3 :(得分:0)

我知道已有一个已接受的答案,但我需要有关如何获得产品价格的更多信息。

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变量,该数组包含列表中显示的所有产品。

希望这有帮助。

答案 4 :(得分:-1)

简单的解决方案

转到客户 - &gt;组并单击要修改的组上的编辑:

查找价格显示方法选项,然后根据需要选择包含或排除价格,然后保存更改:

按ctrl + f5进行检查。完成