Add bundle product to cart without having to specify the options

后端 未结 4 1127
-上瘾入骨i
-上瘾入骨i 2021-02-03 13:30

I have bundle products with 3 checkboxes checked as default. I want to add a bundle product from the page category list (list.phtml) without having to specify the o

4条回答
  •  离开以前
    2021-02-03 14:08

    Joras' solution works, but it can create multiple items in the quote, each containing the same bundle (with identical selections). The reason is that when comparing a a newly added bundle with the quote items, Magento (tested on 1.9.2.2) creates a bundel_identity string composed out of

    [product_id]_[option_id_1]_[option_qty_]_[option_id_2]_[option_qty_2]...

    The this string depends on the order of the parameters submitted. To follow the order specified in the product settings use :

     $typeInstance = $product->getTypeInstance(true)
                        ->setStoreFilter($product->getStoreId(), $product);
    
                    $optionCollection = $typeInstance->getOptionsCollection($product);
     foreach ($optionCollection as $option) {
    // build your query string here....
    
    }
    

    Also it is quite a hacky¡ to do that inside the template. Better option imo

    override Mage_Catalog_Block_Product_List::getAddToCartUrl($product, $additional = array())
    

提交回复
热议问题