Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9200875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:52:04+00:00 2026-06-17T22:52:04+00:00

I am doing a magento customization site I need to add certain product details

  • 0

I am doing a magento customization site I need to add certain product details to database so i have used the function addAction() in Mage checkout controller, inorder to make it a module I have to override the cartController’s Addaction()

I have referenced the stackoverflow’s overriding controller questions but no use it is using the coding in Mage checkout controllers

I have used below code,

code\local\SmartGrowth\CompatibleWith\etc

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <SmartGrowth_CompatibleWith>
            <version>0.1.0</version>
        </SmartGrowth_CompatibleWith>
    </modules>
<!-- Configure our module's behavior in the global scope -->
 <global>
        <blocks>
            <catalog>
                <rewrite>
                    <product_view>SmartGrowth_CompatibleWith_Block_CompatibleWith</product_view>
                </rewrite>
            </catalog>
        </blocks>

    </global>

    <frontend>
        <routers>
            <checkout>
               <use>standard</use>

                    <modules>
                        <SmartGrowth_CompatibleWith_Checkout  before="Mage_Checkout">SmartGrowth_CompatibleWith_Checkout</SmartGrowth_CompatibleWith_Checkout>
                    </modules>

            </checkout>
        </routers>

    </frontend>

</config>

app\code\local\SmartGrowth\CompatibleWith\controllers\Checkout

  require_once 'Mage/Checkout/controllers/CartController.php';
class SmartGrowth_CompatibleWith_Checkout_CartController extends Mage_Core_Controller_Front_Action
{

    public function addAction()
    {

        $cart   = $this->_getCart();

        $params = $this->getRequest()->getParams();
        $postData = Mage::app()->getRequest()->getPost();

            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();
            $related = $this->getRequest()->getParam('related_product');

            /**
             * Check product availability
             */
            if (!$product) {
                $this->_goBack();
                return;
            }

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

            $cart->save();
            $cart_id = $cart->getQuote()->getId();

            $product_id=Mage::helper('core')->escapeHtml($product->getId());

           $write = Mage::getSingleton('core/resource')->getConnection('core_write');
           $readresult=$write->query("SELECT item_id FROM  mage_sales_flat_quote_item WHERE quote_id='$cart_id' AND product_id='$product_id'");
           $row = $readresult->fetch() ;
            $item_id=$row['item_id'];
             $brand = Mage::getSingleton('core/session')->getMyModelbrandData();

            if($postData['check_value']==1)
            {
                $myData   = Mage::getSingleton('core/session')->getMyModelTypeData();
               $myDataver = Mage::getSingleton('core/session')->getMyModelVersionData();

            }else if($postData['check_value']==2)
            {
                 $model_type = $postData['model_type']; 
                 $myDataver  = Mage::getSingleton('core/session')->getMyModelVersionData();

            }else if($postData['check_value']==3)
            {
                $model_version =$postData['model_version'];
                $myData   = Mage::getSingleton('core/session')->getMyModelTypeData();

            }else if($postData['check_value']==4)
            {
                $model_type    =$postData['model_type']; 
                $model_version =$postData['model_version'];
            }

            /*if($postData['model_type']!=''&& $postData['model_version']!='')
            {
                $model_type    =$postData['model_type']; 
                $model_version =$postData['model_version'];
            }else
            {
            $myData = Mage::getSingleton('core/session')->getMyModelTypeData();
            $myDataver = Mage::getSingleton('core/session')->getMyModelVersionData();   
            }*/
            if($myData !=''):
              // now $write is an instance of Zend_Db_Adapter_Abstract
              $readresult=$write->query("SELECT * FROM mage_eav_attribute_option_value WHERE option_id='$myData'");
              $row = $readresult->fetch() ;
               $model_type=$row['value'];
               endif;

               if($myDataver !=''):
                $readresult1=$write->query("SELECT * FROM mage_eav_attribute_option_value WHERE option_id='$myDataver'");
                $row1 = $readresult1->fetch() ;
                $model_version=$row1['value'];
                endif;

            $write->beginTransaction();  
            $fields = array();  
            $fields['model_type']    = $model_type;  
            $fields['model_version'] = $model_version;  
            $fields['brand']         = $brand;
            $where = $write->quoteInto('item_id =?', $item_id);  
            $write->update('mage_sales_flat_quote_item', $fields, $where);  
            $write->commit();

            /**
             * @todo remove wishlist observer processAddToCart
             */
            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($product->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();
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T22:52:05+00:00Added an answer on June 17, 2026 at 10:52 pm

    instead of using overriding method You can write observer for magento events .

    code\local\SmartGrowth\CompatibleWith\etc

     <frontend>
                 <events>
                    <checkout_cart_add_product_complete>
                        <observers>
                           <SmartGrowth_CompatibleWith_Model_Observer>
                              <type>singleton</type>
                              <class>SmartGrowth_CompatibleWith_Model_Observer</class>
                              <method>cartproductcomplete</method>
                           </SmartGrowth_CompatibleWith_Model_Observer>
                       </observers>
                    </checkout_cart_add_product_complete>
                </events>
              </frontend>
    

    and write the observer code in
    code\local\SmartGrowth\CompatibleWith\Model\Observer.php

    class SmartGrowth_CompatibleWith_Model_Observer {
    
    public function cartproductcomplete() {
    
    //Database operation
    }
    
    
    }
    

    Is better to use events than overriding method

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Magento installation with around 60 attribute sets. I need to add
I am doing a magento customization site , am new to magento anyboby pls
I'm doing some development work on a Magento site network (multi-store install). What I'm
Doing some jquery animation. I have certain divs set up with an attribute of
I am doing custom product reports in magento. I followed as the steps in
I have added a Bundled Product in Magento programmatically, using all the options /
I have an eZ Publish and a Magento site on two different servers, and
We are doing some SEO optimizations on our Magento store front and I need
I found a strange problem while doing some unit-testing on Magento. I have a
I am developing a Magento site. I have access to a local host and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.