質問

以下のコードで定義されているいくつかのカスタムフィールドを使用して、製品レビューをプログラムで追加したい

$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に移行されている顧客を検索するロジック。 //したがって、mage_customer_model_customerを保持している$ _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();

// rating_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帰属
所属していません magento.stackexchange
scroll top