I have a problem where I can't get my custom attribute called upsell to get shown as my upsell image.
Attribute information
Attribute code: upsell
Scope: Store View
Catalog Input type for store owner: Media Image
Apply To: All product Types
I have created the thumbnail in the skin/frontend/.../images/catalog/product/placeholder/
Here's the code to show the image
<img src="<?php echo $this->helper('catalog/image')->init($_item, 'upsell')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(150); ?>" alt="<?php echo $this->htmlEscape($_item->getName()) ?>" />
If I change the ($_item, 'upsell') to ($_item, 'thumbnail') it's showing the right thumbnail.
Did I miss something in the process of creating the attribute?
ayTo call an image you can use:
$this->helper('catalog/image')->init($_product, 'product_details_image')->resize()
and the full script is:
<?php
$_detailsImg = $this->helper('catalog/image')->init($_product,'product_details_image')->resize();
if ($_detailsImg != 'no_selection'):
$_detailsImg ='<img src="'.$this->helper('catalog/image')->init($_product, 'product_details_image')->resize().'" alt="'.$this->htmlEscape($this->getImageLabel()).' "/>';
echo $_helper->productAttribute($_product, $_detailsImg , 'product_details_image');
endif;
?>
Please change product_details_image to your attribute image code.
In case you don’t have image assigned to the product you will get this error : Image file was not found. in (var/ reports)
so to fix this create an image with same name as the attribute code (product_details_image.jpg) to act as placeholder and add it to:
skin/frontend/base/default/images/catalog/product/placeholder/
Also you can add it to your skin folder. that is it.
EDIT:
I would rewrite the upsell.phtml again, get all ids add it to an array call product collections, filter by ids and you are ready to call any attribute including the media image - and I can confirm this works for me
EDIT:
This is may sound stupid but I can't find any other way, I had to load the collection for each product I hope some one can find other way.
I did try to call one collection and filter it using products IDs ( up sell products IDs ) but it didn't work.
<?php if(count($this->getItemCollection()->getItems())):
$items = $this->getItemCollection()->getItems();
?>
<div class="box-up-sell">
<ul class="products-grid up-sell-grid">
<?php foreach ($items as $item): ?>
<li class="item">
<?php $product = Mage::getModel('catalog/product')->load($item->getId()); ?>
<span><?php echo $product->getName(); ?></span>
<img src="<?php echo Mage::helper('catalog/image')->init($product, 'measurements_guide_image')->resize(200, 200); ?>" alt="">
</li>
<?php endforeach ?>
</ul>
</div>
<?php endif ?>
You need to add this media attribute to product flat setting:
<frontend>
<product>
<collection>
<attributes>
<upsell/>
</attributes>
</collection>
</product>
</frontend>
At this code at my module config.xml and then you need to reindex from index management.
Related
I want to display dynamic post categories with images in a grid layout in a custom template.
I am using Category Images plugin to assign an image to categories.
<ul>
<?php foreach (get_categories() as $cat) : ?>
<li>
<img src="<?php echo z_taxonomy_image_url($cat->term_id); ?>" />
<?php echo $cat->cat_name; ?>
</li>
<?php endforeach; ?>
</ul>
you can get the image like this and then put it in the html of your need, see i am not a html developer so have no idea, i gave you how you can get the image and name now put the structure as you need
I am trying to build a simple gallery with WordPress Advanced Custom Fields and the repeater field plugin. I need to display a thumbnail image which you click to enlarge the main image (I am using Fancybox). Does anyone know whether it is possible to get the link to the image thumbnail WordPress automatically generates?
I can get the main image link:
/wp-content/uploads/2014/12/slide1.jpg
But need to get this image link:
/wp-content/uploads/2014/12/slide1-150x150.jpg
Here is my code:
<?php if(get_field('gallery')): ?>
<ul>
<?php while(has_sub_field('gallery')): ?>
<a class="fancybox" href="<?php the_sub_field('image'); ?>" data-fancybox-group="gallery" title="Lorem ipsum dolor sit amet"><img src="<?php the_sub_field('image'); ?>" alt="" width="200px;" height="auto"/></a>
<?php endwhile; ?>
<?php while(has_sub_field('video_link')): ?>
<a class="fancybox-media" href="<?php the_sub_field('video_link_snippet'); ?>"><img src="<?php the_sub_field('video_image'); ?>"/></a>
<?php endwhile; ?>
</ul>
<?php endif; ?>
You can absolutely do this with Advanced Custom Fields and Wordpress. To do so, go into the custom fields and change the sub field 'image' so that it returns the Image Object instead of the Image URL. See 'return value' here.
Once this field returns the object, try var_dumping the field to see your URL options:
var_dump(the_sub_field('image'));
This should show you the different thumbnail sizes enabled in your system and allow you to easily get the thumbnail you'd like. One possible example:
// Get image object with all sizes...
$image = the_sub_field('image');
$size = 'thumbnail';
// Get URL from sizes based on our $size var
$url = $image['sizes'][$size];
// Now we have the thumbnail URL
echo $url;
Let me know if you run into problems! For more documentation and many more options, try the Advanced Custom Fields documentation for the Image field.
I've got an image carousel in a site. I want to display the image alt tag or title below the image when I do mover over. At the same time I want to display that same name in another h1 tag.
The code is in PHP and Magento implementation. I know it is a simple trick. But I tried all the codes using jQuery after, append and replacewith functions. These functions are working. But I couldn't display the alt or title name.
Php Code:
<ul id="mycarousel" class="jcarousel-skin-tango alt">
<?php
// products
if(!isset($CatID))
$CatID = 10; // Set to classic collection if empty;
$_category = Mage::getModel('catalog/category')->load($CatID);
$products = Mage::getModel('catalog/product')->getCollection()
->addAttributeToFilter('status', 1)//enabled
->addCategoryFilter($_category);
foreach($products as $index=>$prod):
$product = Mage::getModel('catalog/product')->load($prod->getId());
echo '<li style="border: none;">
<a class="thumbActImg1" href="'.$product->getProductUrl().'" data-rel="'.(string)Mage::helper('catalog/image')->init($product, 'small_image')->keepFrame(FALSE)->resize($_resize, $_resize).'" alt="'. $product->getName() .'">
<div class="thumbActImg2">
<img src="'.$product->getThumbnailUrl(80, 80).'" alt="'. $product->getName() .'" />
</div>
</a>
</li>';
endforeach;
?>
</ul>
jQuery code:
jQuery(this,'img.thumbActImg2').after('<div class="pname"><?php echo $product->getName()?></div>');
jQuery('#pro_name h1').replaceWith('<h1><?php echo $product->getName()?></h1>');
Right now, I used php echo in order to display name. But it displaying the current page product name instead of mover over image name.
Could anyone help me out please.
Hi,
the PHP-Code is evaluated once, when the site is generated. So the <h1><?php echo $product->getName()?></h1> is always the same text.
You have to rewrite/get the current information from the image, when it's cycled (if I understand you). So here is what may work for you:
//insert the code, where the carousel is triggered
//get the alt attribute from image and replace h1 content
jQuery('#pro_name h1').html(jQuery('img.thumbActImg2').attr('alt'));
I hope this is what you're looking for, the problem isn't descripted very briefly.
Greetings Mat
I am trying to show image thumbnail of products in order view page (sales_order/view) area of Magento. Adding preview image of the product as a column.
I have my line as the below:
load($_item->getProductId()); ?>init($_product, 'thumbnail')->resize(75, 75); ?>"
alt="<?php echo $this->htmlEscape($_product['name']); ?>" border="0" width="75" />
But this just pulls through a blank box with no image at all in it, not even the Magento default image.
It will likely just be name of field or attribute slightly off? Or maybe even casing? But can't really see what I'm doing wrong.
If I replace:
load($_item->getProductId());
with:
load($_item['product_id'])->getData('image')
I can pull in the location of the image which shows on the page. But can't get it to work to actually display the image.
Can pull thumbnail of product in fine on the product grid page, but can't locate page to replicate code from.
Any help to polish off above would be appreciated.
Final code was the below. To get this working add it to /app/design/adminhtml/default/default/template/sales/order/view/items/renderer/default.phtml
<td class="a-center">
<?php $product = Mage::getModel('catalog/product')->setStoreId($_item->getOrder()->getStoreId())->load($_item->getProductId());?>
<p align="center">
<img src="<?php echo Mage::helper('catalog/image')->init($product, 'small_image')->resize(75); ?>" width="75" height="75" />
</p>
</td>
You can show ordered item image with below code
$order = Mage::getModel('sales/order')->load($orderId);
foreach($order->getAllItems() as $item){
$product=Mage::getModel('catalog/product')->load($item->getProductId());
echo Mage::helper('catalog/image')->init($product, 'small_image')->resize(50,50);
}
this can be helpful for you i think you just need to place your attribute value
http://magentocodes.blogspot.in/2013/01/get-custom-attribute-value-in-magento.html
hy,
i'm trying to add a link to the new order email that the customer is getting when he is placeing a new order in magento (my version 1.6.2.0 )
i have edited /public_html/app/design/frontend/base/default/template/email/order/items/order/default.phtml
with the following:
<?php $_item = $this->getItem() ?>
<?php $_order = $this->getItem()->getOrder() ?>
----
<!-- Start of edit file -->
<a href="<?php echo $this->getProductUrl($_item) ?>">
<?php echo $this->htmlEscape($this->getSku($_item)) ?></a>
When i receive the confirmation email in the sku column the color changes form black ( default css ) to light blue link like, but it does not have any link property as shown below:
email_photo
I have also tried :
<a href="<?php echo $this->getUrlPath($_item) ?>">
<?php echo $this->htmlEscape($this->getSku($_item)) ?></a>
and i end up with the same thing.
Can anyone tell me what i'm doing wrong ?
Thanks.
In line
<a href="<?php echo $this->getUrlPath($_item) ?>">
$this is an instance of block *Mage_Sales_Block_Order_Email_Items_Order_Default*. It does not have a function getUrlPath() or getProductUrl.
You should use your $_item variable to get a product object and then it to get its URL
$_item->getProduct()->getProductUrl()
I earlier tried this code:
<?php echo $this->htmlEscape($this->getSku($_item)) ?>
Magento 2
To link a product name with its product page in your order emails, edit following files:
Magento_Sales/templates/email/items/order/default.phtml
Magento_Sales/templates/email/items/invoice/default.phtml
Magento_Sales/templates/email/items/shipment/default.phtml
To get the product URL, use the following snippet of code and insert it into a href attribute of the link.
<?= $_item->getProduct()->getProductUrl(); ?>
For example,
<p class="product-name"> <?= $block->escapeHtml($_item->getName()); ?> </p>
The result of the snippet of code will be a clickable product name in Magento Emails.
Tutorial from: https://themes.email/magento/product-links-in-magento-order-emails.html