Magento Stress Testing Checkout – Auto Add Products To Cart

Every once in a while, we run into an issue where the checkout process either stalls or redirects back to the main checkout screen, when adding a significant amount of products to the cart. There are a whole host of issues that can cause this, but the most tedious process of debugging it, is adding all of the products to the cart in the first place. We’ve written a small script to automatically add products to your cart by simply visiting the script on the website.

The script currently grabs the first 100 products that are enabled in your Magento system. You can easily tune up/down depending how many products you actually have in inventory. Be careful running it though, if you run it more than once, then it will simply re-add the same products, so you’ll double up the amount of each that you first had.

Save this script as a PHP file and run from the root of your store in any web-browser.
ie: http://store.com/cartfiller.php

<?php
require_once 'app/Mage.php'; 
Mage::app();
Mage::getSingleton('core/session', array('name' => 'frontend'));  
 
 
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
 
$products = Mage::getModel('catalog/product')
    ->getCollection()
    ->addAttributeToSelect('*')
    ->addAttributeToFilter('status', array('eq' => 1)) //show only enabled
	;
$products->getSelect()->limit(100);
$products->load();
 
 
 
 
 
 
// Get cart instance
$cart = Mage::getSingleton('checkout/cart'); 
$cart->init();
 
 
//add the products to the cart
foreach($products as $product) {
	$id=$product->getId();
	$cart->addProduct($id, array('qty' => 1));
	print "<BR> adding :$id to your cart";	
 
}
	$cart->save();
 
// update session
Mage::getSingleton('checkout/session')->setCartWasUpdated(true);
 
 
?>Done Filling your cart go here: <a href="/checkout/cart/"> CHECKOUT</a>
Posted in Magento Tagged with: , , , , ,

Customer Love

I have had the pleasure of working with Jeremy on several innovative projects. With each experience, I was continually impressed with Jeremy’s ability to interpret requirements, translate them into a technical application, and deliver solutions on time and on budget. On many occasions, Jeremy demonstrated his acumen in researching technical approaches and developing innovative solutions. He is a highly skilled data mining and word press expert. Most impressive is Jeremy’s ability to consult on a wide variety of technologies with ease and ability to speak to the business challenges and solutions in a concise and substantive manner. He has always been a pleasure to work with maintaining a positive demeanor and responsiveness to customer needs. I’m happy to give my highest recommendation to Jeremy

- Daniel Kerns