cancel
Showing results for 
Search instead for 
Did you mean: 

Creating a product

SOLVED

Creating a product

Hi,

 

currently I'm trying to import products to my magento installation. The product is saved successfully in the choosen category. Only the price and tax class is empty / not selected and the product is set as inactive.
I guess my product is not set active since the required price is missing.

 

$vmProdPrice = mysql_fetch_array(mysql_query($mysqlQuery, $this->mysqlHandle), MYSQL_ASSOC);
$mProd->setPrice((float)$vmProdPrice['product_price']);
$mProd
	->setCategoryIds($mCatParentArr)
	->setAttributeSetId(4)
	->setVisibility(1)
	->setType('Simple Product')
	->setName($vmProd['product_name'])
	->setDescription($vmProd['product_desc'])
	->setShortDescription($vmProd['product_s_desc'])
	->setStatus(2)
	->setTaxClassId(2)
	->setWeight(0)
	->setCreatedAt( strtotime('now') );

try {
	$mProd->save();
} catch (Exception $e) {
	echo Mage::log( $e->getMessage() );
}

 

NOTE: I set the weight attribute requirement to false, so i suppose "weight 0" shouldn't be the problem any more.

Any suggestions?
Thanks
Nik

Tags (2)
2 REPLIES

Re: Creating a product

I will debug with two ways..

 

1)Change $mProd->setPrice() with a static value and check if the product is created with price. May be the value is empty.

 

2)check the value of 2 in tax rule and see what rule is defined.

Re: Creating a product

Thanks for your reply @sathyashrayan,

 

I'm still not totally sure what caused the problem. I found another post about creating a product and modified my code.
Tax class ID 2 refers to "Taxable Goods" what is also a "PRODUCT" class type and should have been working (See table tax_class). Well, my products should have the tax class "Shipping", so i changed it to 4.

Status 2 appears to be the disabled state, what still does not explain the price issue to me. Could it have been the visibility.?
Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH == 4
Does the visibility has any impact on calculating/storing the price?

 

$mProd = Mage::getModel('catalog/product');
$mProd
	->setWebsiteIds( array($this->websiteId) )
	->setSku($vmProd['product_sku']);
$mProd->setPrice((float)$vmProdPrice['product_price']);
$mProd
	->setCategoryIds($mCatParentArr)
	->setAttributeSetId(4) // default
	->setTypeId('simple')
	->setCreatedAt( strtotime('now') )
	->setName($vmProd['product_name'])
	// ->setWeight(0)
	->setStatus(1)
	->setTaxClassId(4) // shipping
	->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH) //catalog and search
	->setMetaTitle('test meta title 2')
	->setMetaDescription('test meta description 2')
	->setDescription($vmProd['product_desc'])
	->setShortDescription($vmProd['product_s_desc'])
	// ->setMediaGallery(array('images' => array(), 'values' => array()))
	->setStockData( array('use_config_manage_stock' => 0, 'manage_stock' => 1, 'min_sale_qty' => 0, 'max_sale_qty' => 0, 'is_in_stock' => 1, 'qty' => $vmProd['product_in_stock']) );
try {
	$mProd->save();
} catch (Exception $e) {
	echo Mage::log( $e->getMessage() );
}



Regards
Nik