0

I have a bundle product with a fixed price, and options with fixed price. For example :

Main Product 599.00
o subproduct 0.00 
o second product +15.00
o third product +25.00

After changing the price of subproduct (the simple product), magento changes option prices in all bundled products which contain this simple product like so ( after adding 10 euro to the price of the simple subproduct ):

Main Product 599.00
o subproduct 0.00 
o second product +25.00
o third product +35.00

I do not want magento to change the bundled products options prices after saving the simple product with a new price. How can this be accomplished ?

edit : found custom observer :

// Change Option Prices Observer Method
public function changeOptionPrices($observer){

    $_product = $observer->getProduct();
    $parentIds = Mage::getResourceSingleton('bundle/selection')->getParentIdsByChild($_product->getId());

    // IF PRODUCT TYPE == SIMPLE
    if($_product->getTypeId() == 'simple' && count($parentIds) >= 1){

        $price = $_product->getOrigData('price');

        foreach ($parentIds as $id) {
            $product = Mage::getModel('catalog/product')->load($id);
            if($product->getId()){

            $product->getTypeInstance(true)->setStoreFilter($product->getStoreId(), $product);
            $optionCollection = $product->getTypeInstance(true)->getOptionsCollection($product);
            $selectionCollection = $product->getTypeInstance(true)->getSelectionsCollection($product->getTypeInstance(true)->getOptionsIds($product), $product);
            $optionCollection->appendSelections($selectionCollection);

            $optionRawData = array();
            $selectionRawData = array();
            $default_option_data = array();
            $ids = array();
            $i = 0;

            foreach ($optionCollection as $option) {
                $optionRawData[$i] = array(
                    'option_id' => $option->getOptionId(), //my addition. important otherwise, options going to be duplicated
                    'required' => $option->getData('required'),
                    'position' => $option->getData('position'),
                    'type' => $option->getData('type'),
                    'title' => $option->getData('title')?$option->getData('title'):$option->getData('default_title'),
                    'delete' => ''
                    );

                foreach ($option->getSelections() as $selection) {


                    $selection_price = $selection->getSelectionPriceValue();

                    if($_product->getId() == $selection->product_id){

                        if(!$selection->getIsDefault()){
                            $old_price = $_product->getOrigData('price');
                            $new_price = $_product->getPrice();
                            if($old_price > $new_price){
                                $selection_price -= ($old_price - $new_price);
                            } else if($new_price > $old_price) {
                                $selection_price += ($new_price - $old_price);
                            }

                        }
                        else{
                            $selection_price = $selection->getSelectionPriceValue();
                            $old_price = $_product->getOrigData('price');
                            $new_price = $_product->getPrice();
                            $diff = ($new_price-$old_price);
                            $ids[] = $i;
                            $default_option_data[$i][]=array(
                                'product_id' => $selection->getProductId(),     
                                'is_default' => $selection->getIsDefault(),
                                'selection_price_type' => $selection->getSelectionPriceType(),
                                'selection_price_value' => $selection_price,
                                'difference' => $diff,
                            );

                        }

                    }
                    $selectionRawData[$i][] = array(
                        'product_id' => $selection->getProductId(),
                        'position' => $selection->getPosition(),
                        'is_default' => $selection->getIsDefault(),
                        'selection_price_type' => $selection->getSelectionPriceType(),
                        'selection_price_value' => $selection_price,
                        'selection_qty' => $selection->getSelectionQty(),
                        'selection_can_change_qty' => $selection->getSelectionCanChangeQty(),
                        'delete' => ''
                        );
                }
                $i++;
            }

            if(!empty($default_option_data) && !empty($ids)){
                foreach ($ids as $id) {
                    $diff_array = $default_option_data[$id];
                    $selection_array = $selectionRawData[$id];
                    foreach ($selection_array as $key => $value) {
                        if($value['is_default'] == 1){
                            $selectionRawData[$id][$key] = $value;
                        }else{
                            $selectionRawData[$id][$key] = $value;
                            $selectionRawData[$id][$key]['selection_price_value']-=$diff_array[0]['difference'];
                        }
                    }

                }
            }
            $product->setBundleOptionsData($optionRawData);   //changed it to $product
            $product->setBundleSelectionsData($selectionRawData); 
            $product->setCanSaveBundleSelections(true); 
            //$product->setData('bundle_item_lock', '0'); // remove lock
            $product->save();


        }

    }
    }



    // IF PRODUCT TYPE == BUNDLE with LOCK
    if($_product->getTypeId() == 'bundle' && $_product->getBundleItemLock()){

        $_product->getTypeInstance(true)->setStoreFilter($_product->getStoreId(), $_product);
        $optionCollection = $_product->getTypeInstance(true)->getOptionsCollection($_product);
        $selectionCollection = $_product->getTypeInstance(true)->getSelectionsCollection($_product->getTypeInstance(true)->getOptionsIds($_product), $_product);
        $optionCollection->appendSelections($selectionCollection);

        $optionRawData = array();
        $selectionRawData = array();

        $i = 0;

        $optionNewRawData = array();
        $selectionNewRawData = array();

    // set optionRawData
    foreach ($optionCollection as $option) {
                $optionRawData[$i] = array(
                    'option_id' => $option->getOptionId(), 
                    'required' => $option->getData('required'),
                    'position' => $option->getData('position'),
                    'type' => $option->getData('type'),
                    'title' => $option->getData('title')?$option->getData('title'):$option->getData('default_title'),
                    'delete' => ''
                    );

    // set selectionRawData                         
    foreach ($option->getSelections() as $selection) {
                    $selection_price = $selection->getSelectionPriceValue();
                    $selectionRawData[$i][] = array(
                        'product_id' => $selection->getProductId(),
                        'position' => $selection->getPosition(),
                        'is_default' => $selection->getIsDefault(),
                        'selection_price_type' => $selection->getSelectionPriceType(),
                        'selection_price_value' => $selection_price,
                        'selection_qty' => $selection->getSelectionQty(),
                        'selection_can_change_qty' => $selection->getSelectionCanChangeQty(),
                        'delete' => ''
                        );
                }
                $i++;
            }

    // recalculate selectionRawData
    foreach($selectionRawData as $key => $value){
                $selectionNewRawData[$key] = $this->SelectionCalc($value);
            }

            //Mage::register('product', $_product);
            //Mage::register('current_product', $_product);

            $_product->setBundleOptionsData($optionRawData);   
            $_product->setBundleSelectionsData($selectionNewRawData);
            $_product->setCanSaveBundleSelections(true); 

}

}
  • - I found a custom observer who did this trickery. Question no longer needed to be answered. Magento does not come with this functionality by default. – Kurdt94 Dec 9 '15 at 15:27
  • Would you mind adding this observer as an answer? Otherwise this post is going to be frustrating for future searchers. – Fabian Schmengler Jan 13 '16 at 22:21
  • Added the observer ( product save after ) – Kurdt94 Jan 14 '16 at 10:10
  • You can answer your own question, no need to edit the question itself :) – Fabian Schmengler Jan 14 '16 at 10:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.