Magento Customization - Magento Custom Development - Custom Magento Extension

int(0)

Programatically add bundle product to cart in Magento



Sometimes, clients requirements exceed the defaults built into the Magento. Recently we came across a task that among other things required manipulation of bundle products in Magento. In order to help my coworker Tomas I wrote this little code snippet that programatically adds bundle product to cart.

$params = array( 'product' => 164, 'related_product' => null, 'bundle_option' => array( 21 => 58, 20 => 55, 11 => 28, 12 => array( 0 => 31, ), 13 => array( 0 => 32, 1 => 35, ), ), 'options' => array( 3 => 'olaaaaaaaa', ), 'qty' => 2, );

$cart = Mage::getSingleton('checkout/cart');

$product = new Mage_Catalog_Model_Product(); $product->load(164);

$cart->addProduct($product, $params); $cart->save();

Mage::getSingleton('checkout/session')->setCartWasUpdated(true);

$message = $this->__('Custom message: %s was successfully added to your shopping cart.', $product->getName()); Mage::getSingleton('checkout/session')->addSuccess($message);

The above source code might need a bit explanation. There are two major things to keep an eye on bundle product view page, custom options and bundle items.

Custom options are set in the array

'options' => array( 3 => 'olaaaaaaaa', ),

And bundle item options are set in array

'bundle_option' => array( 21 => 58, 20 => 55, 11 => 28, 12 => array( 0 => 31, ), 13 => array( 0 => 32, 1 => 35, ), ),

Check out the screenshot for additional info.

In summary “all” you need to do is to send the proper field name-values as a params. You can then use this code from within controller or as a fast fix from within view file.



What is Magento?

Magento is a perfect example of successful startup project that has evolved into the well-known leader of the industry within a short period of time. The team of brilliant web developers and marketers have managed to make an eCommerce miracle by reaching 450,000 downloads during 6 months.

Magento eCommerce engine opens you a world of great opportunities by offering tons of great shop maintenance features including but not limited to slick website management, powerful payment system, flexible marketing tools and efficient shipping options.

Full Time Hiring

Hire expert developer for Fulltime & Experience the benefit of our hire developer service:

  • Strict working hours each day
  • Stay in contact with your hire team
  • Provision of daily reporting

Part Time Hiring

Get part time hire web developer service that helps you to fulfil all your needs & get benefits like:

  • No hidden charges
  • Quality work delivered
  • Team management authority

Hourly Hiring

Save time & money with Hourly basis service to hire developer for superior quality & economical package:

  • Hire developer on hourly basis
  • Client centric approach
  • Get maximum ROI

Money-Back Guarantee

If you are not completely satisfied with our service you can cancel within the first 14 days and we will refund the unused proportion of your fees in full.
Hire Developers FAQs

Hire Developers Now

Testimonials

Pamelvel
Fantastic suppliers. They are great to work with and get the job done quickly and effeciently. I would recommend their work over and over again. They are the best!
RM2
I have nothing but praise for cheapestandbest. They have delivered an amazing website and put up with my fussiness and mind changing with professionalism. I would definitely use them again and recommend them wholeheartedly
ffrogaus
The project was much more complex than I thought. Sougata Pati kept me informed and patiently did the necessary work. Because of the complexity a further payment was negotiated. I felt this was entirely justified.The time frame was long as I was away for a few weeks and no fault of cheapestandbest . I now have the base to develop the website I want. Help after the job was done has been very good.
Suprios
Produced great work and was pushed to deliver work in a particular direction which was followed. Communication was constant and responses were quick. Thanks again, i will be in touch if further work is required on this project.
spolevoy
Good experience. When problems came up, they were dealt with an in efficient and timely manner. Amit (the director of the company) gets involved if things dont go as planned and makes sure they are corrected. Overall, excellent job.
Design Image
Excellent communication throughout the project.Very professional and provided exceptional results.I am extremely happy with their commitment, especially by Manisha. Ethical, hardworking and committed.
Mu-Zeek
Provider is the best in the industry. They have alot of knowledge in programing and design. They have a very close communication with a client. I would recommended other people to use them
FSfashion

I loved the end product! Quality work for the price. They were very quick to reply back to my messages even though I couldn't get back to them because of my schedule or because of the time difference. The detail of my vision wasn't realized but they got the general idea and I'm satisfied. They were very quick to help me fix bugs in my template.

ali nawaz

indianelite.com have been extremely efficient and fast in working on my project. The work i recieved was top notch. I would recommend them to anyone anytime. simply AWESOME!!!!!!! Excellent communication and professional. A++++

Abilene masood
indianelite.com is helpful, skillful, and always meet customer's expectation. We are happy to finish another project.
Scroll to Top

Call us at (Tollfree) 1-877-826-5825                               Fax- 1-866-335-6066