我想通过下面的代码上定义的一些自定义字段以编程方式添加产品评论

$review = Mage::getModel('review/review')
->setEntityPkValue(intval($pressquote->product_id)) //product id
->setStatusId(intval($pressquote->status))
->setDetail($pressquote->text)
->setTitle('')
->setEntityId(1)                     
->setStatusId(intval($pressquote->status))          //approved
->setCustomerId(null)                       //null is for administrator
->setNickname($pressquote->source)
->setLink($pressquote->link)                            //custom field
->setLinktext($pressquote->linktext)                   //custom field
->setYear($pressquote->year)                            //custom field
->setStoreId(1)                                          
->setStores(array('base'))                              
->save();

但这对我不起作用。.我检查了我的代码,它停止了 save(). 。什么地方出了错?我尝试已经删除了自定义字段,但什么也没发生

有帮助吗?

解决方案

//调用Magento环境

require_once 'app/Mage.php';
Mage::app();

//设置自己的循环以从源购物车中进行评论。

//逻辑以查找已经迁移到Magento的客户。 //因此,您有$ _customer持有mage_customer_model_customer

//重要:设置客户会话。 //评级/选项模型资源检查客户会话以获取客户ID。

$_session = Mage::getSingleton('customer/session')->setCustomer($_customer)->setCustomerAsLoggedIn($_customer);

//添加评论

$_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();

//用数组或其他内容映射您的评分_id到您的option_id

$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)
);

//现在保存评分

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;

其他提示

$review = Mage::getModel('review/review');
$review->setEntityPkValue(147);//product id
$review->setStatusId(1); // approved
$review->setTitle("title");
$review->setDetail("detail");
$review->setEntityId(1);                                      
$review->setStoreId(Mage::app()->getStore()->getId());                    
$review->setCustomerId(273);//null is for administrator
$review->setNickname("Me");
$review->setReviewId($review->getId());
$review->setStores(array(Mage::app()->getStore()->getId()));                    
$review->save();

$review->aggregate();

参考::

http://www.magentocommerce.com/boards/viewthread/199171/

许可以下: CC-BY-SA归因
scroll top