Minimum Quantity at Checkout

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
rnowak7074
Ensign (ENS)
Ensign (ENS)
Posts: 5
Joined: Thu Oct 23, 2008 1:52 pm

Minimum Quantity at Checkout

Post by rnowak7074 » Thu Mar 05, 2009 3:00 pm

I have a store that has t-shirts with color swatches setup. The store owner doesn't want to allow anyone to purchase unless they purchase at least 12 of a product. But, because a shopper can buy 3 of a pink shirt and 4 of a green shirt, etc., I can't set the minimum quantity on the product level. The problem I have is that a shopper can order less that the minimum quantity of 12. Is there anyway I can prevent this without custom code. If there isn't, what effort will be required to prevent this?

Thank you,
Rhonda

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Minimum Quantity at Checkout

Post by mazhar » Fri Mar 06, 2009 5:49 am

On order level there is a maximum/minimum order total setting available in store settings but for quantity restriction, there is no such option out of the box. It will probably take some programming effort to accomplish this. For example you can update

Code: Select all

private void ValidateOrderMinMaxAmounts()
method to look like

Code: Select all

private void ValidateOrderMinMaxAmounts()
    {
//MINIMUM QTY CHK
        int quantity = 0;
        foreach (BasketItem bi in Token.Instance.User.Basket.Items)
            if (bi.OrderItemType == OrderItemType.Product)
                quantity += bi.Quantity;
        if (quantity < 12)
        {
            CheckoutPanel.Visible = false;
            OrderBelowMinimumAmountMessage.Text = "You must purchase at least 12 products";
            return;
        }
        

        // IF THE ORDER AMOUNT DOES NOT FALL IN VALID RANGE SPECIFIED BY THE MERCHENT
        LSDecimal orderTotal = Token.Instance.User.Basket.Items.TotalPrice();
        StoreSettingCollection settings = Token.Instance.Store.Settings;
        decimal minOrderAmount = settings.OrderMinimumAmount;
        decimal maxOrderAmount = settings.OrderMaximumAmount;
        if ((minOrderAmount > orderTotal) || (maxOrderAmount > 0 && maxOrderAmount < orderTotal))
        {
            CheckoutPanel.Visible = false;
            OrderBelowMinimumAmountMessage.Visible = (minOrderAmount > orderTotal);
            if (OrderBelowMinimumAmountMessage.Visible) OrderBelowMinimumAmountMessage.Text = string.Format(OrderBelowMinimumAmountMessage.Text, minOrderAmount);
            OrderAboveMaximumAmountMessage.Visible = !OrderBelowMinimumAmountMessage.Visible;
            if (OrderAboveMaximumAmountMessage.Visible) OrderAboveMaximumAmountMessage.Text = string.Format(OrderAboveMaximumAmountMessage.Text, maxOrderAmount);
        }
        else
        {
            CheckoutPanel.Visible = true;
        }
    }

User avatar
mfreeze
Commodore (COMO)
Commodore (COMO)
Posts: 421
Joined: Mon Jan 24, 2005 2:07 pm
Location: Washington, NJ
Contact:

Re: Minimum Quantity at Checkout

Post by mfreeze » Thu Sep 23, 2010 12:13 pm

I have a similar situation but the restriction is that customer must purchase a multiple of the minimum quantity that is set for each product. For example, if the mininum is set to 3, the customer can purchase only 3,6,9,etc.

I know I can alter the updowncontrol source code but what the customer wants is a simpler solution. If the total ordered for an item is not a multiple of the minimum quantity specified for the product, issue a message saying something like "the quantity specified for item xxx (the item that has the error) must be a multiple of yyy (the item's minimum quantity). Please change the quantity specified" then disable the checkout button until they alter it to a correct quantity.

So what I need to do is calculate whether the total quantity specified for an item is a multiple of the minimum quantity and if not issue the message and disable the checkout link until they change the quantity to a multiple.

Any ideas how I could do this?
Mary E Freeze

Freeze Frame Graphics
Web Hosting and Design, ASP and CFMX Development

http://www.ffgraphics.com

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Minimum Quantity at Checkout

Post by mazhar » Fri Sep 24, 2010 6:12 am

You can write a validation method in checkout process on some suitable location. This method may be implemented in way to iterate over basket items and versify their item quantities for multiples. If basket passes the verification then let it proceed otherwise show some dynamic message to client.

For example in ConLib/OnePageCheckout.ascx file add asp.net label control at some suitable location like like

Code: Select all

<asp:Label ID="MessageLabel" runat="server" EnableViewState="false"></asp:Label>
and then locate CheckingOut method in ConLib/OnePageCheckout.ascx.cs file and put following code just after the opening curly brace of this method

Code: Select all

foreach (BasketItem basketItem in _Basket.Items)
        {
            if(basketItem.OrderItemType == OrderItemType.Product)
            {
                double rem = basketItem.Quantity % 2;
                if (rem != 0)
                {
                    MessageLabel.Text = string.Format("Please enter quantity in multiple of 2 for {0}",basketItem.Name);
                    e.Cancel = true;
                    return;
                }
            }
        }
Now try checking out with some item in your basket having invalid quantity. You will see that when you will try to complete the order it will ask you to adjust your quantity first.

User avatar
mfreeze
Commodore (COMO)
Commodore (COMO)
Posts: 421
Joined: Mon Jan 24, 2005 2:07 pm
Location: Washington, NJ
Contact:

Re: Minimum Quantity at Checkout

Post by mfreeze » Tue Oct 05, 2010 1:55 pm

Mazur,

This is so close to what I need but I can't get it working the way I want.

I want to place the code in basket.ascx.cs and have the divisor be the minimum quantity defined for each product. I tried to add

Code: Select all

Decimal minamount = Product.MinQuantity;
to define the amount I want to divide by but get the message "error CS0120: An object reference is required for the nonstatic field, method, or property 'CommerceBuilder.Products.Product.MinQuantity.get' ".

I need to pull the minimum quantity defined for the product then determine if the quantity ordered is a multiple.

Here's what I have in basket.ascx.cs that isn't working, any ideas what I might be doing wrong?

Code: Select all

        if ((minOrderAmount > orderTotal) || (maxOrderAmount > 0 && maxOrderAmount < orderTotal))
        {
            CheckoutButton.Enabled = false;
            GoogleCheckoutButton.Enabled = false;
            OrderBelowMinimumAmountMessage.Visible = (minOrderAmount > orderTotal);
            if (OrderBelowMinimumAmountMessage.Visible) OrderBelowMinimumAmountMessage.Text = string.Format(OrderBelowMinimumAmountMessage.Text, minOrderAmount);
            OrderAboveMaximumAmountMessage.Visible = !OrderBelowMinimumAmountMessage.Visible;
            if (OrderAboveMaximumAmountMessage.Visible) OrderAboveMaximumAmountMessage.Text = string.Format(OrderAboveMaximumAmountMessage.Text, maxOrderAmount);
        }
        else
        {
            foreach (BasketItem item in basket.Items)
            {
                if (item.OrderItemType == OrderItemType.Product)
                {
                    Decimal minamount = Product.MinQuantity;
                    decimal rem = item.Quantity % minamount;
                    if (rem != 0)
                    {
                        OrderNotMultipleMessage.Text = string.Format("Please enter quantity in multiple of Product.MinQuantity for {0}", item.Name);
                        CheckoutButton.Enabled = false;
                        return;
                    }
                }

         
        else
                {
                    CheckoutButton.Enabled = true;
                    GoogleCheckoutButton.Enabled = true;
                    OrderAboveMaximumAmountMessage.Visible = false;
                    OrderBelowMinimumAmountMessage.Visible = false;
                }
            }
Mary E Freeze

Freeze Frame Graphics
Web Hosting and Design, ASP and CFMX Development

http://www.ffgraphics.com

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Minimum Quantity at Checkout

Post by mazhar » Wed Oct 06, 2010 9:53 am

You have some problem in your posted code, use this one instead

Code: Select all

if ((minOrderAmount > orderTotal) || (maxOrderAmount > 0 && maxOrderAmount < orderTotal))
{
    CheckoutButton.Enabled = false;
    GoogleCheckoutButton.Enabled = false;
    OrderBelowMinimumAmountMessage.Visible = (minOrderAmount > orderTotal);
    if (OrderBelowMinimumAmountMessage.Visible) OrderBelowMinimumAmountMessage.Text = string.Format(OrderBelowMinimumAmountMessage.Text, minOrderAmount);
    OrderAboveMaximumAmountMessage.Visible = !OrderBelowMinimumAmountMessage.Visible;
    if (OrderAboveMaximumAmountMessage.Visible) OrderAboveMaximumAmountMessage.Text = string.Format(OrderAboveMaximumAmountMessage.Text, maxOrderAmount);
}
else
{
    CheckoutButton.Enabled = true;
    GoogleCheckoutButton.Enabled = true;
    OrderAboveMaximumAmountMessage.Visible = false;
    OrderBelowMinimumAmountMessage.Visible = false;
 
}

foreach (BasketItem item in Token.Instance.User.Basket.Items)
        {
            if (item.OrderItemType == OrderItemType.Product)
            {
                Decimal minamount = item.Product.MinQuantity;
                if (minamount > 0)
                {
                    decimal rem = item.Quantity % minamount;
                    if (rem != 0)
                    {
                        OrderNotMultipleMessage.Text = string.Format("Please enter quantity in multiple of {0} for {1}",item.Product.MinQuantity,item.Name);
                        CheckoutButton.Enabled = false;
                        return;
                    }
                }
            }
        }

User avatar
mfreeze
Commodore (COMO)
Commodore (COMO)
Posts: 421
Joined: Mon Jan 24, 2005 2:07 pm
Location: Washington, NJ
Contact:

Re: Minimum Quantity at Checkout

Post by mfreeze » Wed Oct 06, 2010 2:39 pm

That worked perfectly. Thank you so much.
Mary E Freeze

Freeze Frame Graphics
Web Hosting and Design, ASP and CFMX Development

http://www.ffgraphics.com

Post Reply