How can I explicitly get product image URLs which use the insecure media URL as their base?
-
12-12-2019 - |
Question
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?
Solution
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)
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange