Как добавить отзывы о продукте прогматически
-
16-10-2019 - |
Вопрос
Я хочу программно добавить обзоры продуктов с некоторыми пользовательскими полями, определенными в моем коде ниже
$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
// Важно: настроить сессию клиента. // Ресурс модели рейтинга/опция проверяет сеанс клиента, чтобы получить идентификатор клиента.
$_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();
Ссылка::