1

Hi have a issue with the following issues which are connected to one and other.

  • I cannot delete images programatically from my products.
  • Images do show on 1 view and not on the other (same store/website)

I imported the photos via this function

Here are some screenshots

Default storeview: http://cl.ly/image/0p3L102K342h

storeview1: http://cl.ly/image/1E3E270s393D

Storeview2: http://cl.ly/image/1u220a0R2D0w

public function UploadFoto($product, $fotos){
        $img = 0;

        foreach ($fotos as $foto) {
            Conn::log(' img:'.$foto, 'status');
            $img++;
            if(strlen($foto)>3){
                if($img==1){

                    $pathdeel = substr($foto,0,1).'/'.substr($foto,1,1);
                    $file = Mage::getBaseDir('media') . DS . 'catalog/product'. DS . $pathdeel . DS . $foto;


                    $product->addImageToMediaGallery($file, array('thumbnail', 'small_image', 'image'), true, false); //assigning image, thumb and small image to media gallery
                }else{
                    $pathdeel = substr($foto,0,1).'/'.substr($foto,1,1);
                    $file = Mage::getBaseDir('media') . DS . 'catalog/product'. DS . $pathdeel . DS . $foto;
                    $product->addImageToMediaGallery($file, array(), true, false); //assigning image, thumb and small image to media gallery
                }

            }
        }
    }
0

You can assign the images for each storeview separately. Maybe your script is initialized in a store(view) instead of the admin as a script. That could explain the current behavior.

Start your script like this

// Initialize admin store
require('app/Mage.php');
Mage::app('admin')->setUseSessionInUrl(false);

This way you are using the admin to set new data.

Magento does support out of the box deleting of images from a product, but it will not unlink these files on the filesystem. Take a look here for a script to to take care of that.

You could investigate Mage_Catalog_Model_Product_Attribute_Backend_Media to take image import automation further.

  • Kom jou ook overal tegen haha... Thanks ik ga het vandaag even proberen.. – Kay Int Veen Mar 12 '15 at 6:53
  • Yes, success!!! – Jeroen Mar 12 '15 at 7:45

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.