Category Issues in Zen Cart Mods

This page describes category problems you can encounter when using the following Zen Cart mods: If you're unsure about discounting mods and which one to use for your particular need, please refer to the Zen Cart Matrix-o-discounts.

Discounting Mods (and other mods) using categories

Mod Category Functions
Quantity Discounts Discount Basis Total by Category, user exits exclude_category() or apply_special_category_discount()
Better Together Linkages add_prod_to_cat(), add_cat_to_prod(), add_cat_to_cat() or add_twoforone_cat()
Combination Discounts Linkages using CAT
Big Spender Constraints or discounts using CAT
Big Chooser Constraints or discounts using CAT
Gift Wrap at Checkout User exits exclude_category() or apply_category_wrap_surcharge()
Newsletter Discount user exit exclude_category()
Impulse Buy Constraints using CAT
Auto Add Triggers or auto_adds using CAT
Table Discounts Constraints using CAT


Category Handling in Discount Mods

Determining a product's category in Zen Cart can be confusing. Products are initially created in one category, but can be "linked" to other categories. In my mods, the "linked" categories are ignored; products are considered to be in the the parent category in which they were initially created. This value is reflected in a field called "master_categories_id" in the products table, with one such setting per product.

ToolCategory Definition
Quantity Discounts The parent category id, as determined by the master_categories_id field in the products table. Linked Categories are not used.
Better Together Same as Quantity Discounts
Military Discount Same as Quantity Discounts
Newsletter Discounts Same as Quantity Discounts
Combination Discounts The parent category id, as determined by the master_categories_id field in the products table, and all parents of that category. Linked Categories are not used.
Big Spender Same as Combination Discounts
Big Chooser Same as Combination Discounts
Table Discounts Same as Combination Discounts


Category Handling in Other Mods

ToolCategory Definition
Spender AutoCoupon Same as Big Spender.
Chooser AutoCoupon Same as Big Chooser.
Impulse Buy Same as Big Chooser.
Auto Add Same as Big Chooser.


Master Categories are used for Linked Products

References to "category" in the above modules are really references to the master_categories_id field in the products table. For linked products, this will not be the parent category that you see in the breadcrumb when you're looking at the product info page, but rather, the parent category of the original product which was linked. For example, look at this product. You'd think that the parent category was Big Linked, but in fact, it's Drama. To determine the master category used by a product, you can use this query in a phpMyAdmin SQL query window. We'll look at product 16
select master_categories_id
   from products 
   where products_id = 16;
Obviously if your tables have a prefix, you must include this (use "zen_products" if your prefix is "zen_" for instance).

This query, run on the database above, would give you the answer "15". So the the master category for product 16 is 15.

Master Categories set to 0 problem

This is the most common root cause of category problems. Category functions use the master_categories_id field in the products_table. Sometimes databases get messed up and have the master_categories_id in the products table set to 0. To verify whether this is your problem, use the following query in a phpMyAdmin SQL query window:
select p.products_id, p.master_categories_id, s.products_id, s.categories_id
   from products p, products_to_categories s
   where p.products_id = s.products_id 
   and p.master_categories_id = 0;
Obviously if your tables have a prefix, you must include this (use "zen_products p, zen_products_to_categories s" if your prefix is "zen_" for instance).

There is a facility within Zen Cart to fix this problem. Back up your database, then go to Admin -> Tools -> Store Manager, and click on "Reset ALL Products Master Categories ID". Note that this will use the first category id used if you have Linked Products, which may not be what you want; you may need to use phpMyAdmin and fix this problem on a case by case basis if you use Linked Products.

Once you update master categories, you must also run the Products Price Sorter, which is also under Store Manager.

Category Handling in Mods

In all mods, the "category" is the master category. The difference between the free mods and the commercial mods is whether you can chain back up the category list or whether you are restricted to only the direct ancestor.

In the free mods - Better Together, Quantity Discounts, Newsletter Discount, Military Discount and Gift Wrap at Checkout - the "category" that is used is the master category, which will be the parent category for all but linked products. For linked products, it will be the parent category of the original product which was linked. The master category is not the top level category when subcategories are in use.
Men's Clothing 
     |
     ---->  Shirts
            |
            -------> shirt A 
                     shirt B
                     shirt C 
In this example, (assuming no linked products), the parent category of "shirt A" is "Shirts," not "Men's Clothing." "Mens' Clothing" would be considered the top level category.

My commercial mods - Combination Discounts, Big Chooser, Big Spender, Chooser AutoCoupon and Spender AutoCoupon - can use categories at any level, not just direct ancestor (parent) categories. The master category is still used to determine parent category, but you can use the parent of that category as well, all the way back to the top level category.

Men's Clothing (category 3)
     |
     ---->  Shirts (category 5)
     |      |
     |      -------> shirt A 
     |               shirt B
     |               shirt C 
     ---->  Pants (category 6)
     |      |
     |      -------> pants A 
     |               pants B
     |               pants C 
     ---->  Shoes (category 7) 
     |
      --------->  Dress Shoes (category 12) 
     |            |
     |            -------> dress shoes A 
     |                     dress shoes B
     |                     dress shoes C 
      --------->  Casual Shoes (category 18) 
                  |
                  -------> casual shoes A 
                           casual shoes B
                           casual shoes C 

Specifying "Men's Clothing" as a category in one of the commercial mods will include all items in Shirts, Pants and Shoes.

Specifying "Shoes" (CAT 7) as a category will include both dress shoes and casual shoes.

Quantity Discounts can be modified to use top level categories instead of parent categories, but it can only use one level (i.e. either parent or top level); if you need to group by different levels depending on product, you need to use Combination Discounts or Big Chooser.

Here's an example of a situation where parent category and master category are not the same. Consider this list of products, all non-linked:

Men's Clothing (category 3)
     |
     ---->  Shirts (category 5)
     |      |
     |      -------> shirt 10
     |               shirt 11 
     |               shirt 12 
Formal Men's Clothing (category 8)
     |
     ---->  Shirts (category 9)
     |      |
     |      -------> shirt 20
     |               shirt 21 
     |               shirt 22 


If someone wanted to create a linked product out of shirt 20 so that it would display under category 5, it would look like this:

Men's Clothing (category 3) | ----> Shirts (category 5) | | | -------> shirt 10 | shirt 11 | shirt 12 | shirt 20 (linked) Formal Men's Clothing (category 8) | ----> Shirts (category 9) | | | -------> shirt 20 | shirt 21 | shirt 22

Shirt 20 would still only match CAT 9 for Better Together, and CAT 9 or 8 for the commercial mods. The master category - the parent category of the original product id - is the one which is used. CAT 5 and 3 would not match for shirt 20.

How to tell if your stock is organized into subcategories

In the Admin page, go to Catalog -> Categories/Products, and click on the category you're not sure about. If the entries that appear on the next page have file folders to the left of their names, then these are subcategories. If the products are directly below these folders, then these folders are the parent folder numbers you will use for category inclusions, exclusions and special discounts. If what is below these subcategories is more subcategories, continue drilling down until you get to products, and then go back one level. This is the "parent" category.

Marketing Text and Linked Items in Better Together and Friends

If you are using the Marketing text feature in Better Together, Combination Discounts, Big Chooser or Big Spender, and you have linked products in a category that is discounted, you will see misleading marketing text messages when you view those items.

The fix in those modules is done by editing the appropriate marketing file (tpl_better_together_marketing.php, tpl_combination_discounts_marketing.php, tpl_big_chooser_marketing.php or tpl_bigspender_marketing.php).

Look for the line that says
if ($discount->check() > 0) {
Then make two changes:
  1. Insert the following two lines below this line:
         $product_to_categories = $db->Execute("select master_categories_id from " . 
           TABLE_PRODUCTS . " where products_id = '" . (int)$_GET['products_id'] . "'");
         $category = $product_to_categories->fields['master_categories_id'];
    
  2. Change all instances of the string "$current_category_id" to "$category".
This change is not required unless you have linked products in a category which is discounted.

Marketing Text and Linked Items in Quantity Discounts

If you are using the Marketing text feature in Quantity Discounts, and you have linked products in a category that is discounted, and you are using one of the category exits (i.e. exclude_category() or apply_special_category_discount()), you will see misleading marketing text messages when you view those items.

The fix in those modules is done by editing tpl_product_info_display where you put the marketing text logic.

Look for the line that says
if ($discount->check() > 0) {
Then make two changes:
  1. Insert the following two lines below this line:
         $product_to_categories = $db->Execute("select master_categories_id from " . 
           TABLE_PRODUCTS . " where products_id = '" . (int)$_GET['products_id'] . "'");
         $category = $product_to_categories->fields['master_categories_id'];
    
  2. Change all instances of the string "$current_category_id" to "$category".
Of course, you will also need to add logic to the get_*() method you are using from Quantity Discounts to reflect your category exceptions.

This change is not required unless you have linked products in a category which is discounted, and you're discounting in different ways for different categories.

Version issues with Categories

  • You MUST be running Zen Cart 1.3.5 or higher to use category functions in these modules.
  • Is the file includes/classes/shopping_cart.php identical to the copy in the distribution of Zen Cart? Some people have modified this file from an older version of Zen Cart and not merged with more recent changes made by the core team.
  • If you are using Better Together add_twoforone_cat() you must upgrade to Better Together 1.5 or higher, and you must install the language file as is. You may of course edit this file after installation, but do not simply merge your old language file; prior versions had a bad definition which broke add_twoforone_cat(); prior versions also had other inconsistencies and errors.




Certificates of appreciation most welcome!
If the information you learned reading this site is helping your store make more money, please consider making a donation. Thank you!


Want more Zen Cart?     Tips and Tricks     Contributions     Extensions     Custom Software     Newsletter

Terms | Privacy | SiteMap | Newsletter | Contact Me | Contents © 2003-2010 That Software Guy, Inc.
Zen Cart Project Home Page | Zen Cart Forum | Zen Cart™ is © Zen Ventures, LLC.