phpmagento-1.9

Magento: post review as guest user


I'm working on an import/export Product Reviews script, and the export works just fine, except that it doesn't really export ID for guest users. But when I want to import products, I create a customer object, and I assign that customer ID to review I'm creating, but that doesn't work, and I assume it's because of customer ID(Magento doesn't really say what's wrong).

$_customer =  Mage::getModel('customer/customer')->load($_row['customer_id']);

where $_row is is a row from CSS file I'm loading. Now, here's where I create a review:

$_review = Mage::getModel('review/review')
                ->setEntityPkValue($_product->getId())
                ->setStatusId($_row['status_id'])
                ->setTitle($_row['title'])
                ->setDetail($_row['detail'])
                ->setEntityId(1) // review_entity: 1 - Product
                ->setStoreId($_row['store_id'])
                ->setStores(array($_row['store_id']))
                ->setCustomerId($_customer->getId()) //null is for administrator
                ->setNickname($_row['nickname'])
                ->save();

So, my question would be, how to programmaticaly create a review as a guest user?


Solution

  • you are doing correct for customer review if you want to create review as a guest then you have to use below snippet.

    $review->setCustomerId(null);
    $review->setNickname("SimBeez");