【问题标题】:How to display product price with and without tax at a time in product list for Prestashop?如何在 Prestashop 的产品列表中一次显示含税和不含税的产品价格?
【发布时间】:2014-06-07 21:52:43
【问题描述】:

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

我使用的是 Prestashop 1.6 版。

目前含税价格显示在产品列表中。我也想显示不含税的价格。

我该怎么做?我一直在寻找解决方案,但无法为我找到可行的解决方案。

【问题讨论】:

    标签: php prestashop prestashop-1.6


    【解决方案1】:

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

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

    添加此项以显示不含税价格:

    {convertPrice price=$product.price_tax_exc}
    

    确保在 PrestaShop 后台中将Template compilation 设置为Force compilationCache 设置为No -> Advanced Parameters -> Performance

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        【解决方案3】:

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

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

        正如其他 cmets 所说,如果您在模板中,则可以根据您正在修改的视图获取产品 ID。

        在 product.tpl(单一产品视图)中有一个 $product 变量。在 product-list.tpl 中有 $products 变量,这是一个包含列表中显示的所有产品的数组。

        希望这会有所帮助。

        【讨论】:

          【解决方案4】:

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

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

          【讨论】:

          • 有一个更简单的解决方案可以在 PHP 中显示这些值。您将需要 id_product 和 id_product_attribute 并且您必须通过 $p = new Product(your_product_id) 创建新的产品对象,然后是 $p->getPrice(true, id_product_attribute) ,这就是含税价格。对于不征税,在第一个参数中使用 false。
          【解决方案5】:

          简单的解决方案

          转到客户 -> 组,然后单击要修改的组上的编辑:

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

          按 ctrl + f5 检查。完成

          【讨论】:

          • 他想同时显示含税和不含税的价格。没有之一。
          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2018-07-03
          • 1970-01-01
          • 2013-04-08
          • 2020-11-17
          • 1970-01-01
          • 2010-11-01
          • 1970-01-01
          相关资源
          最近更新 更多