Forums / Templates, Stylesheets, Page Layout / Help a newbie install a piece of javascript with product vars on a product page

Help a newbie install a piece of javascript with product vars on a product page

Started by jhkaplan on 30 Apr 2012, 8:01 PM · Views: 3,420

Results 1 to 19 of 19
30 Apr 2012, 8:01 PM
#1
jhkaplan avatar

jhkaplan

New Zenner

Join Date:
Nov 2010
Posts:
9
Plugin Contributions:
0

Help a newbie install a piece of javascript with product vars on a product page

Hi all,

I'm trying to install a piece of javascript on a client's ZC store. We don't do webdev, we're a 3rd party working with them to get this installed so I don't have any experience designing/customizing Zencart stores.

This js needs to go in a specific area of the product page and needs to be installed on every product page. I'm guessing I enter this in the template product_info_display.php file? They're using theme360 if that helps. I don't know PHP very well so I'm not sure exactly where to place this.

Additionally, the js needs to have product page variables/template tags inserted into it. These vars include: brand/manufacturer, part number, price, title. Where can I find these template tags/vars? Is there a wiki or some documentation with a list somewhere?

I appreciate any and all help! I'm digging around in a lot of these php files but am really unsure where everything goes. Placement of this script is key and I dont want to break anything.

Thanks!

jhkaplan

30 Apr 2012, 8:35 PM
#2
schoolboy avatar

schoolboy

Totally Zenned

Join Date:
Jun 2005
Location:
Cumbria, UK
Posts:
10,327
Plugin Contributions:
0

Re: Help a newbie install a piece of javascript with product vars on a product page

It sounds like a lot of what you want to appear can be handled by standard functionality, switched on or off in various places in the admin panel.

These will not be "template" issues, because the stuff you want to appear is MOSTLY resident in the database.

But you are trying to build a Cessna out of a 747...

Just configure the admin switches and you will have all the data you need.

Additionally, "Theme360" sounds like a template monster template, and these are HUGELY PROBLEMATIC in their own right. As they are highly customised, you may struggle to get help on this forum. They can wreck core behaviour.

20 years a Zencart User

30 Apr 2012, 8:45 PM
#3
jhkaplan avatar

jhkaplan

New Zenner

Join Date:
Nov 2010
Posts:
9
Plugin Contributions:
0

Re: Help a newbie install a piece of javascript with product vars on a product page

schoolboy:

It sounds like a lot of what you want to appear can be handled by standard functionality, switched on or off in various places in the admin panel.

These will not be "template" issues, because the stuff you want to appear is MOSTLY resident in the database.

But you are trying to build a Cessna out of a 747...

Just configure the admin switches and you will have all the data you need.

Additionally, "Theme360" sounds like a template monster template, and these are HUGELY PROBLEMATIC in their own right. As they are highly customised, you may struggle to get help on this forum. They can wreck core behaviour.

Thanks. Again, I'm pretty new to ZenCart, so I dont understand what you mean by 'switched on or off in various places in the admin panel.'. I need to insert the JS on product pages and update the JS with product vars so we can dynamically display an image based on a True/False statement from what the vars pass back to us.

1 May 2012, 7:34 AM
#4
gjh42 avatar

gjh42

Black Belt

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

Re: Help a newbie install a piece of javascript with product vars on a product page

Are these product variables going to change dynamically for a single product? If so, how and why would they change? If they do not change while the user is viewing the product, there is no need for javascript.
We really need more specific info before we can give accurate advice.

1 May 2012, 7:59 AM
#5
schoolboy avatar

schoolboy

Totally Zenned

Join Date:
Jun 2005
Location:
Cumbria, UK
Posts:
10,327
Plugin Contributions:
0

Re: Help a newbie install a piece of javascript with product vars on a product page

jhkaplan:

Thanks. Again, I'm pretty new to ZenCart, so I dont understand what you mean by 'switched on or off in various places in the admin panel.'.

This is an EXTREMELY GOOD REASON why you should not be fooling about with the core code. It is like a bus driver attempting heart surgery.

Before you look at very complex issues such as dynamic rendering, using JS, and possibly custom coded calls to the database, start by learning how zencart works on a user level.

It would appear that you have scant knowledge of CMS systems, because you don't seem to know that ZC operates off a database (your focus is on using JS to collect info from FILES).

I am not criticising you for your lack of knowledge, but the person you are trying to help would not be very impressed if they were in lying a hospital operating theatre, and a bus driver was wielding the scalpel.

20 years a Zencart User

1 May 2012, 2:11 PM
#6
jhkaplan avatar

jhkaplan

New Zenner

Join Date:
Nov 2010
Posts:
9
Plugin Contributions:
0

Re: Help a newbie install a piece of javascript with product vars on a product page

schoolboy:

This is an EXTREMELY GOOD REASON why you should not be fooling about with the core code. It is like a bus driver attempting heart surgery.

Before you look at very complex issues such as dynamic rendering, using JS, and possibly custom coded calls to the database, start by learning how zencart works on a user level.

It would appear that you have scant knowledge of CMS systems, because you don't seem to know that ZC operates off a database (your focus is on using JS to collect info from FILES).

I am not criticising you for your lack of knowledge, but the person you are trying to help would not be very impressed if they were in lying a hospital operating theatre, and a bus driver was wielding the scalpel.

Maybe I'm not explaining it correctly, but most of what you said above is wrong. But if you're not here to help, please move on. I'm looking for constructive help, not to be told I dont belong.

1 May 2012, 2:16 PM
#7
jhkaplan avatar

jhkaplan

New Zenner

Join Date:
Nov 2010
Posts:
9
Plugin Contributions:
0

Re: Help a newbie install a piece of javascript with product vars on a product page

gjh42:

Are these product variables going to change dynamically for a single product? If so, how and why would they change? If they do not change while the user is viewing the product, there is no need for javascript.
We really need more specific info before we can give accurate advice.

No, we're just using the js var collection to collect the product fields (ie brand, part number). Forget I said the word dynamic; something else about what the script displays is dynamic, but it's based off of the collection of the brand and part number variables. IE if brand=sony then display this image, if brand=panasonic then display this image. We're just using the collection of the brand and MPN as pieces of an equation, calculated on our end, to dynamically display an image on the product page.

The piece of the script I'm working on looks like this:

// * Product Page Fields //
'Brand' : 'XXXXX',
'MPN' : 'XXXXX',

The XXXX would be replaced by the CMS vars. In other systems I've worked with, it's something like [brand] or [manufacturer_sku]. I'm new to the Zencart world and am trying to figure out what these variables are. I'll have to work with ZC multiple times this year (as well as 10,000 other CMS's for the same type of implementation), so I'm trying to collect as much knowledge as I can to get the implementation figured out.

Thanks for your help!

1 May 2012, 2:17 PM
#8
gjh42 avatar

gjh42

Black Belt

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

Re: Help a newbie install a piece of javascript with product vars on a product page

Then please explain your needs in more detail so we can actually help you.
OK, you just did:)

1 May 2012, 2:25 PM
#9
gjh42 avatar

gjh42

Black Belt

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

Re: Help a newbie install a piece of javascript with product vars on a product page

From your description, you have no need of javascript for this. What you want will either be part of the core Zen Cart functionality (displaying a product image), available in a free addon from Plugins or require some PHP (not js) code tweaking in a file. You will enter all this product information into your admin in Catalog > Categories/Products and other places, and set admin switches in (for example) Configuration > Product Listing for the multiple product listing page and Configuration > Layout Settings for the individual product page.

1 May 2012, 2:30 PM
#10
gjh42 avatar

gjh42

Black Belt

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

Re: Help a newbie install a piece of javascript with product vars on a product page

In tpl_product_info_display.php, the variable that holds the product's model number is $products_model. The brand would be $manufacturers_name.
There will be different variable names for these in some other pages like product listing, and some pages would not have the information readily available (if the page does not handle products).

1 May 2012, 2:35 PM
#11
jhkaplan avatar

jhkaplan

New Zenner

Join Date:
Nov 2010
Posts:
9
Plugin Contributions:
0

Re: Help a newbie install a piece of javascript with product vars on a product page

gjh42:

In tpl_product_info_display.php, the variable that holds the product's model number is $products_model. The brand would be $manufacturers_name.
There will be different variable names for these in some other pages like product listing, and some pages would not have the information readily available (if the page does not handle products).

Perfect, exactly what i was looking for. Is there a list anywhere of all the product page variables? The ones I need are:
Brand (check)
Part Number (check)
Product Name
Product Sale Price
Condition

Not all are required, but they'd be nice to have.

Thank you again for your help gjh!

1 May 2012, 3:03 PM
#12
gjh42 avatar

gjh42

Black Belt

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

Re: Help a newbie install a piece of javascript with product vars on a product page

Just look through tpl_product_info_display.php - most of the product variables there are remarkably intuitive.
"Condition" is not a standard Zen Cart database field or variable, so if you want that for every product you will need to do some serious modification. You might be able to hijack some other text field that you will not be using to carry the condition information.

The sale price is embedded in some very complex coding called with the zen_get_products_display_price() function, as it can depend on several other conditions as to what displays. There may be a function that can be used to retrieve just the sale price; if so, it would probably be found in /includes/functions/functions_lookups.php. DO NOT edit anything in that file!

I still think you are reinventing the wheel with what you are probably doing. Javascript is not the right way to handle basic page functionality; it can and should all be done with PHP.

1 May 2012, 3:32 PM
#13
fairestcape avatar

fairestcape

Totally Zenned

Join Date:
Mar 2008
Location:
Cape Town & London (depends on the season)
Posts:
2,957
Plugin Contributions:
0

Re: Help a newbie install a piece of javascript with product vars on a product page

gjh42:

I still think you are reinventing the wheel with what you are probably doing. Javascript is not the right way to handle basic page functionality; it can and should all be done with PHP.

I must agree with Glenn... I can't see what you are trying to achieve with all of this, that isn't already available to you - unless of course you are intending to use the ZC "engine" for different purposes from what it was intended.

The variables you have listed (with the exception of a few that are not part of the core Dbase schema) are ALREADY all possible to render in a product info page (and in many other places), and you have the "luxury" of being able to "switch" the majority of these on or off, via simple toggles in the webshop admin area. There are several HUNDRED configurable options available to you - either through these admin area switches, or via some very simple edits to existing php files.

So just WHY you are trying to re-invent the wheel is a puzzle.

But... you are free to make whatever changes you wish. It is OpenSource software afterall.

If you download a copy of the software and look in the zc_install folder, open the MAIN SQL file in a plain text editor, and you will see ALL the dbase tables and ALL the fields. This will give you an overview of what tables carry the variables you are after.

As Glenn says, JS is not the way to manage this... You should code your customisations in PHP.

1 May 2012, 3:42 PM
#14
schoolboy avatar

schoolboy

Totally Zenned

Join Date:
Jun 2005
Location:
Cumbria, UK
Posts:
10,327
Plugin Contributions:
0

Re: Help a newbie install a piece of javascript with product vars on a product page

jhkaplan:

Maybe I'm not explaining it correctly, but most of what you said above is wrong. But if you're not here to help, please move on. I'm looking for constructive help, not to be told I dont belong.

Everybody is welcome here, and I don't recall saying "you don't belong".

You said: "I'm pretty new to ZenCart, so I dont understand what you mean by 'switched on or off in various places in the admin panel."

... which to me is quite a direct admission that you do not know what you are doing (with Zencart).

My comments are frank, I admit, and I do not wish to offend, but if you have not even botherd to examine the user functions available to you, through an interface that a complete non-tecchie could understand, then one must assume you don't know how this system works.

So I do apologise if you took offence... but I still recommend you take some time to at least learn the basics of the admin area. To me that is fundamental of you intend to inflict (probably unneccessary) changes on the code.

20 years a Zencart User

1 May 2012, 3:45 PM
#15
jhkaplan avatar

jhkaplan

New Zenner

Join Date:
Nov 2010
Posts:
9
Plugin Contributions:
0

Re: Help a newbie install a piece of javascript with product vars on a product page

schoolboy:

Everybody is welcome here, and I don't recall saying "you don't belong".

You said: "I'm pretty new to ZenCart, so I dont understand what you mean by 'switched on or off in various places in the admin panel."

... which to me is quite a direct admission that you do not know what you are doing (with Zencart).

My comments are frank, I admit, and I do not wish to offend, but if you have not even botherd to examine the user functions available to you, through an interface that a complete non-tecchie could understand, then one must assume you don't know how this system works.

So I do apologise if you took offence... but I still recommend you take some time to at least learn the basics of the admin area. To me that is fundamental of you intend to inflict (probably unneccessary) changes on the code.

I did see how to turn vars on/off in the admin, and knew immediately this is not what i was looking to do. I didnt take offense, i just hate internet commentors who waste time by not helping when someone asks for help, that's all.

1 May 2012, 4:07 PM
#16
jhkaplan avatar

jhkaplan

New Zenner

Join Date:
Nov 2010
Posts:
9
Plugin Contributions:
0

Re: Help a newbie install a piece of javascript with product vars on a product page

Ok let's forget about the javascript part of it, I think it's throwing everyone off. If I were to just want to create a 'box' that had a list of all the product attributes I mentioned (brand, partnumber, price), what would that code look like? All i need is the text values, no styling, no borders, nothing.

In the PHP file, what is the minimum i'd need to get those 3 values to show up?

1 May 2012, 4:11 PM
#17
gjh42 avatar

gjh42

Black Belt

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

Re: Help a newbie install a piece of javascript with product vars on a product page

Sometimes what a question really needs is a swift kick and "you shouldn't be doing that, or doing it in that way", not enabling a wrong path.

From your PM, I see that you are trying to make some sort of "verified by" badge which is typically done with js. I should really have insisted on your explaining the actual business reason/result you wanted rather than just the detail of what variable you wanted to pick up; then we all would have understood what you were after.

Apparently this badge includes the display of the product name, model, brand, etc., though I don't see how or where from the demo you showed me.
Javascript does not import PHP variables directly. If you want to use the value of a PHP variable in js, you need to echo the variable.

// * Product Page Fields //
'Brand' : '$manufacturers_name',
'MPN' : '$products_model',
//'RetailerSKU' : '',
'ProductName' : '$products_name',
//'ProductPrice' : 'XXXXX',
//'Condition' : 'XXXXX',
//'StockStatus' : 'XXXXX'
}});

</script>

needs to be like

// * Product Page Fields //
'Brand' : '<?php echo $manufacturers_name;?>',
'MPN' : '<?php echo $products_model;?>',
//'RetailerSKU' : '',
'ProductName' : '<?php echo $products_name;?>',
//'ProductPrice' : 'XXXXX',
//'Condition' : 'XXXXX',
//'StockStatus' : 'XXXXX'
}});

</script>
1 May 2012, 4:18 PM
#18
jhkaplan avatar

jhkaplan

New Zenner

Join Date:
Nov 2010
Posts:
9
Plugin Contributions:
0

Re: Help a newbie install a piece of javascript with product vars on a product page

You rock, that solved it. Thank you so much!

1 May 2012, 4:35 PM
#19
gjh42 avatar

gjh42

Black Belt

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

Re: Help a newbie install a piece of javascript with product vars on a product page

I see now what you are doing... you are pulling all of the technical info from the manufacturer's website and displaying it in tabs instead of saving it directly in your database and displaying it from there.