php - Use all images from my default store on my new store view

162

I have a new store view and i've updated all the products using the magento admin:**Manage Products > Select all > Update Attributes** and then selecting the new store. Now that all my products are affiliated with my new store view i'm having a problem with all my images. On the front end it shows all placeholders. In the admin panel when i click on a product and then images.. it may have images but it's not selected to use base image, small image or thumbnail.

Is there a way to update all images on my new store view to use the default store view main images?

require_once 'abstract.php';

class Attach_Default_Store_Images Extends Mage_Shell_Abstract {

    public function run()
    {
        $products = Mage::getModel('catalog/product')->getCollection();
        foreach ($products as $product) {
            $productFrom = $product->setStoreId(1)->getImage();
            $productTo = $product->setStoreId(13)
            ->setImage($productFrom)
            ->setSmallImage($productFrom)
            ->setThumbnail($productFrom);
            echo "Images Updated\n";
            $product->save();
   }

        Mage::getModel('catalog/product_image')->clearCache();
        echo "Image Cache Cleared\n";

    }


    public function usageHelp()
    {
        return <<<USAGE
Usage:  php -f cache.php -- [options]
        php -f cache.php -- clean

  clean             Clean Old Cache
  help              This help

USAGE;
    }
}

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

Run a shell script with above?

887

Answer

Solution:

You can use magmi for this , just export the products CSV from magento admin, and re-import the required fields like SKU, image, small_image and thumbnail through magmi and it will do your work very fast and easily.

145

Answer

Solution:

$products = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*');
foreach ($products as $product) {
    if (!$product->hasImage()) continue;
    if (!$product->hasSmallImage()) $product->setSmallImage($product->getImage());
    if (!$product->hasThumbnail()) $product->setThumbnail($product->getImage());
    $product->save();
}
276

Answer

Solution:

Run this script in your magento root:

<?php
    ini_set('memory_limit','2048M');
    error_reporting(E_ALL);
    ini_set('display_errors', '1');

    require_once('app/Mage.php');
    Mage::app('default');
    $storeId = 0;
    Mage::app()->setCurrentStore(Mage::getModel('core/store')->load($storeId));

    $from_id    = 1 // product id from;
    $to_id  = 1000 // product id to;
    $products = Mage::getModel('catalog/product')
    ->getCollection()
    ->addAttributeToSelect('*')
    ->addFieldToFilter('entity_id',array('gteq'=>$from_id))
    ->addFieldToFilter('entity_id',array('lteq'=>$to_id));

    foreach ($products as $product) {   

     if (!$product->getImage()) continue;
    if (!$product->getSmallImage()) $product->setSmallImage($product->getImage());
    if (!$product->getThumbnail()) $product->setThumbnail($product->getImage()); 
    $product->save(); 

    }
    ?>

People are also looking for solutions to the problem: php - block quote ignore empty lines and keep opening new quotes

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.