1

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();
}
0

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.

|improve this answer|||||
0

Here the solution is

  $main_product = $observer->getEvent()->getProduct();
    $associated_product = $observer->getEvent()->getQuoteItem();
    if($product->getTypeId() == 'configurable'){
      //to get the id or sku of associated product use the following.
     //  $asoc_id is Configurbale product id 
      $ConfigProductId = $quoteitem->getProduct()->getId(); 
    //$assoc_sku is simple Product id
      $assoc_sku = $quoteitem->getProduct()->getSku();
     // Associated Product id  
     $Assocate;IdPro=Mage::getModel("catalog/product")->loadByAttribute('sku',$assoc_sku)->getId()
    }
|improve this answer|||||

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.