Programmatically adding configurable products to the cart with SCP Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?Wrong price for configurable product in cartPulling simple products into cart from configurableOverride SCP (Simple Configurable Products) BlockAdding multiple configurable product variations adding first one multiple timesProgrammatically adding products to the cart with SCPAdding multiple simple products belonging to a configurable product to cartWithout extension can I add configurable product to cart?How to show cheapest simple product price on product listHow do display the firstItem/Maximal Price in Configurable products? Anyone? programmatically Magento 2.2.3Simple Configurable Products Extension Bugs

"klopfte jemand" or "jemand klopfte"?

What does it mean that physics no longer uses mechanical models to describe phenomena?

Central Vacuuming: Is it worth it, and how does it compare to normal vacuuming?

GDP with Intermediate Production

New Order #6: Easter Egg

Delete free apps from library

Does the Mueller report show a conspiracy between Russia and the Trump Campaign?

Caught masturbating at work

i2c bus hangs in master RPi access to MSP430G uC ~1 in 1000 accesses

What are the main differences between the original Stargate SG-1 and the Final Cut edition?

How can I prevent/balance waiting and turtling as a response to cooldown mechanics

In musical terms, what properties are varied by the human voice to produce different words / syllables?

Did any compiler fully use 80-bit floating point?

How many morphisms from 1 to 1+1 can there be?

Simple HTTP Server

Constant factor of an array

What order were files/directories output in dir?

A term for a woman complaining about things/begging in a cute/childish way

Most effective melee weapons for arboreal combat? (pre-gunpowder technology)

What does 丫 mean? 丫是什么意思?

I can't produce songs

Tips to organize LaTeX presentations for a semester

Moving a wrapfig vertically to encroach partially on a subsection title

How many time has Arya actually used Needle?



Programmatically adding configurable products to the cart with SCP



Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?Wrong price for configurable product in cartPulling simple products into cart from configurableOverride SCP (Simple Configurable Products) BlockAdding multiple configurable product variations adding first one multiple timesProgrammatically adding products to the cart with SCPAdding multiple simple products belonging to a configurable product to cartWithout extension can I add configurable product to cart?How to show cheapest simple product price on product listHow do display the firstItem/Maximal Price in Configurable products? Anyone? programmatically Magento 2.2.3Simple Configurable Products Extension Bugs



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















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



checkout/cart/add?product=10940&qty=1&super_attribute[134]=22


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










share|improve this question
















bumped to the homepage by Community 10 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • Have you got solution?

    – Jalpesh Patel
    May 3 '17 at 12:10

















0















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



checkout/cart/add?product=10940&qty=1&super_attribute[134]=22


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










share|improve this question
















bumped to the homepage by Community 10 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • Have you got solution?

    – Jalpesh Patel
    May 3 '17 at 12:10













0












0








0








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



checkout/cart/add?product=10940&qty=1&super_attribute[134]=22


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










share|improve this question
















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



checkout/cart/add?product=10940&qty=1&super_attribute[134]=22


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







magento-1.9 configurable-product cart






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 28 '18 at 5:12









Teja Bhagavan Kollepara

2,99241949




2,99241949










asked Dec 28 '15 at 18:53









Rv SoniRv Soni

1113




1113





bumped to the homepage by Community 10 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 10 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.














  • Have you got solution?

    – Jalpesh Patel
    May 3 '17 at 12:10

















  • Have you got solution?

    – Jalpesh Patel
    May 3 '17 at 12:10
















Have you got solution?

– Jalpesh Patel
May 3 '17 at 12:10





Have you got solution?

– Jalpesh Patel
May 3 '17 at 12:10










2 Answers
2






active

oldest

votes


















0














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');
$cart->init();
// Add a product with custom options
$params = array(
'product' => $configurableProduct->getId(),
'qty' => 1,
'super_attribute' => $options
);
$request = new Varien_Object();
$request->setData($params);
$cart->addProduct($configurableProduct, $request);
$session = Mage::getSingleton('customer/session');
$session->setCartWasUpdated(true);
$cart->save();



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.






share|improve this answer

























  • 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 '15 at 18:07


















0














I had the same challenge. To solve this I created a custom controller which I could call via a URL then placed Vicky Dev's code in the action that I was calling from the URL. It worked for me.






share|improve this answer























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "479"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f95240%2fprogrammatically-adding-configurable-products-to-the-cart-with-scp%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    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');
    $cart->init();
    // Add a product with custom options
    $params = array(
    'product' => $configurableProduct->getId(),
    'qty' => 1,
    'super_attribute' => $options
    );
    $request = new Varien_Object();
    $request->setData($params);
    $cart->addProduct($configurableProduct, $request);
    $session = Mage::getSingleton('customer/session');
    $session->setCartWasUpdated(true);
    $cart->save();



    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.






    share|improve this answer

























    • 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 '15 at 18:07















    0














    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');
    $cart->init();
    // Add a product with custom options
    $params = array(
    'product' => $configurableProduct->getId(),
    'qty' => 1,
    'super_attribute' => $options
    );
    $request = new Varien_Object();
    $request->setData($params);
    $cart->addProduct($configurableProduct, $request);
    $session = Mage::getSingleton('customer/session');
    $session->setCartWasUpdated(true);
    $cart->save();



    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.






    share|improve this answer

























    • 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 '15 at 18:07













    0












    0








    0







    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');
    $cart->init();
    // Add a product with custom options
    $params = array(
    'product' => $configurableProduct->getId(),
    'qty' => 1,
    'super_attribute' => $options
    );
    $request = new Varien_Object();
    $request->setData($params);
    $cart->addProduct($configurableProduct, $request);
    $session = Mage::getSingleton('customer/session');
    $session->setCartWasUpdated(true);
    $cart->save();



    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.






    share|improve this answer















    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');
    $cart->init();
    // Add a product with custom options
    $params = array(
    'product' => $configurableProduct->getId(),
    'qty' => 1,
    'super_attribute' => $options
    );
    $request = new Varien_Object();
    $request->setData($params);
    $cart->addProduct($configurableProduct, $request);
    $session = Mage::getSingleton('customer/session');
    $session->setCartWasUpdated(true);
    $cart->save();



    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.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited May 23 '17 at 12:37









    Community

    1




    1










    answered Dec 28 '15 at 18:59









    Vicky DevVicky Dev

    1,28761539




    1,28761539












    • 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 '15 at 18:07

















    • 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 '15 at 18:07
















    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 '15 at 18:07





    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 '15 at 18:07













    0














    I had the same challenge. To solve this I created a custom controller which I could call via a URL then placed Vicky Dev's code in the action that I was calling from the URL. It worked for me.






    share|improve this answer



























      0














      I had the same challenge. To solve this I created a custom controller which I could call via a URL then placed Vicky Dev's code in the action that I was calling from the URL. It worked for me.






      share|improve this answer

























        0












        0








        0







        I had the same challenge. To solve this I created a custom controller which I could call via a URL then placed Vicky Dev's code in the action that I was calling from the URL. It worked for me.






        share|improve this answer













        I had the same challenge. To solve this I created a custom controller which I could call via a URL then placed Vicky Dev's code in the action that I was calling from the URL. It worked for me.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Oct 20 '17 at 5:34









        Clinton FongClinton Fong

        1




        1



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Magento Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f95240%2fprogrammatically-adding-configurable-products-to-the-cart-with-scp%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Disable / Remove link to Product Items in Cart Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?How can I limit products that can be bought / added to cart?Remove item from cartHide “Add to Cart” button if specific products are already in cart“Prettifying” the custom options in cart pageCreate link in cart sidebar to view all added items After limit reachedLink products together in checkout/cartHow to Get product from cart and add it againHide action-edit on cart page if simple productRemoving Cart items - ObserverRemove wishlist items when added to cart

            Helsingin valtaus Sisällysluettelo Taustaa | Yleistä sotatoimista | Osapuolet | Taistelut Helsingin ympäristössä | Punaisten antautumissuunnitelma | Taistelujen kulku Helsingissä | Valtauksen jälkeen | Tappiot | Muistaminen | Kirjallisuutta | Lähteet | Aiheesta muualla | NavigointivalikkoTeoksen verkkoversioTeoksen verkkoversioGoogle BooksSisällissota Helsingissä päättyi tasan 95 vuotta sittenSaksalaisten ylivoima jyräsi punaisen HelsinginSuomalaiset kuvaavat sotien jälkiä kaupungeissa – katso kuvat ja tarinat tutuilta kulmiltaHelsingin valtaus 90 vuotta sittenSaksalaiset valtasivat HelsinginHyökkäys HelsinkiinHelsingin valtaus 12.–13.4. 1918Saksalaiset käyttivät ihmiskilpiä Helsingin valtauksessa 1918Teoksen verkkoversioTeoksen verkkoversioSaksalaiset hyökkäävät Etelä-SuomeenTaistelut LeppävaarassaSotilaat ja taistelutLeppävaara 1918 huhtikuussa. KapinatarinaHelsingin taistelut 1918Saksalaisten voitonparaati HelsingissäHelsingin valtausta juhlittiinSaksalaisten Helsinki vuonna 1918Helsingin taistelussa kaatuneet valkokaartilaisetHelsinkiin haudatut taisteluissa kaatuneet punaiset12.4.1918 Helsingin valtauksessa saksalaiset apujoukot vapauttavat kaupunginVapaussodan muistomerkkejä Helsingissä ja pääkaupunkiseudullaCrescendo / Vuoden 1918 Kansalaissodan uhrien muistomerkkim

            Adjektiivitarina Tarinan tekeminen | Esimerkki: ennen | Esimerkki: jälkeen | Navigointivalikko