php - creating product programatically in magento with table prefix -


I am trying to programmatically make the product in Magenta. This script works well with the default installation. However this shows below the error when I try to create a product in those Magnesto installation where I have given the table prefix. You can tell me what I need to change

Integrity Handicap Violation: A foreign key fails in constraint ( databasename_magento : 1452 can not be added or one child update line. catalog_category_product_index , barrier FK_CAT_CTGR_PRD_IDX_CTGR_ID_CAT_CTGR_ENTT_ENTT_ID foreign key ( category_id ) rEFERENCES catalog_category_entity ( `unit _ )

  $ product = new Mage_Catalog_Model_Product (); $ Products & gt; setSku ($ sku); $ Products & gt; setAttributeSetId (9); $ Products & Gt; se TTypeId ( 'simple'); $ product - & gt; Setnam ('55 '); $ Products & gt; Setgrekraideedis (array (7)); # Some cat ID, my 7 $ Products & gt; set Vebsaids ID (Array (1)); # Website ID, My H1 (default frontend) $ product- & gt; setDescription ('gift card full description here'); $ product-> setShortDescription ('Gift Card Short Description Here' ); $ Product- & gt; setPrice ('200'); # Set some value $ product- & gt; SetWait (4.0000); $ Product- & gt; SetVisibility (Mage_Catalog_Model_Product_Visibility :: VISIBILITY_NOT_VISIBLE); $ Product- & gt; SetStatus (1); $ Product- & gt; SetTaxClassId (0); # My default tax square $ product- & gt; Set stockadata (array ('is_in_stock' => 1, 'qty' => 9999)); $ Product- & gt; Save ();  

The error message clearly indicates that violation of foreign key integrity Category_id field

  $ product-> Set categoriIds (array (7)); # There is some cat id, I have 7  

The above statement should contain an error because the value defined by you is not present in the specified parent column catalog_category_entity (entity_id) .

Change the input to the existing value in the original table and move it. And it should work.


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -