3

I am trying to create the product programatically, like this:

 Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
 $data0['name'] = 'Gundamz';
 $data0['sku'] = 'Gundamz123';
 $data0['weight'] = 2;
 $data0['status'] = 1;
 $data0['attribute_set_id'] = 4;
 $data0['tax_class_id'] = 0;
 $data0['visibility'] = 4;
 $data0['description'] = 'Gundam Blade';
 $data0['short_description'] = "Authentic Gundam Blade";
 $data0['price'] = "20033.32";

 $product = Mage::getModel('catalog/product');
 $product->setTypeId('simple');
 $product->setAttributeSetId($dat['attribute_set_id']);
 $product->setData($data0);
 $product->save();

but the price and weight always empty after I save the product.

Any idea, how to fix this ?

0

Both weight and price are decimals with a scale of 4.

Most likely it's not working because you are inserting them as strings instead of decimals. Try setting it by using:

 $product->setWeight(2.0000);
 $product->setPrice(20033.32);

In general it's better practice to use the setters instead of setData().

Detailed article: http://inchoo.net/magento/programming-magento/programatically-manually-creating-simple-magento-product/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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