Forums / Setting Up Categories, Products, Attributes / How do I add fields to a product page?

How do I add fields to a product page?

Locked

Views: 2,672

Results 1 to 19 of 19
This thread is locked. New replies are disabled.
20 Mar 2009, 5:39 PM
#1
suehigman avatar

suehigman

New Zenner

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

How do I add fields to a product page?

Hi there,

I am curious as to whether I can recreate the additional information I have on products (the following link is my old store)

http://www.emeraldparts.com/index.cfm?fuseaction=product.display&product_ID=133&ParentCat=83

Where if you click on the associated Figure # (ex. 12-02) the manual associated with this particular part will open up in PDF.

I basically just wrote a custom tag (Coldfusion) and then called that script in the product description field.

Now I have moved to a Zen Cart store (the bosses found a template that they liked better)in PHP. I am new to PHP, my question is how do I recreate the same process?

I am running Zen Cart 1.3.8a and here is a link to my current store.

http://emeraldspares.com/products/index.php?main_page=product_info&cPath=11_67&products_id=3375

I have copied my PDF Manuals over and was able to export my sql table from the old store and then import it into MYSQL.

I just need help implementing the fields on the template.

Thanks
Sue

20 Mar 2009, 6:59 PM
#2
gjh42 avatar

gjh42

Black Belt

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

Re: How do I add fields to a product page?

So your bosses got seduced by a Template Monster template, I see. Too bad it took that to bring them to Zen Cart - TM is notorious for hardcoding functions, disabling standard ZC admin switches, and doing things in non-standard ways. It will be harder to maintain and customize this template than one built to ZC specs.

Something it looks like you have done to further complicate matters is saving backup copies of stylesheets in the /css/ folder:

<link rel="stylesheet" type="text/css" href="includes/templates/theme096/css/stylesheet.css" /> <link rel="stylesheet" type="text/css" href="includes/templates/theme096/css/stylesheet_as_sidebox.css" /> <link rel="stylesheet" type="text/css" href="includes/templates/theme096/css/stylesheet_boxes.css" /> <link rel="stylesheet" type="text/css" href="includes/templates/theme096/css/stylesheet_css_buttons.css" /> <link rel="stylesheet" type="text/css" href="includes/templates/theme096/css/stylesheet_header_menu.css" /> <link rel="stylesheet" type="text/css" href="includes/templates/theme096/css/stylesheet_main.css" /> <link rel="stylesheet" type="text/css" href="includes/templates/theme096/css/stylesheet_mainold.css" /> <link rel="stylesheet" type="text/css" href="includes/templates/theme096/css/stylesheet_tm.css" /> <link rel="stylesheet" type="text/css" href="includes/templates/theme096/css/stylesheet_tm[1].css" /> <link rel="stylesheet" type="text/css" href="includes/templates/theme096/css/stylesheetold.css" />

These are still being used in your store, even though you have changed their names; if you want to keep backups, save them elsewhere, or change .css to .bak so they are not seen as stylesheets.

You can add an HTML link to the location of the PDF file in the product description. I don't know if something else is needed to make the link open as a PDF since I haven't used them.

20 Mar 2009, 8:07 PM
#3
suehigman avatar

suehigman

New Zenner

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

Re: How do I add fields to a product page?

Thanks Glen. The stylesheets are on my list of cleanup.

I am not sure posting the link in the description would work as sometimes I have several links.

20 Mar 2009, 8:19 PM
#4
gjh42 avatar

gjh42

Black Belt

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

Re: How do I add fields to a product page?

You can put as many links as you want in the description, attached to text or to an image. Each link can only go to one place, but that is always the case, as far as I know.

22 Mar 2009, 4:18 PM
#5
suehigman avatar

suehigman

New Zenner

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

Re: How do I add fields to a product page?

Thank you.

I will keep at it. I just feel that populating the data dynamically s the way to go.

Thanks
Sue

22 Mar 2009, 5:55 PM
#6
suehigman avatar

suehigman

New Zenner

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

Re: How do I add fields to a product page?

On another thought....I could populate the links using the Easy Populate correct?

Sue

23 Mar 2009, 4:59 AM
#7
gjh42 avatar

gjh42

Black Belt

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

Re: How do I add fields to a product page?

I suppose that would depend in part on how you want to present the links. I haven't used Easy Populate so can't advise on its abilities.
As part of the description, the links would be handled by Easy Populate; would that qualify as "populate dynamically" for your purposes?

23 Mar 2009, 12:27 PM
#8
suehigman avatar

suehigman

New Zenner

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

Re: How do I add fields to a product page?

Not really.....Basically I created a new table in Zen Cart (zen_product_manual).

All I want to do is call particular fields from this table that equal the model number and display them on tbl_product_info_display page. In the following section:

<!--eof Product details list --> <!--bof Product description --> <?php if ($products_description != '') { ?> <div id="productDescription" class="productGeneral biggerText"><?php echo stripslashes($products_description); ?></div> <?php } ?> <!--eof Product description --> <br class="clearBoth" />

Not sure how to do this.

23 Mar 2009, 1:15 PM
#9
suehigman avatar

suehigman

New Zenner

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

Re: How do I add fields to a product page?

In Coldfusion (the old store) I was able to create this page...

<head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> <cfquery name="getmanual" datasource="eesparts" dbtype="ODBC"> SELECT Distinct Manual, Figure, item, rev, link, Name FROM machine_manuals WHERE productID = '#URL.Product_ID#' ORDER BY Manual, Figure </cfquery> </head> <table border="0"> <tbody> <tr> <td nowrap="nowrap"><font size="1">Manual</font></td> <td nowrap="nowrap"><font size="1">Figure</font></td> <td nowrap="nowrap"><font size="1">Item</font></td> <td nowrap="nowrap"><font size="1">Rev</font></td> <td nowrap="nowrap"><font size="1">Name</font></td> </tr> <cfoutput query="Getmanual"> <tr> <td nowrap="nowrap"><font size="1">#manual#</font></td> <td nowrap="nowrap"><a href="#getmanual.link#"><font size="1">#getmanual.figure#</font></a></td> <td nowrap="nowrap"><a href="#getmanual.link#"><font size="1">#getmanual.item#</font></a></td> <td nowrap="nowrap"><font size="1">#getmanual.name#</font></td> </tr></cfoutput> </tbody> </table> <body> </body> </html>

Then in the admin section of the store under the product description I just called <p>%manual%</p.

So in ZenCart (new store), I have set up the same back end

  1. uploaded the pdf files
  2. created the table

the piece I am trying to learn is how does PHP/Zen Cart query the table? then display the variables

Sue

23 Mar 2009, 2:25 PM
#10
gjh42 avatar

gjh42

Black Belt

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

Re: How do I add fields to a product page?

You didn't say that you already had the data in a ZC table. That does change the answer considerably.
You can't use PHP directly in a product description, but there is a way to replace a placeholder in a description with PHP or other code processed at runtime. This could get the fields and insert them as desired.

You would not use a whole HTML document (NO <head> etc., only formatting tags); you could add the HTML and the PHP/ MySQL query to the description output area in /includes/templates/your_template/templates/tpl_product_info_display.php, or you could make a file named something like manual_call.php with the code and include that at this point.
There is a thread about adding boilerplate to product descriptions, with link to blog posts that give detailed info.

The query would be very similar to your cfquery. I suggest looking at some queries in Zen Cart files to see the details of how they should be set up.

23 Mar 2009, 2:50 PM
#11
suehigman avatar

suehigman

New Zenner

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

Re: How do I add fields to a product page?

Glen! Thank You!

I believe that is what I need. Is it over my head? yes, but I will get there.

I am so close...

Thanks again Sue

23 Mar 2009, 4:12 PM
#12
suehigman avatar

suehigman

New Zenner

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

Re: How do I add fields to a product page?

I am back with a question.

if I have a template that i am using and the instructions call for me to create a custom directory....under which directory to implement it

  1. includes/templates/custom/templates/tpl_product_info_display.php

or

  1. includes/templates/theme096/custom/templates/tbl_product_info_display.php

also...doesn't custom have to be in capital letters?

Sue

23 Mar 2009, 4:18 PM
#13
gjh42 avatar

gjh42

Black Belt

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

Re: How do I add fields to a product page?

If your template's foldername is /theme096/, that is what you would use. The "CUSTOM" is simply a convention to indicate a generic name that should be replaced by your own name. All lowercase is generally best, as it avoids capitalization errors, and some processes are case sensitive. You should have

/includes/templates/theme096/templates/tpl_product_info_display.php

23 Mar 2009, 7:02 PM
#14
suehigman avatar

suehigman

New Zenner

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

Re: How do I add fields to a product page?

I am back hopefully for the last time. I have followed the instructions and even tweeked it so it will call the php include from the product description.

Now I am attempting to write a manualcall.php file that will display the records.

If someone has a moment can you tell me if I headed in the right direction??? Be kind this is my first php fil.....and maybe my last ;)

<? // Connect database include("connectdb.php"); // Get all records in all columns from table and put it in $result. $result=mysql_query("select Manual, Figure, Item, rev, link, Name from zen_products_manuals where itemnumber = v_products_model Order By Manual, Figure"); /*Split records in $result by table rows and put them in $row. Make it looping by while statement. */ while($row=mysql_fetch_assoc($result)){ </head> <body> <table border="0"> <tbody> <tr> <td nowrap="nowrap"><font size="1">Manual</font></td> <td nowrap="nowrap"><font size="1">Figure</font></td> <td nowrap="nowrap"><font size="1">Item</font></td> <td nowrap="nowrap"><font size="1">Rev</font></td> <td nowrap="nowrap"><font size="1">Name</font></td> </tr> <cfoutput query="Getmanual"> <tr> <td nowrap="nowrap"><font size="1"><?php echo $row['manual']; ?>"</font></td>
        <td nowrap="nowrap"><?php echo $row['figure']; ?>"<a href="#getmanual.link#"><font size="1">#getmanual.figure#</font></a></td>
		<td nowrap="nowrap"><?php echo $row['item']; ?>"<a href="#getmanual.link#"><font size="1">#getmanual.item#</font></a></td>
        <td nowrap="nowrap"><font size="1"><?php echo $row['name']; ?>"</font></td>
    </tr></cfoutput>
</tbody>
</table> </body> </html>

I do need to wrap an a href around the variable Figure (as it is a hyperlink in the table).

Sue

23 Mar 2009, 8:05 PM
#15
gjh42 avatar

gjh42

Black Belt

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

Re: How do I add fields to a product page?

Not a MySQL expert, so I won't try to advise on the query, but I do have a few comments on the file you posted.

Get rid of items in red.

<? // Connect database include("connectdb.php"); //You shouldn't need to specifically connect to the db // Get all records in all columns from table and put it in $result. //use the zen db functions which are specifically built to handle the queries in ZC. $result=mysql_query("select Manual, Figure, Item, rev, link, Name from zen_products_manuals where itemnumber = v_products_model Order By Manual, Figure"); /*Split records in $result by table rows and put them in $row. Make it looping by while statement. */ while($row==mysql_fetch_assoc($result)){ //== is the test; = is assignment </head> <body> <table border="0"> <tbody> <tr> //use <th> for the heading row <th nowrap="nowrap"><font size="1">Manual</font></th> //you don't need to put font tags everywhere - this is officially deprecated. Use the stylesheet to set sizes, fonts etc. <td nowrap="nowrap"><font size="1">Figure</font></td> <td nowrap="nowrap"><font size="1">Item</font></td> <td nowrap="nowrap"><font size="1">Rev</font></td> <td nowrap="nowrap"><font size="1">Name</font></td> </tr> <cfoutput query="Getmanual"> //this is not going to do anything in PHP <tr> <td nowrap="nowrap"><font size="1"><?php echo $row['manual']; ?>"</font></td> <td nowrap="nowrap"><?php echo $row['figure']; ?>"<a href="#getmanual.link#"><font size="1">#getmanual.figure#</font></a></td> <td nowrap="nowrap"><?php echo $row['item']; ?>"<a href="#getmanual.link#"><font size="1">#getmanual.item#</font></a></td> <td nowrap="nowrap"><font size="1"><?php echo $row['name']; ?>"</font></td> </tr></cfoutput> </tbody> </table> </body> </html>

There are too many different things here to show comprehensibly in one file listing.
Getting rid of the bad HTML tags and PHP include first (also moving <table> tags outside of loop):```php

<?php //it is recommended to always use the full <?php opening, not the shorthand <? // Connect database //include("connectdb.php"); // Get all records in all columns from table and put it in $result. $result=mysql_query("select Manual, Figure, Item, rev, link, Name from zen_products_manuals where itemnumber = v_products_model Order By Manual, Figure"); /*Split records in $result by table rows and put them in $row. Make it looping by while statement. */ // close PHP before outputting HTML, or else use PHP echo statement // echo '<table border="0"><tbody>'; ?> <table border="0"> <tbody> <tr> <th nowrap="nowrap">Manual</th> <th nowrap="nowrap">Figure</th> <th nowrap="nowrap">Item</th> <th nowrap="nowrap">Rev</th> <th nowrap="nowrap">Name</th> </tr> <?php while($row=mysql_fetch_assoc($result)){ //while may not be best kind of loop - foreach is made for stepping through arrays ?> <tr> <td nowrap="nowrap"><?php echo $row['manual']; ?></td> <!-- these #getmanual.link# will need to be replaced with PHP statements --> <td nowrap="nowrap"><?php echo $row['figure']; ?>"<a href="#getmanual.link#">#getmanual.figure#</a></td> <td nowrap="nowrap"><?php echo $row['item']; ?>"<a href="#getmanual.link#">#getmanual.item#</a></td> <td nowrap="nowrap"><?php echo $row['name']; ?></td> </tr> <?php } //end of while loop ?> </tbody> </table> ```
24 Mar 2009, 6:21 PM
#16
suehigman avatar

suehigman

New Zenner

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

Re: How do I add fields to a product page?

ok...I am back..I am still very close but also close to saying the hell with it it :)

3 things to resolve

  1. I was able to write the query
<?php //it is recommended to always use the full <?php opening, not the shorthand <? // Get all records in all columns from table and put it in $result. $query="select Manual, Figure, Item, rev, link, Name from zen_product_manuals where itemnumber = '6630206' Order By Manual, Figure"; $result=mysql_query($query) or die(mysql_error()); ?>

and it works but I want to be able to replace the hard coded '6630206' with the actual products_model or products_id from the zen_products table.
How does PHP handle url variables. In coldfusion I would write something like the following
<cfquery name="getmanual" datasource="eesparts" dbtype="ODBC">
SELECT Distinct Manual, Figure, item, rev, link, Name
FROM powerscreen_machines
WHERE productID = '#URL.Product_ID#'
ORDER BY Manual, Figure
</cfquery>

  1. With the help of Glen he was able to teach me a bit of PHP templates. So with this template the header rows appear and the correct amount of rows or recordcount outputs but there is no data...see the example
    http://emeraldspares.com/products/index.php?main_page=product_info&cPath=11_67&products_id=3373

and the php

<?php //it is recommended to always use the full <?php opening, not the shorthand <? // Get all records in all columns from table and put it in $result. $query="select Manual, Figure, Item, rev, link, Name from zen_product_manuals where itemnumber = '6630206' Order By Manual, Figure"; $result=mysql_query($query) or die(mysql_error()); ?> <table border="0"> <tbody> <tr> <th nowrap="nowrap">Manual</th> <th nowrap="nowrap">Figure</th> <th nowrap="nowrap">Item</th> <th nowrap="nowrap">Rev</th> <th nowrap="nowrap">Name</th> </tr> <?php while($row=mysql_fetch_array($result)){ //while may not be best kind of loop - foreach is made for stepping through arrays ?> <tr> <td nowrap="nowrap"><?php echo $row['manual']; ?></td> <!-- these #getmanual.link# will need to be replaced with PHP statements --> <td nowrap="nowrap"><?php echo $row['figure']; ?>"<a href="#getmanual.link#">#getmanual.figure#</a></td> <td nowrap="nowrap"><?php echo $row['item']; ?>"<a href="#getmanual.link#">#getmanual.item#</a></td> <td nowrap="nowrap"><?php echo $row['name']; ?></td> </tr> <?php } //end of while loop ?> </tbody> </table>

3 and last how do I wrap an ahref around an echo row so it would be something like

?php echo $row['figure']; ?>"<a href="?php echo $row['link'];?>#getmanual.link#">?php echo $row['figure']; ?></a>

Thanks
Sue

25 Mar 2009, 1:09 AM
#17
suehigman avatar

suehigman

New Zenner

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

Re: How do I add fields to a product page?

Yeah!!! With some help, I learned that it was my capital letters. Beginner Mistake!

I just need to understand how I can call the products_model or products_id from the where statement of my query.

Basically my #1.

Sue

25 Mar 2009, 1:35 AM
#18
suehigman avatar

suehigman

New Zenner

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

Re: How do I add fields to a product page?

I got it thanks!!!!

it was and correct me if I am wrong...

itemnumber = $products_model

Sue

25 Mar 2009, 4:19 PM
#19
gjh42 avatar

gjh42

Black Belt

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

Re: How do I add fields to a product page?

Yes, I believe MySQL uses one = in this situation; PHP would use == to test equality. One = in PHP would set $itemnumber to the value of $products_model, no matter what.

You need to refine the "while" - it is not going to test correctly and needs to increment the counter.

while($row==mysql_fetch_array($result)){

This will actually test $row against mysql_fetch_array($result); but how are you assigning values to $row in the first place?
$row=mysql_fetch_array($result) will do the assignment, but does not belong in a while test area. You need to assign it first, then run an appropriate test.

Look at some while loops in ZC files for a handle on how they work in the ZC context.
And again, a foreach() may work better than a while() here. Have you looked at the PHP references in https://www.w3schools.com?