0

I'm trying to alter a price based on some custom options set. Therefore I'm trying to get the value a customer has entered, not the default values set in the backend. To do this I'm using the event catalog_product_get_final_price used in Mage_Bundle_Model_Product_Price. I have registered the following observer:

public function observer_callback($evt_obs)
{
    $event = $evt_obs->getEvent();
    $data  = $event->getData();
    /* @var $collection Mage_Catalog_Model_Resource_Product_Collection */
    $collection = $data['collection'];

    $items = $collection->getItems();

    /* @var $item Mage_Catalog_Model_Product */
    foreach ($items as $item) {
        if ( $item->getName() ==  'Bundel Test2') {

            $options = $item->getCustomOptions();

            /* @var $option Mage_Catalog_Model_Product_Option */
            foreach ($options as $option) {
                // Here I'm trying to get the value given by the user/customer
                var_dump($option->getData());
            }

        }
    }
    return $this;
}

It is a custom option from a bundle type. So the product can't be configurable. I'm new to magento so I'm probably missing something.

Can anyone help me?

4

1 回答 1

0

希望这段代码可以帮助你:

public function productFinalPrice($observer){
     $product    = $observer->getEvent()->getProduct();

     $productType=$product->getTypeID();

     if($productType == 'your_product_type')
     {

        $option = $product->getCustomOptions();
        $searchedOption = null;  

        //search for your option;
        foreach ($product->getOptions() as $o) {

            if($o->getTitle()=="your_attribute_title" && $o->getType()=="your_type_of_option(eg. area"){
                $optionId = $o->getOptionId();//got your searched optionId
                break;
            }
        }


        foreach($option as $key => $o) {
            if($key == "option_".$optionId) {
                $searchedOption = $o;
               //here you get the option object with the values in it
            }
        }


        $articleNumber = $searchedOption->getData('value'); // getthe value of your option


            //calculate final price like you need it
            $product->setFinalPrice($finalPrice);
     }  
     return $this;     
}

此致

于 2013-03-08T12:04:59.410 回答