Post by i2Paq » Thu Jul 08, 2010 7:47 pm

JAY6390 wrote:eek avoid <br/> 's all you can. Use a div instead around it. That should work
Maybe, but that is the best, but I'm just beginning to learn and have no idea how to adjust that.

Norman in 't Veldt
Moderator OpenCart Forums

_________________ READ and Search BEFORE POSTING _________________

Our FREE search: Find your answer FAST!.

[How to] BTW + Verzend + betaal setup.


User avatar
Global Moderator

Posts

Joined
Mon Nov 09, 2009 7:00 pm
Location - Winkel - The Netherlands

Post by fido-x » Thu Jul 08, 2010 9:26 pm

OK, here's an alternative. Instead of using the "<br />" as previously suggested, do this instead. Find this block of code:

Code: Select all

<?php if ($display_price) { ?>
<?php if (!$products[$j]['special']) { ?>
<span style="color: #900; font-weight: bold;"><?php echo $products[$j]['price']; ?></span>
<?php } else { ?>
<span style="color: #900; font-weight: bold; text-decoration: line-through;"><?php echo $products[$j]['price']; ?></span> <span style="color: #F00;"><?php echo $products[$j]['special']; ?></span>
<?php } ?>
<?php } ?>
and replace with:

Code: Select all

<?php if ($display_price) { ?>
<div style="display: block;">
<?php if (!$products[$j]['special']) { ?>
<span style="color: #900; font-weight: bold;"><?php echo $products[$j]['price']; ?></span>
<?php } else { ?>
<span style="color: #900; font-weight: bold; text-decoration: line-through;"><?php echo $products[$j]['price']; ?></span> <span style="color: #F00;"><?php echo $products[$j]['special']; ?></span>
<?php } ?>
</div>
<?php } ?>

Image
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool

If you're not living on the edge ... you're taking up too much space!


User avatar
Expert Member

Posts

Joined
Sat Jun 28, 2008 1:09 am
Location - Tasmania, Australia

Post by i2Paq » Fri Jul 09, 2010 1:09 am

fido-x wrote:OK, here's an alternative. Instead of using the "<br />" as previously suggested, do this instead.
My code was slightly different but I managed to get the div's in the right postition and now it looks OK.

Last question; I want the Special Price on the Product page below the striked out "normal" price.
This because it looks better.

I've played around with the code but cannot get it below each other so I'm hoping on a last bit of help ;)

Code: Select all

<table style="width: 100%; border-collapse: collapse;">
        <tr>
          <td style="text-align: center; width: 250px; vertical-align: top;"><a href="<?php echo $popup; ?>" title="<?php echo $heading_title; ?>" class="thickbox" rel="gallery"><img src="<?php echo $thumb; ?>" title="<?php echo $heading_title; ?>" alt="<?php echo $heading_title; ?>" id="image" style="margin-bottom: 3px;" /></a><br />
            <span style="font-size: 11px;"><?php echo $text_enlarge; ?></span></td>
          <td style="padding-left: 15px; width: 296px; vertical-align: top;"><table width="100%">
              <?php if ($display_price) { ?>
              <tr>              
                <td><b><?php echo $text_price; ?></b></td>
                <td><?php if (!$special) { ?>
                  <div class="price"><?php echo $price; ?></div>
                  <?php } else { ?>
                  <div class="price"><span class="ifspecial"><?php echo $price; ?></span> <span class="special"><?php echo $special; ?></span></div>
                  <?php } ?></td>                 
              </tr>
              <?php } ?>
              <tr>
                <td><b><?php echo $text_availability; ?></b></td>
                <td><?php echo $stock; ?></td>
              </tr>
              <tr>
                <td><b><?php echo $text_model; ?></b></td>
                <td><?php echo $model; ?></td>
              </tr>
              <?php if ($manufacturer) { ?>
              <tr>
                <td><b><?php echo $text_manufacturer; ?></b></td>
                <td><a href="<?php echo str_replace('&', '&', $manufacturers); ?>"><?php echo $manufacturer; ?></a></td>
              </tr>
              <?php } ?>
              <?php if ($review_status) { ?>
              <tr>
                <td><b><?php echo $text_average; ?></b></td>
                <td><?php if ($average) { ?>
                  <img src="catalog/view/theme/default/image/stars_<?php echo $average . '.png'; ?>" alt="<?php echo $text_stars; ?>" style="margin-top: 2px;" />
                  <?php } else { ?>
                  <?php echo $text_no_rating; ?>
                  <?php } ?></td>
              </tr>
              <?php } ?>
            </table>

Norman in 't Veldt
Moderator OpenCart Forums

_________________ READ and Search BEFORE POSTING _________________

Our FREE search: Find your answer FAST!.

[How to] BTW + Verzend + betaal setup.


User avatar
Global Moderator

Posts

Joined
Mon Nov 09, 2009 7:00 pm
Location - Winkel - The Netherlands

Post by i2Paq » Fri Jul 09, 2010 1:44 am

Got it!

I used the <div> in the wrong way, here's the correct code:

Code: Select all

<?php if ($display_price) { ?>
              <tr>              
                <td><b><?php echo $text_price; ?></b></td>
                <td><?php if (!$special) { ?>
                  <div class="price"><?php echo $price; ?></div>
                  <?php } else { ?>
                  <div class="price"><span class="ifspecial"><?php echo $price; ?></span></div> <div class="price"><span class="special"><?php echo $special; ?></span></div>
                  <?php } ?></td>                 
              </tr>
              <?php } ?>

Norman in 't Veldt
Moderator OpenCart Forums

_________________ READ and Search BEFORE POSTING _________________

Our FREE search: Find your answer FAST!.

[How to] BTW + Verzend + betaal setup.


User avatar
Global Moderator

Posts

Joined
Mon Nov 09, 2009 7:00 pm
Location - Winkel - The Netherlands

Post by silanli_53 » Wed Aug 18, 2010 3:44 am

Add to Cart button product reviews pictures of the stars How do I get to the bottom.
campaign with images of stars, change products, free shipping, delivery, etc. immediately. Add pictures and comments as a way to use the system to cancel I think ..


Sample issues;
http://forum.opencart.com/viewtopic.php?f=21&t=18694

Cafe Koltuk Çeşitleri

Laptop Sırt Çantası


User avatar
New member

Posts

Joined
Fri Feb 19, 2010 8:54 am


Post by hbuchel » Fri Sep 03, 2010 12:25 am

Edit, nevermind. Appeared to have fixed this. Its because of the way the text editor mocks up your description I'm guessing. If I save it while viewing the source (with all the extra spans removed) it appears to fix it. Leaving this here in case others may find it of some use.

Hi, this works beautifully for me. I've added short descriptions to my related products on the product page. However, some of them the description just shows up as "..." without any description and some of them are showing up properly. Any idea why that might be?

Here is my array from my controller file.

Code: Select all

$this->data['products'][] = array(
					'product_id'    => $result['product_id'],
					'name'    		=> $result['name'],
					'description'    => preg_replace('/[\r\n\s]+/', ' ', strip_tags(substr(html_entity_decode($result['description']),0,80)))."...",  
					'model'   		=> $result['model'],
					'rating'  		=> $rating,
					'stars'   		=> sprintf($this->language->get('text_stars'), $rating),
					'price'   		=> $price,
					'options'   	=> $options,
					'special' 		=> $special,
					'image'   		=> $this->model_tool_image->resize($image, 38, 38),
					'thumb'   		=> $this->model_tool_image->resize($image, $this->config->get('config_image_related_width'), $this->config->get('config_image_related_height')),
					'href'    		=> $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/product&product_id=' . $result['product_id']),
					'add'    		=> $add
				);
And here is my related products loop

Code: Select all

<?php for ($i = 0; $i < sizeof($products); $i = $i + 4) { ?>
	    	<?php for ($j = $i; $j < ($i + 4); $j++) { ?>
				<?php if (isset($products[$j])) { ?>
					<div class="product_related">
						<a href="<?php echo str_replace('&', '&', $products[$j]['href']); ?>"><img src="<?php echo $products[$j]['thumb']; ?>" title="<?php echo $products[$j]['name']; ?>" class="trigger" alt="<?php echo $products[$j]['name']; ?>" /></a>
						<div class="popup">
							<h4><?php echo $products[$j]['name']; ?></h4> 
							<?php echo $products[$j]['description']; ?>
						</div>
					</div>
				<?php } ?>
			<?php } ?>        
		<?php } ?>

I have my descriptions set to popup with a little jquery and css. All of it works, minus random products not showing any description and just the "..." I've tried adjusting the product description in my admin panel so that there isn't any extra spaces or random code from the WYSIWYG editor. Thanks if anyone can provide any insight to this.

New member

Posts

Joined
Mon Aug 30, 2010 9:41 pm

Post by chrisplaneta » Fri Oct 15, 2010 10:58 pm

Hi hbuchel.

I had an exactly same problem. My PHP isn't maybe very good but I will try to explain how to make it work. I guess this happens because in your code:

Code: Select all

'description'    => preg_replace('/[\r\n\s]+/', ' ', strip_tags(substr(html_entity_decode($result['description']),0,80)))."...",
the order of functions is wrong. Here is what happens:
1. full description is read from database
2. all the html tags are changed into their safe equivalents e.g.

Code: Select all

<p>
changes into

Code: Select all

<p>
(if you have many tags before your actual text you may end up having whole bunch of useless code before it)
3. this whole mess is than shortened to 80 elements
4. Eventually All the tags that remained in these 80 elements are thrown away

In some cases it may happen than you will end up having nothing left since tags took all these 80 elements.

My code looks like that:

Code: Select all

'description'   => substr(strip_tags(html_entity_decode($result['description'])),0,180)."...",
The difference is quite simple: The text is shortened after all the tags are gotten rid off

I hope it will work for you

Go visit me at http://ChrisPlaneta.com

If you are a temaplate developer you might be interested in my nude Opencart theme - Cornerstone. It is available for download from this site http://chrisplaneta.com/freebies/corner ... art-theme/


User avatar
Newbie

Posts

Joined
Fri Oct 08, 2010 8:47 pm

Post by twuncher » Tue Oct 19, 2010 7:19 am

would it be possible to have the short description but keep the tags? so we can have bolds and stuff, might be useful to have product summarys at the top of the description so that it appears in the short description?

Newbie

Posts

Joined
Sat May 15, 2010 7:42 pm

Post by chrisplaneta » Fri Oct 22, 2010 5:54 am

Sure! I am actually a designer not a PHP programmer but I came up with this code.

1. Add this line to your category.php after $this->data['products'][] = array(

Code: Select all

'description'   => $this->shortDesc($result['description']),
2. Paste the code below before line "private function getCategories($parent_id, $level = 0) {"

Code: Select all

private function shortDesc($string){						
		if(strpos($string,'<!--desc-->')!=false){
			$descEnd = strpos($string,'<!--desc-->');
			$shortDesc = html_entity_decode(substr($string, 0, $descEnd));
			return $shortDesc;
		}else{
			return 'No description';
		}
	}
To create a short description you must:
1. Go to your product page in the admin panel
2. Switch to HTML (code) view in the text editor
3. Insert this piece of code where you would like your description to end <!--desc-->
4. Save changes

Now short explanation what my code does.
1. The first line grabs the whole description and runs a function shortDesc() on it
2. This function looks in your whole text for <!--desc--> which is an equivalent of <!--desc-->
3. Now it assigns to $shortDesc value everything in your code until <!--desc--> and changes entities like > into html applicable
4. It returns the $shortDesc to the first function that in turn saves it as one of the values of a given product.

I hope you get it.

Feel free to improve my code.

Go visit me at http://ChrisPlaneta.com

If you are a temaplate developer you might be interested in my nude Opencart theme - Cornerstone. It is available for download from this site http://chrisplaneta.com/freebies/corner ... art-theme/


User avatar
Newbie

Posts

Joined
Fri Oct 08, 2010 8:47 pm

Post by i2Paq » Thu Nov 11, 2010 7:43 pm

chrisplaneta wrote:
2. Paste the code below before line "private function getCategories($parent_id, $level = 0) {"

Code: Select all

private function shortDesc($string){						
		if(strpos($string,'<!--desc-->')!=false){
			$descEnd = strpos($string,'<!--desc-->');
			$shortDesc = html_entity_decode(substr($string, 0, $descEnd));
			return $shortDesc;
		}else{
			return 'No description';
		}
	}
What file are your referring to?

Norman in 't Veldt
Moderator OpenCart Forums

_________________ READ and Search BEFORE POSTING _________________

Our FREE search: Find your answer FAST!.

[How to] BTW + Verzend + betaal setup.


User avatar
Global Moderator

Posts

Joined
Mon Nov 09, 2009 7:00 pm
Location - Winkel - The Netherlands

Post by jamies » Tue Jun 07, 2011 3:06 am

anyone have a add-on for this??

Newbie

Posts

Joined
Fri Jun 03, 2011 11:00 pm

Post by i_like » Tue Oct 25, 2011 5:12 pm

Thank you Qphoria for your answer. I found your answer very very helpful. A big thank you. :) O0

Newbie

Posts

Joined
Tue Oct 25, 2011 5:10 pm

Post by dealstation » Wed Nov 16, 2011 5:44 pm

I use version 1.5.1.1 maybe someone knows how you can change it please.

I've tried everything. thanks

New member

Posts

Joined
Tue Aug 16, 2011 7:59 am

Post by helixconcepts » Mon Nov 21, 2011 10:22 pm

It would be helpful to know how to approach this in the latest version 1.5.1.3

Newbie

Posts

Joined
Thu Nov 10, 2011 9:58 pm

Post by gtamborero » Wed Nov 30, 2011 10:49 pm

Hi! Working with opencart 1.5 or newer

How to do the excerpt (cut the text string) without cutting words?

Here is my code, I hope It can help you!:
file affected:
yoursite/catalog/view/theme/default/template/product/category.tpl
Aproximate line: 80.

Search for: $product['description']; and delete it or comment it (//$product['description'];)

In the same line copy and paste this code:

Code: Select all

$thetext= substr($description,0,strrpos(substr($description,0,300)," "));
echo strip_tags($thetext);
Where the number 300 is a letter counter, so adjust it to any value!

Newbie

Posts

Joined
Fri Aug 19, 2011 5:24 pm

Post by seanx » Thu Dec 01, 2011 6:04 pm

I have just joined and I hope I will learn a lot of new information here.
I admire the valuable information you offered in your article. Excellent submission very good post.Keep posting thumbs up.

High School Diploma


Newbie

Posts

Joined
Thu Dec 01, 2011 5:49 pm


Post by ThePath » Tue Dec 03, 2013 11:50 pm

Hi everyone,

I know this is an ancient thread but I wanted to do this on a new site using v1.5.6

So I made a vqmod that you can download for free here:

http://the1path.com/opencart-themes-mod ... escription

Hope you find it useful!

Image

OpenCart Theme Options - See All My Extensions - OpenCart Themes and Mods


User avatar
Active Member

Posts

Joined
Fri Jun 26, 2009 11:53 pm
Location - Scotland

Post by DCivit » Tue Jun 10, 2014 6:55 pm

I do not understand why there are so many complicated answer for something that can be very simple. May be there are reasons but i think this is a simple way:

If you have a description echo like this....

Code: Select all

<?php echo $product['description']; ?>
You can excerpt doing this in the template .tpl file directly and just show the first 100 characters.

Code: Select all

<?php echo substr ($product['description'],0,100); ?>
What do you think about this solution ... ?

User avatar
Newbie

Posts

Joined
Fri Aug 10, 2012 9:25 am
Location - Spain, Madrid
Who is online

Users browsing this forum: No registered users and 25 guests