0

Is it possible to get the Swatch value id or name from the checkout_cart_product_add_before observer? I've passed the Product using

$product = $observer->getProduct();
$productId = $observer->getProduct()->getId();

but I can't find anywhere online on how to get the swatch value or child id of the saved product, currently, it only passes the configurableID and I need the Simple id. Looping through the associated products is no good as I need the one that was selected

1

In your observer, you can get the child product data using this code.

    $info = $observer->getInfo();
    $product = $observer->getProduct();
    if ($product->getTypeId() == "configurable") {
        $configClass = $product->getTypeInstance();
        $childProduct = $configClass->getProductByAttributes($info['super_attribute'], $product);
        $sku = $childProduct->getSku();
        $productId = $childProduct->getId();
    }
0

In event 'checkout_cart_product_add_before' arguments are as below as $product and $request. You can get the swatch value from $request variable.

 Mage::dispatchEvent('checkout_cart_product_add_before', array(
             'product' => $product,
              'request' => $request
        ));

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.