Forums / General Questions / How to include php code into a product description

How to include php code into a product description

Locked

Views: 4,524

Results 1 to 11 of 11
This thread is locked. New replies are disabled.
5 Jan 2008, 2:25 AM
#1
andy1234 avatar

andy1234

Zen Follower

Join Date:
Oct 2006
Posts:
148
Plugin Contributions:
0

How to include php code into a product description

Hi,

Is there a way to include a php code into a product description from the admin panel? It looks as including jscript works fine, but tags <?....?> are ignored.

Any suggestions?

Thanks

5 Jan 2008, 2:31 AM
#2
yellow1912 avatar

yellow1912

Totally Zenned

Join Date:
Oct 2006
Posts:
5,422
Plugin Contributions:
0

Re: How to include php code into a product description

Of course it will be ignored, why do you want to do so? > andy1234:

Hi,

Is there a way to include a php code into a product description from the admin panel? It looks as including jscript works fine, but tags <?....?> are ignored.

Any suggestions?

Thanks

I no longer provide installation support on forum for all my modules. However, if there are real bugs with the modules please feel free to contact me

5 Jan 2008, 2:39 AM
#3
andy1234 avatar

andy1234

Zen Follower

Join Date:
Oct 2006
Posts:
148
Plugin Contributions:
0

Re: How to include php code into a product description

I need to include a flash object with dynamic flashvars parameters. Instead of adding the code to each product description, it would be more elegant to include a call to a php function, which generates the flash structure

I could do it with jscript,, but would prefer php

5 Jan 2008, 2:43 AM
#4
yellow1912 avatar

yellow1912

Totally Zenned

Join Date:
Oct 2006
Posts:
5,422
Plugin Contributions:
0

Re: How to include php code into a product description

You can not do that, because PHP is server side, so it is executed BEFORE sending to your browser. If you put it inside desc, it will be treated not as php code but just plain text.

There is one way to use php tho: in your product_info template file, you can put the php code there to echo the flash. (say if your product name is abc, then echo flash abc.swf, not so hard rite?)

andy1234:

I need to include a flash object with dynamic flashvars parameters. Instead of adding the code to each product description, it would be more elegant to include a call to a php function, which generates the flash structure

I could do it with jscript,, but would prefer php

I no longer provide installation support on forum for all my modules. However, if there are real bugs with the modules please feel free to contact me

5 Jan 2008, 2:52 AM
#5
andy1234 avatar

andy1234

Zen Follower

Join Date:
Oct 2006
Posts:
148
Plugin Contributions:
0

Re: How to include php code into a product description

No, i cannot do this. There is a single flash file, where I pass parameters (xml file) different for different products. In other words, each product has its own xml file, which is a variable for flash.

I can include the whole object code, but it would be easier to call it as a function of the passed variables.

I cannot understand your statement that " You can not do that, because PHP is server side". Of course, it should be done on a server side, but each product description is included by php include statement anyway

5 Jan 2008, 2:56 AM
#6
yellow1912 avatar

yellow1912

Totally Zenned

Join Date:
Oct 2006
Posts:
5,422
Plugin Contributions:
0

Re: How to include php code into a product description

Your product description is saved into database, and when Zen display that product it does something like this:

echo $product_description; (just an example).

$product_description; is a string, and treated as so.

I no longer provide installation support on forum for all my modules. However, if there are real bugs with the modules please feel free to contact me

5 Jan 2008, 3:02 AM
#7
drbyte avatar

drbyte

Sensei

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

Re: How to include php code into a product description

From "Similar Threads" at the bottom of this page:
http://www.zen-cart.com/forum/showthread.php?t=59826 ... see post #4

Or, since you're wanting to add a specific element common to all products, you could just alter your template to display the element where needed, and name your object based on the product id or model etc.
Or, you could add another field in the database to store specific object filename which you call separately, via the template.

It really depends on exactly what you want to accomplish.
Be careful not to think of the solution before you fully define the need/problem.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

5 Jan 2008, 3:02 AM
#8
yellow1912 avatar

yellow1912

Totally Zenned

Join Date:
Oct 2006
Posts:
5,422
Plugin Contributions:
0

Re: How to include php code into a product description

There are many ways to get around without putting php code inside product description. Please provide these info:

  1. Does this flash appear on all product desc, or just some?
  2. Do you currently use product model (or have plan to use)? (I ask this question for a specific reason)
  3. Can you provide a sample description? (with flash)

I no longer provide installation support on forum for all my modules. However, if there are real bugs with the modules please feel free to contact me

5 Jan 2008, 3:21 AM
#9
andy1234 avatar

andy1234

Zen Follower

Join Date:
Oct 2006
Posts:
148
Plugin Contributions:
0

Re: How to include php code into a product description

Here is the whole story.

  1. I am using tabbed products, while one of the tabs is the flash movie with the specific xml file (different for different products) here is an example of such a code via object tag:
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="550" height="400" id="test3" align="middle">
<param name="allowScriptAccess" value="sameDomain" /><param name="flashVars" value="currxml=flash/sample.xml" />
<param name="movie" value="flash/~main.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><embed src="flash/~main.swf" quality="high" flashVars="currxml=flash/sample.xml"  bgcolor="#ffffff" width="550" height="400" name="test3" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
```here is the "flash/sample.xml" variable, which is unique for each product

2) What I need is to make it more simple on the end-user side - just to include something like "myfunction('flash/sample.xml')" instead of the whole object

3) the easiest way woud be to make a jscript function, which writes the whole object, but I cannot use jscript directly, because each priduct page is loaded via ajax. This means that all the jscript write directive are not executed before the browser renders the ajax generated code

One of the solutions would be to delay that jscript execution (what I have to do for other functions) or do it on a server-side via php.

NOTE. I do not use a product model. What is your idea? to use that field?
5 Jan 2008, 3:28 AM
#10
yellow1912 avatar

yellow1912

Totally Zenned

Join Date:
Oct 2006
Posts:
5,422
Plugin Contributions:
0

Re: How to include php code into a product description

Yes, to use that field.
Say you have product A, and we give that product the model: abc.xml.

Now in your product_info template:

We can do something like this (Im writing in pseudo code here)```php
// checking if the product has model
if(exist($pmodel) && strlen(trim($pmodel))>0){
$flash_obj = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="550" height="400" id="test3" align="middle">

<param name="allowScriptAccess" value="sameDomain" /><param name="flashVars" value="currxml=XML_LINK" /> <param name="movie" value="flash/~main.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><embed src="flash/~main.swf" quality="high" flashVars="currxml=XML_LINK" bgcolor="#ffffff" width="550" height="400" name="test3" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /> </object>'; $flash_obj = str_replace('XML_LINK', $pmodel, $flash_obj);

echo $flash_obj;
}

I no longer provide installation support on forum for all my modules. However, if there are real bugs with the modules please feel free to contact me

5 Jan 2008, 5:32 AM
#11
andy1234 avatar

andy1234

Zen Follower

Join Date:
Oct 2006
Posts:
148
Plugin Contributions:
0

Re: How to include php code into a product description

Thank you. It makes sense. The only problem here is that I am using tabbed product mod and the object output needs to be entered after a certain tab.

I am thinking about some other solution (Joomla mambot like). Let's say the whole product description is a string like xxxxx{php code}yyyyyy. We can first extract a substring {php code} and then make something like:

echo $str1;//$str1 = xxxxx
eval($str2); //$str 2 = php code
echo $str3; //$str3 = yyyyy

In this case, we could easily make a library of different functions to be inserted into prod descr.