+ Reply to Thread
Results 1 to 5 of 5

Thread: Add to Cart from Category Page - v3

  1. #1
    Squirrelcart Staff Jamie's Avatar
    Join Date
    May 2002
    Posts
    5,697
    Squirrelcart version
    v3.2.1

    Add to Cart from Category Page - v3

    This tutorial is for Squirrelcart version 3x.

    By default, when you click on a category, product thumbnails are shown. You need to click on those thumbnails in order to open the product's detail page where you can then add the item to the cart.

    This tutorial explains how to configure Squirrelcart so that it displays an add to cart button for each product on the category's page. There are two ways to do this. Method 1 significantly changes the way products appear on the category page. Method 2 does not.


    Method 1 - Change Thumbnails to "Product Detail"

    You can change the way products are displayed on a per category basis. By default, when you view a category products are shown as thumbnails:
    example3.png
    You can change this so that products appear in "detail" mode, just as they do when you click on a thumbnail link:
    example4.png
    1. Login as store admin
    2. Open the category record you wish to alter in the control panel
    3. Locate the Category Viewing fieldset
    4. Inside this fieldset, locate the Category Page fieldset, which controls how this category and its products appear when a link for this category is clicked
    5. Change the Show Products As field to Detail
      example1.png
    6. This will cause each product to appear in full detail, with a description, options, and everything you would normally see if you clicked on a product link. This takes up much more room than a product does in thumbnail view. Because of this, I'd recommend changing the Products per Row field to 1, so each product appears on its own row. Setting this to anything larger will not look good.
      example2.png
    7. Click Save Changes
    The category should now look something like this:
    example4.png

    You may want to alter your CSS to make each product name stand out more.
    Thanks,
    Jamie

    Please rate or review us!
    Hotscripts PHP Resource Index



    It's too bad that whole families have to be torn apart by something as simple as wild dogs. - Jack Handey

  2. #2
    Squirrelcart Staff Jamie's Avatar
    Join Date
    May 2002
    Posts
    5,697
    Squirrelcart version
    v3.2.1
    Method 2 - Alter Thumbnail View to Have an Add to Cart Button

    This method will turn your category page from something like this:
    example3.png

    to this:
    example2.png

    1. In order to do this, you'll need to modify a template. If you haven't already created a custom theme, read this first which will explain how to properly modify template files:
      http://squirrelcart.com/help/3.1.0/?Modifying%20Templates.html

    2. You need a copy of the product_thumbnail.tpl.php template file inside your custom theme folder squirrelcart/themes/YOUR_CUSTOM_THEME/. If you do not have that file in your custom theme, put a copy of that template file there. You can find it in the master theme folder squirrelcart/themes/squirrelcart/

    3. Open squirrelcart/themes/YOUR_CUSTOM_THEME/product_thumbnail.tpl.php in an editor
    4. First we need to add an ID attribute to the <form /> tag. Find your <form /> tag in this template:
      PHP Code:
      <form accept-charset="utf-8" action="<?php print $Form_Action ?>" method="<?php print $Form_Method ?><?php print $Form_Enctype ?> >
    5. If you do not see an id attribute in the opening <form /> tag, add one. Your opening <form /> tag should look like this:
      PHP Code:
      <form id="add_to_cart_form_<?php print $Form_ID?>" accept-charset="utf-8" action="<?php print $Form_Action ?>" method="<?php print $Form_Method ?><?php print $Form_Enctype ?> >


      Note:
      We have plans to add this by default in newer versions, so steps 4 and 5 above may become unnecessary.

    6. Locate this code towards the bottom of the template:
      PHP Code:
              <?php print $Reviews?>
          </form>
      </div>
    7. Before that code add this, which will add the add to cart button, and a hidden quantity field set to 1:
      PHP Code:
              <div class="valign_middle qty_box">
                  <input class="qty" type="hidden" id="quantity" name="quantity" value="1" />
                  <a href="#" id="add_to_cart_link<?php print $Form_ID ?>" class="<?php print $Add_to_Cart_Class ?> btn co_btn_disabled" onclick="document.getElementById('add_to_cart_form_<?php print $Form_ID?>').submit(); return false"></a>
                  <noscript>
                      <input class="co_btn" type="submit" name="no_script[add_to_cart_btn]" value="<?php print $Add_to_Cart_Text ?>" />
                  </noscript>
                  <script type="text/javascript">
                      var addToCartLink = document.getElementById('add_to_cart_link<?php print $Form_ID ?>');
                      if (addToCartLink) addToCartLink.className = addToCartLink.className.replace('co_btn_disabled','');
                  </script>
              </div>
    8. Save the file
    Considerations:
    • To make this as easy for the customer as possible, this approach adds a hidden quantity field set to 1. The customer can change quantities after clicking Add to Cart
    • If a product has options, they will not appear. If the options are not required, the item will be added to the cart as it normally would. If the item has at least one required option, the customer will see an error indicating they must choose an option in order to add the item to the cart.
    Thanks,
    Jamie

    Please rate or review us!
    Hotscripts PHP Resource Index



    It's too bad that whole families have to be torn apart by something as simple as wild dogs. - Jack Handey

  3. #3
    Client
    Join Date
    Nov 2007
    Posts
    171
    Squirrelcart version
    v2.6.3
    I am using 3.0.1 and I tried method 1 and it doesn't work for me.

    I modified my category.tpl.php file but I don't see anything that would make this not work.

    This is all I changed in the file:

    I changed this:
    <div class="cat_name">
    <?php if ($Image_of_Name): ?>
    <a href="<?php print $URL ?>">
    <img src="<?php print $Image_of_Name['dyn'] ?>" width="<?php print $Image_of_Name['width'] ?>" height="<?php print $Image_of_Name['height'] ?>" alt="<?php print $Image_of_Name['alt'] ?>" />
    </a>
    <?php print $Admin_Link ?>
    <?php else: ?>
    <h2>
    <a href="<?php print $URL?>"><?php print $Content_Name ?></a> <?php print $Admin_Link ?>
    </h2>
    <?php endif; ?>
    </div>

    to this:
    <div class="cat_name">
    <?php if ($Image_of_Name): ?>
    <a href="<?php print $URL ?>">
    <img src="<?php print $Image_of_Name['dyn'] ?>" width="<?php print $Image_of_Name['width'] ?>" height="<?php print $Image_of_Name['height'] ?>" alt="<?php print $Image_of_Name['alt'] ?>" />
    </a>
    <?php print $Admin_Link ?>
    <?php else: ?>
    <h2>
    <?php print $Content_Name ?><a href="<?php print $URL?>"><?php print $Admin_Link ?></a>
    </h2>
    <?php endif; ?>
    </div>

    Any other reason why I can't show the product detail on the category page?

  4. #4
    Client
    Join Date
    Nov 2007
    Posts
    171
    Squirrelcart version
    v2.6.3
    I found the fix for it at:
    http://www.ldev.com/forums/showthrea...product+detail

    Sorry I didn't look first.

  5. #5
    Client
    Join Date
    Nov 2007
    Posts
    55
    Squirrelcart version
    v3.0.0

    Question about method 2 of adding Add to Cart buttons to thumbnails

    Jamie,

    Is it possible to use this revised template for certain categories of products, but use the normal click to see product details, choose options, etc. display for other categories?

    If the add to cart button is there, does the rest of the item display still function as a link to the product detail page?

    I can imagine that I might be able to write css rules to hide the Add to Cart button from products that need options, but wondered if there was another way.

    Thanks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts