2012-09-04 00:42
浏览 82


I found the script below and its been said that it works, but I"m just not sure where or how they got the file/script to work and was hoping someone could help me shed some light.

There are multiple ways to import things into Magento - through a custom xml data file or just through a php script and thats what this says it is but i'm curious as to where its pulling the data from that its supposedly importing?

ini_set('memory_limit', '128M');

require_once 'path-to-Mage.php';

Mage::app()->setCurrentStore(4); //desired store id
$review = Mage::getModel('review/review');
$review->setEntityPkValue(147);//product id
$review->setStatusId(1); //approved
$review->setCustomerId(273);//null is for administrator

So if this is my php script where am I putting it? And can someone help me formulate the xml script I would use for importing?

Thanks in advance for any and all help


图片转代码服务由CSDN问答提供 功能建议

我找到了下面的脚本,据说它有效,但我不确定它们在哪里或如何 让文件/脚本工作,并希望有人可以帮助我解决问题。

有多种方法可以将内容导入Magento - 通过自定义xml数据文件或只是通过php 脚本,这就是说它是什么,但我很好奇它从哪里拉出数据所谓的导入?

ini_set('memory_limit'  ,'128M'); 
Mage :: app(); 
Mage :: app() - &gt; setCurrentStore(4); //所需的商店ID  
 $ review = Mage :: getModel('review / review'); 
 $ review-&gt; setEntityPkValue(147); // product id 
 $ review-&gt; setStatusId(1); 
 $ review-  &gt; setTitle(“title”); 
 $ review-&gt; setDetail(“detail”); 
 $ review-&gt; setEntityId(1); 
 $ review-&gt; setStoreId(Mage :: app()  - &gt; getStore() - &gt; getId()); 
 $ review-&gt; setS  tatusId(1);  //已批准
 $ review-&gt; setCustomerId(273); // null代表管理员
 $ review-&gt; setNickname(“Me”); 
 $ review-&gt; setReviewId($ review-&gt; getId  ()); 
 $的审查 - &GT; setStores(阵列(法师::应用程序() - &GT; getStore() - &GT;的getId()));  
 $ review-&gt; save(); 
 $ review-&gt; aggregate(); 

所以,如果这是我的PHP 脚本我把它放在哪里? 并且有人可以帮我制定我用于导入的xml脚本吗?



  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dporu02280 2012-09-04 03:14

    What format are your reviews in currently that you wish to import?

    It seems you'd need to expand on this script, for example :open a file containing your reviews, cycle through them and use the above code inside this loop, replacing "title" and "detail" etc with the actual review information.

    Edited based on your comments below *****

    I'm assuming you have PHP and Magento coding experience - if not, perhaps you should look to get assistance from a developer.

    ini_set('memory_limit', '128M'); 
    require_once 'path-to-Mage.php'; 
    $fp = fopen($fileLocation, 'r');
    Mage::app()->setCurrentStore(4); //desired store id 
    while($line = fgetcsv($fp)) {
         $review = Mage::getModel('review/review'); 
     $review->setEntityPkValue($line[0]);//product id 
     $review->setStatusId($line[5]); //approved 
     $review->setCustomerId($line[6]);//null is for administrator 

    You'll obviously need to replace $fileLocation with the directory location and file name of your CSV file. Each row of your CSV will be read into an array $line. The columns will map to the element numbers in the array. e.g. $line[0] is the first column of the row. You'll need to alter the element references so that the data matches up to your CSV columns.

    This is enough for you to get going.

    打赏 评论
  • doutan5724 2019-08-04 05:19

    If you want to import via pure SQL, then you can use the below set of queries:

    -- Edit values
    SET @PRODUCT_ID         = 123;
    SET @STORE_ID           = 1;
    SET @CUSTOMER_ID        = NULL;
    SET @REVIEW_TITLE       = 'Lorem Ipsum';
    SET @REVIEW_DETAIL      = 'Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit...';
    SET @REVIEW_RATING      = 5; -- Between 1 to 5
    SET @REVIEW_NICKNAME    = 'John Doe';
    SET @REVIEW_CREATED_AT  = '2019-07-15'; -- OR date in YY-mm-dd HH:ii:ss format
    -- No need to Edit
    SET @REVIEW_ENTITY_ID   = (SELECT entity_id FROM rating_entity WHERE entity_code = 'product'); -- 1: product, ...
    SET @REVIEW_STATUS_ID   = (SELECT status_id FROM review_status WHERE status_code = 'Pending'); -- 1: Approved, 2: Pending, 3: Not Approved
    INSERT INTO review SET created_at = @REVIEW_CREATED_AT, entity_id = @REVIEW_ENTITY_ID, entity_pk_value = @PRODUCT_ID, status_id = @REVIEW_STATUS_ID;
    INSERT INTO review_detail SET review_id = @REVIEW_ID, store_id = @STORE_ID, title = @REVIEW_TITLE, detail = @REVIEW_DETAIL, nickname = @REVIEW_NICKNAME, customer_id = @CUSTOMER_ID;
    INSERT INTO review_store SET review_id = @REVIEW_ID, store_id = 0;
    INSERT INTO review_store SET review_id = @REVIEW_ID, store_id = @STORE_ID;
    INSERT INTO rating_option_vote SET option_id = 5, remote_ip = '', remote_ip_long = 0, customer_id = @CUSTOMER_ID, entity_pk_value = @PRODUCT_ID, rating_id = @REVIEW_ENTITY_ID,
    review_id = @REVIEW_ID, percent = 100, value = @REVIEW_RATING;

    You can get detailed steps here:

    打赏 评论

相关推荐 更多相似问题