Page 1 of 2

Display model number in related products

Posted: Sat Dec 10, 2011 6:54 pm
by waps
Hi Guys

How do I show the model number next to each product shown in the related products div in the product.tpl.

I tried $product['model'] but it doesnt work ?

Re: Display model number in related products

Posted: Sat Dec 10, 2011 8:37 pm
by waps
not to worry guys,

managed to get it working

Re: Display model number in related products

Posted: Thu Dec 15, 2011 12:16 pm
by Brook
How did you display Product Model next to Product Name when selecting Related Products? I have multiple Products with the same Product Name. Product Model uniquely identifies my Products.

Any suggestions?

Re: Display model number in related products

Posted: Thu Dec 15, 2011 12:34 pm
by straightlight
For v1.5.x:

In catalog/controller/product/product.php file,

find:

Code: Select all

'reviews'    => sprintf($this->language->get('text_reviews'), (int)$result['reviews']),
add after:

Code: Select all

'model'		 => $result['model'],
Then, in view/theme/default/template/product/product.tpl file,

find:

Code: Select all

<div class="image"><a href="<?php echo $product['href']; ?>"><img src="<?php echo $product['thumb']; ?>" alt="<?php echo $product['name']; ?>" /></a></div>
        <?php } ?>
        <div class="name"><a href="<?php echo $product['href']; ?>"><?php echo $product['name']; ?></a></div>
replace with:

Code: Select all

 <div class="image"><a href="<?php echo $product['href']; ?>"><img src="<?php echo $product['thumb']; ?>" alt="<?php echo $product['name']; ?> (<?php echo $product['model']; ?>)" title="<?php echo $product['name']; ?> (<?php echo $product['model']; ?>)"/></a></div>
        <?php } ?>
        <div class="name"><a href="<?php echo $product['href']; ?>"><?php echo $product['name']; ?></a> (<?php echo $product['model']; ?>)</div>

Re: Display model number in related products

Posted: Thu Dec 15, 2011 10:16 pm
by Brook
I have OpenCart 1.5.1.3 installed. How do I display Product Model next to Product Name in Related Products?

Re: Display model number in related products

Posted: Fri Dec 16, 2011 12:15 am
by straightlight
The above instructions are for v1.5.1.3 and does work as described.

Re: Display model number in related products

Posted: Fri Dec 16, 2011 12:50 am
by Brook
Thank you. I wasn't sure if this was for 1.4.9.6 or 1.5.1.3 I will try this out.

Re: Display model number in related products

Posted: Fri Dec 16, 2011 12:58 am
by straightlight
Right. I have now modified the instructions above stating these modifications are for v1.5.1.3 release.

Re: Display model number in related products

Posted: Sun Dec 18, 2011 12:35 am
by Brook
How do I display the Product SKU next to the Product Name in the "Admin" when selecting Related Products? (OpenCart version 1.5.1.3)

Re: Display model number in related products

Posted: Sun Dec 18, 2011 12:43 am
by straightlight
In admin/controller/catalog/product.php file,

find:

Code: Select all

'name'       => $related_info['name']
add above:

Code: Select all

'model'       => $related_info['model'],
In admin/view/template/catalog/product_form.tpl file,

find:

Code: Select all

<div id="product-related<?php echo $product_related['product_id']; ?>" class="<?php echo $class; ?>"> <?php echo $product_related['name']; ?><img src="view/image/delete.png" />
replace with:

Code: Select all

<div id="product-related<?php echo $product_related['product_id']; ?>" class="<?php echo $class; ?>"> <?php echo $product_related['name']; ?> (<?php echo $product_related['model']; ?>)<img src="view/image/delete.png" />
This should work as expected.

Re: Display model number in related products

Posted: Sun Dec 18, 2011 12:48 am
by Brook
Thank you. I will give it a try.

Re: Display model number in related products

Posted: Sun Dec 18, 2011 1:33 am
by Brook
Works great! When using the AutoComplete feature when selecting a Product to add to the Related Products currently only the Product Name is displayed when I begin typing. How do I display Product Model next to the Product Name when I begin typing?

Re: Display model number in related products

Posted: Sun Dec 18, 2011 1:41 am
by straightlight
Untested so make a backup of admin/view/template/catalog/product_form.tpl file,

in this section:

Code: Select all

$('input[name=\'related\']').autocomplete({
find:

Code: Select all

label: item.name,
replace with:

Code: Select all

label: item.name + '(' + item.model + ')',
This could probably work.

Re: Display model number in related products

Posted: Sun Dec 18, 2011 2:20 am
by Brook
Thank you again for you help. Good news! Your Product Model code works

Code: Select all

label: item.name + '(' + item.model + ')',
If I want to display Product SKU next to Product Name when typing in the AutoComplete Related Products box what code should I use? I tried the following code

Code: Select all

label: item.name + '(' + item.sku + ')',
But this did not work, when I typed in the Product Name using the AutoComplete Feature, the Product Name would display, but the Product SKU would not display next to the Product Name, instead it would display as "Product Name (undefined)" instead of "Product Name (SKU)".

Any ideas?

Re: Display model number in related products

Posted: Sun Dec 18, 2011 2:24 am
by straightlight
Inclusively, yes.

However, you'd also need to state the following from admin/controller/catalog/product.php file

where:

Code: Select all

'name'       => html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8'),
'model'      => $result['model'],
to add below:

Code: Select all

'sku'      => $result['sku'],

Re: Display model number in related products

Posted: Sun Dec 18, 2011 2:31 am
by Brook
You are the man! Thank you. Thank you. Works great! This is a big deal to the way my cart works since my Products are uniquely idenitified by Product SKU.

Re: Display model number in related products

Posted: Sun Dec 18, 2011 2:35 am
by straightlight
You're making the right choice by displaying the products by SKU politically. Most eCommerce manufacturers does not provide this solution while this should be included at least as an option. :)

Re: Display model number in related products

Posted: Fri Mar 30, 2012 10:16 am
by mirza
it's good...
but i have a lot of same names products.(~500)
how can i search by product model_?
thanks for your replies..

Re: Display model number in related products

Posted: Fri Mar 30, 2012 10:23 am
by straightlight
Simply follow all my instructions above but in your case from this post:

http://forum.opencart.com/viewtopic.php ... 63#p231290

replace the last step

from:

Code: Select all

<div id="product-related<?php echo $product_related['product_id']; ?>" class="<?php echo $class; ?>"> <?php echo $product_related['name']; ?> (<?php echo $product_related['model']; ?>)<img src="view/image/delete.png" />
to read:

Code: Select all

<div id="product-related<?php echo $product_related['product_id']; ?>" class="<?php echo $class; ?>"> <?php echo $product_related['model']; ?><img src="view/image/delete.png" />
exceptionally. This should work as expected. If you need to search by models, I would strongly recommend the use of the SKU inclusively.

Re: Display model number in related products

Posted: Sat Mar 09, 2013 3:20 am
by richdtt
It's a nice feature to show the sku/model while you're doing a search by name in the add related products.

How would you modify it so it autocompletes based on name OR sku instead?