Forums / All Other Contributions/Addons / Boilerplate mod- separate it from description?

Boilerplate mod- separate it from description?

Locked

Views: 4,147

Results 1 to 20 of 20
This thread is locked. New replies are disabled.
19 Jan 2009, 2:50 AM
#1
robbie_newbie avatar

robbie_newbie

New Zenner

Join Date:
Jan 2009
Posts:
3
Plugin Contributions:
0

Boilerplate mod- separate it from description?

Greetings, all, and thanks for an amazing treasure trove of information. I've gotten pretty far in developing my new site and, though I was previously only familiar with HTML, managed to do quite a bit thanks to your posts, mods and patience. A few times I spent that extra half hour searching here or toying with code rather than post...but now I must!

I successfully ran That Software Guy's Boilerplate mod- http://www.thatsoftwareguy.com/zencart_php_in_description.html

  • and it puts the boiler text right after the description. What I'd like is to put the boiler text separate and further down, below the Add To Cart button. That's where I want to mention a few policies (shipping, etc.) common to items in certain categories. I'm using the category aspect of the mod (second example on TSG's page).

I have one item up to test it-
a l e x a n d e r s g i f t s . c a /index.php?main_page=product_info&cPath=65&products_id=180

I put the code at the end so the regular description is at top, as usual, and then it's repeated at the bottom with the boiler text ("Overview: Delivery...").

Latest version of ZenCart.

Thanks,

Robbie

19 Jan 2009, 7:24 AM
#2
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Boilerplate mod- separate it from description?

What you want to do is actually simpler than the standard version of this mod. Since the boilerplate string starts out separate from the description variable, you just need to add an output for it in the appropriate location in tpl_product_info_display.php.
Something like```php

<?php echo '<span class="boilerplate">' . YOUR_BOILERPLATE_TEXT . '</span>'; ?>

If there is some condition for displaying it (like the category), you will need code to distinguish when the condition is met; otherwise, it will display in all product info pages.
19 Jan 2009, 3:41 PM
#3
robbie_newbie avatar

robbie_newbie

New Zenner

Join Date:
Jan 2009
Posts:
3
Plugin Contributions:
0

Re: Boilerplate mod- separate it from description?

I understand in general, but I'm not that good with new code. According to TSG, I made a my_defines.php page and it contains-

<?php

$descr_stringlist = array("PHP_CATBASKETS_DESC", "PHP_CATCHOCOLATES_DESC", "PHP_CATCOOKIES_DESC"); 

define('PHP_CATBASKETS_DESC', 'Overview:<br />Delivery by courrier across Canada- $8. No weekend delivery. <br />Extra charge for wrong address. <br />'); 
define('PHP_CATCHOCOLATES_DESC', 'These decals will be shipped in two weeks after receiving your order.'); 
define('PHP_CATCOOKIES_DESC', 'These decals will be shipped in three weeks after receiving your order.'); 

?>

(I'm using the first for now while I tinker.)

And then I added his code where I want it in tpl_product_info_display.php -

<!--bof Product description -->
<?php if (($products_description != '') || ($current_category_id == 65) ) { ?>
<div id="productDescription" class="productGeneral biggerText">
<?php 
   $stripped_products_description = $products_description;
   if ($current_category_id == 65)  {
      $stripped_products_description = $stripped_products_description . PHP_CATBASKETS_DESC;
   }
   echo stripslashes($stripped_products_description); 
   echo '</div>';
?>
<?php } ?> 
<!--eof Product description -->

I tried adjusting the above, but it was based on guessing. Would you know how to modify it to do what you're saying?

Robbie

21 Jan 2009, 2:51 AM
#4
robbie_newbie avatar

robbie_newbie

New Zenner

Join Date:
Jan 2009
Posts:
3
Plugin Contributions:
0

Re: Boilerplate mod- separate it from description?

I figured it out!

<?php if (($current_category_id == x) ) echo '<span class="PHP_BOILER1_DESC">' .  PHP_BOILER1_DESC . '</span>'; ?> 

(PHP_BOILER1_DESC and others are defined in the new file of my_defines.php)

Thanks!

R

22 Jan 2009, 12:33 AM
#5
jjdoench avatar

jjdoench

New Zenner

Join Date:
Feb 2008
Posts:
41
Plugin Contributions:
0

Re: Boilerplate mod- separate it from description?

On a similar note...

I have linked products in multiple categories. For example, Fabric>All Fabrics, and Fabric>by Color>Red. There are dozens of sub-categories in the Fabric department.

Is there a way to do this other than repeating the line of php over and over for each category? Is that even a good idea? Would it slow down the cart tremendously?

What I have now is:

<?php if (($current_category_id ==713) ) echo '<span class="PHP_BOILER1_DESC">' . PHP_BOILER1_DESC . '</span>'; ?> <?php if (($current_category_id ==1055) ) echo '<span class="PHP_BOILER1_DESC">' . PHP_BOILER1_DESC . '</span>'; ?>

Thus hitting 2 of the 100+ categories/subcategories... any thoughts?

I'm using ZC 1.3.8. I haven't uploaded these changes to my live store yet.

Thanks,
Jessica
https://www.bestfriendsquilts.com

22 Jan 2009, 3:03 AM
#6
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Boilerplate mod- separate it from description?

If it's the same description constant for all of those categories, you can compress the statements into one test on an array of numbers.
See Parent Categories Separated In 3 sideboxes, post 41, for an example to include all subcats of the given topcats (it is written for use in tpl_categories.php, and would need to be tweaked for use in other files).

To choose individual subcats for the code execution, remove the (int) from the first line.
To use in tpl_product_info_display.php, use this```php
if(in_array($_GET['cPath'], explode(",",'3,7,7_25'))) {
// code to be executed
}

22 Jan 2009, 3:13 AM
#7
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Boilerplate mod- separate it from description?

For tidiness, here is a version to include all subcats of the given topcats, in files like product_listing.php or tpl_product_info_display.php:

if(in_array((int)$_GET['cPath'], explode(",",'3,7,11'))) {
  // code to be executed
}  
```List the top category ids, separated by commas, with no spaces.
4 May 2009, 2:03 AM
#8
giftmeister avatar

giftmeister

Zen Follower

Join Date:
Jan 2009
Location:
Montreal, Canada
Posts:
230
Plugin Contributions:
0

Re: Boilerplate mod- separate it from description?

Can you spell out the code for when there are multiple top categories- NOT subcats- calling the same description constant?

Example from my tpl_product_info_display...here are two top categories (there are actually five) calling the same description:

<?php if (($current_category_id == 65) ) echo '<span class="PHP_CATBASKETS_DESC">' .  PHP_CATBASKETS_DESC . '</span>'; ?> 
<?php if (($current_category_id == 66) ) echo '<span class="PHP_CATBASKETS_DESC">' .  PHP_CATBASKETS_DESC . '</span>'; ?> 

Cheers,

R

4 May 2009, 10:31 AM
#9
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,720
Plugin Contributions:
56

Re: Boilerplate mod- separate it from description?

if ( ($current_category_id == 66) ||
($current_category_id == 67) ||
($current_category_id == 68) ||
($current_category_id == 69) ) {
echo '<span class="PHP_CATBASKETS_DESC">' . PHP_CATBASKETS_DESC . '</span>';
}

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.

5 May 2009, 12:30 AM
#10
giftmeister avatar

giftmeister

Zen Follower

Join Date:
Jan 2009
Location:
Montreal, Canada
Posts:
230
Plugin Contributions:
0

Re: Boilerplate mod- separate it from description?

Whoa, swguy himself! Thanks!

28 May 2009, 9:48 PM
#11
giftmeister avatar

giftmeister

Zen Follower

Join Date:
Jan 2009
Location:
Montreal, Canada
Posts:
230
Plugin Contributions:
0

Re: Boilerplate mod- separate it from description?

Darn, I just realized I needed to set the boilerplate text for product IDs, not category IDs, as most of my items are in 2-3 categories (main category like Baskets, then Occasion and Price). I figured I'll mention this here in case someone else is about to be temporarily stupid.

R

29 May 2009, 12:02 AM
#12
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,720
Plugin Contributions:
56

Re: Boilerplate mod- separate it from description?

Instructions on adding conditional statements (for product or category) to your product info page are provided here:

http://www.thatsoftwareguy.com/zencart_conditional_messages.html

Scott

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.

12 Feb 2010, 7:22 PM
#13
bp22 avatar

bp22

New Zenner

Join Date:
Nov 2008
Posts:
17
Plugin Contributions:
0

Re: Boilerplate mod- separate it from description?

swguy:

if ( ($current_category_id == 66) ||
($current_category_id == 67) ||
($current_category_id == 68) ||
($current_category_id == 69) ) {
echo '<span class="PHP_CATBASKETS_DESC">' . PHP_CATBASKETS_DESC . '</span>';
}

I understand that this applies the same message to four different categories, but how would one apply five different boilerplate texts to five different categories?

12 Feb 2010, 7:29 PM
#14
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,720
Plugin Contributions:
56

Re: Boilerplate mod- separate it from description?

if ($current_category_id == 66) {
echo '<span class="PHP_CATBASKETS_DESC">' . PHP_CATBASKETS_DESC66 . '</span>';
} else if ($current_category_id == 67) {
echo '<span class="PHP_CATBASKETS_DESC">' . PHP_CATBASKETS_DESC67 . '</span>';
} else if ($current_category_id == 68) {
echo '<span class="PHP_CATBASKETS_DESC">' . PHP_CATBASKETS_DESC68 . '</span>';
}

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.

12 Feb 2010, 8:25 PM
#15
bp22 avatar

bp22

New Zenner

Join Date:
Nov 2008
Posts:
17
Plugin Contributions:
0

Re: Boilerplate mod- separate it from description?

Thanks, got that part of it working. But now if a product in one of those categories does not have a description, the message does not display.

<!--bof Product description -->
	<?php if (($products_description != '') || ($current_category_id == 17) ) { ?>
	<div id="productDescription">
	<?php 
	   $stripped_products_description = $products_description;
		if ($current_category_id == 17)  {
			echo $stripped_products_description . CAT_A ; }
		else if ($current_category_id == 34) {
			echo $stripped_products_description . CAT_B ; }
		else if ($current_category_id == 43) {
			echo $stripped_products_description . CAT_C ; }
	   echo stripslashes(); 
	   echo '</div>';
	?>
	<?php } ?>
<!--eof Product description -->
12 Feb 2010, 8:49 PM
#16
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Boilerplate mod- separate it from description?

<?php if (($products_description != '') || ($current_category_id == 17) ) { You can eliminate the part in red if you do not need the boilerplate to depend on the existence of the description.
12 Feb 2010, 10:15 PM
#17
bp22 avatar

bp22

New Zenner

Join Date:
Nov 2008
Posts:
17
Plugin Contributions:
0

Re: Boilerplate mod- separate it from description?

gjh42:

<?php if (($products_description != '') || ($current_category_id == 17) ) { You can eliminate the part in red if you do not need the boilerplate to depend on the existence of the description.

Thanks, but it did not work. A description still must be present for the message to appear.

13 Feb 2010, 2:01 AM
#18
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Boilerplate mod- separate it from description?

There is presumably some larger part of the code that needs to be tweaked for this, not visible from the snippet you posted.

13 Feb 2010, 4:37 AM
#19
bp22 avatar

bp22

New Zenner

Join Date:
Nov 2008
Posts:
17
Plugin Contributions:
0

Re: Boilerplate mod- separate it from description?

gjh42:

<?php if (($products_description != '') || ($current_category_id == 17) ) { You can eliminate the part in red if you do not need the boilerplate to depend on the existence of the description.

I got it working. That whole first line had to go. Here's what it ended up looking like:

<!--bof Product description -->
	<div id="productDescription">
	<?php 
	   $stripped_products_description = $products_description;
	   echo stripslashes($stripped_products_description); 
		if ($current_category_id == 34)  {
			echo '<div class="alertExtra">' . WARNING1 . '</div>'; }
		else if ($current_category_id == 43) {
			echo '<div class="alertExtra">' . WARNING2 . '</div>'; }
		else if ($current_category_id == 17) {
			echo '<div class="alertExtra">' . WARNING3 . '</div>'; }
	   echo '</div>';
	?>
<!--eof Product description -->
21 Oct 2010, 3:34 PM
#20
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Boilerplate mod- separate it from description?

While looking at this thread, it occurred to me that there is some unfinished business here.
The final code is not a corrected version of the code in post 15, but a different solution. It outputs the boilerplate text in a separate div after the description, not affecting the description at all. It should leave the standard "if" in place, and should be written something like```php

<!--bof Product description --> <?php if ($products_description != '') { ?>
<div id="productDescription">
<?php $stripped_products_description = $products_description; echo stripslashes($stripped_products_description); echo '</div>'; } if ($current_category_id == 34) { echo '<div class="alertExtra">' . WARNING1 . '</div>'; } else if ($current_category_id == 43) { echo '<div class="alertExtra">' . WARNING2 . '</div>'; } else if ($current_category_id == 17) { echo '<div class="alertExtra">' . WARNING3 . '</div>'; } ?> <!--eof Product description -->