tags:

views:

98

answers:

2

I ask this question, since I am trying to get the images I have just copied from Domain A to work in Domain B, (which is using the same database).

http://DOMAIN_A/magento/media/catalog/product/cache/1/image/9df78eab33525d08d6e5fb8d27136e95/b/0/b0041-1.jpg

I think knowing what the 32 character string is, which help me find a good explanation why the images are not being found in the front or backend of Magento after reinstall on DOMAIN B.

RE: Magento version 1.4.0.1

A: 

Here's the code that creates that filename path, found in Mage_Catalog_Model_Product_Image:

    // build new filename (most important params)
    $path = array(
        Mage::getSingleton('catalog/product_media_config')->getBaseMediaPath(),
        'cache',
        Mage::app()->getStore()->getId(),
        $path[] = $this->getDestinationSubdir()
    );
    if((!empty($this->_width)) || (!empty($this->_height)))
        $path[] = "{$this->_width}x{$this->_height}";

    // add misk params as a hash
    $miscParams = array(
            ($this->_keepAspectRatio  ? '' : 'non') . 'proportional',
            ($this->_keepFrame        ? '' : 'no')  . 'frame',
            ($this->_keepTransparency ? '' : 'no')  . 'transparency',
            ($this->_constrainOnly ? 'do' : 'not')  . 'constrainonly',
            $this->_rgbToString($this->_backgroundColor),
            'angle' . $this->_angle,
            'quality' . $this->_quality
    );

    // if has watermark add watermark params to hash
    if ($this->getWatermarkFile()) {
        $miscParams[] = $this->getWatermarkFile();
        $miscParams[] = $this->getWatermarkImageOpacity();
        $miscParams[] = $this->getWatermarkPosition();
        $miscParams[] = $this->getWatermarkWidth();
        $miscParams[] = $this->getWatermarkHeigth();
    }

    $path[] = md5(implode('_', $miscParams));

    // append prepared filename
    $this->_newFile = implode('/', $path) . $file; // the $file contains heading slash

So, the hash is generated from the configuration info (aspect ratio, etc), as well as the watermark info. This information will not usually change. However, I do see that the path is partially generated from the store_id of the current store, so your trouble may be there.

Is there a reason you can't let Magento use its normal caching procedures for both stores? Since Magento checks the filesystem for the cached image, there shouldn't be a conflict.

Hope that helps!

Thanks, Joe


Upon contemplation, are you just trying to get the catalog images to work in both domains? The non-cached version of the catalog images are at %magento%/media/catalog/product. Copy the directories from that location and your catalog images should work.

Joseph Mastey
Thanks Joe.I tried to copy just the catalog/product/ images, still no joy, then I tried to delete the cached images, again, no joy. Result - still joyless and still stuck trying to get the images to load after 4 days!
Daniel Higgins
both installations have the same store_id
Daniel Higgins
A: 

Moving over the cached images isn't going to go far, since they will be deleted next time you flush the Magento cache. So, having moved the images that are in /media/catalog/product, flush the Magento image cache. Make sure that the file permissions are correct for reading. Then, head into Mage_Catalog_Model_Product_Image and take a look at the following code (approx line 270):

    if ($file) {
        // add these for debugging
        Mage::log($baseDir.$file);
        Mage::log(file_exists($baseDir.$file));
        Mage::log($this->checkMemory($baseDir.$file));

        if ((!file_exists($baseDir . $file)) || !$this->_checkMemory($baseDir . $file)) {
            $file = null;
        }
    }

Add a var_dump or Mage::log statement in there (depending on whether you have logging enabled), and verify that the path to the images is correct, and that you have enough memory for the operation. This is the code that will choose the default image for you if no image path exists. If you still can't get it, post the output of those three logging statements and we'll keep trying. :)

Joseph Mastey
I emptied the images cache, cleaned the cache in the admin panel, still did not work. Then I added your lines and tried a different product.I got a error screen with a message about exception handling.Here are the 3 lines from the system.log2010-05-27T15:36:24+00:00 DEBUG (7): /var/www/vhosts/handmadejewelleryuk.co.uk/subdomains/dev/httpdocs/media/catalog/product/n/0/n0014-2_1.jpg2010-05-27T15:36:24+00:00 DEBUG (7):~(this looks correct to me)
Daniel Higgins
That's only two lines. And you say you got a tilde character from the log? Make sure that the file mentioned exists and is readable (give it world-readable permissions).At least we know it's looking for a real file now.
Joseph Mastey
since then I have been unable to get it to look for a real file, it does not make it into the if($file) loop.. and just loads the placeholder... Got that Magento sinking feeling after a spell of optimism! Thank you Joseph :)
Daniel Higgins
Here is a snippet of the directory listing to show the images file exist and permissions are 777'ed<pre>[root@webspacecommerce log]# ls -al /var/www/vhosts/handmadejewelleryuk.co.uk/subdomains/dev/httpdocs/media/catalog/product/n/0/total 10816drwxrwxrwx 2 apache apache 4096 Mar 19 11:57 .drwxrwxrwx 3 apache apache 4096 Mar 19 10:27 ..-rwxrwxrwx 1 apache apache 175246 Mar 19 10:27 n0001-1.jpg-rwxrwxrwx 1 apache apache 348826 Mar 19 10:27 n0001-2.jpg-rwxrwxrwx 1 apache apache 332710 Mar 19 10:27 n0001-3.jpg</pre>
Daniel Higgins
If it isn't even getting to the if($file) location, you need to look further upstream for the issue. See if anything gets passed into that function at all, or whether it *is* passed in but something else overwrites it to null. Or even whether you're requesting an image type that doesn't exist for some reason (e.g. 'thmb' versus 'thumb').
Joseph Mastey