簡體   English   中英

PrestaShop在函數getPackageShipping中設置運營商價格,無需覆蓋自定義模塊的費用

[英]PrestaShop set carrier price in function getPackageShippingCost of custom module without overriding

我正在開發一個模塊,當客戶在訂單頁面中時(訂單的第2步),該模塊可以修改承運人的價格。 以前,我創建了一些與模塊關聯的載體,因此當我以客戶的身份到達訂單頁面時,prestashop在模塊代碼上調用了我的方法getPackageShippingCost

public function getPackageShippingCost($id_carrier = null, $use_tax = true, $default_country = null, $product_list = null, $id_zone = null)

我看到模塊中收到的$id_carrier var確實不是$id_carrier ,我看到的是實際的Cart Object,所以我需要在訂單頁面中顯示該購物車中的運輸商列表。

目前,我正在嘗試獲取帶有以下內容的承運商列表:

$carriers = Carrier::getCarriers($cookie->id_lang, true, false, false, NULL, PS_CARRIERS_AND_CARRIER_MODULES_NEED_RANGE);

但是getPackageShippingCost多次調用過getPackageShippingCost ,我得到的$carriers var總是一樣,如果沒有返回價格,我總是需要向函數返回價格,價格是免費返回的。 問題是我無法檢測到指定載波的迭代。

解決了修改或覆蓋classes / Cart.php的問題,但是我不想使用覆蓋,我認為只有使用模塊中的getPackageShippingCost方法才可以實現。

最后,我修改了覆蓋。 是最糟糕的解決方案。

class Cart extends CartCore

{

public function getPackageShippingCost($id_carrier = null, $use_tax = true, Country $default_country = null, $product_list = null, $id_zone = null)
{
    global $array_precios;
    if ($array_precios == null)
        $array_precios = Tools::jsonDecode(Module::getInstanceByName('mymodule')->buscarPreciosmymodule(Context::getContext()->cart->id, false), true);
    if (!Module::getInstanceByName('mymodule')->isMyModuleCarrier($id_carrier)) {
        return parent::getPackageShippingCost($id_carrier, $use_tax, $default_country, $product_list, $id_zone);
    }
    $objCarrier = new Carrier($id_carrier);
    if (array_key_exists($objCarrier->url, $array_precios))
    {            
        return($array_precios[$objCarrier->url]['importe']);
    }
}

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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