Skip to content

Commit 60afa15

Browse files
committed
handle secure and unsecure media url
1 parent d5a287b commit 60afa15

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

code/Helper/Entity/Producthelper.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -586,8 +586,6 @@ public function getObject(Mage_Catalog_Model_Product $product)
586586
try
587587
{
588588
$customData['thumbnail_url'] = $thumb->toString();
589-
$customData['thumbnail_url'] = str_replace(array('https://', 'http://'
590-
), '//', $customData['thumbnail_url']);
591589
}
592590
catch (\Exception $e)
593591
{
@@ -605,7 +603,6 @@ public function getObject(Mage_Catalog_Model_Product $product)
605603
try
606604
{
607605
$customData['image_url'] = $image->toString();
608-
$customData['image_url'] = str_replace(array('https://', 'http://'), '//', $customData['image_url']);
609606
}
610607
catch (\Exception $e)
611608
{
@@ -622,7 +619,9 @@ public function getObject(Mage_Catalog_Model_Product $product)
622619
$customData['media_gallery'] = array();
623620

624621
foreach ($product->getMediaGalleryImages() as $image)
622+
{
625623
$customData['media_gallery'][] = str_replace(array('https://', 'http://'), '//', $image->getUrl());
624+
}
626625
}
627626
}
628627

code/Helper/Image.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function toString()
1515
$model->setBaseFile($this->getProduct()->getData($model->getDestinationSubdir()));
1616

1717
if ($model->isCached())
18-
return $model->getUrl();
18+
return $this->getUrl($model);
1919

2020
if ($this->_scheduleRotate)
2121
$model->rotate($this->getAngle());
@@ -26,6 +26,15 @@ public function toString()
2626
if ($this->getWatermark())
2727
$model->setWatermark($this->getWatermark());
2828

29-
return $model->saveFile()->getUrl();
29+
return $this->getUrl($model->saveFile());
30+
}
31+
32+
public function getUrl($model)
33+
{
34+
$baseDir = Mage::getBaseDir('media');
35+
$path = str_replace($baseDir . DS, "", $model->getNewFile());
36+
$url = str_replace(DS, '/', $path);
37+
38+
return $url;
3039
}
3140
}

design/frontend/template/topsearch.phtml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ $group_id = Mage::getSingleton('customer/session')->getCustomer()->getGroupId();
1313
$currency_code = Mage::app()->getStore()->getCurrentCurrencyCode();
1414
$price_key = $config->isCustomerGroupsEnabled(Mage::app()->getStore()->getStoreId()) ? '.'.$currency_code.'.group_'.$group_id : '.'.$currency_code.'.default';
1515

16+
$image_base_url = Mage::getBaseUrl('media');
17+
1618
$title = '';
1719
$description = '';
1820
$content = '';
@@ -77,7 +79,7 @@ $placeholder = $this->__('Search for products, categories, ...');
7779
<script type="text/template" id="autocomplete_products_template">
7880
<a class="algoliasearch-autocomplete-hit" href="{{url}}">
7981
{{#thumbnail_url}}
80-
<div class="thumb"><img src="{{thumbnail_url}}" /></div>
82+
<div class="thumb"><img src="<?php echo $image_base_url; ?>{{thumbnail_url}}" /></div>
8183
{{/thumbnail_url}}
8284

8385
<div class="info">
@@ -117,7 +119,7 @@ $placeholder = $this->__('Search for products, categories, ...');
117119
<a class="algoliasearch-autocomplete-hit" href="{{url}}">
118120
{{#image_url}}
119121
<div class="thumb">
120-
<img src="{{image_url}}" />
122+
<img src="<?php echo $image_base_url; ?>{{image_url}}" />
121123
</div>
122124
{{/image_url}}
123125

@@ -291,7 +293,7 @@ $placeholder = $this->__('Search for products, categories, ...');
291293
<a href="{{url}}" class="result">
292294
<div class="result-content">
293295
<div class="result-thumbnail">
294-
{{#image_url}}<img src="{{{ image_url }}}" />{{/image_url}}
296+
{{#image_url}}<img src="<?php echo $image_base_url; ?>{{{ image_url }}}" />{{/image_url}}
295297
{{^image_url}}<span class="no-image"></span>{{/image_url}}
296298
</div>
297299
<div class="result-sub-content">

0 commit comments

Comments
 (0)