Magento Custom Image Attribute from Related Products - image

So from the product view i am getting related products to display. For reasons i wont get into i need to display the image of the related product but it has to be a custom image attribute. So i have created a custom image attribute called colour_swatch and i need to access it and display it on screen. I have done some reading on the issue and have not managed to find a solution to fit my needs.
So here is my code:
<?php foreach($this->getItems() as $_item): ?>
<div class="eachProductRelated">
<a href="<?php echo $_item->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_item->getName()) ?>" class="product-image">
<img src="<?php echo $this->helper('catalog/image')->init($_item, 'colour_swatch') ?>"
width="20px" alt="<?php echo $this->htmlEscape($_item->getName()) ?>"/>
</a>
</div>
<?php endforeach ?>
If we replace colour_swatch with small image that of course will work. I have read that you can't access a custom image attribute if you aren't calling it directly from the product view. And a lot of the solutions i have seen seem to be massively overkill, Surely there is a simpler solution???
Might be worth telling you that i get the following error message:
a:5:{i:0;s:25:"Image file was not found.";i:1;s:4015:"#0
/Users/Frank/Sites/bosideng/app/code/core/Mage/Catalog/Helper/Image.php(163):
Mage_Catalog_Model_Product_Image->setBaseFile(NULL)
Is it possible that i have to do some kind of if no_selected check ?

I have figured out this issue and pardon my French but it was a ridiculous and a stupid oversight by Magento.
When setting up your new custom image attribute you must set 'Use In Product Listing' to yes in the drop down before you select the attribute type 'Media Image' because guess what!? When you select Media Image, Magento hides that option.
Credit to this guy whose post i found after ages of searching: http://thedistance.co.uk/journal/2011-10/missing-magento-media-images

Hello i think you add new image url in custom image attribute then call may be help you
<img src="<?php echo Mage::getModel('catalog/product')->load($product)->getData('colour_swatch'); ?>"

For those of you creating custom image type using installer, add the following to make image visible on both listing and view pages:
$this->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'colour_swatch', array(
'group' => 'Images',
'type' => 'varchar',
'frontend' => 'catalog/product_attribute_frontend_image',
'label' => 'Color Swatch',
'input' => 'media_image',
'class' => '',
'source' => '',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
'visible' => true,
'required' => false,
'default' => '',
'used_in_product_listing' => true,
));

If Flat Catalog Category and Use Flat Catalog Product is set to Yes, then you can add the specific attributes to the collection
Like
$collection = Mage::getResourceModel('catalog/product_collection');
$collection->addAttributeToSelect('*');
$collection->addAttributeToSelect('attributes_name');
This is working perfect for me

Related

how to apply select2 in Yii2 dropdown list

In yii2 basic ActiveForm i have added a drop-down list and in it used the "options" array to add my attributes .i want to add select2 in my drop-down but it is not working .i have searched on web and found this method of "options" array i have used below but still its showing no output in the view
<div class="col-xs-6 col-lg-6">
<div class="form-group form-material floating" data-plugin="formMaterial">
<div class="example"> <b role="presentation"></b>
<?= $form->field($model, 'corporation_status')->dropDownList(Yii::$app->appstatues->status,['options'=>['class'=>'form-control','prompt'=>'abc','data-plugin'=>'select2']])->label('Stat'); ?>
</div>
</div>
</div>
Any help would be much appreciated.
Use extension https://github.com/kartik-v/yii2-widget-select2
many good extensions is there too:
http://demos.krajee.com/
Found the solution for "select2" to be added to your drop-down list do the following steps:
Add following css and js files to your "AppAsset":
https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css
https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js
and in the form field add 'data-plugin'=>'select2' like this:
<?= $form->field($model, 'corporation_status')->dropDownList(Yii::$app->appstatues->status,['prompt' => 'hello','data-plugin'=>'select2','class'=>'form-control'])->label('Status'); ?>
Run this command to install kartik\select2 widget for yii2
php composer.phar require kartik-v/yii2-widget-select2 "#dev"
Then to use the widget.
//Include kartik\select2 Class
use kartik\select2\Select2;
// Normal select with ActiveForm & model
echo $form->field($model, 'corporation_status')->widget(Select2::classname(), [
'data' => Yii::$app->appstatues->status,
'options' => ['prompt' => 'Select a state ...'],
'pluginOptions' => [
'allowClear' => true
],
]);

Joomla 3.5.1 - PHP Notice: Undefined index: doTask

I'm developing a backend component for Joomla and when I access certain views of my component the notice below gets logged. I'm currently running Joomla 3.5.1. Has anyone got the same notice?
PHP Notice: Undefined index: doTask in /var/www/html/layouts/joomla/toolbar/popup.php on line 14
The reason for the notice was that I created a popup button like this:
$layout->render(array('name' => 'print', 'text' => JText::_('BUTTON_PRINT'), 'class' => 'icon-print'));
Adding doTask parameter fixed the problem and the notice is not showing anymore.
$layout->render(array('name' => 'print', 'doTask' => '', 'text' => JText::_('BUTTON_PRINT'), 'class' => 'icon-print'));
I looked at the popup.php file and after that it was pretty easy to figure out the cause. As you can see $doTask variable is used every time when a popup button is rendered.
<button value="<?php echo $doTask; ?>" class="btn btn-small modal" data-toggle="modal" data-target="#modal-<?php echo $name; ?>">

Yii2 how to display images saved in web folder

I have images saved in /web/uploads/PROJECT in Yii2. How do i display them on page? below is my codes but its broken link image.
Controller:
$img = Yii::$app->request->baseUrl.'/web/uploads/PROJECT/';
$image = Html::img($img.$img_obj['AVATAR'],["width"=>"600px"]);
View:
echo $data;
Do i have to set any rights to display it? Right-clicking and opening image in new tab shows the url "/web/uploads/PROJECT/3fioobapJ5vRk_wdCEzDJbQWyO66inWO.jpg" which seems to be correct but page displays "Not Found (#404)"
Can anyone kindly advise? Thanks!
Strangely, using the below codes displays the images correctly.
$img = Url::to('#web/uploads/PROJECT/').$img_obj['AVATAR'];
$image = '<img src="'.$img.'" width="600" />';
<img src="<?= Yii::$app->request->baseUrl . '/backend/web/uploads/' . $model->profile_photo ?>" class=" img-responsive" >
<?php echo Html::img('#web/img/icon.png', ['class' => 'pull-left img-responsive']); ?>
The static images should be placed inside web/any_folder_name
to access in YII 2:
<?= Html::img('#web/any_folder_name/bg1.jpg', ['alt'=>'some', 'class'=>'thing']);?>
Add this code in your Grid View:
[
'attribute'=>'photo',
'value' => Html::a(Html::img(Yii::getAlias('#web').'/image/'.$st_data->photo, ['alt'=>'some', 'class'=>'thing', 'height'=>'100px', 'width'=>'100px']), ['site/zoom']),
'format' => ['raw'],
],

Woocommerce ajax message issue

I've got this working well except for one small problem.
I have a custom archive-product.php page which shows each product with a quantity selector...
<ul class="woo-products">
<?php
$args = array( 'post_type' => 'product', 'posts_per_page' => 100, 'product_cat' => 'hair-extensions' );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
<li class="product">
<a href="<?php echo get_permalink( $loop->post->ID ) ?>" title="<?php echo esc_attr($loop->post->post_title ? $loop->post->post_title : $loop->post->ID); ?>">
<h3><?php the_title(); ?></h3>
<?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog'); else echo '<img src="'.woocommerce_placeholder_img_src().'" alt="Placeholder" width="300px" height="300px" />'; ?>
<?php echo the_excerpt(); ?>
<span class="price"><?php echo $product->get_price_html(); ?></span>
</a>
<?php // woocommerce_template_loop_add_to_cart( $loop->post, $product ); ?>
<?php
add_action('woocommerce_after_shop_loop_item','woocommerce_template_single_add_to_cart');
remove_action('woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
do_action( 'woocommerce_after_shop_loop_item' );
?>
</li>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
</ul>
If I add a product from there, it goes into my cart no problem. But if I then click on the product to visit it's own page, I see a "this product was added to your cart" message.
Likewise if while on the shop page I add several different products they go into my cart, but if I visit one of those product pages I will see "this product was added to your cart" message several times (once for each product I added to my cart).
Here's an image which might help with my description of the problem: http://i.imgur.com/hou3ZRW.png
In my code above if I un-comment out this line...
woocommerce_template_loop_add_to_cart( $loop->post, $product );
...and remove these lines...
add_action('woocommerce_after_shop_loop_item','woocommerce_template_single_add_to_cart');
remove_action('woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
do_action( 'woocommerce_after_shop_loop_item' );
...it works fine except that I don't have the quantity selector option any more.
Any suggestions as to how to stop the "this product was added to your cart" message appearing when I visit a product page after adding it to the cart would be helpful.
This helped me get around the problem, but including the quantity selectors using a different method the problem went away:
http://christianvarga.com/how-to-add-quantity-to-product-archives-in-woocommerce-and-keep-ajax/
There is a function in WooCommerce called wc_clear_notices That does exactly what you need.
It was introduced in WooCommerce 2.1, you can see the very brief documentation here: http://hookr.io/functions/wc_clear_notices/
See Woocommerce cart notice showing multiple times for a way to implement it.

CodeIgniter img tag

I'm using following code to display an image with CodeIgniter framework.
<?php echo img('sample/logo.png'); ?>
And this is producing following output::
<img alt="" src="http://localhost:8080/test/css/sample/logo.png">
Why it does not closes the tag with />
Also, how can i specify the alt text when i echo image?
thanks
According to user guide, it should end with />. I tried it out, and it works.
If you want a shorter tag, use this:
<?php echo img(array('src'=>'image/picture.jpg', 'alt'=> 'alt information')); ?>
Sometimes if you view source using certain browsers (firefox, chrome), it omits the /> tag. Try view source using a notepad or something, it should display proper /> tag.
$image_properties = array(
'src' => 'sample/logo.png',
'alt' => 'Me, demonstrating how to eat 4 slices of pizza at one time',
'class' => 'post_images',
'width' => '200',
'height' => '200',
'title' => 'That was quite a night',
'rel' => 'lightbox',
);
img($image_properties);
// <img src="http://site.com/index.php/sample/logo.png" alt="Me, demonstrating how to eat 4 slices of pizza at one time" class="post_images" width="200" height="200" title="That was quite a night" rel="lightbox" />
reference : http://codeigniter.com/user_guide/helpers/html_helper.html#img
Dont echo an image like that, do it like this:
echo "<img src='sample/logo.png' alt='my company name' title='my company logo' border='0' />";
Remeber the location you have there is relative, you should try to stick to absolute paths were possible eg: "/test/css/sample/logo.png" to avoid confusion.
(sorry, missed the bit where you said you were using a framework).

Resources