Zen Cart custom software development, Zen Cart modules, Zen Cart Expert eCommerce with Zen Cart!

Zen Cart Default Attribute

Zen Cart Default Attribute

A Zen Cart™ mod which allows single valued defaultable attributes (such as PDF-only downloads) can be added directly from a listing page, rather than from the product_info page only. This means your customers can add these products from the search page, category listing page, featured products page, or the new and all products pages.

Donate: This is free software. Show your appreciation by supporting my efforts. Donate

Relevance: Zen Cart™ 1.5.5 - 1.5.6 only. This feature is built in to Zen Cart 1.5.7+

Current Version: 1.2 (version history)

Support Thread: Default Attribute Support Thread

Cost: Free, but donation appreciated

Installed Cost: $200.00 Buy Professional Installation by That Software Guy

Installation Difficulty: Moderate to High

Installation Instructions: click here for installation instructions

Location: Zen Cart Plugins, under Template Alterations

Download: Default Attribute in Zen Cart Plugins

Add-Ons: Coming soon: interoperability with my Zen Cart mods that facilitate adding products to the cart:
FAQ: click here for FAQs

See it Live: Go to the document category my demo2 store. You will notice that the PDF document (product 180) can be added to the cart, even though it has an attribute (since it's a downloadable product).


Overview:

In a stock Zen Cart install, products which have attributes - even if these attributes have only one value, such as a single download attribute - may not be added from the listing page. This mod permits you to overcome this restriction.

So that instead of seeing this:
Zen Cart without Default Attribute

Your customers see this:
Zen Cart with Default Attribute

Installation Instructions:



  1. Back up everything! Try this in a test environment prior to installing it on a live shop.
  2. Use the 1.5.5 or 1.5.6 folder, depending on your cart version.
  3. Rename the responsive_classic directory (under includes/modules) to the name of your template directory. Merge template and core file changes if needed.
  4. Copy the files to your cart's top level directory.
  5. Make the following changes to includes/classes/shopping_cart.php:

    - In function actionBuyNow, change
          if (zen_has_product_attributes($_GET['products_id'])) {
    
    to
          if (zen_requires_attribute_selection($_GET['products_id'])) {
    
    - In function add_cart, below display_debug_messages add
        if (zen_has_product_attributes($products_id, 'false') && empty($attributes)) {
          if (!zen_requires_attribute_selection($products_id)) {
            // Build attributes array; determine correct qty
            $attributes = array();
            $query = $db->Execute("SELECT options_id, options_values_id FROM " . TABLE_PRODUCTS_ATTRIBUTES . " WHERE products_id = " . (int)$products_id); 
            foreach ($query as $attr_rec) {
              $attributes[$attr_rec['options_id']] = $attr_rec['options_values_id']; 
            }
            $qty += $this->in_cart_product_total_quantity($products_id); 
          }
        }
    
  6. Be sure you have the setting Admin > Configuration > Product Listing > Display Product Add to Cart Button set to 1 or 2.

Major Versions

  • 1.2 07/05/2020 - Corrected install instructions.
  • 1.1a 08/15/2019 - Simplified 1.5.5 install
  • 1.1 08/12/2019 - Updates for 1.5.5f and 1.5.6.
  • 1.0a 09/12/2016 - Fix for adding multiple products on listing page
  • 1.0 07/15/2016 - First Release

FAQ

Q: What do you mean by "defaultable attributes" or "single valued defaultable attributes?"
A: The two terms mean the same thing. They're just attributes for which a default value can be selected without needing input from the product info page. "Single valued" means the attribute has just one value. For example, a radio button with just one value (such as "PDF" or "ZIP file") is single valued. A radio button with two values (such as "red" or "green") would not be single valued. Similarly, "defaultable" means the single value can be easily set without needing additional input. For example, product with a single TEXT attribute would be single valued but not defaultable, since it's not known what the correct value would be. Similarly, a product requiring a file upload would not be defaultable.

Note that in order to take advantage of defaultable attributes, you need my Default Attribute contribution if your Zen Cart version is lower than 1.5.7. (It has been built in since Zen Cart 1.5.7.)

Q: Does this feature work without needing a plugin in Zen Cart 1.5.7?
A: Yes, but note that in Zen Cart 1.5.7, the following patch from Zen Cart 1.5.7a is required: Pull Request 3629