簡體   English   中英

如何在Prestashop的產品列表中一次顯示有稅和無稅的產品價格?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM