Leveraging the Gift Wrap feature for optional upcharges to a product

by Joe Payne 23. April 2015 09:03

Just goes to show, you still can teach an old dog new tricks.

A client needed a way to add an Engraving choice to the product page.   Normally this isn’t an issue, just use the product variant feature.

But in this case, the engraving choice must be optional.   And it has to charge an amount.  And it needs to accept some text for the actual engraved words.

So after a little digging, I settled on a little-used feature in AbleCommerce known as Gift Wrap.    Gift Wrap is a way to associate a secondary charge to any product.   The basket page and the checkout pages automatically know how to handle Gift Wrap. 

By default, AbleCommerce handles Gift Wrap selection during checkout.   So the first modification was to get gift wrap to apply on the product page.   This means the BuyProductDialog control is the place to start.    I used a checkbox to render a separate panel that included the text box control.    The contents of the text box control are set to the giftmessage property available on each line item object.

Then it’s just a matter of setting the correct Id for the gift wrap on the line item before it’s added to the basket.

Basket page needed some text changes to replace “Gift Wrap” with “Engraving”…super easy to do.

Checkout needed modified to skip the gift wrap page normally encountered by default AbleCommerce behavior.

At that point, I’m done – the client can now easily associate an optional upcharge for Engraving on specific products within the store catalog. 

Tags: , ,

AbleCommerce Gold | Personal

AbleCommerce Gold How To Clean Up Anonymous Users

by Joe Payne 14. April 2014 15:45

Even though Able Gold has a manual cleanup option in the Maintenance page, it doesn’t always work well.  The problem arises from how Able must delete each user individually.  Not such a big deal when you have 500 users to clear out.  

It’s a very different story when you have 2,000,000 unwanted users.   A SQL query can delete all of the unwanted records in a single command.

Below is the updated query to work with Able Gold schema.  Obviously change the dates to something more recent. 

If the queries do not remove as many records as you expected, you might want to remove the “AND (AffiliateId IS NOT NULL)” criteria if you don’t care about affiliate reporting.

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 ) 
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 ) 
AND (LastActivityDate IS NULL OR LastActivityDate <'June 30, 2009'))
 
DELETE FROM ac_Users 
WHERE StoreId = 1 AND IsAnonymous = 1 
AND (AffiliateId IS NOT NULL ) 
AND (LastActivityDate IS NULL OR LastActivityDate <'June 30, 2009')

Tags: , , ,

AbleCommerce Gold | Tech Support

NHibernate sub query on Orders filtering by usergroup

by Joe Payne 17. Maart 2014 09:31

A client had a need to filter the Monthly Sales Summary report by group membership.  In other words, restrict the totals to orders placed by users only in a specific user group.

The initial NHibernate query is such:

ICriteria criteria = NHibernateHelper.CreateCriteria<CommerceBuilder.Orders.Order>("O")
    .CreateCriteria("Items", "OI", NHibernate.SqlCommand.JoinType.InnerJoin)
    .Add(Restrictions.Eq("O.Store", AbleContext.Current.Store));

 

So I added a dropdown that is populated by GroupDataSource.LoadAll().  Then it seemed easy enough to just add this code which I found in the UserSearchCriteria.cs file:

if (groupId >= 0)
{
    criteria.CreateCriteria("O.User.UserGroups", "UG", NHibernate.SqlCommand.JoinType.InnerJoin)
    .Add(Restrictions.Eq("UG.Id.Group.Id", this.GroupId));
}

The problem is, this code throws a big ol’ NHibernate error “nhibernate multi-part identifier <someobject> could not be bound”

For some reason, NHibernate couldn’t resolve the relationship of Order –> User –> UserGroups –> Group.   The code I swiped from UserSearchCriteria had no problem with it.  But here it just wouldn’t work.

I finally figured out the solution was to create a new reference to the User table and base the criteria from there.   So instead of starting at the Order object level, the join and restriction starts as the User object level which sort of makes sense now that I’m typing this…

if (groupId >= 0)
{
    criteria.CreateCriteria("O.User", "U", NHibernate.SqlCommand.JoinType.InnerJoin)
        .CreateCriteria("U.UserGroups", "UG")
        .Add(Restrictions.Eq("UG.Id.Group.Id", groupId));
}

Finally, the end result is the NHibernate query now properly searches the orders for only those records where the user that placed the order is a member of a specific GroupId.

Tags: , , , ,

AbleCommerce Gold | Personal

AbleCommerce Gold Upgrade errors from 7.0.7

by Joe Payne 14. Februarie 2014 11:00

Ran into an odd timeout issue today.  It was disguising itself as an nHibernate problem during the upgrade of an AbleCommerce 7.0.7 store to AbleCommerce Gold R6.

 

The initial error was complaining about nHibernate null Id issues with Catalog.Webpage.  Which made no sense since the upgrade is converting the data, not adding to it.

So I dug into the /install/upgrade.aspx page and saw that indeed new web pages were being added.  And the error was crashing when store.settings.Save() was being called.

I eventually noticed an “errorList” string array variable and exposed it via debug.   It showed me that the SQL upgrade scripts were causing a timeout.   This was silently crashing the upgrade.

After a quick Google search, I found the solution.  In the RunScript() routine within Upgrade.aspx.cs, you have to increase the command timeout value.   Apparently the database I was upgrading was enormous and my local SQL server isn’t really known for speed.  Combine the two factors and you can easily result in timeouts.

Note the addition of setting the CommandTimeout parameter below:

try
{
    SqlCommand command = new SqlCommand(sql, conn);
    command.CommandTimeout = 300;
    command.ExecuteNonQuery();
}

Tags: , , , ,

AbleCommerce Gold | Tech Support

Problem with Jr. Admin security permissions in upgraded AbleCommerce 7 sites

by Joe Payne 28. Januarie 2014 11:33

As of Gold R6…

After upgrading an AbleCommerce 7.x website to AbleCommerce Gold, you’ll find the Junior Admin permissions do not work as expected.

In the Old Able 7.x, the role name was “Jr. Admin”.   However in Able Gold, the role name was changed to “Junior Admin”.  This value is hard-coded in various web.config files as well as the /app_data/adminmenu.xml file.

If you upgrade Able 7.x to AbleCommerce Gold, the value does not get updated.  As a result, the new Able Gold install cannot accurately identify a user as an admin user if they are a member of only the Junior Admins group assigned to the Junior Admin role.

The fix is simple.   Open the ac_Roles table in the database and replace the “Jr. Admin” value with “Junior Admin”.   Do the same for the lower case value as well.

Tags: , ,

AbleCommerce Gold | AC7 Articles | Tech Support

Month List