Get subtotal and compare (minimum order value)

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 years ago
Thanks worked perfectly!!
13 years ago
Glad I could help.
12 years ago
Thank you for making this code available!

I have started implementing it my local copy of the nopCommerce 1.9 source. One thing I noticed is that the nop source/architecture has changed enough that I need to modify your example code in MiniShoppingCart.ascx.cs (no worries there).

Then I moved on to OrderSummary.ascx.cs, and noticed this:
//minimum order subtotal
                bool minOrderSubtotalAmountOK = this.OrderService.ValidateMinOrderSubtotalAmount(cart, NopContext.Current.User);
                if (minOrderSubtotalAmountOK)
                {
                    phMinOrderSubtotalAmount.Visible = false;
                    lMinOrderSubtotalAmount.Visible = false;
                    btnCheckout.Visible = true;
                }
                else
                {
                    decimal minOrderSubtotalAmount = this.CurrencyService.ConvertCurrency(this.OrderService.MinOrderSubtotalAmount, this.CurrencyService.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
                    lMinOrderSubtotalAmount.Text = string.Format(GetLocaleResourceString("Checkout.MinOrderSubtotalAmount"), PriceHelper.FormatPrice(minOrderSubtotalAmount, true, false));
                    phMinOrderSubtotalAmount.Visible = true;
                    lMinOrderSubtotalAmount.Visible = true;
                    btnCheckout.Visible = false;
                }


Does that mean that minimum order feature was incorporated into the 1.9 release? If so:
1. How does one set this in the admin area, I didn't see anything like that, but maybe I haven't checked in the right place.
2. It still seems that MiniShoppingCart.ascx.cs would need to be modified

Thanks!
12 years ago
cisfc wrote:

Does that mean that minimum order feature was incorporated into the 1.9 release? If so:
1. How does one set this in the admin area, I didn't see anything like that, but maybe I haven't checked in the right place.
2. It still seems that MiniShoppingCart.ascx.cs would need to be modified

Thanks!


It is possible that it was added to 1.90, but I'm not sure. I'd have to look at it to figure out where to set it in the admin section, I'm sure it is there... I just don't know off the top of my head.

Not sure about the mini shopping cart, you may want to edit it just in case...
12 years ago
Thanks for the quick response!

FYI, once I cleared my head :) I went to:
Admin > Configuration > All Settings

And saw there are two settings there:
Order.MinOrderSubtotalAmount
Order.MinOrderAmount

I modified Order.MinOrderSubtotalAmount to my desired value, and voila, OrderSummary.ascx hides the checkout button as desired (look Ma, no code!)

It looks like the Order.MinOrderAmount setting is only referenced from CheckoutConfirm.ascx.cs...I'm just going to guess here that if you play with this setting, it will let you go all the way up to the point of submitting your order, then not show you the Next button if minimum order amount has not been reached. In other words, this one is for order sub total plus shipping plus whatever else, whereas the Order.MinOrderSubtotalAmount one is calculated before shipping etc.

However, as you mention, MiniShoppingCart.ascx.cs still indeed needs to be manually addressed. I'm trying a slightly modified version of your code to see how that does, will report back.
12 years ago
Yeah that did the trick alright. Out of the box, the shopping cart page will automatically display a string resource about the order needs to be more than __X__ amount, if the cart is currently under that, and the Checkout button is hidden. SWEET.

So to summarize...if you want to set a minimum amount on the order subtotal (as there is a different setting for order total after shipping, tax, etc.):

1) Make changes to MiniShoppingCartBoxControl.ascx.cs, as bfranklin825 so kindly documented. Make a few extra mods so that it works with 1.9. (small API changes)
2) Go into the admin area and update the Order.MinOrderSubtotalAmount setting to whatever you want the minimum to be.

So maybe someone in the future will want to see the code mods from #1? Sure, but with the disclaimer that I took the shortest path approach to solve the problem (aka hacked through). I'm sure there are some things I didn't consider, and some API things that are better approaches, of which I am currently ignorant.


        protected override void OnPreRender(EventArgs e)
        {
            if (this.SettingManager.GetSettingValueBoolean("Common.ShowMiniShoppingCart"))
            {
                var shoppingCart = this.ShoppingCartService.GetCurrentShoppingCart(ShoppingCartTypeEnum.ShoppingCart);
                if (shoppingCart.TotalProducts == 0)
                {
                    phCheckoutInfo.Visible = false;
                    lShoppingCart.Text = GetLocaleResourceString("MiniShoppingCartBox.NoItems");

                    lvCart.Visible = false;
                }
                else
                {
                    // ###############################################
                    // ### Changing code according to below URL to create minimum order
                    // ###  feature. Having to take some license, since the nopCommerce
                    // ###  source code has changed since the forum post was published:
                    // ###  Check out bfranklin825's post here: http://bit.ly/kq7ski
                    
                    string orderSubTotal = GetOrderSubtotal(shoppingCart);
                    // ###  This can return a string if "order is calculated during checkout".
                    // ### Also, I'm not worrying about checking the minimum with discounts
                    // ### applied. There's some usable info in the forum post to help
                    // ### if that's part of your requirements
                    decimal parsedSubTotal;
                    if (! Decimal.TryParse(orderSubTotal, out parsedSubTotal))
                    {
                     // ### "Calculated during checkout". You may want to do something else
                    // ### here besides defaulting to 0.00. Or use bfranklin825's
                    // ### protected decimal GetComparableSubTotal(ShoppingCart shoppingcart)
                    // ### method listed at:
                    // ### http://bit.ly/kq7ski
                        parsedSubTotal = decimal.Zero;
                    }

                    if (parsedSubTotal < OrderService.MinOrderSubtotalAmount)
                    {
                        phCheckoutInfo.Visible = false;
                    }
                    else
                    {
                        phCheckoutInfo.Visible = true;
                    }
                    // ### Need to comment out the below so above will work
                    // phCheckoutInfo.Visible = true;
                    // ###############################################

                    
                    if (shoppingCart.TotalProducts == 1)
                    {
                        //lShoppingCart.Text = string.Format(GetLocaleResourceString("MiniShoppingCartBox.OneItemText"), string.Format("<a href=\"{0}\" class=\"items\">{1}</a>", SEOHelper.GetShoppingCartUrl(), GetLocaleResourceString("MiniShoppingCartBox.OneItem")));
                        lShoppingCart.Text = string.Format("<a href=\"{0}\" class=\"items\">{1}</a>", SEOHelper.GetShoppingCartUrl(), GetLocaleResourceString("MiniShoppingCartBox.OneItem"));
                    }
                    else
                    {
                        //lShoppingCart.Text = string.Format(GetLocaleResourceString("MiniShoppingCartBox.SeveralItemsText"), string.Format("<a href=\"{0}\" class=\"items\">{1}</a>", SEOHelper.GetShoppingCartUrl(), string.Format(GetLocaleResourceString("MiniShoppingCartBox.SeveralItems"), shoppingCart.TotalProducts)));
                        lShoppingCart.Text = string.Format("<a href=\"{0}\" class=\"items\">{1}</a>", SEOHelper.GetShoppingCartUrl(), string.Format(GetLocaleResourceString("MiniShoppingCartBox.SeveralItems"), shoppingCart.TotalProducts));
                    }

                    //lblOrderSubtotal.Text = GetLocaleResourceString("MiniShoppingCartBox.OrderSubtotal", GetOrderSubtotal(shoppingCart));

                    if (this.SettingManager.GetSettingValueBoolean("Display.ItemsInMiniShoppingCart", false))
                    {
                        lvCart.Visible = true;
                        lvCart.DataSource = shoppingCart;
                        lvCart.DataBind();
                    }
                    else
                    {
                        lvCart.Visible = false;
                    }

                }
            }
            else
            {
                this.Visible = false;
            }

        }
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.