I am using the SCP extension so that prices are taken from the simple product and not the configurable. I am using url approach to add product in the cart


This url adds product into cart but price is taken from first associated product only. same price is rendered in all associated products.


1 Answer 1


Can you try below code ?

$_product = $this->getProduct();
$parentIds = Mage::getResourceSingleton('catalog/product_type_configurable')->getParentIdsByChild($_product->getId());
// check if something is returned
if (!empty(array_filter($parentIds))) {
    $pid = $parentIds[0];

    // Collect options applicable to the configurable product
    $configurableProduct = Mage::getModel('catalog/product')->load($pid);
    $productAttributeOptions = $configurableProduct->getTypeInstance(true)->getConfigurableAttributesAsArray($configurableProduct);
    $options = array();

    foreach ($productAttributeOptions as $productAttribute) {
        $allValues = array_column($productAttribute['values'], 'value_index');
        $currentProductValue = $_product->getData($productAttribute['attribute_code']);
        if (in_array($currentProductValue, $allValues)) {
            $options[$productAttribute['attribute_id']] = $currentProductValue;

    // Get cart instance
    $cart = Mage::getSingleton('checkout/cart'); 
    // Add a product with custom options
    $params = array(
        'product' => $configurableProduct->getId(),
        'qty' => 1,
        'super_attribute' => $options
    $request = new Varien_Object();
    $cart->addProduct($configurableProduct, $request);
    $session = Mage::getSingleton('customer/session');

Main thing about adding configurable product to cart is what data/options are passed to super_attribute.

For more information please check this out.

Hope this helps.

  • thanks, but I am trying to add product via url. So can you please suggest what parameter do I need to add along with super attribute to add the associated product's price in the cart.
    – Rv Soni
    Dec 30, 2015 at 18:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.