How to add simple product to cart instead of configurable product












1















I want to prevent configurable products from ending up in the cart. I want to add their simple product equivalent to the cart.



Despite this being a fairly normal request, I haven't found anything that is doing this.



I currently have an observer set up to work on checkout_cart_add_product_complete
checkout_cart_add_product_complete



I'm able to manipulate the cart from here (add, remove items), but I can't remove a configurable product (nor its options).



Does anyone know how this is possible?



Observer.php



class Mymodule_Addtocartredirect_Model_Customizablereplace {
public function replaceItems($observer) {
$quote = Mage::getSingleton('checkout/session')->getQuote();
$storeId = Mage::app()->getStore()->getStoreId();

foreach ($quote->getAllItems() as $item) {
$result = array();
Mage::log("We have a product! " . $item->getSku(),null,"test.log");
if($item->getOptionByCode('simple_product')) {
$childProduct = $item->getOptionByCode('simple_product')->getProduct()->getId();
Mage::log("We have ".$childProduct,null,"test.log");
}

if ($option = $item->getOptionByCode('simple_product')) {
$cartHelper = Mage::helper('checkout/cart')->getCart();
$quantity = $item->getQty();
$childProduct = $option->getProduct();
Mage::log("Child Product: ".$childProduct->getSku()." (".$childProduct->getId().")",null,"test.log");
$cartHelper->removeItem($item->getId());
$cartHelper->addItem($childProduct->getId(),$quantity);
}
}
$quote->collectTotals()->save();
}
}









share|improve this question


















  • 1





    By Magento design, Magento adds the configurable product for any simple product . When you remove the product and try to use : $cartHelper->addItem($childProduct->getId(),$quantity); Magento would add both the simple and configurable product back again. Is there a reach you're trying to remove the configurable product? Perhaps you could look to get rid of the need to do that because this won't work because of the way Magento is built for configurable products.

    – Paras Sood
    Mar 8 '16 at 21:03













  • We are exporting orders from Magento to a 3rd party ERP, but it does not handle configurable items well. The easiest solution appears to be changing Magento's behavior. Can I replace the configurable product with the simple product?

    – travisw
    Mar 9 '16 at 12:35






  • 2





    Why don't you make changes in the code that sends the order over to the EPR, wherein you don't send the configurable product but only the simple one?

    – Paras Sood
    Mar 9 '16 at 13:15











  • I didn't develop the connector for the ERP, so I'm not familiar enough with it to make those modifications. I assumed the Magento modification would be somewhat simple.

    – travisw
    Mar 10 '16 at 12:00






  • 1





    I also strongly advise against this change. This is expected Magento core behaviour and some extensions (like my Spranks_ConfigurableTierPrices) rely on this behaviour.

    – Simon
    Mar 16 '16 at 12:39
















1















I want to prevent configurable products from ending up in the cart. I want to add their simple product equivalent to the cart.



Despite this being a fairly normal request, I haven't found anything that is doing this.



I currently have an observer set up to work on checkout_cart_add_product_complete
checkout_cart_add_product_complete



I'm able to manipulate the cart from here (add, remove items), but I can't remove a configurable product (nor its options).



Does anyone know how this is possible?



Observer.php



class Mymodule_Addtocartredirect_Model_Customizablereplace {
public function replaceItems($observer) {
$quote = Mage::getSingleton('checkout/session')->getQuote();
$storeId = Mage::app()->getStore()->getStoreId();

foreach ($quote->getAllItems() as $item) {
$result = array();
Mage::log("We have a product! " . $item->getSku(),null,"test.log");
if($item->getOptionByCode('simple_product')) {
$childProduct = $item->getOptionByCode('simple_product')->getProduct()->getId();
Mage::log("We have ".$childProduct,null,"test.log");
}

if ($option = $item->getOptionByCode('simple_product')) {
$cartHelper = Mage::helper('checkout/cart')->getCart();
$quantity = $item->getQty();
$childProduct = $option->getProduct();
Mage::log("Child Product: ".$childProduct->getSku()." (".$childProduct->getId().")",null,"test.log");
$cartHelper->removeItem($item->getId());
$cartHelper->addItem($childProduct->getId(),$quantity);
}
}
$quote->collectTotals()->save();
}
}









share|improve this question


















  • 1





    By Magento design, Magento adds the configurable product for any simple product . When you remove the product and try to use : $cartHelper->addItem($childProduct->getId(),$quantity); Magento would add both the simple and configurable product back again. Is there a reach you're trying to remove the configurable product? Perhaps you could look to get rid of the need to do that because this won't work because of the way Magento is built for configurable products.

    – Paras Sood
    Mar 8 '16 at 21:03













  • We are exporting orders from Magento to a 3rd party ERP, but it does not handle configurable items well. The easiest solution appears to be changing Magento's behavior. Can I replace the configurable product with the simple product?

    – travisw
    Mar 9 '16 at 12:35






  • 2





    Why don't you make changes in the code that sends the order over to the EPR, wherein you don't send the configurable product but only the simple one?

    – Paras Sood
    Mar 9 '16 at 13:15











  • I didn't develop the connector for the ERP, so I'm not familiar enough with it to make those modifications. I assumed the Magento modification would be somewhat simple.

    – travisw
    Mar 10 '16 at 12:00






  • 1





    I also strongly advise against this change. This is expected Magento core behaviour and some extensions (like my Spranks_ConfigurableTierPrices) rely on this behaviour.

    – Simon
    Mar 16 '16 at 12:39














1












1








1








I want to prevent configurable products from ending up in the cart. I want to add their simple product equivalent to the cart.



Despite this being a fairly normal request, I haven't found anything that is doing this.



I currently have an observer set up to work on checkout_cart_add_product_complete
checkout_cart_add_product_complete



I'm able to manipulate the cart from here (add, remove items), but I can't remove a configurable product (nor its options).



Does anyone know how this is possible?



Observer.php



class Mymodule_Addtocartredirect_Model_Customizablereplace {
public function replaceItems($observer) {
$quote = Mage::getSingleton('checkout/session')->getQuote();
$storeId = Mage::app()->getStore()->getStoreId();

foreach ($quote->getAllItems() as $item) {
$result = array();
Mage::log("We have a product! " . $item->getSku(),null,"test.log");
if($item->getOptionByCode('simple_product')) {
$childProduct = $item->getOptionByCode('simple_product')->getProduct()->getId();
Mage::log("We have ".$childProduct,null,"test.log");
}

if ($option = $item->getOptionByCode('simple_product')) {
$cartHelper = Mage::helper('checkout/cart')->getCart();
$quantity = $item->getQty();
$childProduct = $option->getProduct();
Mage::log("Child Product: ".$childProduct->getSku()." (".$childProduct->getId().")",null,"test.log");
$cartHelper->removeItem($item->getId());
$cartHelper->addItem($childProduct->getId(),$quantity);
}
}
$quote->collectTotals()->save();
}
}









share|improve this question














I want to prevent configurable products from ending up in the cart. I want to add their simple product equivalent to the cart.



Despite this being a fairly normal request, I haven't found anything that is doing this.



I currently have an observer set up to work on checkout_cart_add_product_complete
checkout_cart_add_product_complete



I'm able to manipulate the cart from here (add, remove items), but I can't remove a configurable product (nor its options).



Does anyone know how this is possible?



Observer.php



class Mymodule_Addtocartredirect_Model_Customizablereplace {
public function replaceItems($observer) {
$quote = Mage::getSingleton('checkout/session')->getQuote();
$storeId = Mage::app()->getStore()->getStoreId();

foreach ($quote->getAllItems() as $item) {
$result = array();
Mage::log("We have a product! " . $item->getSku(),null,"test.log");
if($item->getOptionByCode('simple_product')) {
$childProduct = $item->getOptionByCode('simple_product')->getProduct()->getId();
Mage::log("We have ".$childProduct,null,"test.log");
}

if ($option = $item->getOptionByCode('simple_product')) {
$cartHelper = Mage::helper('checkout/cart')->getCart();
$quantity = $item->getQty();
$childProduct = $option->getProduct();
Mage::log("Child Product: ".$childProduct->getSku()." (".$childProduct->getId().")",null,"test.log");
$cartHelper->removeItem($item->getId());
$cartHelper->addItem($childProduct->getId(),$quantity);
}
}
$quote->collectTotals()->save();
}
}






configurable-product cart event-observer simple-product






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 8 '16 at 20:23









traviswtravisw

4361028




4361028








  • 1





    By Magento design, Magento adds the configurable product for any simple product . When you remove the product and try to use : $cartHelper->addItem($childProduct->getId(),$quantity); Magento would add both the simple and configurable product back again. Is there a reach you're trying to remove the configurable product? Perhaps you could look to get rid of the need to do that because this won't work because of the way Magento is built for configurable products.

    – Paras Sood
    Mar 8 '16 at 21:03













  • We are exporting orders from Magento to a 3rd party ERP, but it does not handle configurable items well. The easiest solution appears to be changing Magento's behavior. Can I replace the configurable product with the simple product?

    – travisw
    Mar 9 '16 at 12:35






  • 2





    Why don't you make changes in the code that sends the order over to the EPR, wherein you don't send the configurable product but only the simple one?

    – Paras Sood
    Mar 9 '16 at 13:15











  • I didn't develop the connector for the ERP, so I'm not familiar enough with it to make those modifications. I assumed the Magento modification would be somewhat simple.

    – travisw
    Mar 10 '16 at 12:00






  • 1





    I also strongly advise against this change. This is expected Magento core behaviour and some extensions (like my Spranks_ConfigurableTierPrices) rely on this behaviour.

    – Simon
    Mar 16 '16 at 12:39














  • 1





    By Magento design, Magento adds the configurable product for any simple product . When you remove the product and try to use : $cartHelper->addItem($childProduct->getId(),$quantity); Magento would add both the simple and configurable product back again. Is there a reach you're trying to remove the configurable product? Perhaps you could look to get rid of the need to do that because this won't work because of the way Magento is built for configurable products.

    – Paras Sood
    Mar 8 '16 at 21:03













  • We are exporting orders from Magento to a 3rd party ERP, but it does not handle configurable items well. The easiest solution appears to be changing Magento's behavior. Can I replace the configurable product with the simple product?

    – travisw
    Mar 9 '16 at 12:35






  • 2





    Why don't you make changes in the code that sends the order over to the EPR, wherein you don't send the configurable product but only the simple one?

    – Paras Sood
    Mar 9 '16 at 13:15











  • I didn't develop the connector for the ERP, so I'm not familiar enough with it to make those modifications. I assumed the Magento modification would be somewhat simple.

    – travisw
    Mar 10 '16 at 12:00






  • 1





    I also strongly advise against this change. This is expected Magento core behaviour and some extensions (like my Spranks_ConfigurableTierPrices) rely on this behaviour.

    – Simon
    Mar 16 '16 at 12:39








1




1





By Magento design, Magento adds the configurable product for any simple product . When you remove the product and try to use : $cartHelper->addItem($childProduct->getId(),$quantity); Magento would add both the simple and configurable product back again. Is there a reach you're trying to remove the configurable product? Perhaps you could look to get rid of the need to do that because this won't work because of the way Magento is built for configurable products.

– Paras Sood
Mar 8 '16 at 21:03







By Magento design, Magento adds the configurable product for any simple product . When you remove the product and try to use : $cartHelper->addItem($childProduct->getId(),$quantity); Magento would add both the simple and configurable product back again. Is there a reach you're trying to remove the configurable product? Perhaps you could look to get rid of the need to do that because this won't work because of the way Magento is built for configurable products.

– Paras Sood
Mar 8 '16 at 21:03















We are exporting orders from Magento to a 3rd party ERP, but it does not handle configurable items well. The easiest solution appears to be changing Magento's behavior. Can I replace the configurable product with the simple product?

– travisw
Mar 9 '16 at 12:35





We are exporting orders from Magento to a 3rd party ERP, but it does not handle configurable items well. The easiest solution appears to be changing Magento's behavior. Can I replace the configurable product with the simple product?

– travisw
Mar 9 '16 at 12:35




2




2





Why don't you make changes in the code that sends the order over to the EPR, wherein you don't send the configurable product but only the simple one?

– Paras Sood
Mar 9 '16 at 13:15





Why don't you make changes in the code that sends the order over to the EPR, wherein you don't send the configurable product but only the simple one?

– Paras Sood
Mar 9 '16 at 13:15













I didn't develop the connector for the ERP, so I'm not familiar enough with it to make those modifications. I assumed the Magento modification would be somewhat simple.

– travisw
Mar 10 '16 at 12:00





I didn't develop the connector for the ERP, so I'm not familiar enough with it to make those modifications. I assumed the Magento modification would be somewhat simple.

– travisw
Mar 10 '16 at 12:00




1




1





I also strongly advise against this change. This is expected Magento core behaviour and some extensions (like my Spranks_ConfigurableTierPrices) rely on this behaviour.

– Simon
Mar 16 '16 at 12:39





I also strongly advise against this change. This is expected Magento core behaviour and some extensions (like my Spranks_ConfigurableTierPrices) rely on this behaviour.

– Simon
Mar 16 '16 at 12:39










3 Answers
3






active

oldest

votes


















0














Few days back,I did the same,by creating a custom module
Create a module and in the CartController.php file, create the following:



<?php 
require_once 'Mage/Checkout/controllers/CartController.php';
class Yourname_Mymodule_CartController extends Mage_Checkout_CartController
{
public function addAction()
{
if (!$this->_validateFormKey()) {
$this->_goBack();
return;
}
$cart = $this->_getCart();
$params = $this->getRequest()->getParams();
try {
if (isset($params['qty'])) {
$filter = new Zend_Filter_LocalizedToNormalized(
array('locale' => Mage::app()->getLocale()->getLocaleCode())
);
$params['qty'] = $filter->filter($params['qty']);
}

$product = $this->_initProduct();
$child = $product->getTypeInstance(true)->getProductByAttributes($params['super_attribute'], $product);
$related = $this->getRequest()->getParam('related_product');


if (!$child) {
$this->_goBack();
return;
}

$cart->addProduct($child, $params);
if (!empty($related)) {
$cart->addProductsByIds(explode(',', $related));
}

$cart->saveSpecial();

$this->_getSession()->setCartWasUpdated(true);


Mage::dispatchEvent('checkout_cart_add_product_complete',
array('product' => $product, 'request' => $this->getRequest(), 'response' => $this->getResponse())
);

if (!$this->_getSession()->getNoCartRedirect(true)) {
if (!$cart->getQuote()->getHasError()) {
$message = $this->__('%s was added to your shopping cart.', Mage::helper('core')->escapeHtml($child->getName()));
$this->_getSession()->addSuccess($message);
}
$this->_goBack();
}
} catch (Mage_Core_Exception $e) {
if ($this->_getSession()->getUseNotice(true)) {
$this->_getSession()->addNotice(Mage::helper('core')->escapeHtml($e->getMessage()));
} else {
$messages = array_unique(explode("n", $e->getMessage()));
foreach ($messages as $message) {
$this->_getSession()->addError(Mage::helper('core')->escapeHtml($message));
}
}

$url = $this->_getSession()->getRedirectUrl(true);
if ($url) {
$this->getResponse()->setRedirect($url);
} else {
$this->_redirectReferer(Mage::helper('checkout/cart')->getCartUrl());
}
} catch (Exception $e) {
$this->_getSession()->addException($e, $this->__('Cannot add the item to shopping cart.'));
Mage::logException($e);
$this->_goBack();
}
}
}


Create a new save function



<?php
class Yourname_Mymodule_Model_Cart extends Mage_Checkout_Model_Cart
{
public function save()
{
Mage::dispatchEvent('checkout_cart_save_before', array('cart'=>$this));

$this->getQuote()->getBillingAddress();
$this->getQuote()->getShippingAddress()->setCollectShippingRates(true);
$this->getQuote()->collectTotals();
$this->getQuote()->save();
$this->getCheckoutSession()->setQuoteId($this->getQuote()->getId());
Mage::dispatchEvent('checkout_cart_save_after', array('cart'=>$this));
foreach($this->getQuote()->getAllItems() as $_item)
{
$_item->setCustomPrice($_item->getPrice());
$_item->setRowTotal($_item->getPrice()*$_item->getQty());
$_item->setBaseRowTotal($_item->getBasePrice()*$_item->getQty());
$_item->setOriginalCustomPrice($_item->getCustomPrice());
$_item->setCalculationPrice($_item->getCustomPrice());
}
return $this;
}

public function saveSpecial()
{
Mage::dispatchEvent('checkout_cart_save_before', array('cart'=>$this));

$this->getQuote()->getBillingAddress();
$this->getQuote()->getShippingAddress()->setCollectShippingRates(true);
$this->getQuote()->collectTotals();
$this->getQuote()->save();
$this->getCheckoutSession()->setQuoteId($this->getQuote()->getId());

Mage::dispatchEvent('checkout_cart_save_after', array('cart'=>$this));
return $this;
}
}


Done!!






share|improve this answer































    0














    I know this is not the answer you are looking for but it may be a solution for you.



    My suggestion



    I would change my products visibility section for each config item.



    If you look at product editing section in admin, you will find field called visibility.




    1. You need to set each parent config item's visibility as Not visible individually.

    2. Then set each associated product (child product)'s visibility as 'Catalog Search`.


    This will make sure all your parent item not displayed at site but all associated (child) products are and when user add them to cart, they all will be simple products.



    Then your ERP will handle it as required.






    share|improve this answer
























    • I want our users to find the configurable product page because it can present dozens of different products in an easy selection style. I don't think hiding the configurable product will accomplish what we want (at least not how we want it to work).

      – travisw
      Mar 17 '16 at 11:33



















    0














    Despite this being an almost 3-year-old question, I figured I'd add my own answer since I was trying to do this myself and hopefully someone will find my solution useful.



    All I did was add a plugin to MagentoCheckoutControllerCartAdd



    <?php
    namespace VendorModuleControllerPluginCart;

    class Add
    {

    public function beforeExecute(
    MagentoCheckoutControllerCartAdd $subject
    ) {
    $params = $subject->getRequest()->getParams();
    if (isset($params['selected_configurable_option']) && $params['selected_configurable_option'] !== '') {
    $params['product'] = $params['item'] = $params['selected_configurable_option'];
    $params['selected_configurable_option'] = '';
    unset($params['super_attribute']);
    $subject->getRequest()->setParams($params);
    }
    }
    }





    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%2f105303%2fhow-to-add-simple-product-to-cart-instead-of-configurable-product%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      Few days back,I did the same,by creating a custom module
      Create a module and in the CartController.php file, create the following:



      <?php 
      require_once 'Mage/Checkout/controllers/CartController.php';
      class Yourname_Mymodule_CartController extends Mage_Checkout_CartController
      {
      public function addAction()
      {
      if (!$this->_validateFormKey()) {
      $this->_goBack();
      return;
      }
      $cart = $this->_getCart();
      $params = $this->getRequest()->getParams();
      try {
      if (isset($params['qty'])) {
      $filter = new Zend_Filter_LocalizedToNormalized(
      array('locale' => Mage::app()->getLocale()->getLocaleCode())
      );
      $params['qty'] = $filter->filter($params['qty']);
      }

      $product = $this->_initProduct();
      $child = $product->getTypeInstance(true)->getProductByAttributes($params['super_attribute'], $product);
      $related = $this->getRequest()->getParam('related_product');


      if (!$child) {
      $this->_goBack();
      return;
      }

      $cart->addProduct($child, $params);
      if (!empty($related)) {
      $cart->addProductsByIds(explode(',', $related));
      }

      $cart->saveSpecial();

      $this->_getSession()->setCartWasUpdated(true);


      Mage::dispatchEvent('checkout_cart_add_product_complete',
      array('product' => $product, 'request' => $this->getRequest(), 'response' => $this->getResponse())
      );

      if (!$this->_getSession()->getNoCartRedirect(true)) {
      if (!$cart->getQuote()->getHasError()) {
      $message = $this->__('%s was added to your shopping cart.', Mage::helper('core')->escapeHtml($child->getName()));
      $this->_getSession()->addSuccess($message);
      }
      $this->_goBack();
      }
      } catch (Mage_Core_Exception $e) {
      if ($this->_getSession()->getUseNotice(true)) {
      $this->_getSession()->addNotice(Mage::helper('core')->escapeHtml($e->getMessage()));
      } else {
      $messages = array_unique(explode("n", $e->getMessage()));
      foreach ($messages as $message) {
      $this->_getSession()->addError(Mage::helper('core')->escapeHtml($message));
      }
      }

      $url = $this->_getSession()->getRedirectUrl(true);
      if ($url) {
      $this->getResponse()->setRedirect($url);
      } else {
      $this->_redirectReferer(Mage::helper('checkout/cart')->getCartUrl());
      }
      } catch (Exception $e) {
      $this->_getSession()->addException($e, $this->__('Cannot add the item to shopping cart.'));
      Mage::logException($e);
      $this->_goBack();
      }
      }
      }


      Create a new save function



      <?php
      class Yourname_Mymodule_Model_Cart extends Mage_Checkout_Model_Cart
      {
      public function save()
      {
      Mage::dispatchEvent('checkout_cart_save_before', array('cart'=>$this));

      $this->getQuote()->getBillingAddress();
      $this->getQuote()->getShippingAddress()->setCollectShippingRates(true);
      $this->getQuote()->collectTotals();
      $this->getQuote()->save();
      $this->getCheckoutSession()->setQuoteId($this->getQuote()->getId());
      Mage::dispatchEvent('checkout_cart_save_after', array('cart'=>$this));
      foreach($this->getQuote()->getAllItems() as $_item)
      {
      $_item->setCustomPrice($_item->getPrice());
      $_item->setRowTotal($_item->getPrice()*$_item->getQty());
      $_item->setBaseRowTotal($_item->getBasePrice()*$_item->getQty());
      $_item->setOriginalCustomPrice($_item->getCustomPrice());
      $_item->setCalculationPrice($_item->getCustomPrice());
      }
      return $this;
      }

      public function saveSpecial()
      {
      Mage::dispatchEvent('checkout_cart_save_before', array('cart'=>$this));

      $this->getQuote()->getBillingAddress();
      $this->getQuote()->getShippingAddress()->setCollectShippingRates(true);
      $this->getQuote()->collectTotals();
      $this->getQuote()->save();
      $this->getCheckoutSession()->setQuoteId($this->getQuote()->getId());

      Mage::dispatchEvent('checkout_cart_save_after', array('cart'=>$this));
      return $this;
      }
      }


      Done!!






      share|improve this answer




























        0














        Few days back,I did the same,by creating a custom module
        Create a module and in the CartController.php file, create the following:



        <?php 
        require_once 'Mage/Checkout/controllers/CartController.php';
        class Yourname_Mymodule_CartController extends Mage_Checkout_CartController
        {
        public function addAction()
        {
        if (!$this->_validateFormKey()) {
        $this->_goBack();
        return;
        }
        $cart = $this->_getCart();
        $params = $this->getRequest()->getParams();
        try {
        if (isset($params['qty'])) {
        $filter = new Zend_Filter_LocalizedToNormalized(
        array('locale' => Mage::app()->getLocale()->getLocaleCode())
        );
        $params['qty'] = $filter->filter($params['qty']);
        }

        $product = $this->_initProduct();
        $child = $product->getTypeInstance(true)->getProductByAttributes($params['super_attribute'], $product);
        $related = $this->getRequest()->getParam('related_product');


        if (!$child) {
        $this->_goBack();
        return;
        }

        $cart->addProduct($child, $params);
        if (!empty($related)) {
        $cart->addProductsByIds(explode(',', $related));
        }

        $cart->saveSpecial();

        $this->_getSession()->setCartWasUpdated(true);


        Mage::dispatchEvent('checkout_cart_add_product_complete',
        array('product' => $product, 'request' => $this->getRequest(), 'response' => $this->getResponse())
        );

        if (!$this->_getSession()->getNoCartRedirect(true)) {
        if (!$cart->getQuote()->getHasError()) {
        $message = $this->__('%s was added to your shopping cart.', Mage::helper('core')->escapeHtml($child->getName()));
        $this->_getSession()->addSuccess($message);
        }
        $this->_goBack();
        }
        } catch (Mage_Core_Exception $e) {
        if ($this->_getSession()->getUseNotice(true)) {
        $this->_getSession()->addNotice(Mage::helper('core')->escapeHtml($e->getMessage()));
        } else {
        $messages = array_unique(explode("n", $e->getMessage()));
        foreach ($messages as $message) {
        $this->_getSession()->addError(Mage::helper('core')->escapeHtml($message));
        }
        }

        $url = $this->_getSession()->getRedirectUrl(true);
        if ($url) {
        $this->getResponse()->setRedirect($url);
        } else {
        $this->_redirectReferer(Mage::helper('checkout/cart')->getCartUrl());
        }
        } catch (Exception $e) {
        $this->_getSession()->addException($e, $this->__('Cannot add the item to shopping cart.'));
        Mage::logException($e);
        $this->_goBack();
        }
        }
        }


        Create a new save function



        <?php
        class Yourname_Mymodule_Model_Cart extends Mage_Checkout_Model_Cart
        {
        public function save()
        {
        Mage::dispatchEvent('checkout_cart_save_before', array('cart'=>$this));

        $this->getQuote()->getBillingAddress();
        $this->getQuote()->getShippingAddress()->setCollectShippingRates(true);
        $this->getQuote()->collectTotals();
        $this->getQuote()->save();
        $this->getCheckoutSession()->setQuoteId($this->getQuote()->getId());
        Mage::dispatchEvent('checkout_cart_save_after', array('cart'=>$this));
        foreach($this->getQuote()->getAllItems() as $_item)
        {
        $_item->setCustomPrice($_item->getPrice());
        $_item->setRowTotal($_item->getPrice()*$_item->getQty());
        $_item->setBaseRowTotal($_item->getBasePrice()*$_item->getQty());
        $_item->setOriginalCustomPrice($_item->getCustomPrice());
        $_item->setCalculationPrice($_item->getCustomPrice());
        }
        return $this;
        }

        public function saveSpecial()
        {
        Mage::dispatchEvent('checkout_cart_save_before', array('cart'=>$this));

        $this->getQuote()->getBillingAddress();
        $this->getQuote()->getShippingAddress()->setCollectShippingRates(true);
        $this->getQuote()->collectTotals();
        $this->getQuote()->save();
        $this->getCheckoutSession()->setQuoteId($this->getQuote()->getId());

        Mage::dispatchEvent('checkout_cart_save_after', array('cart'=>$this));
        return $this;
        }
        }


        Done!!






        share|improve this answer


























          0












          0








          0







          Few days back,I did the same,by creating a custom module
          Create a module and in the CartController.php file, create the following:



          <?php 
          require_once 'Mage/Checkout/controllers/CartController.php';
          class Yourname_Mymodule_CartController extends Mage_Checkout_CartController
          {
          public function addAction()
          {
          if (!$this->_validateFormKey()) {
          $this->_goBack();
          return;
          }
          $cart = $this->_getCart();
          $params = $this->getRequest()->getParams();
          try {
          if (isset($params['qty'])) {
          $filter = new Zend_Filter_LocalizedToNormalized(
          array('locale' => Mage::app()->getLocale()->getLocaleCode())
          );
          $params['qty'] = $filter->filter($params['qty']);
          }

          $product = $this->_initProduct();
          $child = $product->getTypeInstance(true)->getProductByAttributes($params['super_attribute'], $product);
          $related = $this->getRequest()->getParam('related_product');


          if (!$child) {
          $this->_goBack();
          return;
          }

          $cart->addProduct($child, $params);
          if (!empty($related)) {
          $cart->addProductsByIds(explode(',', $related));
          }

          $cart->saveSpecial();

          $this->_getSession()->setCartWasUpdated(true);


          Mage::dispatchEvent('checkout_cart_add_product_complete',
          array('product' => $product, 'request' => $this->getRequest(), 'response' => $this->getResponse())
          );

          if (!$this->_getSession()->getNoCartRedirect(true)) {
          if (!$cart->getQuote()->getHasError()) {
          $message = $this->__('%s was added to your shopping cart.', Mage::helper('core')->escapeHtml($child->getName()));
          $this->_getSession()->addSuccess($message);
          }
          $this->_goBack();
          }
          } catch (Mage_Core_Exception $e) {
          if ($this->_getSession()->getUseNotice(true)) {
          $this->_getSession()->addNotice(Mage::helper('core')->escapeHtml($e->getMessage()));
          } else {
          $messages = array_unique(explode("n", $e->getMessage()));
          foreach ($messages as $message) {
          $this->_getSession()->addError(Mage::helper('core')->escapeHtml($message));
          }
          }

          $url = $this->_getSession()->getRedirectUrl(true);
          if ($url) {
          $this->getResponse()->setRedirect($url);
          } else {
          $this->_redirectReferer(Mage::helper('checkout/cart')->getCartUrl());
          }
          } catch (Exception $e) {
          $this->_getSession()->addException($e, $this->__('Cannot add the item to shopping cart.'));
          Mage::logException($e);
          $this->_goBack();
          }
          }
          }


          Create a new save function



          <?php
          class Yourname_Mymodule_Model_Cart extends Mage_Checkout_Model_Cart
          {
          public function save()
          {
          Mage::dispatchEvent('checkout_cart_save_before', array('cart'=>$this));

          $this->getQuote()->getBillingAddress();
          $this->getQuote()->getShippingAddress()->setCollectShippingRates(true);
          $this->getQuote()->collectTotals();
          $this->getQuote()->save();
          $this->getCheckoutSession()->setQuoteId($this->getQuote()->getId());
          Mage::dispatchEvent('checkout_cart_save_after', array('cart'=>$this));
          foreach($this->getQuote()->getAllItems() as $_item)
          {
          $_item->setCustomPrice($_item->getPrice());
          $_item->setRowTotal($_item->getPrice()*$_item->getQty());
          $_item->setBaseRowTotal($_item->getBasePrice()*$_item->getQty());
          $_item->setOriginalCustomPrice($_item->getCustomPrice());
          $_item->setCalculationPrice($_item->getCustomPrice());
          }
          return $this;
          }

          public function saveSpecial()
          {
          Mage::dispatchEvent('checkout_cart_save_before', array('cart'=>$this));

          $this->getQuote()->getBillingAddress();
          $this->getQuote()->getShippingAddress()->setCollectShippingRates(true);
          $this->getQuote()->collectTotals();
          $this->getQuote()->save();
          $this->getCheckoutSession()->setQuoteId($this->getQuote()->getId());

          Mage::dispatchEvent('checkout_cart_save_after', array('cart'=>$this));
          return $this;
          }
          }


          Done!!






          share|improve this answer













          Few days back,I did the same,by creating a custom module
          Create a module and in the CartController.php file, create the following:



          <?php 
          require_once 'Mage/Checkout/controllers/CartController.php';
          class Yourname_Mymodule_CartController extends Mage_Checkout_CartController
          {
          public function addAction()
          {
          if (!$this->_validateFormKey()) {
          $this->_goBack();
          return;
          }
          $cart = $this->_getCart();
          $params = $this->getRequest()->getParams();
          try {
          if (isset($params['qty'])) {
          $filter = new Zend_Filter_LocalizedToNormalized(
          array('locale' => Mage::app()->getLocale()->getLocaleCode())
          );
          $params['qty'] = $filter->filter($params['qty']);
          }

          $product = $this->_initProduct();
          $child = $product->getTypeInstance(true)->getProductByAttributes($params['super_attribute'], $product);
          $related = $this->getRequest()->getParam('related_product');


          if (!$child) {
          $this->_goBack();
          return;
          }

          $cart->addProduct($child, $params);
          if (!empty($related)) {
          $cart->addProductsByIds(explode(',', $related));
          }

          $cart->saveSpecial();

          $this->_getSession()->setCartWasUpdated(true);


          Mage::dispatchEvent('checkout_cart_add_product_complete',
          array('product' => $product, 'request' => $this->getRequest(), 'response' => $this->getResponse())
          );

          if (!$this->_getSession()->getNoCartRedirect(true)) {
          if (!$cart->getQuote()->getHasError()) {
          $message = $this->__('%s was added to your shopping cart.', Mage::helper('core')->escapeHtml($child->getName()));
          $this->_getSession()->addSuccess($message);
          }
          $this->_goBack();
          }
          } catch (Mage_Core_Exception $e) {
          if ($this->_getSession()->getUseNotice(true)) {
          $this->_getSession()->addNotice(Mage::helper('core')->escapeHtml($e->getMessage()));
          } else {
          $messages = array_unique(explode("n", $e->getMessage()));
          foreach ($messages as $message) {
          $this->_getSession()->addError(Mage::helper('core')->escapeHtml($message));
          }
          }

          $url = $this->_getSession()->getRedirectUrl(true);
          if ($url) {
          $this->getResponse()->setRedirect($url);
          } else {
          $this->_redirectReferer(Mage::helper('checkout/cart')->getCartUrl());
          }
          } catch (Exception $e) {
          $this->_getSession()->addException($e, $this->__('Cannot add the item to shopping cart.'));
          Mage::logException($e);
          $this->_goBack();
          }
          }
          }


          Create a new save function



          <?php
          class Yourname_Mymodule_Model_Cart extends Mage_Checkout_Model_Cart
          {
          public function save()
          {
          Mage::dispatchEvent('checkout_cart_save_before', array('cart'=>$this));

          $this->getQuote()->getBillingAddress();
          $this->getQuote()->getShippingAddress()->setCollectShippingRates(true);
          $this->getQuote()->collectTotals();
          $this->getQuote()->save();
          $this->getCheckoutSession()->setQuoteId($this->getQuote()->getId());
          Mage::dispatchEvent('checkout_cart_save_after', array('cart'=>$this));
          foreach($this->getQuote()->getAllItems() as $_item)
          {
          $_item->setCustomPrice($_item->getPrice());
          $_item->setRowTotal($_item->getPrice()*$_item->getQty());
          $_item->setBaseRowTotal($_item->getBasePrice()*$_item->getQty());
          $_item->setOriginalCustomPrice($_item->getCustomPrice());
          $_item->setCalculationPrice($_item->getCustomPrice());
          }
          return $this;
          }

          public function saveSpecial()
          {
          Mage::dispatchEvent('checkout_cart_save_before', array('cart'=>$this));

          $this->getQuote()->getBillingAddress();
          $this->getQuote()->getShippingAddress()->setCollectShippingRates(true);
          $this->getQuote()->collectTotals();
          $this->getQuote()->save();
          $this->getCheckoutSession()->setQuoteId($this->getQuote()->getId());

          Mage::dispatchEvent('checkout_cart_save_after', array('cart'=>$this));
          return $this;
          }
          }


          Done!!







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 17 '16 at 7:32









          Rahul SinghRahul Singh

          7801726




          7801726

























              0














              I know this is not the answer you are looking for but it may be a solution for you.



              My suggestion



              I would change my products visibility section for each config item.



              If you look at product editing section in admin, you will find field called visibility.




              1. You need to set each parent config item's visibility as Not visible individually.

              2. Then set each associated product (child product)'s visibility as 'Catalog Search`.


              This will make sure all your parent item not displayed at site but all associated (child) products are and when user add them to cart, they all will be simple products.



              Then your ERP will handle it as required.






              share|improve this answer
























              • I want our users to find the configurable product page because it can present dozens of different products in an easy selection style. I don't think hiding the configurable product will accomplish what we want (at least not how we want it to work).

                – travisw
                Mar 17 '16 at 11:33
















              0














              I know this is not the answer you are looking for but it may be a solution for you.



              My suggestion



              I would change my products visibility section for each config item.



              If you look at product editing section in admin, you will find field called visibility.




              1. You need to set each parent config item's visibility as Not visible individually.

              2. Then set each associated product (child product)'s visibility as 'Catalog Search`.


              This will make sure all your parent item not displayed at site but all associated (child) products are and when user add them to cart, they all will be simple products.



              Then your ERP will handle it as required.






              share|improve this answer
























              • I want our users to find the configurable product page because it can present dozens of different products in an easy selection style. I don't think hiding the configurable product will accomplish what we want (at least not how we want it to work).

                – travisw
                Mar 17 '16 at 11:33














              0












              0








              0







              I know this is not the answer you are looking for but it may be a solution for you.



              My suggestion



              I would change my products visibility section for each config item.



              If you look at product editing section in admin, you will find field called visibility.




              1. You need to set each parent config item's visibility as Not visible individually.

              2. Then set each associated product (child product)'s visibility as 'Catalog Search`.


              This will make sure all your parent item not displayed at site but all associated (child) products are and when user add them to cart, they all will be simple products.



              Then your ERP will handle it as required.






              share|improve this answer













              I know this is not the answer you are looking for but it may be a solution for you.



              My suggestion



              I would change my products visibility section for each config item.



              If you look at product editing section in admin, you will find field called visibility.




              1. You need to set each parent config item's visibility as Not visible individually.

              2. Then set each associated product (child product)'s visibility as 'Catalog Search`.


              This will make sure all your parent item not displayed at site but all associated (child) products are and when user add them to cart, they all will be simple products.



              Then your ERP will handle it as required.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Mar 17 '16 at 0:35









              Adarsh KhatriAdarsh Khatri

              6,67111643




              6,67111643













              • I want our users to find the configurable product page because it can present dozens of different products in an easy selection style. I don't think hiding the configurable product will accomplish what we want (at least not how we want it to work).

                – travisw
                Mar 17 '16 at 11:33



















              • I want our users to find the configurable product page because it can present dozens of different products in an easy selection style. I don't think hiding the configurable product will accomplish what we want (at least not how we want it to work).

                – travisw
                Mar 17 '16 at 11:33

















              I want our users to find the configurable product page because it can present dozens of different products in an easy selection style. I don't think hiding the configurable product will accomplish what we want (at least not how we want it to work).

              – travisw
              Mar 17 '16 at 11:33





              I want our users to find the configurable product page because it can present dozens of different products in an easy selection style. I don't think hiding the configurable product will accomplish what we want (at least not how we want it to work).

              – travisw
              Mar 17 '16 at 11:33











              0














              Despite this being an almost 3-year-old question, I figured I'd add my own answer since I was trying to do this myself and hopefully someone will find my solution useful.



              All I did was add a plugin to MagentoCheckoutControllerCartAdd



              <?php
              namespace VendorModuleControllerPluginCart;

              class Add
              {

              public function beforeExecute(
              MagentoCheckoutControllerCartAdd $subject
              ) {
              $params = $subject->getRequest()->getParams();
              if (isset($params['selected_configurable_option']) && $params['selected_configurable_option'] !== '') {
              $params['product'] = $params['item'] = $params['selected_configurable_option'];
              $params['selected_configurable_option'] = '';
              unset($params['super_attribute']);
              $subject->getRequest()->setParams($params);
              }
              }
              }





              share|improve this answer




























                0














                Despite this being an almost 3-year-old question, I figured I'd add my own answer since I was trying to do this myself and hopefully someone will find my solution useful.



                All I did was add a plugin to MagentoCheckoutControllerCartAdd



                <?php
                namespace VendorModuleControllerPluginCart;

                class Add
                {

                public function beforeExecute(
                MagentoCheckoutControllerCartAdd $subject
                ) {
                $params = $subject->getRequest()->getParams();
                if (isset($params['selected_configurable_option']) && $params['selected_configurable_option'] !== '') {
                $params['product'] = $params['item'] = $params['selected_configurable_option'];
                $params['selected_configurable_option'] = '';
                unset($params['super_attribute']);
                $subject->getRequest()->setParams($params);
                }
                }
                }





                share|improve this answer


























                  0












                  0








                  0







                  Despite this being an almost 3-year-old question, I figured I'd add my own answer since I was trying to do this myself and hopefully someone will find my solution useful.



                  All I did was add a plugin to MagentoCheckoutControllerCartAdd



                  <?php
                  namespace VendorModuleControllerPluginCart;

                  class Add
                  {

                  public function beforeExecute(
                  MagentoCheckoutControllerCartAdd $subject
                  ) {
                  $params = $subject->getRequest()->getParams();
                  if (isset($params['selected_configurable_option']) && $params['selected_configurable_option'] !== '') {
                  $params['product'] = $params['item'] = $params['selected_configurable_option'];
                  $params['selected_configurable_option'] = '';
                  unset($params['super_attribute']);
                  $subject->getRequest()->setParams($params);
                  }
                  }
                  }





                  share|improve this answer













                  Despite this being an almost 3-year-old question, I figured I'd add my own answer since I was trying to do this myself and hopefully someone will find my solution useful.



                  All I did was add a plugin to MagentoCheckoutControllerCartAdd



                  <?php
                  namespace VendorModuleControllerPluginCart;

                  class Add
                  {

                  public function beforeExecute(
                  MagentoCheckoutControllerCartAdd $subject
                  ) {
                  $params = $subject->getRequest()->getParams();
                  if (isset($params['selected_configurable_option']) && $params['selected_configurable_option'] !== '') {
                  $params['product'] = $params['item'] = $params['selected_configurable_option'];
                  $params['selected_configurable_option'] = '';
                  unset($params['super_attribute']);
                  $subject->getRequest()->setParams($params);
                  }
                  }
                  }






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 10 mins ago









                  Joseph G-HJoseph G-H

                  134




                  134






























                      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%2f105303%2fhow-to-add-simple-product-to-cart-instead-of-configurable-product%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

                      Magento 2 controller redirect on button click in phtml file

                      Polycentropodidae