Post by tosal » Fri Oct 04, 2013 2:39 am

Hi, i would like to automaticaly cut off product name in homepage in "featured products" module, for example setting it to 20 characters.
How can i do it?
Last edited by tosal on Sat Oct 05, 2013 10:02 pm, edited 1 time in total.

New member

Posts

Joined
Mon May 20, 2013 12:40 am
Location - italy

User avatar
Guru Member

Posts

Joined
Wed Nov 16, 2011 11:53 am
Location - Singapore

Post by tosal » Fri Oct 04, 2013 4:08 pm

I think the file is /catalog/controller/module/featured.php right?
but i don't know how to set the limit
maybe this should be the strings to change but how?

$this->data['products'] = array();

$products = explode(',', $this->config->get('featured_product'));

if (empty($setting['limit'])) {
$setting['limit'] = 5;
}

$products = array_slice($products, 0, (int)$setting['limit']);

foreach ($products as $product_id) {
$product_info = $this->model_catalog_product->getProduct($product_id); $product_infos[] = $product_info;

if ($product_info) {
if ($product_info['image']) {
$image = $this->model_tool_image->resize($product_info['image'], $setting['image_width'], $setting['image_height']);
} else {
$image = false;
}

if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
$price = $this->currency->format($this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax')));
} else {
$price = false;
}

if ((float)$product_info['special']) {
$special = $this->currency->format($this->tax->calculate($product_info['special'], $product_info['tax_class_id'], $this->config->get('config_tax')));
} else {
$special = false;
}

if ($this->config->get('config_review_status')) {
$rating = $product_info['rating'];
} else {
$rating = false;
}

$this->data['products'][] = array(
'product_id' => $product_info['product_id'],
'thumb' => $image,
'name' => $product_info['name'],
'price' => $price,
'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'])
);
}
}

New member

Posts

Joined
Mon May 20, 2013 12:40 am
Location - italy

Post by MarketInSG » Sat Oct 05, 2013 11:21 am

You want to cut off their name, so you have to find this:

Code: Select all

'name' => $product_info['name'],
and add a substr function

Code: Select all

'name' => substr($product_info['name'], 0, 20),


User avatar
Guru Member

Posts

Joined
Wed Nov 16, 2011 11:53 am
Location - Singapore

Post by tosal » Sat Oct 05, 2013 10:01 pm

Great MarketInSG, it runs.
that's exactly what i was looking for.
Thany you.

New member

Posts

Joined
Mon May 20, 2013 12:40 am
Location - italy

User avatar
Guru Member

Posts

Joined
Wed Nov 16, 2011 11:53 am
Location - Singapore

Post by nightwing » Fri Jul 24, 2020 12:58 am

Hi Marketing SG, great solution, however, how do I add three dots to the end
In version 3.0.3.2 => product/category.php doing the below adds ... to the end of every product name even when it wasn't shortened.

Code: Select all

	'name'        => substr($result['name'], 0, 30) . "...",
MarketInSG wrote:
Sat Oct 05, 2013 11:21 am
You want to cut off their name, so you have to find this:

Code: Select all

'name' => $product_info['name'],
and add a substr function

Code: Select all

'name' => substr($product_info['name'], 0, 20),

Regards,
Nightwing
Access to my Free Extensions: https://www.opencart.com/index.php?rout ... =nightwing


Active Member

Posts

Joined
Tue Nov 05, 2019 11:08 pm


Post by kestas » Fri Jul 24, 2020 2:39 am

nightwing wrote:
Fri Jul 24, 2020 12:58 am
Hi Marketing SG, great solution, however, how do I add three dots to the end
In product/category.php doing the below adds ... to the end of every product name even when it wasn't shortened.

Code: Select all

	'name'        => substr($result['name'], 0, 30) . "...",
MarketInSG wrote:
Sat Oct 05, 2013 11:21 am
You want to cut off their name, so you have to find this:

Code: Select all

'name' => $product_info['name'],
and add a substr function

Code: Select all

'name' => substr($product_info['name'], 0, 20),

Here's the solution for you...

Code: Select all

'name' => strlen($product_info['name']) > 20 ? utf8_substr(html_entity_decode($product_info['name']),0,20)."..." : $product_info['name'],

Custom OpenCart modules and solutions. You can write PM with additional questions... Extensions you can find here


Active Member

Posts

Joined
Tue Oct 12, 2010 2:23 am

Post by nightwing » Fri Jul 24, 2020 3:08 am

kestas, it worked! Thanks
kestas wrote:
Fri Jul 24, 2020 2:39 am
nightwing wrote:
Fri Jul 24, 2020 12:58 am
Hi Marketing SG, great solution, however, how do I add three dots to the end
In product/category.php doing the below adds ... to the end of every product name even when it wasn't shortened.

Code: Select all

	'name'        => substr($result['name'], 0, 30) . "...",
MarketInSG wrote:
Sat Oct 05, 2013 11:21 am
You want to cut off their name, so you have to find this:

Code: Select all

'name' => $product_info['name'],
and add a substr function

Code: Select all

'name' => substr($product_info['name'], 0, 20),

Here's the solution for you...

Code: Select all

'name' => strlen($product_info['name']) > 20 ? utf8_substr(html_entity_decode($product_info['name']),0,20)."..." : $product_info['name'],

Regards,
Nightwing
Access to my Free Extensions: https://www.opencart.com/index.php?rout ... =nightwing


Active Member

Posts

Joined
Tue Nov 05, 2019 11:08 pm


Post by IP_CAM » Fri Jul 24, 2020 3:53 am

Could also be added directly into the Theme File in charge: (NON TWIG Solution, tested in OC v.1.5.6.5, item-description)

Code: Select all

<div class="description"><?php echo utf8_substr(strip_tags(html_entity_decode($product['description'], ENT_QUOTES, 'UTF-8')), 0, 50) . '...'; ?></div>

Please don't send me OC Forum Personal Messages, just contact: jti@jacob.ch
---
OC 1.5.6.5 LIGHT Test Site: http://www.bigmax.ch/shop/
OC 1.5.6.5 V-PRO Test Site: http://www.jacob.ch/shop/
My Github OC Site: https://github.com/IP-CAM
2'600+ FREE OC Extensions on the World's largest Github OC Repository Archive Site.


User avatar
Legendary Member

Posts

Joined
Tue Mar 04, 2014 1:37 am
Location - Switzerland

Post by nightwing » Fri Jul 24, 2020 7:34 am

I see IP Cam, thanks, I already created an ocmod for the controller method. However this could help someone else.
Demo: https://www.jwbasics.com
IP_CAM wrote:
Fri Jul 24, 2020 3:53 am
Could also be added directly into the Theme File in charge: (NON TWIG Solution, tested in OC v.1.5.6.5, item-description)

Code: Select all

<div class="description"><?php echo utf8_substr(strip_tags(html_entity_decode($product['description'], ENT_QUOTES, 'UTF-8')), 0, 50) . '...'; ?></div>

Regards,
Nightwing
Access to my Free Extensions: https://www.opencart.com/index.php?rout ... =nightwing


Active Member

Posts

Joined
Tue Nov 05, 2019 11:08 pm


Post by IP_CAM » Fri Jul 24, 2020 8:28 am

Just figured, to 'round it up' :laugh: since it has not been mentioned as well ... ;)
Ernie

Please don't send me OC Forum Personal Messages, just contact: jti@jacob.ch
---
OC 1.5.6.5 LIGHT Test Site: http://www.bigmax.ch/shop/
OC 1.5.6.5 V-PRO Test Site: http://www.jacob.ch/shop/
My Github OC Site: https://github.com/IP-CAM
2'600+ FREE OC Extensions on the World's largest Github OC Repository Archive Site.


User avatar
Legendary Member

Posts

Joined
Tue Mar 04, 2014 1:37 am
Location - Switzerland

Post by nightwing » Sat Jul 25, 2020 2:05 am

Noted IP_CAM.
IP_CAM wrote:
Fri Jul 24, 2020 8:28 am
Just figured, to 'round it up' :laugh: since it has not been mentioned as well ... ;)
Ernie

Regards,
Nightwing
Access to my Free Extensions: https://www.opencart.com/index.php?rout ... =nightwing


Active Member

Posts

Joined
Tue Nov 05, 2019 11:08 pm

Who is online

Users browsing this forum: No registered users and 8 guests