Page 1 of 1

[Solved] Short description in modules

Posted: Sun Nov 13, 2011 4:57 am
by vimal
Hi

I want to display short description for products in the modules like featured, bestseller etc. How can I add it? I tried to fiddle around with the controller and tpl files but got a lot of undefined errors. I also tried to compare it with the category page to see if I could get some clues but couldn't solve it. I am not really a php programmer and my knowledge in that is really limited.

Could someone please help me? I am using OC1.5.1.3

Thanks!
Vimal.

Re: Short description in modules

Posted: Sun Nov 13, 2011 7:19 am
by wernerrenrew
Hi,

Open catalog/controler/module/special.php
on line 50 you will see an array replace it with this

Code: Select all

$this->data['products'][] = array(
				'product_id' => $result['product_id'],
				'thumb'   	 => $image,
				'name'    	 => $result['name'],
                                'description'    => $result['description'],
				'price'   	 => $price,
				'special' 	 => $special,
				'rating'     => $rating,
				'reviews'    => sprintf($this->language->get('text_reviews'), (int)$result['reviews']),
				'href'    	 => $this->url->link('product/product', 'product_id=' . $result['product_id']),
			);
now open catalog/view/theme/your-theme/template/module/special.tpl
look for this

Code: Select all

<span class="price-old"><?php echo $product['price']; ?></span> <span class="price-new"><?php echo $product['special']; ?></span>
          <?php } ?>
        </div>
right after this you put this

Code: Select all

<div><?php echo "<p>".mb_substr(strip_tags(html_entity_decode($product['description'])), 0, 150)."...</p>"; ?></div>
BTW if you follow the demo link below i made a live example you will also see my free random specials module in action.

Did this solve your problem add [SOLVED] to the title of this topic.

Regards Werner

Re: Short description in modules

Posted: Mon Nov 14, 2011 1:38 am
by vimal
Hi.
I got an error message saying as below.

Code: Select all

Notice: Undefined variable: result in C:\xampp\htdocs\oc1511\catalog\controller\module\featured.php on line 50Notice: Undefined variable: result in C:\xampp\htdocs\oc1511\catalog\controller\module\featured.php on line 50Notice: Undefined variable: result in C:\xampp\htdocs\oc1511\catalog\controller\module\featured.php on line 50Notice: Undefined variable: result in C:\xampp\htdocs\oc1511\catalog\controller\module\featured.php on line 50
Line 50 is

Code: Select all

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

Re: Short description in modules

Posted: Mon Nov 14, 2011 1:55 am
by vimal
And the description only shows ".." excluding the quotation mark.

Re: Short description in modules

Posted: Mon Nov 14, 2011 2:02 am
by vimal
Solved it. The array looks as below.

Code: Select all

$this->data['products'][] = array(
					'product_id' => $product_info['product_id'],
					'thumb'   	 => $image,
					'name'    	 => $product_info['name'],
					'price'   	 => $price,
					'description' => substr(strip_tags(html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8')), 0, 100) . '..',
					'special' 	 => $special,
					'rating'     => $rating,
					'reviews'    => sprintf($this->language->get('text_reviews'), (int)$product_info['reviews']),
					'href'    	 => $this->url->link('product/product', 'product_id=' . $product_info['product_id']),
				);
And in the template file.

Code: Select all

<?php echo $product['description']; ?>

Re: [Solved] Short description in modules

Posted: Mon Nov 14, 2011 2:15 am
by vimal
Hi All,

Just realised that the code above for the array works for featured module only. For other modules,

Replace the line

Code: Select all

'description' => substr(strip_tags(html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8')), 0, 100) . '..',
with

Code: Select all

'description' => substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, 100) . '..',
difference being $result instead of $product_info

You can check in the array what is being used and use the same one.

Re: [Solved] Short description in modules

Posted: Mon Nov 14, 2011 2:30 am
by wernerrenrew
Hi,

My code is solid but you are right that you would need a little ajustment for other modules.

Open catalog/controler/module/special.php
on line 50 you will see an array replace it with this
Your welcome

Regards Werner

Re: [Solved] Short description in modules

Posted: Mon Nov 14, 2011 3:03 am
by vimal
Thanks for your help. Your solution gave me a direction to start hacking :-)