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
Hey guys :)

I want to implement a "minimum order value" to my new site...

I was figuring to EITHER put this in the minishoppingcart or the ordersummary files to hide the checkout button until the minimum order amount is reached...

The problem I am having is this, I can't seem to invoke the subtotal in either of these files in such a way that I can run a comparison like this;


if (MyVariableForSubtotal < 100)
{
       CheckoutButton.Visable = False;
       minimumOrderMessage.Visable = True;
}

What is the quickest and easiest way for me to invoke an instance of the subtotal which I can use the "<" operator on?  Does it need to be a decimal or an integar etc.. ??

Any help would be hugely appreciated!  As I've been stuck on this for a while, I tried replicating the code which shows the sub-total on the minicart, but it just doesn't want to let me convert or compare it!

Thanks :)
13 years ago
bump!

Anyone? :)
13 years ago
Any help on this would also help me a ton.  Thanks.
13 years ago
Do you have access to the ShipmentPackage of the user in your current context?

If so, you can probably calculate the subtotal of your order this way. You could also look up in the code and identify how the subtotal is calculated in the page..

Hope I could be of any help... :-)
13 years ago
I really only have very basic programming knowledge, so I have just been tinkering around with the code.  I know the sub total is being displayed on the page from a component called from outside the page.  I was hoping someone would have a quick and simple solution.  I will dig deeper into the code and see what I can figure out, thanks for your help.
13 years ago
not sure I do have access to shipment package..

I have taken a look at how the subtotal is assigned but it won't let me use the "<" operator on it, or convert it to a decimal or int so that I can

:(  sad days...
13 years ago
major bumpage!

Still struggling here!  Can anyone shed a little light? :)
13 years ago
Here it is... this code hides the checkout button until the cart reaches $100 for the Mini Shopping Cart.

Step 1: after line 59 (the else part of "if shoppingcart.count == 0) add this code:

decimal OrderSubTotal = GetComparableSubTotal(shoppingCart);

if (OrderSubTotal < 100.00m)
{
   btnCheckout.Visible = false;
}
else
{
   btnCheckout.Visible = true;
}

Step 2: right after the OnPreRender function, put this code:

protected decimal GetComparableSubTotal(ShoppingCart shoppingcart)
{
   decimal subTotalDiscountBase = decimal.Zero;
   Discount appliedDiscount = null;
   decimal subtotalBaseWithoutPromo;
   decimal subtotalBaseWithPromo;
   string subtotalerror = ShoppingCartManager.GetShoppingCartSubTotal(shoppingcart,
      NopContext.Current.User, out subTotalDiscountBase,
      out appliedDiscount, out subtotalBaseWithoutPromo, out subtotalBaseWithPromo);

   if (string.IsNullOrEmpty(subtotalerror))
   {
      decimal subtotal = subtotalBaseWithoutPromo;
      return subtotal;
   }
   else
   {
      decimal subtotal = decimal.Zero;
      return subtotal;
   }
}

Check this code out in action at http://www.mynewcomicshop.net

This is just for the mini shopping cart, you can do something similar wherever the cart button is.

Also, you may be able to use subtotalBaseWithPromo for the subtotal... depends on what you need. One gives you the subtotal before any discounts are taken and one gives you the subtotal after discounts are taken - I believe. You might want to play with it.
13 years ago
This works in OrderSummary.ascx.cs control as well...

You just need to add the step 1 code to "protected override void OnPreRender" and add this before "decimal OrderSubTotal...":

var shoppingCart = ShoppingCartManager.GetCurrentShoppingCart(ShoppingCartTypeEnum.ShoppingCart);

and then add the GetComparableSubTotal function somewhere in the class... then you'll have no checkout button on the shoppingcart page until $100 is reached!!

:)

I would suggest informing your customers somewhere what the minimum order is, or they'll be confused... but I'm sure you're going to do that.
13 years ago
will give that a go!

thank you SO much :D
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.