I wrote some code for best-seller product in magento but
I m not getting product image url ....
I need small image for the gallery..
I m developing bestseller slider .....the whole thing is good
but only i m not getting image url...
my code
$current_category = Mage::registry('current_category');
$is_category_filter = Mage::getStoreConfig('productslider/product_setting/category_filter');
$collection = Mage::getResourceModel('reports/product_collection')
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
->addOrderedQty()
->addMinimalPrice()
->addTaxPercents()
->addStoreFilter();
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($collection);
if($current_category && $is_category_filter == '1'){
$current_category_id = Mage::registry('current_category')->getId();
$currentCategory = Mage::getModel('catalog/category')->load($current_category_id);
$collection->addCategoryFilter($currentCategory);
}
$collection->setPageSize(30);
$this->setProductCollection($collection);
return $collection;
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(160, 225) ?>" width="160" height="225" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" />
Related
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.
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;?>
I have a category called new arrivals which has 5 subcategories. I created a custom view called new-arrivals.phtml. I created custom Static Block with the following code in magento
{{block type="core/template" template="custom/new-arrivals.phtml"}}
then from Category setting I changed the display setting>CMS Block to the this cms block that I created. And the display mode is static block only
This view bring all the subcategories of New Arrivals(Bags, Tops, Shoes etc..) with it's products.. Like on this website As you can see on this website it is very fast but on my website with my code it is not. Here it is...
How can I make this load faster. Cache and everything is enabled. I assume that there is something wrong with my code. thank you for your help.
and this is new-arrivals.phtml content:
Magento CE 1.8.1
<?php
//I load all the subcategories here
$category = Mage::getSingleton('catalog/layer')->getCurrentCategory();
$categories = $category->getCollection()
->addAttributeToSelect(array('name', 'thumbnail'))
->addAttributeToFilter('is_active', 1)
->addIdFilter($category->getChildren())
?>
<?php foreach ($categories as $category): ?>
<div class="page-title category-title">
<h1>
<a href="<?php echo $category->getUrl() ?>">
<span><?php echo $category->getName() ?></span>
</a>
</h1>
<?php
// here I load all the products for each category
$_helper = $this->helper('catalog/output');
$category = Mage::getModel('catalog/category')->load($category->getId());
$_productCollection = $category->getProductCollection()->addCategoryFilter($category)
->addAttributeToSelect('*') // add all attributes - optional
->addAttributeToFilter('status', 1) // enabled
->addAttributeToFilter('visibility', 4) //visibility in catalog,search
->addAttributeToSort('date_added', 'ASC');
?>
<div class="product-count"><?php echo $count; ?> <?php echo $this->__('Products'); ?></div>
<?php if(!$_productCollection->count()): ?>
<p class="note-msg"><?php echo $this->__('There are no products matching the selection.') ?></p>
<?php else: ?>
<div class="category-products">
<?php // Grid Mode ?>
<?php
$_span = 'span3';
$_grid_pro = 4;
?>
<?php $_collectionSize = $_productCollection->count() ?>
<?php $_columnCount = $_grid_pro; //$this->getColumnCount(); ?>
<?php $i=0; foreach ($_productCollection as $_product): ?>
<?php if ($i++%$_columnCount==0): ?>
<?php // all the others stuff ....... ?>
Load this file using ajax or jquery.
Second one you run your code on footer and make one variable then using jquery or java script, you will show your all data in particular div, for example like this
if (count($_subcategories) > 0){
$top_menu .= '<ul>';
foreach($_subcategories as $_subcategory){
$prodCollection = Mage::getModel('catalog/category')- >load($_subcategory->getId())
->getProductCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('type_id', array('eq' => 'grouped'))
->addAttributeToFilter('no_to_show', array('F' => 78));
if($prodCollection->count() !=0){
$top_menu .= '<li'; if($current_category == $_subcategory->getId()){$top_menu .= ' id="activesub"';}$top_menu .= '>'.$_subcategory->getName().'';
$_subcategories = Mage::getModel('catalog/category')->load($_subcategory->getId());
$_childsub = $_subcategories->getChildrenCategories();
$CatTotalCount = count($_childsub);
if($cntr == 0){
$firstCount = $CatTotalCount;
}
if($firstCount >= 7){
$loopCount = ($firstCount-1);
}else{
$loopCount = 6;
}
if($CatTotalCount >0){
$top_menu .= '<ul>';
$secCntr = 0;
foreach($_childsub as $_child_subcat){
$prodCollection2 = Mage::getModel('catalog/category')->load($_child_subcat->getId())->getProductCollection()->addAttributeToSelect('*')->addAttributeToFilter('type_id', array('eq' => 'grouped'))->addAttributeToFilter('no_to_show', array('F' => 78));
if( $secCntr>$loopCount){
$secCntr = 0;
$top_menu .= '</ul><ul>';
}
$secCntr++;
if($prodCollection2->count() !=0):
$top_menu .= '<li'; if($current_category == $_child_subcat->getId()){$top_menu .= ' id="activesub"';}$top_menu .= '>'.$_child_subcat->getName().'</li>';
endif;
} }
}
$top_menu .= '</ul></li>';
$cntr++;
}
$top_menu .= '</ul>';
}
jQuery(document).ready(function() {
document.getElementById('top_menus').innerHTML = '';
jQuery('#mega-menu-8').dcMegaMenu({
rowItems: '3',
speed: 'fast',
effect: 'fade'
});
});
How can i show new products from a specific category in magento and just show its image,Name , and description? And is it possible to add it on the newsletter?
Use this code below. Set your news_from_date and news_to_date dates and the CategoryId
It've created it just now and tested it with a prepared product:
$collection = Mage::getModel('catalog/product')
->getCollection()
->addCategoryFilter(Mage::getModel('catalog/category')->load(3))
->addAttributeToSelect(array('name', 'sku', 'description', 'small_image', 'news_from_date', 'news_to_date', 'category_id'))
->addAttributeToFilter('news_from_date',array('date' => true, 'gteq' => '2013-05-03'))
->addAttributeToFilter('news_to_date', array('date' => true, 'lteq' => '2013-11-25') )
;
foreach ($collection as $product)
{
var_dump( $product->getName() );
var_dump( $product->getDescription() );
var_dump( $product->getNewsFromDate() );
var_dump( $product->getNewsToDate() );
}
<?php
$categoryid = 12;
$category = new Mage_Catalog_Model_Category();
$category->load($categoryid);
$collection = $category->getProductCollection();
$collection->addAttributeToSelect('*');
foreach ($collection as $_product) { ?>
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(200); ?>" width="200" height="200" alt="" /> <?php echo $_product->getName(); ?>
enter code here
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; ?>