Generate Test Products

Posted . Visible to the public.

I took this script from somewhere (sorry I forgot where!) but it didn't work for 1.9.1.0, so I fixed it up. Really basic, but useful, I used it to test pagination:

<?php
require 'app/Mage.php';
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
for ($i = 0; $i < 100; $i++) {
    Mage::getModel('catalog/product')
        ->setWebsiteIds(array(1))
        ->setAttributeSetId(4)
        ->setTypeId('simple')
        ->setSku($i)
        ->setStatus(1)
        ->setTaxClassId(2)
        ->setVisibility(4)
        ->setName("Product Number $i")
        ->setDescription("This widget will give you years of trouble-free widgeting.")
        ->setShortDescription("High-end widget.")
        ->setPrice(99.99)
        ->setCategoryIds(array(152))
        ->setWeight(1.0)
        ->setStockData(array(
            'use_config_manage_stock' => 0,
            'manage_stock' => 1,
            'min_sale_qty' => 1,
            'max_sale_qty' => 2,
            'is_in_stock' => 1,
            'qty' => 999
        ))
        ->save();
};
Mike Whitby
Posted by Mike Whitby to Magento (2015-06-04 08:44)