So I am creating a Magento product when I call this if statement and it returns false, that all works...
I just want to create the URL or create a URL redirect for the product in the same statement
It needs to be within the same if statement as I want it to be created at the same time of the product creation
Here is my code:
if (!Mage::getModel('catalog/product')->getIdBySku($sku)) {
$product = Mage::getModel('catalog/product');
$product->setName($name);
$product->setSku($sku);
$product->setDescription($desc);
$product->setShortDescription($short);
$stock_data=array(
'use_config_manage_stock' => 0,
'qty' => 0,
'min_qty' => 0,
'use_config_min_qty'=>0,
'min_sale_qty' => 1,
'use_config_min_sale_qty'=>1,
'max_sale_qty' => 9999,
'use_config_max_sale_qty'=>1,
'is_qty_decimal' => 0,
'backorders' => 0,
'notify_stock_qty' => 0,
'is_in_stock' => 0
);
$product->setData('stock_data',$stock_data);
$product->setTaxClassId(2); // default tax class
$product->setAttributeSetId(4); //9 is for default
$product->setWebsiteIds(array(1));
$product->setCategoryIds(array(9));
$product->setStatus(1);//1=Enabled; 2=Disabled;
$product->setVisibility(4);//4 = catalog & search.
try
{
$product->save();
} catch(Exception $e) {
echo $e->getMessage();
}
}