How to increase the viewing site of the catalog browse

By Joe Payne at September 07, 2010 10:49
Filed Under: AC7 Articles

Introduction
Time for some fun. Today's project involves adding a new dropdown list to the admin-side Catalog browse page. This dropdown will let you choose how many items will be shown per-page in the current category. Why you might ask? Well some of us in eCommerce-land have a lot of products in a single category. By a lot, I mean hundreds and hundreds of products. By default, the catalog browse page only shows 40 products at a time. Moving them 40 at a time is a pain.

For example, my
http://www.Solunar.com website has thousands of products available for sale. I didn't hand-enter all of these of course. In fact, I didn't hand enter ANY of them. I wrote an import program that added them all to my store electronically. But my distributor doesn't categorize things the way I want them done, so most all of these products have to be moved around and broken up into appropriate sub-categories.

Enter: The Catalog Browse page. It gives you an elegant set of bulk functions that let you move stuff around in the store catalog with ease. However, I could have literally hundreds of products to move. Moving them 40 at a time is inefficient. So here is my solution: Adding a new dropdown that lets you choose how many items to show on each page of the catalog.

Changes to Make
As always, make a backup copy of your existing files before making these changes.

We're only working with two files today, both located in the /Admin/Catalog/ folder. First, find the browse.aspx file and edit it with your favorite text editor.

Look for this section of code in the Browse.aspx file:

Code:
<td align="right">
    <asp:ImageButton ID="ParentCategory" runat="server" SkinID="ParentCategoryIcon" OnClick="ParentCategory_Click" EnableViewState="false" ToolTip="Parent Category" />
</td>



and change it to look like this:

Code:
<td align="right">
    Show
    <asp:DropDownList ID="list_PageSize" runat="server" AutoPostBack="true" >
        <asp:ListItem Text="20" Value="20" />
        <asp:ListItem Text="40" Value="40" />
        <asp:ListItem Text="100" Value="100" />
        <asp:ListItem Text="All" Value="10000" />
    </asp:DropDownList>&nbsp;&nbsp;&nbsp;&nbsp;
    <asp:ImageButton ID="ParentCategory" runat="server" SkinID="ParentCategoryIcon" OnClick="ParentCategory_Click" EnableViewState="false" ToolTip="Parent Category" />
</td>



Save the changes. What you've just done is add a new dropdown list control to the page HTML code. However, we're not done yet. We haven't told IIS what to do with that dropdown list. Right now, you could select the choices all day long and nothing will happen. So let's add that server-side code to make it work the way we want.

Edit the browse.aspx.cs code-behind file and find the following section of code:

Code:
    protected void Page_Load(object sender, EventArgs e)
    {
        BulkOptions.Attributes.Add("onchange", "if(!confirmSelection()) return false;");
    }



And change it to look like this:

Code:
    protected void Page_Load(object sender, EventArgs e)
    {
        BulkOptions.Attributes.Add("onchange", "if(!confirmSelection()) return false;");
        // BEGIN MOD: AbleMods.com
        // 9-7-2010
        // Set pagesize of the grid control

        // if first time here, set default for the dropdown
        if (!Page.IsPostBack)
            list_PageSize.SelectedValue = "40";
       
        // Set pagesize
        CGrid.PageSize = AlwaysConvert.ToInt(list_PageSize.SelectedValue);
       
        // END MOD:  AbleMods.com
    }


Save your changes. Upload the modified files if necessary and give it a test.

What Just Happened?
The changes are actually very simple from a programming standpoint. All we've done is add a new ASP.Net dropdown list control to the HTML page. That dropdown list has the choices available for the number of items to show each time a category is clicked.
Then we added a few lines of code to the Page_Load() section of the programming. This Page_Load() section fires every time the browse.aspx is loaded. Keep in mind that this page is using AJAX, so the page is "loaded" every time you click something that doesn't leave the page entirely. Once we're in this Page_Load() section of the programming, we see if this is the first time here with the "Page.IsPostBack()" test. If it is the first time, then we set the default choice on the dropdown list to 40. That number 40 just happens to be what the original default is in the browse.aspx file.
The last step is to tell the gridview control how many items to show per-page based on what choice is selected on the new dropdown list control.

Conclusion
This modification adds a nifty bit of functionality to your catalog browse page. By letting you see more products in a category in a single page, you can really leverage the bulk catalog features. Enjoy! :)

GetUpsellProducts() throws a null exception if ChildProductId is not found

By Joe Payne at August 09, 2010 08:12
Filed Under: AC7 Articles, Personal, Tech Support

Found an interesting problem with my AbleCommerce 7.0.3 installation after doing a test upgrade to 7.0.5 last night.

My add to cart button wouldn't work after the upgrade.  It kept saying Object reference blah blah blah.  Put everything into the debugger and figured out I have some bad data in the storefront.

I had several (384 to be exact) ChildProductId's assigned to real products in the ac_UpsellProducts table.  Upsells are products that are advertised after the original product is added to the cart.  Obviously you wouldn't want to upsell a product that no longer exists - thus there's a foreign key constraint on the ProductId.  That way, any products that get deleted automatically delete their link in any upsell products and visa versa.

Somehow in my data, that wasn't happening.  I have products assigned as an upsell to a main product, and those products no longer exist.  This was causing addtocartlink.ascx to throw a null reference exception when it hit the GetUpSellProducts method.

Easy fix is to just clean out any bad upsells using this query:

delete ac_upsellproducts
from ac_upsellproducts
left outer join ac_products on ac_upsellproducts.childproductid = ac_products.productid
where ac_products.productid is null

How to show same categories on every page

By Joe Payne at August 04, 2010 15:42
Filed Under: AC7 Articles, Tech Support

You may have noticed by now that AbleCommerce 7 does not show all categories in the left side menu.  Once you drill into a sub-category, the left side shows you only sub-categories from that point forward in the store catalog.  AC7 makes it a tad confusing since now you don't really know how to go back up unless you notice the breadcrumbs.

That's swell if you have a sufficiently large catalog tree.  Many stores do not have a large one.  They would like to see all categories on every page that uses the Left Sidebar 1.  This is incredibly simple to implement.

Edit your Left Sidebar 1 scriptlet.  You can do this from either the Admin side or by switching to Edit Mode on the visitor side ( assuming you're logged in as an admin).

the Left Sidebar 1 defaults to:
[[ConLib:SimpleCategoryList]]

Just change it to:
[[ConLib:SimpleCategoryList CategoryId="0"]]

Now save your change.  You'll see the results immediately - the category list control will always pull from the root level of the catalog to display all sub-categories at level 1.  Suweet !!

AbleCommerce 7 How to Clean up anonymous users table

By Joe Payne at July 23, 2010 14:59
Filed Under: AC7 Articles

Needed to find this for a client today, so I thought I would post it to the blog and (hopefully) make it easier to find the next time.

With older versions of AC7 i.e. 7.0.3 and earlier, there sometimes is an issue where user maintenance does not run completely through.  As days go on, this problem becomes more pronounced as the ac_Users table continues to grow.  At some point, you'll start noticing slow site performance and degradation.  Check your ac_Users table and you'll probably find hundreds of thousands of old user records.

This query will clean those out in one quick swoop.  After that, the user maintenance routine should be able to keep up.  Just change the date in the three query statements for the cutoff date you want.  Also make sure to set the database name for your particular installation at the beginning of the file.

USE <YourDBName>
DELETE FROM ac_Baskets
WHERE UserId IN (SELECT UserId FROM ac_Users WHERE StoreId = 1 AND IsAnonymous = 1
AND (AffiliateId IS NOT NULL OR ReferringAffiliateId IS NOT NULL)
AND (LastActivityDate IS NULL OR LastActivityDate <'June 30, 2009'))

DELETE FROM ac_Wishlists
WHERE UserId IN (SELECT UserId FROM ac_Users WHERE StoreId = 1 AND IsAnonymous = 1
AND (AffiliateId IS NOT NULL OR ReferringAffiliateId IS NOT NULL)
AND (LastActivityDate IS NULL OR LastActivityDate <'June 30, 2009'))

DELETE FROM ac_Users
WHERE StoreId = 1 AND IsAnonymous = 1
AND (AffiliateId IS NOT NULL OR ReferringAffiliateId IS NOT NULL)
AND (LastActivityDate IS NULL OR LastActivityDate <'June 30, 2009')

RMA Manager ideas for next release

By Joe Payne at July 17, 2010 10:50
Filed Under: RMA Manager

I'm thinking about new features I could add to the RMA Manager module.

Once thing that comes to mind is the ability to automatically re-order items being returned.  This could be easily tied to the Return Reason.  The thinking is that items returned for a specific reason could automatically be added to a new order for the same customer.  That would make it very handy to handle exchange returns.

Another idea is the ability to issue a specific kind of refund.  Right now the module shows you dollar amounts but doesn't offer a mechanism for the actual refund process.