January 5, 2017

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.

require_once 'app/Mage.php'; 
Mage::getSingleton('core/session', array('name' => 'frontend'));  
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
$products = Mage::getModel('catalog/product')
    ->addAttributeToFilter('status', array('eq' => 1)) //show only enabled
// Get cart instance
$cart = Mage::getSingleton('checkout/cart'); 
//add the products to the cart
foreach($products as $product) {
	$cart->addProduct($id, array('qty' => 1));
	print "<BR> adding :$id to your cart";	
// update session
?>Done Filling your cart go here: <a href="/checkout/cart/"> CHECKOUT</a>