tags:

views:

40

answers:

1

I am trying to import product reviews from an older site to our new Magento site.

I am having troubles trying to create the actual product review in a script. Has anyone tried doing this before and know how to accomplish this?

It looks like reviews use the entity models and I can't seem to get the review object to do what I want it to do. Here is what I have tried doing so far and its throwing back some an error about foreign keys not being respected. Not sure how to make this work. Any help would be appreciated.

$review = Mage::getModel('review/review');

$review->setEntityPkValue(141292);

$review->setStatusId(1);

$review->setTitle("This is an inserted title");

$review->setDetail("This is an inserted detail");

$review->setNickname("First Last");

$review->save();

Thanks

Josh Pennington

+1  A: 

Hi Josh,

My guess would be that it's asking for a product and store to link the review with. Reading the install sql (under app/code/core/Mage/Review/sql/, it looks like there are constraints between review and each of:

  • core_store
  • catalog_product_entity
  • review_status
  • review_entity

Hope this helps, JD

Jonathan Day
Thanks much. Your solution helped me find the answer. All I had to do was add $review->setEntityId(1); to the code and it worked perfectly.
Josh Pennington