Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Adding products via PHP Code
 
itzik
Member
 
Total Posts:  36
Joined:  2008-07-21
 

I’m trying to add products to the database via PHP code...so far I have this:

$newProduct Mage::getModel('catalog/product')
    ->
setStoreId('default')
    ->
setAttributeSetId(9)
    ->
setPrice($price)
    ->
setSku($uid)
    ->
setName($name)
    ->
setWeight(1)
    ->
setDescription('Description not available.')
    ->
setQty(500)
    ->
setStatus(Mage_Catalog_Model_Product_Status::STATUS_ENABLED)
    ->
save(); 
  

  
  
//echo 'OK Product ID: '.$newProduct->getId();
  //echo "Name:$name<br>Price:$price";
  
}
  
catch (Mage_Core_Exception $e{
    
//echo $e->getMessage();
  
}
  
catch (Exception $e{
    
//echo $e;
  
}

But when the product is added, it doesn’t show in the store because Quantity is set to null, and Stock Availability is set to “Out of Stock”.  Does anyone know how to set these values as well?

Unfortunately I can’t use SOAP because I am running version 1.0 and updating at this point would cause me to lose many customizations.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Brandlive_br
Guru
 
Avatar
Total Posts:  653
Joined:  2008-05-19
Buenos Aires, Argentina
 

I’m using my own massive import process.
I made tests with Magento 1.0.x, trying to import 220k products. You can read into Dataflow forum, that’s a great problem, but I think that we can get a better solution soon.

Going back to your question about price, quantity and other fields.
In my process I use and external php process and run a store precedure into my database. Check this inserts for some attributes:

INSERT INTO catalog_product_entity_decimal(
      
entity_type_id,
      
attribute_id,
      
store_id,
      
entity_id,
      
value
    
VALUES (
      
4,
      
49,
      
[store_id],
      
[entity_id],
      
[your_product_price]
    
),(
      
4,
      
54,
      
[store_id],
      
[entity_id],
      
[your_product_price]
    
);

Check into eav tables to know attributes id.
I’m not so sure, but I think that if you got a product without quantity, it can be displayed at your store.

I hope this helps you a little.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Brandlive_br
Guru
 
Avatar
Total Posts:  653
Joined:  2008-05-19
Buenos Aires, Argentina
 

Sorry, the second: [your_product_price] it really [your_product_weight].

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top