Zen Cart Logo
Forums / General Questions / Confirmation: can't use php in Product Descriptions?

Confirmation: can't use php in Product Descriptions?

Locked

Views: 18,968

Results 1 to 20 of 34
This thread is locked. New replies are disabled.
14 Jun 2008, 9:27 PM
#1
karma_lab avatar

karma_lab

Zen Follower

Join Date:
Apr 2008
Posts:
135
Plugin Contributions:
0

Confirmation: can't use php in Product Descriptions?

I saw this mentioned about a year ago elsewhere here; I'm wondering if it's still true that you cannot use embedded php in Product Descriptions.

Because, what is strange, is that this does work for the define pages. For example, for my main page, I simply have this:

<?php include('MainPage.html'); ?>

Then, I can work on the main page in DreamWeaver, and just upload it to the site instead of having to copy and paste it into the define pages main page area.

Too bad it doesn't work for product descriptions. I was going to put them all in a folder and have them loaded dynamically. Then I could easily update them in DreamWeaver. :(

14 Jun 2008, 9:47 PM
#2
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Confirmation: can't use php in Product Descriptions?

If you search the forum for "boilerplate" you'll see some discussions and links to ways to alter your site's code for workarounds.

15 Jun 2008, 3:03 AM
#3
karma_lab avatar

karma_lab

Zen Follower

Join Date:
Apr 2008
Posts:
135
Plugin Contributions:
0

Re: Confirmation: can't use php in Product Descriptions?

Thanks, but that's not what I'm looking for - I've seen that thread.

I'm not looking to define boilerplate to include in each of many product descriptions.

My product descriptions are extended HTML pages, with pictures, and HTML formatted text. They are all different. No boilerplate.

I want each product description to be a separate page in Dreamweaver, that I can edit to my heart's content in a program made to do it, and then just "put" the file (upload to the site), and ZenCart automatically reflects the results of my edits.

Here is a comparison of what I would like to do.

Scenario 1 (if could use php include in Product Descriptions.):

  1. Edit product description in DreamWeaver.
  2. Upload to site (one click in DreamWeaver).
  3. View changes in browser.

Scenario 2: (current situation)

  1. Edit product description in DreamWeaver.
  2. Copy Product Description.
  3. Open Product in ZenCart admin > Categories > Products.
  4. Paste in new description.
  5. Hit preview button.
  6. Hit OK.
  7. View changes in browser.

Notice the difference in the number of steps? :smile: This becomes quite tedious, quite quickly, when working on complex product descriptions using CSS formatting.

The BOILERPLATE workaround is not even applicable here.

Why can you use php include in a Define Pages page, and not in a Product Description?

15 Jun 2008, 5:18 AM
#4
davewest avatar

davewest

Totally Zenned

Join Date:
Dec 2007
Location:
Payson, AZ
Posts:
1,075
Plugin Contributions:
7

Re: Confirmation: can't use php in Product Descriptions?

Why can you use php include in a Define Pages page, and not in a Product Description?

In a nut shell.. Define pages are php pages, where product descriptions are stored in a database as text, not php pages.

Somewhere down the line dreamweaver started working more with interpreters such as asp, php and databases like MySQL. Had to if it wanted to survive.. I jump from 4 to 8, so that's where I'm at. Dream 8 has the ability to use MySQL and php with live edits if you have a working server to access. The server can be on the internet or local. I've used it with Uniform Server, php5 and MySQL5, but for info, it's a pain to set up and just as flaky as normal for dreamweaver. The Adobe web site has info on setting it up.

Not sure if you can edit product description, but something to try.

15 Jun 2008, 5:43 AM
#5
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Confirmation: can't use php in Product Descriptions?

karma-lab:

Here is a comparison of what I would like to do.

Scenario 1 (if could use php include in Product Descriptions.):

  1. Edit product description in DreamWeaver.
  2. Upload to site (one click in DreamWeaver).
  3. View changes in browser.

Scenario 2: (current situation)

  1. Edit product description in DreamWeaver.
  2. Copy Product Description.
  3. Open Product in ZenCart admin > Categories > Products.
  4. Paste in new description.
  5. Hit preview button.
  6. Hit OK.
  7. View changes in browser.

Notice the difference in the number of steps?
Not entirely correct.

You forgot to include a couple important items:

Scenario 1 (if could use php include in Product Descriptions.):

  1. Edit product description in DreamWeaver.
  2. Upload to site (one click in DreamWeaver).
  3. Open Product in ZenCart admin > Categories > Products.
  4. Paste in the required PHP code for to include() the file uploaded via DW, as the product description content.
  5. Hit preview button.
  6. Hit OK.
  7. View changes in browser.

As far as I can tell it seems to be the same number of steps.

15 Jun 2008, 7:02 AM
#6
gjh42 avatar

gjh42

Black Belt

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

Re: Confirmation: can't use php in Product Descriptions?

From what I can tell, it would be the same number of steps to create a new product, but simpler to edit the description afterward.

My recollection of the boilerplate thread leads me to believe that you could use the $_GET[products_id] variable as a component of a filename to be included, so that tpl_product_info_display.php could insert the correct individual product description content by the process described.

You would have to name your files with the product id as part of the name. If your model numbers are unique and suitable for inclusion in a filename, you could use those instead.

15 Jun 2008, 9:10 AM
#7
karma_lab avatar

karma_lab

Zen Follower

Join Date:
Apr 2008
Posts:
135
Plugin Contributions:
0

Re: Confirmation: can't use php in Product Descriptions?

DrByte:

Not entirely correct.

You forgot to include a couple important items:

Scenario 1 (if could use php include in Product Descriptions.):

  1. Edit product description in DreamWeaver.
  2. Upload to site (one click in DreamWeaver).
  3. Open Product in ZenCart admin > Categories > Products.
  4. Paste in the required PHP code for to include() the file uploaded via DW, as the product description content.
  5. Hit preview button.
  6. Hit OK.
  7. View changes in browser.

As far as I can tell it seems to be the same number of steps.

Nope, not true.

If I were able to put this in a product description:

<?php include ('myProduct.html'); ?> 

...then my scenario is correct. All I have to do is edit the 'myProduct.html' file, and hit refresh on the browser, to see the results of my edits. Am I missing something?

This is already what I am doing with my main page, which is set up through the Define Pages section. I just have:

<?php include ('mainPage.html'); ?> 

All I do is edit the mainPage.html page in the root of my store, upload it, and hit the browser refresh, and it's all there. No need to go through the tedious process of locating the correct page in the zencart admin interface and pasting some chunk of html into it.

15 Jun 2008, 9:34 AM
#8
karma_lab avatar

karma_lab

Zen Follower

Join Date:
Apr 2008
Posts:
135
Plugin Contributions:
0

Re: Confirmation: can't use php in Product Descriptions?

DrByte:

Not entirely correct.

You forgot to include a couple important items:

[snip]

As far as I can tell it seems to be the same number of steps. One other point: You may be correct for the first setting up of the page. I just realized this now. But that's not what I was talking about. For every edit after that, my scenario is correct. And that's my point. When tweaking a product description, especially through CSS (as we all know, it's especially finicky, especially for different browsers), it's common to tweak and upload the same product description dozens of times. If you could just use 'php include' to include an html page for a product description, so much of this tedium would be removed.

15 Jun 2008, 8:20 PM
#9
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Confirmation: can't use php in Product Descriptions?

There are lots of ways to alter the default behavior of the code, perhaps by writing a direct database content-editor of your own, or by writing in the ability to include external files, or any number of different solutions.
Feel free to get creative, and please come back and share what you come up with so we can all benefit from it. Hopefully it supports multiple languages, as Zen Cart does now, so that others can use it too.

15 Jun 2008, 11:57 PM
#10
swguy avatar

swguy

Administrator

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

Re: Confirmation: can't use php in Product Descriptions?

Here's the new tip: adding boilerplate files to your descriptions.

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

I wrote some logic to do it automatically based on product id or category id, but I came back to doing it this way because it's the most flexible.

Good luck,
swguy

16 Jun 2008, 12:33 AM
#11
gjh42 avatar

gjh42

Black Belt

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

Re: Confirmation: can't use php in Product Descriptions?

Excellent! Looks like maximized flexibility and utility to me :)

16 Jun 2008, 3:23 AM
#12
karma_lab avatar

karma_lab

Zen Follower

Join Date:
Apr 2008
Posts:
135
Plugin Contributions:
0

Re: Confirmation: can't use php in Product Descriptions?

swguy:

Here's the new tip: adding boilerplate files to your descriptions.

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

I wrote some logic to do it automatically based on product id or category id, but I came back to doing it this way because it's the most flexible.
Thanks a bunch for figuring out how to do this. It works great for what I wanted to do, which is edit my product descriptions in a dedicated HTML editor and simply upload them as files to a directory on my site.

In fact, you might want to consider editing your explanation of the article on your site, because it still seems to imply that the use is to add repetitive boilerplate chunks to existing product descriptions, when it would be useful to mention that another use of it is to grab each product description in full from a file that you can edit and upload from another application, such as a dedicated HTML editor.

Thanks again!

16 Jun 2008, 4:24 AM
#13
karma_lab avatar

karma_lab

Zen Follower

Join Date:
Apr 2008
Posts:
135
Plugin Contributions:
0

Re: Confirmation: can't use php in Product Descriptions?

As an alternative, I actually just figured out how to allow the use of php inside Product Descriptions (after reading a thread about how to allow the use of php inside ez pages).

Inside your tpl_product_info_display.php file, near the middle you will find:

 <!--bof Product description -->
<?php if ($products_description != '') { ?>
<div><?php echo stripslashes($products_description) ?><br/><br/>

Change this to:

 <!--bof Product description -->
<?php if ($products_description != '') { ?>
<div><?php echo eval(stripslashes('?>'.$products_description)); ?><br/><br/>

...and now php include works. You can do something like this, for a product description:

 <?php include('includes/languages/english/MyFolder/MyProduct.html'); ?>
16 Jun 2008, 4:44 AM
#14
karma_lab avatar

karma_lab

Zen Follower

Join Date:
Apr 2008
Posts:
135
Plugin Contributions:
0

Re: Confirmation: can't use php in Product Descriptions?

Of course, there's always a "fly in the ointment" - a problem with both of the methods discussed here (the HTML_INCLUDE method, and the php include), is that, if you want to use it for your whole product description, then it only works on the product info page, but not the piece of the product info description that is normally parsed and used in the category pages, the featured products list, the specials list, etc.

With the HTML_INCLUDE method, you actually see that phrase 'HTML_INCLUDE_DVD' as the complete product description in the products list(s).

With the php include modification, you get nothing in the product lists. I guess with the php include method, you would need to modify several other template files as well if you want the text of your product description to appear there. I'm going to look into that.

16 Jun 2008, 6:30 AM
#15
karma_lab avatar

karma_lab

Zen Follower

Join Date:
Apr 2008
Posts:
135
Plugin Contributions:
0

Re: Confirmation: can't use php in Product Descriptions?

I just finished getting the php include concept to work on all the various pages (featured, specials, new products etc.)

The basic idea is to eval() the product description first into a variable (using output buffering), and then perform whatever string cleaning and truncation is normally done on the results of that eval(). It's basically the same mod in each spot, just sometimes the code or variables are a bit different.

I'm not going to detail each mod, because this was a bunch of work and I'm not sure anyone really wants to go through this, it will be extremely helpful for me, but maybe not for anyone else to work in this fashion. But here's the basic idea:

includes/templates/CUSTOM/common/tpl_tabular_display.php

replace:

$list_box_contents[$rows]['description'] = zen_trunc_string(zen_clean_html(stripslashes(zen_get_products_description($listing->fields['products_id'], $_SESSION['languages_id']))), PRODUCT_LIST_DESCRIPTION);

...with:

ob_start();
eval(stripslashes('?>'.zen_get_products_description($listing->fields['products_id'], $_SESSION['languages_id'])));
$contents = ob_get_contents();
ob_end_clean(); 
$list_box_contents[$rows]['description'] = zen_trunc_string(zen_clean_html($contents), PRODUCT_LIST_DESCRIPTION);

includes/templates/CUSTOM/templates/tpl_modules_products_all_listing.php

replace:

$disp_text = zen_get_products_description($products_all->fields['products_id']);
$disp_text = zen_clean_html($disp_text);

$display_products_description = stripslashes(zen_trunc_string($disp_text, PRODUCT_ALL_LIST_DESCRIPTION, '<a href="' . zen_href_link(zen_get_info_page($products_all->fields['products_id']), 'cPath=' . zen_get_generated_category_path_rev($products_all->fields['master_categories_id']) . '&products_id=' . $products_all->fields['products_id']) . '"> ' . MORE_INFO_TEXT . '</a>'));

...with:

$disp_text = zen_get_products_description($products_all->fields['products_id']);

ob_start();
eval(stripslashes('?>'.$disp_text));
$contents = ob_get_contents();
ob_end_clean(); 

$contents = zen_clean_html($contents);

$display_products_description = zen_trunc_string($contents, PRODUCT_ALL_LIST_DESCRIPTION, '<a href="' . zen_href_link(zen_get_info_page($products_all->fields['products_id']), 'cPath=' . zen_get_generated_category_path_rev($products_all->fields['master_categories_id']) . '&products_id=' . $products_all->fields['products_id']) . '"> ' . MORE_INFO_TEXT . '</a>');

includes/templates/CUSTOM/templates/tpl_modules_products_featured_listing.php
includes/templates/CUSTOM/templates/tpl_modules_products_new_listing.php
includes/templates/CUSTOM/templates/tpl_specials_default.php

...these are all virtually identical to the one above for products_all_listing.

One caveat: I'm already using a custom theme that has some modifications, so I cannot guarantee that this will match 100%. But the concept behind it is clear, for anyone who understands a bit of php.

Hope that helps anyone who wants to have the freedom of having every single product description reside on the server as a separate HTML file. :wink:

16 Jun 2008, 10:56 AM
#16
swguy avatar

swguy

Administrator

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

Re: Confirmation: can't use php in Product Descriptions?

karma-lab:

Of course, there's always a "fly in the ointment" - a problem with both of the methods discussed here (the HTML_INCLUDE method, and the php include), is that, if you want to use it for your whole product description, then it only works on the product info page, but not the piece of the product info description that is normally parsed and used in the category pages, the featured products list, the specials list, etc.

I added a brief treatment of this topic.

In fact, you might want to consider editing your explanation of the article on your site, because it still seems to imply that the use is to add repetitive boilerplate chunks to existing product descriptions, when it would be useful to mention that another use of it is to grab each product description in full from a file that you can edit and upload from another application, such as a dedicated HTML editor.

Your application of this technique is sui generis. Everyone else just wanted boilerplate. Nevertheless, I added this suggestion too.

Good luck,
Software Guy

16 Jun 2008, 7:34 PM
#17
karma_lab avatar

karma_lab

Zen Follower

Join Date:
Apr 2008
Posts:
135
Plugin Contributions:
0

Re: Confirmation: can't use php in Product Descriptions?

swguy:

Your application of this technique is sui generis. Everyone else just wanted boilerplate. Nevertheless, I added this suggestion too.When I was searching for ways to use php include on product descriptions, I found several other threads of people wanting to do this exact same thing. So I don't think it's necessarily that unique. But thanks for your help.

17 Jun 2008, 12:06 AM
#18
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Confirmation: can't use php in Product Descriptions?

You could also just use a simple script to read all your description files en masse and insert them into the database as the product descriptions. A lot less touching of core code that way. But that would require you to click a link in the admin area to read them in.

17 Jun 2008, 2:13 AM
#19
karma_lab avatar

karma_lab

Zen Follower

Join Date:
Apr 2008
Posts:
135
Plugin Contributions:
0

Re: Confirmation: can't use php in Product Descriptions?

DrByte:

You could also just use a simple script to read all your description files en masse and insert them into the database as the product descriptions. A lot less touching of core code that way. But that would require you to click a link in the admin area to read them in.Thanks for the suggestion, but I know some php whereas I know next to nothing about mySQL. And the potential of screwing up the database always scares me. So this way works pretty good for me. I've been using it today and the amount of time it has been saving me while adding products and tweaking layouts and CSS is amazing. It would be nice to make this change in a future version of Zencart, it seems not so difficult. The way I did it above still works for normal product descriptions.

19 Jun 2008, 11:06 PM
#20
rmjr avatar

rmjr

New Zenner

Join Date:
May 2005
Posts:
48
Plugin Contributions:
0

Re: Confirmation: can't use php in Product Descriptions?

How can I get the HTML or php includes to work with the tabbed products light mod?

I tried both mods in the tpl_product_info_display.php file, and neither worked.

I have attached the tpl_tabbed_products_lite.php file, but I deleted the javascript check and the header to make it fit the filesize requirements.

Any help would be great because I have 70 products with the same pricing description that I would like to update once, not 70 times.

Thanks in advance!

Rod