2

My script currently works for all stores except the store it's pulling from. I want to pull all reviews from my default store / main store and only push the reviews to my new store with a websiteId = 13 and storeId = 13

Here's my code below:

<?php
require_once 'abstract.php';
class Mage_Shell_Review extends Mage_Shell_Abstract
{

    public function run()
    {
        $ids    = Mage::getModel('review/review')->getCollection()->getAllIds();
        $stores = Mage::getModel('core/store')
            ->getCollection()
            ->getAllIds();

        $adapter = Mage::getSingleton('core/resource')->getConnection('core_write');

        $table = 'review_store';
        try {
            $adapter->beginTransaction();
            $adapter->truncateTable($table);
            $values=array();
            foreach ($ids as $id) {
                foreach ($stores as $storeId) {
                    $values[]="($id,$storeId)";
                }
            }
            $values=implode(",\n",$values);
            $query="INSERT INTO $table (`review_id`,`store_id`) VALUES $values;";
            $adapter->query($query);
            $adapter->commit();
            Mage::app()->getCacheInstance()->flush();
            Mage::app()->cleanCache();
            echo "OK\n";
        } catch (Exception $e) {
            $adapter->rollBack();
            print_r($e->getTrace());
        }
    }
}

$shell = new Mage_Shell_Review();
$shell->run();

I haven't tested it yet because i don't want to effect all stores... i only need the reviews from default to populate the new store with the id of 13.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.