1

I am trying to create an virtual product programatically by using below code.When I execute this script from root of the store I am getting an error :

No date part in '' found.

require_once('app/Mage.php'); //Path to Magento
umask(0);
Mage::app();
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$product = Mage::getModel('catalog/product');

$product
->setWebsiteIds(array(1)) //website ID the product is assigned to, as an array
->setAttributeSetId(4) //ID of a attribute set named 'default'
->setTypeId('virtual') //product type
->setCreatedAt(strtotime('now')) //product creation time
->setSku('test') //SKU
->setName('Test Product') //product name
->setWeight(4.0000)
->setStatus(1) //product status (1 - enabled, 2 - disabled)
->setTaxClassId(0) //tax class (0 - none, 1 - default, 2 - taxable, 4 - shipping)
->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE) //catalog and search visibility
->setPrice(0) //price in form 11.22
->setCost(0) //price in form 11.22
->setDescription('This is a long description')
->setShortDescription('This is a short description')

->setStockData(array(
                   'use_config_manage_stock' => 0, //'Use config settings' checkbox
                   'manage_stock'=>0, //manage stock
                   'min_sale_qty'=>1, //Minimum Qty Allowed in Shopping Cart
                   'max_sale_qty'=>2, //Maximum Qty Allowed in Shopping Cart
                   'is_in_stock' => 1, //Stock Availability
                   'qty' => 999 //qty
               )
);

 try{ 
    $product->save();

  }catch(Exception $e){
    Mage::log($e->getMessage());
  }

Thank you in advance.

1 Answer 1

2

I'm not sure, but I think that there is a problem with param passed to setCreatedAt() method. Try to remove it (or change strtotime('now') to date('Y-m-d H:i:s')) and see what happens.

1
  • I faced the exact issue and solved by following @SeStro 's solution. Thanks. Commented Jun 21, 2016 at 8:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.