2016-09-20 53 views
-1

我需要實現一個簡單的functionnality我的Prestashop(v1.6.1.0)排序可用載波:基於車產品

根據車的內容(產品參考)我需要運營商,這將是可用的排序爲第4個「運送」頁面/選項卡上的用戶。

舉個例子:我有3個運輸公司,但只有當購物車的產品參考資料中有一個以1開頭(這意味着它是新鮮的食物並且不能通過該運輸公司運送)時,才能刪除其中一個主題。

我該怎麼做?

+1

這不是支持網站或Prestashop的KB,而是開發者社區。你試過什麼了? https://stackoverflow.com/help/mcve –

回答

0

覆蓋功能getAvailableCarrierListCarrier類。

編輯最後循環:

if ($product->width > 0 || $product->height > 0 || $product->depth > 0 || $product->weight > 0) 
{ 
    foreach ($carrier_list as $key => $id_carrier) 
    { 
     $carrier = new Carrier($id_carrier); 

     // Get the sizes of the carrier and the product and sort them to check if the carrier can take the product. 
     $carrier_sizes = array((int)$carrier->max_width, (int)$carrier->max_height, (int)$carrier->max_depth); 
     $product_sizes = array((int)$product->width, (int)$product->height, (int)$product->depth); 
     rsort($carrier_sizes, SORT_NUMERIC); 
     rsort($product_sizes, SORT_NUMERIC); 

     if (($carrier_sizes[0] > 0 && $carrier_sizes[0] < $product_sizes[0]) 
      || ($carrier_sizes[1] > 0 && $carrier_sizes[1] < $product_sizes[1]) 
      || ($carrier_sizes[2] > 0 && $carrier_sizes[2] < $product_sizes[2])) 
     { 
      $error[$carrier->id] = Carrier::SHIPPING_SIZE_EXCEPTION; 
      unset($carrier_list[$key]); 
     } 

     if ($carrier->max_weight > 0 && $carrier->max_weight < $product->weight * $cart_quantity) 
     { 
      $error[$carrier->id] = Carrier::SHIPPING_WEIGHT_EXCEPTION; 
      unset($carrier_list[$key]); 
     } 


     //Here goes the magic 
     foreach ($cart->getProducts(false, $product->id) as $cart_product) { 
      $aProduct = new Product($cart_product['id_product']); 
      if (substr($aProduct->reference, 0, 1) == 1) { 
       unset($carrier_list[$key]); 
      } 
     } 


    } 
} 

return $carrier_list; 

仍然較好,不需要覆蓋整個功能:

public static function getAvailableCarrierList(Product $product, $id_warehouse, $id_address_delivery = null, $id_shop = null, $cart = null, &$error = array()) 
{ 
    $carrier_list = parent::getAvailableCarrierList($product, $id_warehouse, $id_address_delivery, $id_shop, $cart, &$error); 

    if (is_null($cart)) 
     $cart = Context::getContext()->cart; 

    if ($product->width > 0 || $product->height > 0 || $product->depth > 0 || $product->weight > 0) 
    { 
     foreach ($carrier_list as $key => $id_carrier) 
     { 
      //Here goes the magic 
      foreach ($cart->getProducts(false, $product->id) as $cart_product) { 
       $aProduct = new Product($cart_product['id_product']); 
       if (substr($aProduct->reference, 0, 1) == 1) { 
        unset($carrier_list[$key]); 
       } 
      } 
     } 
    } 

    return $carrier_list; 
} 

未經檢驗。

相關問題