2010-12-02 2 views
2

Je crée manuellement des avis dans Magento et j'essaie de savoir comment j'ajoute l'information de notation dedans? Je peux ajouter les critiques sans problème, mais je suis aux prises avec les valeurs d'évaluation (valeurs étoiles). J'ai un tableau qui ressemble à ceci: tableau ("Prix" => 80, "Valeur" => 60, "Qualité" => 60); Comment puis-je l'ajouter au système stellaire et à la note récapitulative?Magento - Comment ajouter des informations de notation à une revue

Merci.

Ok, c'est donc ce que j'ai jusqu'à présent: Cela ajoute un commentaire:

$review->setEntityPkValue(23);//product id 
$review->setStatusId(1); 
$review->setTitle("title"); 
$review->setDetail("detail"); 
$review->setEntityId($review->getEntityIdByCode(Mage_Review_Model_Review::ENTITY_PRODUCT_CODE)); 
$review->setStoreId(Mage::app()->getStore()->getId());      
$review->setStatusId(1); //approved 
$review->setNickname("Me"); 
$review->setReviewId($review->getId()); 
$review->setStores(array(Mage::app()->getStore()->getId()));      
$review->save(); 
$review->aggregate(); 

Cela ajoute une note pour une revue < -Je suis coincé ici!

// this is some test code to add the rating review 
$rating[0]['Price']  = 80; 
$rating[0]['Value']  = 100; 
$rating[0]['Quality'] = 80; 
$product_id = 23; 
$review_id = 631; 
foreach ($rating as $ratingId => $optionId) { 
// This is the bit where it all seems to go wrong!: 
     Mage::getModel('rating/rating') 
     ->setRatingId(1) 
     ->setReviewId($review_id) 
     ->addOptionVote($val, $product_id); 
} 

Merci!

+1

Ce que vous entendez par "manuel" n'est pas clair. Ecrivez-vous du code pour créer les avis? Et vous cherchez ce que vous devez faire pour ajouter une valeur d'évaluation? Postez le code que vous avez fait et vous aurez plus de chances d'obtenir une réponse. –

+0

Bonjour Alan. Merci d'avoir répondu. Oui, j'écris du code pour créer l'avis et ajouter la valeur d'évaluation (Prix, Qualité, Valeur, etc.). J'ai écrit un code qui crée la critique, mais il n'ajoute pas la note. Je suis loin de mon bureau maintenant, donc je ne peux pas obtenir le code que j'ai écrit mais je le posterai demain quand je peux. Merci – sulman

+0

Ok, j'ai ajouté mon code à la question maintenant. Merci! – sulman

Répondre

1

Cela a fonctionné pour moi:

public function addReview($ratingarray) 
{ 
    $product_id = $ratingarray['product_id']; 
    $storeid = $ratingarray['store_id']; 
    $title = $ratingarray['title']; 
    $customerid = $ratingarray['customer_id']; 
    $nickname = $ratingarray['nickname']; 
    $detail = $ratingarray['detail']; 

    $review = Mage::getModel('review/review'); 
    $review->setEntityPkValue($product_id); 
    $review->setStatusId(1); 
    $review->setTitle($title); 
    $review->setDetail($detail); 
    $review->setEntityId($review->getEntityIdByCode(Mage_Review_Model_Review::ENTITY_PRODUCT_CODE)); 
    $review->setStoreId($storeid); 
    $review->setStatusId(1); //approved 
    $review->setCustomerId($customerid); 
    $review->setNickname($nickname); 
    $review->setReviewId($review->getId()); 
    $review->setStores(array($storeid)); 
    $review->save(); 
    $review->aggregate(); 
    //return "success"; 
    $rating_options = $ratingarray['options']; 
    /*array(
    array(1,2,3,4), 
      array(6,7,8), 
      array(11,12) 
    );*/ 

    $row = count($rating_options); 
    $rating_id = 1; 
    foreach($rating_options as $key1=>$val1) 
    { 
     foreach($val1 as $key2=>$val2) 
     { 
      $_rating = Mage::getModel('rating/rating') 
      ->setRatingId($key1) 
      ->setReviewId($review->getId()) 
      ->addOptionVote($val2,$product_id); 
     } 

    } 
    return "Success"; 
} 

J'appelle cela comme => $ options = array (1 => array (1,2,3,4), 2 => array (6, 7,8), 3 => tableau (11,12)); $ reviewarray = array ('customer_id' => '21', 'product_id' => '176', 'store_id' => '4', 'title' => 'Révision', 'pseudo' => 'XYZ' , 'detail' => 'Produit gentil avec durée de vie warrenty', 'options' => $ options);

Questions connexes