I wonder what's wrong with my codes that the image does not show up as it suppose to. Nothing appears. Just blank. I expect an image would appears.
views/editgalleries.php
<?php foreach ($pictures as $pictures_item): ?>
<td><br><img src="<?php echo base_url('../uploads/'); ?><?php echo $pictures_item['galleries_picture_name']; ?>" height="300" width="200"></td>
<?php endforeach; ?>
Cpages.php
public function edit_galleries_picture()
{
$gallery_id = $this->uri->segment(3);
$data['pictures'] = $this->Mpages->call_gallery_pictures($gallery_id);
$this->load->view('editgalleries', $data);
}
models/Mpages.php
public function call_gallery_pictures($gallery_id)
{
$this->db->where('gallery_id', $gallery_id);
$query = $this->db->get('galleries_pictures');
return $query->result_array();
}
set uploads folder in root directory and try this code
<?php echo base_url('uploads/'.$pictures_item['galleries_picture_name']); ?>
<img src="<?php echo base_url('uploads'); ?>/<?php echo $pictures_item['galleries_picture_name']; ?>" height="300" width="200">
Note that for the 'base_url('../uploads/')',
the '../' part is not required because it's give your host name.
Related
Actually I am working on front-end, but I cannot reach the backend developer and I need to fix a bug.
The problem is exactly this, if there is no image in a content, we get an error like this:
A PHP Error was encountered
A
Severity: Notice
Message: Undefined property: stdClass:$Pictures
Filename:agent/hotel_detail.php
Line Number: 17
Backtrace:
File:/home/tungatour/public_html/application/views/agent/hotel_detail.php
Line: 17
Function: _error_handler
File:/home/tungatour/public_html/application/controllers/Agent.php
Line: 490
Function: view
File:/home/tungatour/public_htm/index.php
I just want to show demo image instead if there is no image. But i dont have any idea how can i do this ?
so i have controller codes about picture this this.
public function post($ID)
{
$viewData["title"] = "Post Details";
$data = $this->db->where("ID", $ID)->get("post")->row();
$data->Meta = json_decode($data->Meta);
$picture = $this->db->where("ID", $data->Meta->Thumbnail)->get("picture")->row();
$viewData["data"] = $data;
$viewData["picture"] = $picture;
$this->load->view('partials/agent/head', $viewData);
$this->load->view('agent/post', $viewData);
$this->load->view('partials/agent/foot', $viewData);
}
also i have this lines` <?php $first = true;
for ($i = 0; $i < $this->db->where_in("ID", $data->Meta->Pictures)->count_all_results("picture"); $i++) { ?>
<li data-target="#carousel-example-generic" data-slide-to="<?= $i ?>" class="<?= $first ? "active" : "" ?>"></li>
<?php $first = false;
} ?>
</ol>
<div class="carousel-inner" role="listbox">
<?php $first = true;
foreach ($this->db->where_in("ID", $data->Meta->Pictures)->get("picture")->result() as $picture) { ?>
<div class="carousel-item <?= $first ? "active" : "" ?>">
<img class="img-fluid" src="<?= $picture->URL ?>" style="height: 420px;width: 100%;object-fit: cover;" />
</div>
<?php $first = false;
} ?>
</div>`
Change this line
<img class="img-fluid" src="<?= $picture->URL ?>" style="height: 420px;width: 100%;object-fit: cover;" />
Update with
<?php if($picture->URL) { ?>
<img class="img-fluid" src="<?= $picture->URL ?>" style="height: 420px;width: 100%;object-fit: cover;" />
<?php } ?>
If the image has a URL, it will display the image. Otherwise it will be empty.
In product view page page, images are serving from this path : link1
media/catalog/product/cache/1/image/350x350/9df78eab33525d08d6e5fb8d27136e95/c/h/image-name.jpg :
but I want to serve from this path : link2
`media/cache/images/1/thumbnail/602f0fa2c1f0d1ba5e241f914e856ff9/catalog/product/c/image-name.jpg` :
media.phtml
<?php
$_product = $this->getProduct();
$_helper = $this->helper('catalog/output');
$dexxtz = Mage::helper('productzoom');
$dexxtz->getCss();
$dexxtz->getJs();
?>
<ul id="etalage">
<li>
<img class="etalage_thumb_image" src="<?php echo $dexxtz->getImageFeatured($this->helper('catalog/image')->init($_product, 'image')); ?>" />
<img class="etalage_source_image" title="<?php echo $_product->getImageLabel(); ?>" src="<?php echo $dexxtz->getImageFeatured($this->helper('catalog/image')->init($_product, 'image'), true); ?>" />
</li>
<?php
foreach ($this->getGalleryImages() as $_image) {
if(Mage::registry('current_product')->getImage() != $_image->getFile()) { ?>
<li>
<img class="etalage_thumb_image" src="<?php echo $dexxtz->getImageFeatured($this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile())); ?>" />
<img class="etalage_source_image" title="<?php echo $_image->getLabel(); ?>" src="<?php echo $dexxtz->getImageFeatured($this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile()), true); ?>" />
</li>
<?php
}
}
?>
</ul>
You need first to copy app/code/core/Mage/Catalog/Model/Product/Image.php to app/code/local/Mage/Catalog/Model/Product/Image.php.
Then take a look to the file you just copied, l.313-319 :
// build new filename (most important params)
$path = array(
Mage::getSingleton('catalog/product_media_config')->getBaseMediaPath(),
'cache',
Mage::app()->getStore()->getId(),
$path[] = $this->getDestinationSubdir()
);
This "$path" array will build your catalog image path. Change it to whatever you like. In your case :
// build new filename (most important params)
$path = array(
Mage::getBaseDir('media'),
'cache/images',
Mage::app()->getStore()->getId(),
$path[] = $this->getDestinationSubdir()
);
Dont forget to modify clear cache path too, l.686 :
public function clearCache()
{
$directory = Mage::getBaseDir('media') . DS.'catalog'.DS.'product'.DS.'cache'.DS;
... to ...
public function clearCache()
{
$directory = Mage::getBaseDir('media') . DS.'cache'.DS.'images'.DS;
Next, go to your media.phtml file. Change :
<?php echo $dexxtz->getImageFeatured($this->helper('catalog/image')->init($_product, 'image')); ?>
...
<?php echo $dexxtz->getImageFeatured($this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile())); ?>
... to ...
<?php echo $dexxtz->getImageFeatured($this->helper('catalog/image')->init($_product, 'thumbnail')); ?>
...
<?php echo $dexxtz->getImageFeatured($this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())); ?>
I am using opencart version 2.0.2.0 and now i am trying to get image or image url in manufacturer page.
I have added the code in catalog/controller/product/manufacturer.php
$manufacturer_image = $this->model_catalog_manufacturer->getManufacturer($manufacturer_id);
if($manufacturer_image){
$this->data['manufacturers_img'] = $this->model_tool_image->resize($manufacturer_image['image'], 120, 120);
}else{
$this->data['manufacturers_img'] = false;
}
and call it in catalog/view/theme/default/template/product/manufacturer_list.tpl
<div class="row">
<?php foreach ($manufacturers as $manufacturer) { ?>
<div class="col-sm-3"><?php echo $manufacturer['name']; ?>
<?php echo ($manufacturers_img) ? '<img src="'.$manufacturers_img.'" alt="'.$manufacturers.'" />' : $manufacturers ;?><br />
</div>
<?php } ?>
</div>
But it's getting error in my /index.php?route=product/manufacturer page
Notice: Undefined variable: manufacturers_img in
/data1/opencart-2.0.2.0/catalog/view/theme/default/template/product/manufacturer_list.tpl
on line 32Array
lets be clear ControllerProductManufacturer index() shows list and info() shows detail of the mfg,
//catalog/controller/product/manufacturer.php:46
Replace
$data['categories'][$key]['manufacturer'][] = array(
with
$manufacturer_image = $this->model_catalog_manufacturer->getManufacturer($result['manufacturer_id']);
if($manufacturer_image){
$mfg_img = $this->model_tool_image->resize($manufacturer_image['image'], 120, 120);
}else{
$mfg_img = false;
}
$data['categories'][$key]['manufacturer'][] = array(
'image'=>$mfg_img,
And in catalog/view/theme/default/template/product/manufacturer_list.tpl:30
inside loop
<?php if($manufacturer['image']):?>
<img src="<?php echo $manufacturer['image']; ?>" alt="<?php echo $manufacturer['name'];?>">
<?php endif;?>
For some reason, only on view-mode icons on the product list, the "?" of the urls are replaced to "#21". Ex.: "#%21mode=list"
Somebody can help me?
Some code:
app/design/frontend/default/themename/template/catalog/product/list/toolbar.phtml
<?php if( $this->isEnabledViewSwitcher() ): ?>
<p class="view-mode">
<?php $_modes = $this->getModes(); ?>
<?php if($_modes && count($_modes)>1): ?>
<label><?php echo $this->__('View as') ?>:</label>
<?php foreach ($this->getModes() as $_code=>$_label): ?>
<?php if($this->isModeActive($_code)): ?>
<strong title="<?php echo $_label ?>" class="<?php echo strtolower($_code); ?>"><?php echo $_label ?></strong>
<?php else: ?>
<?php echo $_label ?>
<?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>
</p>
<?php endif; ?>
app/code//core/Mage/Catalog/Block/Product/List/Toolbar.php
public function getModeUrl($mode)
{
return $this->getPagerUrl( array($this->getModeVarName()=>$mode, $this->getPageVarName() => null) );
}
and...
public function getPagerUrl($params=array())
{
$urlParams = array();
$urlParams['_current'] = true;
$urlParams['_escape'] = true; // I already tried set false, but didn't helps
$urlParams['_use_rewrite'] = true;
$urlParams['_query'] = $params;
return $this->getUrl('*/*/*', $urlParams); // I also tried not use the getUrl and concat the querystring, strangely the replace still happends...
}
I couldn't find the problem, but I make a dirt solution:
<?php echo str_replace('#%21', '&', $this->getModeUrl($_code)); ?>
I wish somebody find a better solution :)
How can I grab the image gallery into the category page in Magento, for a loaded product?
this->getImageGallery($_product)
, won't work..
$product = Mage::getModel('catalog/product')->load($_product->getId());
foreach ($product->getMediaGalleryImages() as $image) {
echo var_export($image->getUrl());
}
If I add the images to a product programmatically then $product->getMediaGalleryImages() has zero images... however
$mediaApi = Mage::getModel('catalog/product_attribute_media_api');
$mediaItems = $mediaApi->items($product->getId());
foreach ($mediaItems as $image) {
error_log('found url: '.$image['file']);
}
works fine
Here's another method which doesn't require loading the entire product object.
<?php $media_gallery = $_product->getMediaGallery(); ?>
<?php foreach ($media_gallery['images'] as $_image):?>
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'image', $_image['file'])->resize(135); ?>" alt="<?php echo $this->escapeHtml($_image['label']) ?>" />
<?php endforeach; ?>