Magento 1.7 – Get Product ID or SKU After Adding Configurable Product to Cart

cartcheckoutmagento-1.7product

Magento 1.7.
I have one configurable product and associated products, also I have some dropdown boxes. After choosing the option from my product, I added it to the cart. I want to now get the product_id or product_sku for the simple product; for configurable products working.

        <checkout_cart_product_add_after>
            <observers>
                <cart_init>
                    <type>singleton</type>
                    <class>ExtraCart_Cart_Model_Observer</class>
                    <method>getProductIdSku</method>
                </cart_init>
            </observers>
        </checkout_cart_product_add_after>

php code :

 public function getProductIdSku(Varien_Event_Observer $observer){
    $product = $observer->getEvent()->getQuoteItem();
    $productSku = $product->getSku();  //for configurable product
    $productQty = $product->getQty();  //for configurable product

    $order = $observer->getEvent();
    $data = $order->getData('sku');  //fr simple product is not working
    $quote = Mage::getSingleton('checkout/session')->getQuote();  //for configurable product

    $sales_quote = Mage::getModel('sales/quote_item_option');...->getId(); getSku();
}

Best Answer

You can get the simple product details on the same event by placing the following code in your observer :

$main_product = $observer->getEvent()->getProduct();
$associated_product = $observer->getEvent()->getQuoteItem();
$productSku = $main_product ->getSku();  //for configurable product
$productQty = $main_product ->getQty();  //for configurable product
if($product->getTypeID() == 'configurable'){
  //to get the id or sku of associated product use the following.
  $simple_product_id = $quoteitem->getProduct()->getId();
  $simple_product_sku = $quoteitem->getProduct()->getSku();
}

Hope this works for you.