/// <summary> /// Ensures that only applicable shipping options are displayed in selector. /// </summary> /// <param name="ds">Dataset with shipping options.</param> protected override DataSet OnAfterRetrieveData(DataSet ds) { if (DataHelper.IsEmpty(ds) || (ShoppingCart == null)) { return(ds); } foreach (DataRow shippingRow in ds.Tables[0].Select()) { ShippingOptionInfo shippingOptionInfo; if (UseNameForSelection) { var shippingName = DataHelper.GetStringValue(shippingRow, "ShippingOptionName"); shippingOptionInfo = ShippingOptionInfoProvider.GetShippingOptionInfo(shippingName, ShoppingCart.SiteName); } else { var shippingID = DataHelper.GetIntValue(shippingRow, "ShippingOptionID"); shippingOptionInfo = ShippingOptionInfoProvider.GetShippingOptionInfo(shippingID); } // Do not remove already selected item even if the option is not applicable anymore // The user would see a different value in UI as is actually stored in the database var canBeRemoved = !EnsureSelectedItem || (ShoppingCart.ShoppingCartShippingOptionID != shippingOptionInfo.ShippingOptionID); if (canBeRemoved && !ShippingOptionInfoProvider.IsShippingOptionApplicable(ShoppingCart, shippingOptionInfo)) { ds.Tables[0].Rows.Remove(shippingRow); } } return(ds); }
/// <summary> /// Validates shopping cart content. /// </summary> public override bool IsValid() { // Force loading current values ShoppingCart.Evaluate(); // Check inventory var checkResult = ShoppingCartInfoProvider.CheckShoppingCart(ShoppingCart); // Check if selected shipping option is applicable if (!ShippingOptionInfoProvider.IsShippingOptionApplicable(ShoppingCart, ShoppingCart.ShippingOption)) { checkResult.ShippingOptionNotAvailable = true; } if (checkResult.CheckFailed) { lblError.Text = checkResult.GetHTMLFormattedMessage(); return(false); } // Check if cart contains at least one product if (ShoppingCart.IsEmpty) { lblError.Text = GetString("com.checkout.cartisempty"); return(false); } return(true); }
/// <summary> /// Checks whether selected shipping option and payment method are valid for given cart. /// </summary> protected bool CheckShippingAndPayment(ShoppingCartInfo cart, out string message) { message = String.Empty; if (!ShippingOptionInfoProvider.IsShippingOptionApplicable(cart, cart.ShippingOption)) { message = GetString("com.checkout.shippingoptionnotapplicable"); return(false); } if (!cart.IsShippingNeeded && (cart.ShippingOption != null)) { // Just remove the shipping option if shipping is not needed cart.ShoppingCartShippingOptionID = 0; } if (!cart.IsShippingNeeded && (cart.PaymentOption != null) && (!cart.PaymentOption.PaymentOptionAllowIfNoShipping)) { // The selected payment is not applicable with no shipping message = GetString("com.checkout.paymentnoshipping"); return(false); } return(true); }
/// <summary> /// Ensures that only applicable shipping options are displayed in selector. /// </summary> /// <param name="ds"></param> /// <returns></returns> protected override DataSet OnAfterRetrieveData(DataSet ds) { if ((ds == null) || (ShoppingCart == null)) { return(ds); } var shippingOptions = ds.Tables[0].Select(); foreach (DataRow optionRow in shippingOptions) { int optionID = ValidationHelper.GetInteger(optionRow["ShippingOptionID"], 0); ShippingOptionInfo option = ShippingOptionInfoProvider.GetShippingOptionInfo(optionID); if ((option != null) && !ShippingOptionInfoProvider.IsShippingOptionApplicable(ShoppingCart, option)) { ds.Tables[0].Rows.Remove(optionRow); } } return(ds); }