Forums / Templates, Stylesheets, Page Layout / Use "categories_name" as Variable (query)

Use "categories_name" as Variable (query)

Views: 483

Results 1 to 6 of 6
30 Apr 2014, 6:10 PM
#1
kenbaker avatar

kenbaker

New Zenner

Join Date:
Dec 2012
Posts:
66
Plugin Contributions:
0

Use "categories_name" as Variable (query)

Asking about variables:

A couple months ago, I began using an includes statement to incorporate boilerplate into my product descriptions. I first began using the statement (incorporated into my tpl_product_info_display.php file) with boilerplate specific to individual manufacturers, so I used the manufacturers_name db field to specify the exact boilerplate that should be loaded, thus:

<?php include ('includes/partners/' . $manufacturers_name . '/' . $manufacturers_name . '-boilerplate.php'); ?>

So far this has worked well: If there's a boilerplate file, the server configures it into the product description; if not, the server just ignores this line of code and proceeds merrily along.

Now, I've come to realize that I could use the same approach to great advantage for boilerplate related to specific categories rather than specific manufacturers, so I tried adding this line of code to my product info display:

<?php include ('includes/partners/' . $manufacturers_name . '/' . $categories_id . '-boilerplate.php'); ?>

It doesn't work, though, I strongly suspect because I haven't properly defined the $categories_id variable. (When I inserted the code for manufacturer boilerplate, I assume that — just by dumb luck — I chose a variable that had already been defined.) I've muddled about for a couple weeks trying to get the second line of code (for categories boilerplate) to work, so far with no luck. I have tried instead using category names as the file variable, as I noticed that the functions_lookups.php included a zen_get_categories_name function, but with no better luck.

If there's a guide for managing this variable definition task, and someone could point me to it, I would be grateful. If on the other hand this is a customization task that really needs to be handled by a professional programmer, I would appreciate knowing that as well. Sometimes it's not clear when I should recognize that a programming task is beyond me.

Thanks,

Ken Baker

30 Apr 2014, 6:21 PM
#2
drbyte avatar

drbyte

Sensei

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

Re: Use "categories_name" as Variable (query)

You can use $current_category_id if you want just the number, or use $cPath if you want the whole tree.

$cPath = '3_10_49'
or in that case this would be true as well:
$current_category_id = '49'

.
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.

30 Apr 2014, 6:28 PM
#3
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,119
Plugin Contributions:
56

Re: Use "categories_name" as Variable (query)

Per DrByte's advice, try using the following:

<?php include ('includes/partners/' . $manufacturers_name . '/' . $current_category_id . '-boilerplate.php'); ?>
30 Apr 2014, 8:39 PM
#4
kenbaker avatar

kenbaker

New Zenner

Join Date:
Dec 2012
Posts:
66
Plugin Contributions:
0

Re: Use "categories_name" as Variable (query)

DrByte,

Works like a charm! In case you're interested in the practical result, I'll share this link to my first page using this new functionality:

http://lunekeltkar.com/catalog/index.php?main_page=product_info&cPath=27_34_45_262_46&products_id=145

As you look at this page, the header, footer, and left and right columns are all rendered via the standard ZC files (with some slight style tweaking). The center division, though, comes from a number of varying sources. Beginning at the top of the column:

  • the breadcrumbs and previous/next block come from the ZC templates;
  • the "Take especial note!" banner comes from an include statement in the tpl_product_info_display.php file (henceforth TPID file);
  • the product image, name, and price come from the ZC templates;
  • the "KeyLinks" come from another include statement in the TPID file;
  • the first paragraph of the product description and the "LookSee Links" come from the database record (product_description);
  • the second and third paragraphs of the product description comes from another include statement in the TPID file (the category boilerplate that you just helped me manage);
  • the last paragraph of the product description (boxed) comes from another include statement in the TPID file (the manufacturer boilerplate; some boilerplate is more involved);
  • the order block comes from the ZC templates;
  • the "Almond Primer" comes from an HTML_A_INCLUDE statement in the database record (product_description), made possible with that gem of an addon Product Articles (I've been working that little guy plumb to death lately); and
  • the social media links come from the ZC templates.
    I'm modestly pleased with the way that my product pages are beginning to shape up, especially the way that they're (finally!) starting to look as though someone with half a brain designed them. I'm afraid that I made quite a mess of them there for a while. I'm also quite pleased that I've been able to manage so much while knowing so little about php programming. I mention this latter as a testament to the design and operation of ZenCart, not to my coding skills (amateurish at best). I don't know your exact role, but clearly you're a Big Guy in some fundamental way. In case you don't hear it enough, the ZC program is really quite exquisite, in that if I give any aspect of it just a bit of time, study, and tinkering, it'll open itself up. Even dead ends (such as my two-week effort to solve the categories_id thing) can be quite lively. And as a last resort, asking questions always gets answers.

Thanks,

Ken Baker

.

30 Apr 2014, 8:47 PM
#5
kenbaker avatar

kenbaker

New Zenner

Join Date:
Dec 2012
Posts:
66
Plugin Contributions:
0

Re: Use "categories_name" as Variable (query)

Hi lat9,

Yep, that worked like Balin in Moria, after one little glitch. I typed in the code "exactly" as you presented it, but it still didn't work. After some head-scratching and perhaps just a bit of unseemly language, I discovered that I had typed "categories" for "category". I really should get in the copy-paste habit.

Appreciate the help,

Ken Baker

1 May 2014, 12:14 PM
#6
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,119
Plugin Contributions:
56

Re: Use "categories_name" as Variable (query)

Yes, cut&paste can be your friend! Nice site, too.