// Invoke the Magento environment
require_once 'app/Mage.php';
Mage::app();
// Set up your own loop to to go through the reviews from the source cart.
// Logic to look up customer that has already been migrated into magento.
// So you have $_customer holding a Mage_Customer_Model_Customer
// IMPORTANT: Set up customer session.
// the rating/option model resource checks the customer session to get the customer ID.
$_session = Mage::getSingleton('customer/session')->setCustomer($_customer)->setCustomerAsLoggedIn($_customer);
// Add the review
$_review = Mage::getModel('review/review');
->setEntityPkValue($_product->getId())
->setStatusId($sc_to_mage_review_status[$row_source_review['Status']])
->setTitle($row_source_review['Title'])
->setDetail($row_source_review['Review'])
->setEntityId(1)
->setStoreId($store)
->setStores(array($store))
->setCustomerId($_customer->getId())
->setNickname($_customer->getFirstname())
->save();
// Map your rating_id to your option_id with an array or something
$rating_options = array(
1 => array(1,2,3,4,5), // <== Look at your database table `rating_option` for these vals
2 => array(6,7,8,9,10),
3 => array(11,12,13,14,15)
);
// Now save the ratings
foreach($rating_options as $rating_id => $option_ids):
try {
$_rating = Mage::getModel('rating/rating')
->setRatingId($rating_id)
->setReviewId($_review->getId())
->addOptionVote($option_ids[$rating_value-1],$_product->getId());
} catch (Exception $e) {
die($e->getMessage());
}
endforeach;
Your review tab in product view page is lack with toolbar. So the solution is adding toolbar block inside your review tab section. From your question, it is not clear that which block that holds CUSTOMER REVIEW
section that comes under Review
tab.
For the sake of better understanding, I assumes it is a block with name customer.review.in.product.view
. In that case, you need to do a layout update somewhat like this
File : app\design\frontend\<package>\<theme>\layout\local.xml
<layout>
<catalog_product_view>
<reference name="content">
<block type="page/html_pager" name="product_review_list.toolbar" />
</reference>
</catalog_product_view>
</layout>
This layout update just inserts a toolbar block inside product view page layout. Job is not over. Now we need to set toolbar block with collection. In this case it is review collection.
For this, find your backend class definition for the block customer.review.in.product.view
and put this code inside
protected function _prepareLayout()
{
parent::_prepareLayout();
if ($toolbar = $this->getLayout()->getBlock('product_review_list.toolbar')) {
$toolbar->setCollection($this->getReviewsCollection());
$this->setChild('toolbar', $toolbar);
}
return $this;
}
Let us analyse the code here. The method that we used here is _prepareLayout()
. This method will invoke during layout preparation. It first try to get a block with name product_review_list.toolbar
. Since we define this block through our layout update, it will get the find our custom block successfully.
Next it sets review collection to this block. In order to set the review collection, it is very important that, customer.review.in.product.view
block class should extend the class Mage_Review_Block_Product_View
.This is because, this class is the place where review collection is loading. I hope the assumed block extends this block. Otherwise this wont work.
Finally our toolbar block is setting as a child block for our review block. You are done. Clear the cache and load the page. It will now paginate review section in your product view page.
I need to mention that, I didn't try this code. That is because, I cannot regenerate the situation with given details. But it should work I guess.
Best Answer
Let's assume that your attribute has
int
type. In this case you can do something like this:Where
272
is the of your attribute id.If you also want to limit a collection to reviews of products with specific attribute set to specific value you can add something like this to the end
Where 24 is the value of your attribute.
If your attribute has different type then just replace
catalog_product_entity_int
with EAV table of your attribute.