Results 1 to 7 of 7
  1. #1
    Join Date
    Sep 2009
    Posts
    15
    Plugin Contributions
    0

    Default HOW CAN I AUTO-SELECT SINGLE-ATTRIBUTE CHOICES DURING ADD-TO-CART process?

    I have configured a downloadable product by using product attributes

    So in brief I have just one attribute which is always the same. I have configured my store to show Add to cart -buttons next to the products in the product listing page.

    However, with my downloadable products, add to cart -buttons are not showing. There is just text more information. Can I somehow make the only attribute the default so that zen cart would allow showing the add to cart button also next to my downloadable products?

    My Zen cart version is 1.3.8.

    Thanks in advance!

  2. #2
    Join Date
    Jun 2005
    Location
    Cumbria, UK
    Posts
    10,263
    Plugin Contributions
    3

    Default Re: Add to cart not showing for for downloadable products in the product listing page

    I'm sure this was raised a couple of years ago... but I don't recall if the thread offered a solution...

    Search about a bit... maybe you'll find it.
    20 years a Zencart User

  3. #3
    Join Date
    Sep 2009
    Posts
    15
    Plugin Contributions
    0

    Default Re: Add to cart not showing for for downloadable products in the product listing page

    Well, I found this one:
    http://www.zen-cart.com/forum/showth...t=98641&page=3

    I'm not sure if this is what you ment. This deals with showing the dropdown box next to the product and has a partly working mod. It doesn't fit for the need since it requires quantity box to be showed and that won't work with downloadable products since there's no point in downloading multiple copies of the same pdf for example..

  4. #4
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Add to cart not showing for downloadable products in the product listing page

    Unlike the addon you linked to earlier, the following code changes do NOT add attribute choices to the product listing. Instead, they simply force the cart to add the *only* one single attribute defined for the given product.
    If a product has only ONE attribute, then a buy-now button will appear. If more than one (including choice between DOC vs PDF formats for example), then the default "more info..." will show.

    There are quite a few edits to make:
    /includes/functions/functions_lookups.php
    around line 226, replace the ENTIRE zen_has_product_attributes function declaration with this:
    Code:
    /*
     *  Check if product has attributes
     */
      function zen_has_product_attributes($products_id, $not_readonly = 'true', $returnCount = FALSE) {
        global $db;
    
        if (PRODUCTS_OPTIONS_TYPE_READONLY_IGNORED == '1' and $not_readonly == 'true') {
          // don't include READONLY attributes to determine if attributes must be selected to add to cart
          $attributes_query = "select pa.products_attributes_id
                               from " . TABLE_PRODUCTS_ATTRIBUTES . " pa left join " . TABLE_PRODUCTS_OPTIONS . " po on pa.options_id = po.products_options_id
                               where pa.products_id = '" . (int)$products_id . "' and po.products_options_type != '" . PRODUCTS_OPTIONS_TYPE_READONLY . "'";
        } else {
          // regardless of READONLY attributes no add to cart buttons
          $attributes_query = "select pa.products_attributes_id
                               from " . TABLE_PRODUCTS_ATTRIBUTES . " pa
                               where pa.products_id = '" . (int)$products_id . "'";
        }
        if ($returnCount == FALSE) {
          $attributes_query .= " limit 1";
        } else {
          $attributes_query = str_replace('select pa.products_attributes_id', 'select count(pa.products_attributes_id) as count', $attributes_query);
        }
    
    //die($attributes_query);
        $attributes = $db->Execute($attributes_query);
    //if ($products_id == 179) die(print_r($attributes->fields, TRUE));
        if ($returnCount == TRUE) {
          return $attributes->fields['count'];
        }
        if ($attributes->recordCount() > 0 && $attributes->fields['products_attributes_id'] > 0) {
          return true;
        } else {
          return false;
        }
      }
    /includes/modules/NAME_OF_YOUR_TEMPLATE_IF_ANY/product_listing.php, line 114, edit as shown:
    Code:
            if (zen_has_product_attributes($listing->fields['products_id'], 'false', TRUE) > 1 or PRODUCT_LIST_PRICE_BUY_NOW == '0') {
    /includes/classes/shopping_cart.php
    in function actionAddProduct(), line 1568 (v1.3.8a), insert the new lines as shown:
    Code:
        if (isset($_POST['products_id']) && is_numeric($_POST['products_id'])) {
          // Add default attribute if not specified and only one attrib exists for this product
          if (!isset($_POST['id']) && zen_has_product_attributes($_POST['products_id'], 'true', TRUE) == 1) {
            $sql = "select distinct popt.products_options_id, popt.products_options_name
                  from        " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib
                  where           patrib.products_id='" . (int)$_POST['products_id'] . "'
                  and             patrib.options_id = popt.products_options_id
                  and             popt.language_id = '" . (int)$_SESSION['languages_id'] . "' LIMIT 1";
            $products_options_names = $db->Execute($sql);
    
            $sql = "select    pov.products_options_values_id, pov.products_options_values_name
                  from      " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov
                  where     pa.products_id = '" . (int)$_POST['products_id'] . "'
                  and       pa.options_id = '" . (int)$products_options_names->fields['products_options_id'] . "'
                  and       pa.options_values_id = pov.products_options_values_id
                  and       pov.language_id = '" . (int)$_SESSION['languages_id'] . "' LIMIT 1 ";
            $products_options = $db->Execute($sql);
            if ($products_options->RecordCount() == 1) {
              $_POST['id'][$products_options_names->fields['products_options_id']] = $products_options->fields['products_options_values_id'];
            }
          }
          // verify attributes and quantity first
    line 1673 change this:
    Code:
      function actionBuyNow($goto, $parameters) {
        global $messageStack;
        if (isset($_GET['products_id'])) {
          if (zen_has_product_attributes($_GET['products_id'])) {
            zen_redirect(zen_href_link(zen_get_info_page($_GET['products_id']), 'products_id=' . $_GET['products_id']));
          } else {
            $add_max = zen_get_products_quantity_order_max($_GET['products_id']);
    to this:
    Code:
      function actionBuyNow($goto, $parameters) {
        global $messageStack;
        if (isset($_GET['products_id'])) {
          $attribCount = zen_has_product_attributes($_GET['products_id'], 'false', TRUE);
          // if product has more than one attrib, go to product page. If has only one, treat as a regular actionAddProduct call
          if ($attribCount > 1) {
            zen_redirect(zen_href_link(zen_get_info_page($_GET['products_id']), 'products_id=' . $_GET['products_id']));
          } elseif ($attribCount == 1) {
            $_GET['action'] = 'add_product';
            $_POST['products_id'] = $_GET['products_id'];
            $_POST['cart_quantity'] = 1;
            $this->actionAddProduct($goto, $parameters);
            return FALSE;
          } else {
            $add_max = zen_get_products_quantity_order_max($_GET['products_id']);
    The above edits deal with the main product listing.

    If you also want to adjust the products_new, products_all, and products_featured pages, you'll need to make a couple more edits to each of those, respectively:

    /includes/templates/NAME_OF_YOUR_TEMPLATE/templates/tpl_modules_products_new_listing.php
    line 85:
    Code:
            if (zen_has_product_attributes($products_new->fields['products_id'], 'false', TRUE) > 2) {
    Same with tpl_modules_products_featured_listing.php and tpl_modules_products_all_listing.php

    /includes/modules/pages/products_new/header_php.php
    line 47:
    Code:
          if (zen_has_product_attributes($check_products_all->fields['products_id'], 'false', TRUE) > 1) {
    and line 55:
    Code:
                      if (zen_has_product_attributes($check_products_all->fields['products_id'], 'false', TRUE) < 2) {
    Same with the header_php.php file for the products_all and products_featured folders.

    These same edits can be applied to v1.3.9 and v1.5.0; just use care since the line numbers have changed in most cases.

    This functionality will be included in v2.0.0
    .

    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.

  5. #5
    Join Date
    Jun 2005
    Location
    Cumbria, UK
    Posts
    10,263
    Plugin Contributions
    3

    Default Re: Add to cart not showing for downloadable products in the product listing page

    DrByte - this is brilliant of you to put this up. I know how busy you must be with 2.0, so the time taken to publish this info is truly appreciated.

    I'll certainly bookmark this page.
    20 years a Zencart User

  6. #6
    Join Date
    Sep 2009
    Posts
    15
    Plugin Contributions
    0

    Default Re: Add to cart not showing for downloadable products in the product listing page

    Thank you very much! I haven't tested the code yet but I will do that and report how it went.

  7. #7
    Join Date
    Jan 2006
    Posts
    5
    Plugin Contributions
    0

    Default Re: Add to cart not showing for downloadable products in the product listing page

    THANK YOU Dr Byte !!!

    Just spent more than 2 hours searching the forums and the net for the solution to removing the "more detail" to basic downloadable products and your mods do exactly this.

    May I suggest this becomes an option in a future release, it's invaluable and much much more user friendly...

    --Olivier
    Last edited by olivierk; 1 Dec 2009 at 02:06 AM. Reason: mispelled

 

 

Similar Threads

  1. CAN select attribute - CANNOT select it's quantity
    By amrami in forum Setting Up Categories, Products, Attributes
    Replies: 1
    Last Post: 27 Dec 2010, 02:29 PM
  2. How can I require a customer to select from a list of attribute options?
    By beyre in forum Setting Up Categories, Products, Attributes
    Replies: 6
    Last Post: 13 Aug 2010, 04:25 AM
  3. How can I restrict shipping choices based on kinds of products in the cart?
    By bladerogers in forum Templates, Stylesheets, Page Layout
    Replies: 8
    Last Post: 14 Sep 2009, 03:51 AM
  4. how can i require a customer to select an attribute?
    By mellonade in forum Basic Configuration
    Replies: 14
    Last Post: 9 Dec 2008, 05:14 AM
  5. Replies: 1
    Last Post: 3 Apr 2008, 04:39 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR