Magento – Get selected Custom Options from configurable product

addtocartconfigurable-productevent-observermagento-1simple-product

the following observer script looks for selected configurable options, to work out the qty needed and adds a simple product (#9236) to the cart.

However, it only works for simple products.
How can I get it to also get configurable products selected custom options?

class My_Observer
{
    public function add_product_qty(Varient_Event_Observer $obs)
    {
        $quote = $obs->getEvent()->getQuote();
        $getquoteitems = $obs->getQuoteItem();

        $custom = $obs->getQuoteItem();
        if ($custom->getParentItem()) {
            $custom = $custom->getParentItem();
        }
        $product_id=$custom->getProductId();

        $helper = Mage::helper('catalog/product_configuration');
        $optionList = $helper->getCustomOptions($getquoteitems);
        if (!empty($optionList[1])) {
            //Custom Options
            $qty = 0;
            $Onelogo = '1x Logo (Setup Required)';
            $Twologo = '2x Logo (Setup Required)';
            $Threelogo = '3x Logo (Setup Required)';

            if (in_array($Onelogo, $optionList[1])) {
                $qty = 1;
            }
            if (in_array($Twologo, $optionList[1])) {
                $qty = 2;
            }
            if (in_array($Threelogo, $optionList[1])) {
                $qty = 3;
            }
            if ($qty > 0) {
                // Mage init
                require_once(Mage::getBaseDir().'/app/Mage.php');
                umask(0);
                Mage::app('default');
                Mage::getSingleton('core/session', array('name' => 'frontend'));

                // Get customer session
                $session = Mage::getSingleton('customer/session');

                // Get cart instance
                $cart = Mage::getSingleton('checkout/cart');
                $cart->init();

                // Add a product (simple); id:12,  qty: 3
                $cart->addProduct(9236, $qty);
                $session->setCartWasUpdated(true);
            }
        }
    }
}

Best Answer

you can get custom option

$quote = $obs->getEvent()->getQuote();
foreach ($quote->getAllVisibleItems() as $item) {
    print_r($item->getOptions());
}