2

Our default site configuration uses a CDN for our insecure media URLs and no CDN for our secure media URLs. This is how things should work the majority of the time, but we have a case that needs to explicitly retrieve insecure URLs despite normally being a secure request.

The code which returns the URLs is using the product and the image helper to return resized versions of the media gallery:

foreach ($product->getMediaGalleryImages() as $image) {
    $imageUrl = (string) Mage::helper('catalog/image')
                ->init($product, 'image', $image->getData('file'))
                ->keepFrame(false)
                ->constrainOnly(true)
                ->resize($imageSize);

    $imageUrls[] = $imageUrl;
}

What's the best way to return resized insecure product gallery image urls?

3

There's a lot of stuff going on to give you those urls. If you really want to swap it to insecure, the easiest way is probably to run str_replace(Mage::getBaseUrl('media', true), Mage::getBaseUrl('media', false), $imageUrl, 1)

2
  • That's what I've put in place temporarily. Any idea if there would be a configurable way to set a given route/handler to always behave as secure/insecure? – STW Dec 1 '14 at 23:29
  • Don't think so, you're calling Catalog/Image->toString to get the url, you could probably extend the class to add a secure parameter to pass down to the getUrl calls. – Richard Dec 2 '14 at 10:08

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.