Magento 用代码批量 添加产品的评论review(通过SKU)
来源:互联网 发布:湖南省地质测绘院 知乎 编辑:程序博客网 时间:2024/05/18 18:02
说明:在网站前台添加评论 review_store 表 要添加2条数据。对比发现 自己的代码 添加的 store_id自动 为0(正常应该有2条,还有一条 store_id为1的)
这里的 1和0 ,分表Magento前台和后台。
所以我 指定了 $StoreId =1; 默认 storeid 是通过
Mage::app()->getStore()->getId() 获取的。
在 \app\code\core\Mage\Review\controllers\ProductController.php
postAction() 方法是处理 前台用户的评论的。
在这个方法里Mage::app()->getStore()->getId() 获取的值为 1。
所以,我这里 指定了 $storeid = 1。
具体实现代码如下:
<?phpdefine('MAGENTO', realpath(dirname(__FILE__)));require_once MAGENTO . '/app/Mage.php';umask(0);Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); //数据$data = array("form_key" => "AGPcNKVldb5KkWBA","ratings" => array(3=>'15',2=>'10',1=>'5'),"nickname" => "jack","title" => "HB82429","detail" => "good");$rating = array(3=>'15',2=>'10',1=>'5');//产品模型对象$product = Mage::getModel('catalog/product')->loadByAttribute('sku',$data['title']);//StoreId手动设置$StoreId = '1';//review模型$review = Mage::getModel('review/review')->setData($data);$review->setEntityId($review->getEntityIdByCode(Mage_Review_Model_Review::ENTITY_PRODUCT_CODE)) ->setEntityPkValue($product->getId()) ->setStatusId(Mage_Review_Model_Review::STATUS_PENDING) ->setCustomerId(Mage::getSingleton('customer/session')->getCustomerId()) ->setStoreId($StoreId) ->setStores(array($StoreId)) ->save();//循环写入rating表foreach ($rating as $ratingId => $optionId) { Mage::getModel('rating/rating') ->setRatingId($ratingId) ->setReviewId($review->getId()) ->setCustomerId(Mage::getSingleton('customer/session')->getCustomerId()) ->addOptionVote($optionId, $product->getId());}$review->aggregate();//集合处理这个是基础核心代码,批量添加评论功能或者去其他网站抓取同sku产品然后写入评论等功能。可在此基础上扩展。
0 0
- Magento 用代码批量 添加产品的评论review(通过SKU)
- magento -- 根据产品的sku获得产品
- Magento 通过SKU 或 属性获取产品和目录
- 在 magento产品页面显示评论表单(review form)
- Magento 查询产品SKU和价格的SQL
- Magento通过分类id获取该分类下的产品(entity_id、type_id、sku、created_at、updated_at、status、visibility)
- magento 产品评论模块的显示
- [Magento代码] 关联SKU到指定的分类下面
- magento如何根据sku显示产品销售量
- magento产品review增加回复
- Bigcommerce:cart页面和wishlist页面添加产品的SKU
- 模拟淘宝的产品SKU信息添加组合
- magento -- 如何在magento中实现产品的批量上传
- magento -- 如何在magento中进行产品的批量上传
- magento批量删除产品
- Magento产品页面显示评论
- magento 获取产品评论数量
- magento按分类批量添加up-sell产品
- 用B-树实现虚拟图书管理系统
- D D - Om Nom and Necklace
- PostgreSQL入门学习之数据库连接相关基础知识
- 【线段树】【4-6组队赛】Problem H
- 社説 20150409 日銀異次元緩和 「物価2%」の達成を焦るな
- Magento 用代码批量 添加产品的评论review(通过SKU)
- Windows和Linux下获取当前可执行文件路径和工作目录
- 人民日报:不告密不揭发是道德底线
- OPENGL 绘制基本图元
- tbb基础之parallel_reduce用法详解
- 面试题-单链表反转
- windows下安装docker
- msgrcv参数错误导致堆栈被破坏
- edk inf 文件解读