1

I need to calculate the total price of my bundle and if the required option of this bundle have promo I need to print the price before the promo and after on catalog/view.

For that I have : (helper)

public function bundleItemsPromo($product) {
    $productId = $product->getId();
    $bundled_product = Mage::getModel('catalog/product')->load($productId);



    $selectionCollection = $bundled_product->getTypeInstance(true)->getSelectionsCollection(
        $bundled_product->getTypeInstance(true)->getOptionsIds($bundled_product), $bundled_product
    );

    $bundled_items_reduct = 0;
    $price = 0;
        foreach($selectionCollection as $option)
        {
            if($price < $option->getPrice()) {
                $price = $option->getPrice();
                if ($option->getSpecialPrice()){
                    $bundled_items_reduct += $price - $option->getSpecialPrice();
                }
            }
        }

    return $bundled_items_reduct;
}

In my foreach I just need calculate the promo only if the product is required
I tried:

$bundled_product->getTypeInstance(true)->getSelectionsCollection(
        $bundled_product->getTypeInstance(true)->getOptionsIds($bundled_product), $bundled_product
    )->hasRequiredOptions()

but...

If you have an idea?

0
class ????_Bundle_Helper_Promo extends Mage_Core_Helper_Abstract {

    /**
     * return the price of required option on bundle, before the promo
     *
     * @param $product
     * @return int
     */
    public function bundleItemsPromo($product) {
        $OptionsCollection = $product->getTypeInstance(true)->getOptionsCollection($product);
    //init bundle option promo
        $bundled_items_reduct = 0;

        foreach($OptionsCollection as $option){
            $price = 0;

            //if option is required
            if($option->getRequired() == 1){

               foreach($option->getSelections() as $productOption){
                    //if option have promo
                    if($productOption->getSpecialPrice()){

                        //init price with the first special price 
                        if ($price==0){
                            $price = $productOption->getPrice();
                            }
                        //look just the smallest price
                        if($price >= $productOption->getPrice()){
                            $price = $productOption->getPrice();
                                //save the price before the promo
                                $bundled_items_reduct += $price -  $productOption->getSpecialPrice();
                        }
                    }
                }
            }
        }

        return $bundled_items_reduct;
    }
}

It works !

This helper returns the price of bundle product before the promo, 1st foreach to find if option is required and 2nd foreach to get option's price.

  • please fix identation and add some explanation – nicolallias Jul 29 '15 at 12:19
  • better ? sorry is not realy easy for me to explain how i make this code in english ^^ – sunwell Jul 29 '15 at 13:12
  • This is way better ;) – nicolallias Jul 29 '15 at 13:16

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.