2015-10-04 134 views
0

我正在銷售具有存款價格的瓶裝飲料。客戶必須支付這筆費用,但可以將瓶子帶到超市購買。我想在沒有存款的產品頁面中顯示產品價格,但是當用戶檢查他的購物車時,需要將這個數量添加到購物車中以獲得每個存款的物品。這裏有一些額外的信息: 並非所有產品都有存款 的存款價格取決於產品prestashop中產品的臨時價格

我設法一個「定金」字段添加到產品頁面的後臺:

http://oi57.tinypic.com/6p9s80.jpg

但是,似乎更改購物車檢出的整個工作流程將是一件非常痛苦的事情。有沒有簡單的方法來完成這項任務?

謝謝!

回答

1

做你想要它是用「產品屬性的組合」 +小代碼更改,一步一個腳印什麼最簡單的方法:

  1. 創建產品屬性如「存款」
  2. 增加它的價值,任何,例如。 「是」
  3. 在產品中創建與「存款:是」的組合,根據需要設置價格影響值,例如, 「$ 10」,並將其設置爲默認組合
  4. 對產品頁面價格顯示沒有function updatePrice()查找線路

    // Apply combination price impact // 0 by default, +x if price is inscreased, -x if price is decreased basePriceWithoutTax = basePriceWithoutTax + +combination.price;

,幷包裝成條件themes/themename/js/product.js「定金」的變化:

if(your_attribute_id != combination.attributes[0]) {  
    basePriceWithoutTax = basePriceWithoutTax + +combination.price; 
} 

但在購物車中您會看到全價。

UPD:

  • 我看不出有什麼好辦法做到這一點的模板,沒有核心的變化,因此,如果您需要它(解決方案還不夠理想) 文件controllers/front/CategoryController.phpuse override)方法assignProductList()改變代碼塊到下一個視圖:

    foreach ($this->cat_products as &$product) { 
        if ($product['id_product_attribute'] && isset($product['product_attribute_minimal_quantity'])) 
         $product['minimal_quantity'] = $product['product_attribute_minimal_quantity']; 
        $combination = new Combination($product['id_product_attribute']); 
        $attributes = $combination->getAttributesName($this->context->language->id); 
        foreach ($attributes as $attribute) { 
         if(your_attribute_id == $attribute['id_attribute']) 
          $product['price_tax_exc'] -= $combination->price; 
        } 
    } 
    
  • 您將需要重複它,你使用所有列出的控制器(你可以不使用的foreach但像你已經做過的那樣通過索引來訪問數組元素),在任何情況下,解決方案都非常針對項目,只是快速修復,通常情況下更好地使用其他方式。

    +0

    嗨,謝謝你的回答!這個想法很好,我正在用組合技巧。問題是這僅適用於產品頁面,而不適用於產品列表頁面(以及所有其他產品列表,例如精選,最佳銷售等)。任何想法? – skirato

    +0

    此外,我不得不調整你的代碼到'if(combination.attributes [0] == 1){ \t \t basePriceWithoutTax = basePriceWithoutTax ++ combination.price; \t}'因爲它是我必須比較的id屬性,所以每個產品的id_product_attribute是不同的。 – skirato

    +0

    '組合。屬性[0]!= 1'當然! (抱歉的垃圾郵件,無法編輯我的評論) – skirato