protected void btnAction_Command(object sender, System.Web.UI.WebControls.CommandEventArgs e) { if (Page.IsValid) { ShippingOptionType shippingType = ShippingOptionType.TotalAmount; if (e.CommandName == "OrderWeight") { shippingType = ShippingOptionType.Weight; } using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection())) { CSData.ShippingOrderValue cat = new CSData.ShippingOrderValue { OrderTotal = 0, Cost = 0, TypeId = (int)shippingType, IncludeRushShipping = false, PrefId = PrefId }; context.ShippingOrderValues.InsertOnSubmit(cat); context.SubmitChanges(); } BindAll(shippingType, false, PrefId); } }
public void BindAll(ShippingOptionType type, bool includeRushShipping) { List <ShippingOrderValue> list = ShippingDAL.GetShippingOrderValue(type, includeRushShipping, DefaultSitePrefereceId); if (!includeRushShipping) { switch (type) { case ShippingOptionType.TotalAmount: rptItems.DataSource = list; rptItems.DataBind(); break; case ShippingOptionType.Weight: rptOrderWeight.DataSource = list; rptOrderWeight.DataBind(); break; } } else { switch (type) { case ShippingOptionType.TotalAmount: rptRushOrderTotal.DataSource = list; rptRushOrderTotal.DataBind(); break; case ShippingOptionType.Weight: rptRushOrderWeight.DataSource = list; rptRushOrderWeight.DataBind(); break; } } }
public ManagerResponse <GetShippingMethodsResult, IReadOnlyCollection <ShippingMethod> > GetShippingMethods( string shopName, Cart cart, ShippingOptionType shippingOptionType, PartyEntity address, List <string> cartLineExternalIdList) { if (cartLineExternalIdList != null && cartLineExternalIdList.Any <string>()) { } CommerceParty commerceParty = null; if (address != null) { commerceParty = this.connectEntityMapper.MapToCommerceParty(address); } var shippingOption = new ShippingOption { ShippingOptionType = shippingOptionType }; var request = new Sitecore.Commerce.Engine.Connect.Services.Shipping.GetShippingMethodsRequest(shippingOption, commerceParty, cart as CommerceCart); GetShippingMethodsResult shippingMethods = this.shippingServiceProvider.GetShippingMethods <GetShippingMethodsRequest, GetShippingMethodsResult>(request); return(new ManagerResponse <GetShippingMethodsResult, IReadOnlyCollection <ShippingMethod> >(shippingMethods, shippingMethods.ShippingMethods)); }
protected void btnRushAction_Command(object sender, System.Web.UI.WebControls.CommandEventArgs e) { if (Page.IsValid) { ShippingOptionType shippingType = ShippingOptionType.TotalAmount; if (e.CommandName == "RushOrderWeight") { shippingType = ShippingOptionType.Weight; } using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection())) { CSData.ShippingOrderValue cat = new CSData.ShippingOrderValue { OrderTotal = 0, Cost = 0, TypeId = (int)shippingType, IncludeRushShipping = true, PrefId = DefaultSitePrefereceId }; context.ShippingOrderValues.InsertOnSubmit(cat); context.SubmitChanges(); } BindAll(shippingType, true); //CategoryDAL.UpdateCategory(0, txtCategory.Text, true); } }
public static List <ShippingOrderValue> GetShippingOrderValue(ShippingOptionType shippingType) { using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection())) { var query = from c in context.ShippingOrderValues where c.TypeId == (int)shippingType select c; return(query.ToList <ShippingOrderValue>()); } }
public static List <ShippingOrderValue> GetShippingOrderValue(ShippingOptionType shippingType, bool includeRushShipping, int prefId) { using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection())) { var query = from c in context.ShippingOrderValues where (c.TypeId == (int)shippingType) && (c.IncludeRushShipping == includeRushShipping) && (c.PrefId == prefId) select c; return(query.ToList <ShippingOrderValue>()); } }
private AddShippingInfoResult AddShippingInfoToCart(CommerceCart cart, ShippingOptionType orderShippingPreferenceType, IEnumerable <ShippingInfo> shipments) { Assert.ArgumentNotNull(cart, nameof(cart)); Assert.ArgumentNotNull(orderShippingPreferenceType, nameof(orderShippingPreferenceType)); Assert.ArgumentNotNull(shipments, nameof(shipments)); var request = new AddShippingInfoRequest(cart, shipments.ToList(), orderShippingPreferenceType); var result = CartServiceProvider.AddShippingInfo(request); result.WriteToSitecoreLog(); return(result); }
public GetShippingMethodsResult GetShippingMethods(Cart cart, ShippingOptionType shippingOptionType) { Assert.ArgumentNotNull(cart, nameof(cart)); Assert.ArgumentNotNull(shippingOptionType, nameof(shippingOptionType)); var shippingOption = new ShippingOption { ShippingOptionType = shippingOptionType }; var request = new GetShippingMethodsRequest(shippingOption, null, cart as CommerceCart); return(this.Execute(request, this.shippingServiceProvider.GetShippingMethods)); }
public AddShippingInfoResult AddShippingInfo( Cart cart, ShippingOptionType shippingOptionType, List <ShippingInfo> shippings) { Assert.ArgumentNotNull(cart, nameof(cart)); Assert.ArgumentNotNull(shippingOptionType, nameof(shippingOptionType)); Assert.ArgumentNotNull(shippings, nameof(shippings)); return(this.Execute( new AddShippingInfoRequest(cart, shippings, shippingOptionType), this.cartServiceProvider.AddShippingInfo)); }
public Result <ShippingModel> GetShippingMethods(GetShippingArgs getShippingArgs) { var model = new ShippingModel(); var result = new Result <ShippingModel>(); try { result.SetResult(model); ManagerResponse <CartResult, Cart> currentCart = this.CartManager.GetCurrentCart(this.StorefrontContext.ShopName, this.VisitorContext.ContactId); if (!currentCart.ServiceProviderResult.Success) { result.SetErrors(currentCart.ServiceProviderResult); return(result); } ShippingOptionType shippingOptionType = ConnectOptionTypeHelper.ToShippingOptionType(getShippingArgs.ShippingPreferenceType); PartyEntity address = null; if (getShippingArgs.ShippingAddress != null) { address = this.EntityMapper.MapToPartyEntity(getShippingArgs.ShippingAddress); } ManagerResponse <GetShippingMethodsResult, IReadOnlyCollection <ShippingMethod> > shippingMethods = this.ShippingManager.GetShippingMethods( this.StorefrontContext.ShopName, currentCart.Result, shippingOptionType, address, null); if (!currentCart.ServiceProviderResult.Success) { result.SetErrors(currentCart.ServiceProviderResult); return(result); } result.Data.ShippingMethods = new List <ShippingMethodModel>(); foreach (var shippingMethod in shippingMethods.ServiceProviderResult.ShippingMethods) { var shippingModel = this.EntityMapper.MapToShippingMethodModel(shippingMethod); result.Data.ShippingMethods.Add(shippingModel); } } catch (Exception ex) { Log.Error(ex.Message, ex, this); result.SetErrors(nameof(this.GetShippingMethods), ex); } return(result); }
public ManagerResponse <AddShippingInfoResult, Cart> AddShippingInfo( Cart cart, List <PartyEntity> partyEntityList, ShippingOptionType shippingOptionType, List <ShippingInfoArgument> shippingInfoList) { Assert.ArgumentNotNull(cart, nameof(cart)); Assert.ArgumentNotNull(shippingOptionType, nameof(shippingOptionType)); Assert.ArgumentNotNull(shippingInfoList, nameof(shippingInfoList)); cart = this.RemoveAllShipmentFromCart(cart); if ((partyEntityList != null) && partyEntityList.Any()) { var cartParties = cart.Parties.ToList(); var commercePartyList = this.connectEntityMapper.MapToCommercePartyList(partyEntityList); cartParties.AddRange(commercePartyList); cart.Parties = cartParties; } if (shippingOptionType != ShippingOptionType.DeliverItemsIndividually) { foreach (var shippingInfo in shippingInfoList) { shippingInfo.LineIds = cart.Lines.Select(lineItem => lineItem.ExternalCartLineId).ToList(); } } var shippings = new List <ShippingInfo>(); foreach (var shippingInfo in shippingInfoList) { shippings.Add(this.connectEntityMapper.MapToCommerceShippingInfo(shippingInfo)); } var addShippingInfoRequest = new AddShippingInfoRequest(cart, shippings, shippingOptionType); var shippingInfoResult = this.cartServiceProvider.AddShippingInfo(addShippingInfoRequest); if (!shippingInfoResult.Success) { shippingInfoResult.SystemMessages.LogSystemMessages(this); } return(new ManagerResponse <AddShippingInfoResult, Cart>(shippingInfoResult, shippingInfoResult.Cart)); }
public void Calculate(Cart cart, int prefID) { SitePreference shippingPreferences = CSFactory.GetCartPrefrence(cart); if (shippingPreferences != null) { ShippingOptionType option = shippingPreferences.ShippingOptionId; IShippingCalculator calculator = _allShippingCalculators[option]; calculator.Calculate(cart, shippingPreferences.ShippingPrefID); //CodeReview: Instead of Cart pref and compute based on the admin pref if (cart.ShippingMethod == UserShippingMethodType.Rush) { ShippingOptionType rushOption = shippingPreferences.RushShippingOptionID; IShippingCalculator rushCalculator = _allRushShippingCalculators[rushOption]; rushCalculator.Calculate(cart, shippingPreferences.RushShippingPrefID); } else { cart.RushShippingCost = 0; } // code Review 10/09/2013 bool additionalShippingScenario = false; bool additionalShippingScenarioWithSingleSKUinCart = false; bool overRideShippingCostforAdditionalShippingScenario = false; bool additionalShippingScenarioWithOtherItems = false; Dictionary <string, string> dicSKUandPrice = new Dictionary <string, string>(); Dictionary <string, string> dicSKUShippingCostWithQtyRange = new Dictionary <string, string>(); Dictionary <string, XmlNode> dicSKUShippingCostWithQtyRangeList = new Dictionary <string, XmlNode>(); SitePreference sitePreference = CSFactory.GetCacheSitePref(); if (!sitePreference.AttributeValuesLoaded) { sitePreference.LoadAttributeValues(); } if (sitePreference.AttributeValues.ContainsKey("additionalshippingscenario")) { if (sitePreference.AttributeValues["additionalshippingscenario"].Value != null) { additionalShippingScenario = sitePreference.AttributeValues["additionalshippingscenario"].BooleanValue; } } if (sitePreference.AttributeValues.ContainsKey("additionalshippingscenariowithsingleskuincart")) { if (sitePreference.AttributeValues["additionalshippingscenariowithsingleskuincart"].Value != null) { additionalShippingScenarioWithSingleSKUinCart = sitePreference.AttributeValues["additionalshippingscenariowithsingleskuincart"].BooleanValue; } } if (sitePreference.AttributeValues.ContainsKey("additionalshippingscenariowithotheritems")) { if (sitePreference.AttributeValues["additionalshippingscenariowithotheritems"].Value != null) { additionalShippingScenarioWithOtherItems = sitePreference.AttributeValues["additionalshippingscenariowithotheritems"].BooleanValue; } } if (sitePreference.AttributeValues.ContainsKey("overrideshippingcostforadditionalshippingscenario")) { if (sitePreference.AttributeValues["overrideshippingcostforadditionalshippingscenario"].Value != null) { overRideShippingCostforAdditionalShippingScenario = sitePreference.AttributeValues["overrideshippingcostforadditionalshippingscenario"].BooleanValue; } } string additionalShippingScenarioSKUandPrice = ""; if (sitePreference.AttributeValues.ContainsKey("additionalshippingscenarioskuandprice")) { if (sitePreference.AttributeValues["additionalshippingscenarioskuandprice"].Value != null) { additionalShippingScenarioSKUandPrice = sitePreference.AttributeValues["additionalshippingscenarioskuandprice"].Value.Trim(); } } if (additionalShippingScenario) { try { string dicKey = ""; string shippingcostwithqtyrange = "no"; if (!additionalShippingScenarioSKUandPrice.Equals("")) { XmlDocument xml = new XmlDocument(); xml.LoadXml(additionalShippingScenarioSKUandPrice); XmlNodeList resources = xml.SelectNodes("skulist/sku"); foreach (XmlNode node in resources) { dicKey = node.Attributes["skuid"].Value + "_" + node.Attributes["shippingprefid"].Value; if (dicSKUandPrice.ContainsKey(dicKey) == false) { dicSKUandPrice.Add(dicKey, node.Attributes["shippingcost"].Value); // node.Attributes["skuid"].Value } shippingcostwithqtyrange = "no"; if (node.Attributes["shippingcostwithqtyrange"] != null) { if (node.Attributes["shippingcostwithqtyrange"].Value != null) { shippingcostwithqtyrange = node.Attributes["shippingcostwithqtyrange"].Value.ToLower(); XmlNode nodeQtyRangeList = node.SelectSingleNode("qtyrangelist"); if (nodeQtyRangeList != null) { if (dicSKUShippingCostWithQtyRangeList.ContainsKey(dicKey) == false) { dicSKUShippingCostWithQtyRangeList.Add(dicKey, nodeQtyRangeList); } } } } if (dicSKUShippingCostWithQtyRange.ContainsKey(dicKey) == false) { dicSKUShippingCostWithQtyRange.Add(dicKey, shippingcostwithqtyrange); } } } else { dicSKUandPrice.Clear(); dicSKUShippingCostWithQtyRange.Clear(); dicSKUShippingCostWithQtyRangeList.Clear(); } dicKey = ""; int lowerQty = 0; int upperQty = 0; string nodeName = ""; string nodeXml = ""; bool cartHasXMlItem = false; foreach (Sku st in cart.CartItems) { string key = st.SkuId.ToString() + "_" + shippingPreferences.ShippingPrefID; if (dicSKUandPrice.ContainsKey(key)) { cartHasXMlItem = true; break; } } if (dicSKUandPrice.Count > 0 && cartHasXMlItem == true) { bool loopSingleSKUinCart = false; if (additionalShippingScenarioWithSingleSKUinCart && cart.ItemCount == 1) { loopSingleSKUinCart = true; decimal shippingCost = 0; decimal skuShippingCost = 0; bool isSKUPresent = false; foreach (Sku st in cart.CartItems) { // if (st.SkuId == currentSetting.SkuId) string key = st.SkuId.ToString() + "_" + shippingPreferences.ShippingPrefID; if (dicSKUandPrice.ContainsKey(key)) { isSKUPresent = true; skuShippingCost = Convert.ToDecimal(dicSKUandPrice[key].ToString()); if (dicSKUShippingCostWithQtyRange[key].ToString().ToLower().Equals("yes") && dicSKUShippingCostWithQtyRangeList.ContainsKey(key) == true && dicSKUShippingCostWithQtyRange.ContainsKey(key) == true) { nodeName = (dicSKUShippingCostWithQtyRangeList[key]).Name; nodeXml = "<" + nodeName + ">" + dicSKUShippingCostWithQtyRangeList[key].InnerXml.ToString() + "</" + nodeName + ">"; XmlDocument doc = new XmlDocument(); doc.LoadXml(nodeXml); XmlNodeList nodeList = doc.SelectNodes("/" + nodeName + "/range"); foreach (XmlNode node in nodeList) { if (node.Attributes["lowerqty"] != null && node.Attributes["upperqty"] != null) { if (node.Attributes["lowerqty"].Value != null && node.Attributes["upperqty"].Value != null) { lowerQty = Convert.ToInt32(node.Attributes["lowerqty"].Value); upperQty = Convert.ToInt32(node.Attributes["upperqty"].Value); if (st.Quantity >= lowerQty && st.Quantity <= upperQty) { if (node.Attributes["shippingcostrange"] != null) { if (node.Attributes["shippingcostrange"].Value != null) { skuShippingCost = Convert.ToDecimal(node.Attributes["shippingcostrange"].Value); break; } } } } } } } st.LoadAttributeValues(); if (st.AttributeValues.ContainsKey("shippingwithquantity")) { if (st.AttributeValues["shippingwithquantity"].Value == null) { shippingCost += skuShippingCost; } else if (st.AttributeValues["shippingwithquantity"].BooleanValue) { shippingCost += skuShippingCost * st.Quantity; } else { shippingCost += skuShippingCost; } } else { shippingCost += skuShippingCost; } } } if (isSKUPresent) { if (overRideShippingCostforAdditionalShippingScenario) { cart.ShippingCost = shippingCost; } else { cart.ShippingCost += shippingCost; } cart.RushShippingCost = 0; } } if (loopSingleSKUinCart == false) { if (additionalShippingScenarioWithOtherItems) { decimal shippingCost = 0; decimal skuShippingCost = 0; bool isSKUPresent = false; foreach (Sku st in cart.CartItems) { // if (st.SkuId == currentSetting.SkuId) string key = st.SkuId.ToString() + "_" + shippingPreferences.ShippingPrefID; if (dicSKUandPrice.ContainsKey(key)) { isSKUPresent = true; skuShippingCost = Convert.ToDecimal(dicSKUandPrice[key].ToString()); if (dicSKUShippingCostWithQtyRange[key].ToString().ToLower().Equals("yes") && dicSKUShippingCostWithQtyRangeList.ContainsKey(key) == true && dicSKUShippingCostWithQtyRange.ContainsKey(key) == true) { nodeName = (dicSKUShippingCostWithQtyRangeList[key]).Name; nodeXml = "<" + nodeName + ">" + dicSKUShippingCostWithQtyRangeList[key].InnerXml.ToString() + "</" + nodeName + ">"; XmlDocument doc = new XmlDocument(); doc.LoadXml(nodeXml); XmlNodeList nodeList = doc.SelectNodes("/" + nodeName + "/range"); foreach (XmlNode node in nodeList) { if (node.Attributes["lowerqty"] != null && node.Attributes["upperqty"] != null) { if (node.Attributes["lowerqty"].Value != null && node.Attributes["upperqty"].Value != null) { lowerQty = Convert.ToInt32(node.Attributes["lowerqty"].Value); upperQty = Convert.ToInt32(node.Attributes["upperqty"].Value); if (st.Quantity >= lowerQty && st.Quantity <= upperQty) { if (node.Attributes["shippingcostrange"] != null) { if (node.Attributes["shippingcostrange"].Value != null) { skuShippingCost = Convert.ToDecimal(node.Attributes["shippingcostrange"].Value); break; } } } } } } } st.LoadAttributeValues(); if (st.AttributeValues.ContainsKey("shippingwithquantity")) { if (st.AttributeValues["shippingwithquantity"].BooleanValue) { shippingCost += skuShippingCost * st.Quantity; } else { shippingCost += skuShippingCost; } } else { shippingCost += skuShippingCost; } } } if (isSKUPresent) { if (overRideShippingCostforAdditionalShippingScenario) { cart.ShippingCost = shippingCost; } else { cart.ShippingCost += shippingCost; } cart.RushShippingCost = 0; } } else { // Check here if cart has only items which in XML SKU List. bool cartHasOnlyXMLSku = false; foreach (Sku st in cart.CartItems) { string key = st.SkuId.ToString() + "_" + shippingPreferences.ShippingPrefID; if (dicSKUandPrice.ContainsKey(key)) { cartHasOnlyXMLSku = true; } else { cartHasOnlyXMLSku = false; break; } } if (cartHasOnlyXMLSku) { decimal shippingCost = 0; decimal skuShippingCost = 0; bool isSKUPresent = false; foreach (Sku st in cart.CartItems) { // if (st.SkuId == currentSetting.SkuId) string key = st.SkuId.ToString() + "_" + shippingPreferences.ShippingPrefID; if (dicSKUandPrice.ContainsKey(key)) { isSKUPresent = true; skuShippingCost = Convert.ToDecimal(dicSKUandPrice[key].ToString()); if (dicSKUShippingCostWithQtyRange[key].ToString().ToLower().Equals("yes") && dicSKUShippingCostWithQtyRangeList.ContainsKey(key) == true && dicSKUShippingCostWithQtyRange.ContainsKey(key) == true) { nodeName = (dicSKUShippingCostWithQtyRangeList[key]).Name; nodeXml = "<" + nodeName + ">" + dicSKUShippingCostWithQtyRangeList[key].InnerXml.ToString() + "</" + nodeName + ">"; XmlDocument doc = new XmlDocument(); doc.LoadXml(nodeXml); XmlNodeList nodeList = doc.SelectNodes("/" + nodeName + "/range"); foreach (XmlNode node in nodeList) { if (node.Attributes["lowerqty"] != null && node.Attributes["upperqty"] != null) { if (node.Attributes["lowerqty"].Value != null && node.Attributes["upperqty"].Value != null) { lowerQty = Convert.ToInt32(node.Attributes["lowerqty"].Value); upperQty = Convert.ToInt32(node.Attributes["upperqty"].Value); if (st.Quantity >= lowerQty && st.Quantity <= upperQty) { if (node.Attributes["shippingcostrange"] != null) { if (node.Attributes["shippingcostrange"].Value != null) { skuShippingCost = Convert.ToDecimal(node.Attributes["shippingcostrange"].Value); break; } } } } } } } st.LoadAttributeValues(); if (st.AttributeValues.ContainsKey("shippingwithquantity")) { if (st.AttributeValues["shippingwithquantity"].BooleanValue) { shippingCost += skuShippingCost * st.Quantity; } else { shippingCost += skuShippingCost; } } else { shippingCost += skuShippingCost; } } } if (isSKUPresent) { if (overRideShippingCostforAdditionalShippingScenario) { cart.ShippingCost = shippingCost; } else { cart.ShippingCost += shippingCost; } cart.RushShippingCost = 0; } } } } } } catch (Exception ex) { CSCore.CSLogger.Instance.LogException("Additional Shipping Scenario Calculation Issue ", ex); throw; } } } else { throw new InvalidOperationException("Missing shipping preferences"); } }
public ActionResult SubmitPayment(string paymentNonce) { var loadCartRequest = new LoadCartRequest("CommerceEngineDefaultStorefront", "Default", "1234"); var loadCartResult = _cartServiceProvider.LoadCart(loadCartRequest); var cart = loadCartResult.Cart as CommerceCart; // Add a shipping address CommerceParty shippingAddress = new CommerceParty(); shippingAddress.ExternalId = "Shipping"; shippingAddress.PartyId = shippingAddress.ExternalId; shippingAddress.Name = "Shipping"; shippingAddress.Address1 = "Barbara Strozzilaan 201"; shippingAddress.Company = "Sitecore"; shippingAddress.Country = "Canada"; shippingAddress.State = "NB"; // State is checked by commerce engine: you can configure it in Commerce shippingAddress.CountryCode = "CA"; // Country is checked by commerce engine shippingAddress.LastName = "Werkman"; shippingAddress.FirstName = "Erwin"; shippingAddress.City = "Amsterdam"; shippingAddress.ZipPostalCode = "1030AC"; var cartParties = cart.Parties.ToList(); cartParties.Add(shippingAddress); cart.Parties = cartParties; ShippingOptionType shippingOptionType = ShippingOptionType.ShipToAddress; ICollection <CommerceShippingInfo> shippingInfoList = new List <CommerceShippingInfo>(); var commerceShippingInfo = new CommerceShippingInfo(); commerceShippingInfo.ShippingOptionType = ShippingOptionType.ShipToAddress; commerceShippingInfo.PartyID = shippingAddress.ExternalId; commerceShippingInfo.ShippingMethodID = "B146622D-DC86-48A3-B72A-05EE8FFD187A"; // Ship Items > Ground commerceShippingInfo.ShippingMethodName = "Ground"; // Method id and name have to match what is configured in Sitecore Commerce Control Panel shippingInfoList.Add(commerceShippingInfo); var csShippingInfoList = new List <ShippingInfo>(); foreach (var shippingInfo in shippingInfoList) { csShippingInfoList.Add(shippingInfo); } // Add a shipping address and shipping method var addShippingInfoRequest = new Sitecore.Commerce.Engine.Connect.Services.Carts.AddShippingInfoRequest(cart, csShippingInfoList, shippingOptionType); var result = _cartServiceProvider.AddShippingInfo(addShippingInfoRequest); Assert.IsTrue(result.Success, String.Join("|", result.SystemMessages.Select(e => e.Message))); // Reload the cart so we have the latest information on how much we need to pay var reloadCartRequest = new LoadCartRequest("CommerceEngineDefaultStorefront", "Default", "1234"); var reloadedCartResult = _cartServiceProvider.LoadCart(reloadCartRequest); Assert.IsTrue(reloadedCartResult.Success, String.Join("|", reloadedCartResult.SystemMessages.Select(e => e.Message))); cart = reloadedCartResult.Cart as CommerceCart; CommerceParty billingAddress = new CommerceParty(); billingAddress.ExternalId = "Billing"; // This should correspond to the PartyId you are setting for the payment info billingAddress.PartyId = billingAddress.ExternalId; billingAddress.Name = "Billing"; billingAddress.Address1 = "Dorpsstraat 50"; billingAddress.Company = "Sitecore"; billingAddress.Country = "Canada"; billingAddress.State = "NB"; // State is checked: you can configure it in Commerce billingAddress.CountryCode = "CA"; billingAddress.LastName = "Werkman"; billingAddress.FirstName = "Erwin"; billingAddress.City = "Amsterdam"; billingAddress.ZipPostalCode = "1234AK"; cart.Parties.Add(billingAddress); var payments = new List <PaymentInfo>(); var federatedPaymentInfo = new FederatedPaymentInfo(); federatedPaymentInfo.PartyID = billingAddress.ExternalId; federatedPaymentInfo.PaymentMethodID = "0CFFAB11-2674-4A18-AB04-228B1F8A1DEC"; // Federated Payment federatedPaymentInfo.Amount = cart.Total.Amount; // Total payment (of all payment methods for a cart) should always be the same as the total amount of the order federatedPaymentInfo.CardToken = paymentNonce; payments.Add(federatedPaymentInfo); var addPaymentInfoRequest = new AddPaymentInfoRequest(cart, payments); var addPaymentInfoResult = _cartServiceProvider.AddPaymentInfo(addPaymentInfoRequest); Assert.IsTrue(addPaymentInfoResult.Success, String.Join("|", addPaymentInfoResult.SystemMessages.Select(e => e.Message))); cart.Email = "*****@*****.**"; // This is necessary otherwise the cart will not become an order // Save the cart as an order var submitVisitorOrderRequest = new SubmitVisitorOrderRequest(cart); var submitVisitorOrderResult = _orderServiceProvider.SubmitVisitorOrder(submitVisitorOrderRequest); Assert.IsTrue(submitVisitorOrderResult.Success, String.Join("|", submitVisitorOrderResult.SystemMessages.Select(e => e.Message))); return(View(submitVisitorOrderResult)); }
protected void btnSave_Command(object sender, System.Web.UI.WebControls.CommandEventArgs e) { if (e.CommandName == "Save") { ShippingOptionType option = ShippingOptionType.TotalAmount; ShippingOptionType optionRush = ShippingOptionType.TotalAmount; if (pnlOrderVal.Visible) { option = ShippingOptionType.TotalAmount; if (this.rptItems.Items.Count > 0) { using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection()) ) { foreach (RepeaterItem lst in rptItems.Items) { if ((lst.ItemType == ListItemType.Item) || (lst.ItemType == ListItemType.AlternatingItem)) { int Id = Convert.ToInt32(((Label)lst.FindControl("lblShippingId")).Text); TextBox txtOrderVal = (TextBox)lst.FindControl("txtOrderItem"); TextBox txtCostVal = (TextBox)lst.FindControl("txtCostItem"); ShippingOrderValue order = context.ShippingOrderValues.Single(p => p.ShippingId == Id); order.OrderTotal = Convert.ToDecimal(txtOrderVal.Text); order.Cost = Convert.ToDecimal(txtCostVal.Text); context.SubmitChanges(); } } } } } //end if for Shipping OrderValue if (pnlWeight.Visible) { option = ShippingOptionType.Weight; if (this.rptOrderWeight.Items.Count > 0) { using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection()) ) { foreach (RepeaterItem lst in rptOrderWeight.Items) { if ((lst.ItemType == ListItemType.Item) || (lst.ItemType == ListItemType.AlternatingItem)) { int Id = Convert.ToInt32(((Label)lst.FindControl("lblShippingId")).Text); TextBox txtOrderVal = (TextBox)lst.FindControl("txtOrderItem"); TextBox txtCostVal = (TextBox)lst.FindControl("txtCostItem"); ShippingOrderValue order = context.ShippingOrderValues.Single(p => p.ShippingId == Id); order.OrderTotal = Convert.ToDecimal(txtOrderVal.Text); order.Cost = Convert.ToDecimal(txtCostVal.Text); context.SubmitChanges(); } } } } } //end if for Shipping OrderWeight if (pnlSkuItem.Visible) { option = ShippingOptionType.SkuBased; if (this.rptSkuItem.Items.Count > 0) { using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection()) ) { foreach (RepeaterItem lst in rptSkuItem.Items) { if ((lst.ItemType == ListItemType.Item) || (lst.ItemType == ListItemType.AlternatingItem)) { int Id = Convert.ToInt32(((Label)lst.FindControl("lblSkuId")).Text); TextBox txtCostVal = (TextBox)lst.FindControl("txtPercentage"); SkuShipping order = context.SkuShippings.FirstOrDefault( p => (p.SkuId == Id) && (p.IncludeRushShipping == false) && (p.PrefId == 1)); if (order != null) { order.Cost = Convert.ToDecimal(txtCostVal.Text); context.SubmitChanges(); } else { SkuShipping item = new SkuShipping(); item.SkuId = Id; item.Cost = Convert.ToDecimal(txtCostVal.Text); item.IncludeRushShipping = false; item.PrefId = 1; context.SkuShippings.InsertOnSubmit(item); context.SubmitChanges(); } } } } } } //end if for Shipping SkuItem level if (pnlFlat.Visible) { option = ShippingOptionType.Flat; } if (cbRushShippingOption.Checked) { if (pnlRushOrderTotal.Visible) { optionRush = ShippingOptionType.TotalAmount; if (this.rptRushOrderTotal.Items.Count > 0) { using ( CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection()) ) { foreach (RepeaterItem lst in rptRushOrderTotal.Items) { if ((lst.ItemType == ListItemType.Item) || (lst.ItemType == ListItemType.AlternatingItem)) { int Id = Convert.ToInt32(((Label)lst.FindControl("lblShippingId")).Text); TextBox txtOrderVal = (TextBox)lst.FindControl("txtOrderItem"); TextBox txtCostVal = (TextBox)lst.FindControl("txtCostItem"); ShippingOrderValue order = context.ShippingOrderValues.Single(p => p.ShippingId == Id); order.OrderTotal = Convert.ToDecimal(txtOrderVal.Text); order.Cost = Convert.ToDecimal(txtCostVal.Text); context.SubmitChanges(); } } } } } if (pnlRushOrderweight.Visible) { optionRush = ShippingOptionType.Weight; if (this.rptRushOrderWeight.Items.Count > 0) { using ( CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection()) ) { foreach (RepeaterItem lst in rptRushOrderWeight.Items) { if ((lst.ItemType == ListItemType.Item) || (lst.ItemType == ListItemType.AlternatingItem)) { int Id = Convert.ToInt32(((Label)lst.FindControl("lblShippingId")).Text); TextBox txtOrderVal = (TextBox)lst.FindControl("txtOrderItem"); TextBox txtCostVal = (TextBox)lst.FindControl("txtCostItem"); ShippingOrderValue order = context.ShippingOrderValues.Single(p => p.ShippingId == Id); order.OrderTotal = Convert.ToDecimal(txtOrderVal.Text); order.Cost = Convert.ToDecimal(txtCostVal.Text); context.SubmitChanges(); } } } } } if (pnlRushSkuItem.Visible) { optionRush = ShippingOptionType.SkuBased; if (this.rptRushSkuItem.Items.Count > 0) { using ( CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection()) ) { foreach (RepeaterItem lst in rptRushSkuItem.Items) { if ((lst.ItemType == ListItemType.Item) || (lst.ItemType == ListItemType.AlternatingItem)) { int Id = Convert.ToInt32(((Label)lst.FindControl("lblSkuId")).Text); TextBox txtCostVal = (TextBox)lst.FindControl("txtPercentage"); SkuShipping order = context.SkuShippings.FirstOrDefault( p => (p.SkuId == Id) && (p.IncludeRushShipping == true) && (p.PrefId == 1)); if (order != null) { order.Cost = Convert.ToDecimal(txtCostVal.Text); context.SubmitChanges(); } else { SkuShipping item = new SkuShipping(); item.SkuId = Id; item.Cost = Convert.ToDecimal(txtCostVal.Text); item.IncludeRushShipping = true; item.PrefId = 1; context.SkuShippings.InsertOnSubmit(item); context.SubmitChanges(); } } } } } } } if (pnlRushFlat.Visible) { optionRush = ShippingOptionType.Flat; } using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection())) { ShippingPref Val = context.ShippingPrefs.FirstOrDefault(x => x.PrefId == DefaultSitePrefereceId); if (Val != null) { if (pnlFlat.Visible) { Val.flatShipping = Convert.ToDecimal(txtFlat.Text); } if (pnlRushFlat.Visible) { Val.RushShippingCost = Convert.ToDecimal(txtRushFlat.Text); } if (cbRushShippingOption.Checked) { Val.RushOptionId = (int)optionRush; } Val.OptionId = (int)option; Val.InCludeRushShipping = cbRushShippingOption.Checked; context.SubmitChanges(); } } // save additional charges if (this.rptShippingCharges.Items.Count > 0) { List <int> deleteList = new List <int>(); using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection())) { foreach (RepeaterItem lst in rptShippingCharges.Items) { if ((lst.ItemType == ListItemType.Item) || (lst.ItemType == ListItemType.AlternatingItem)) { int id = Convert.ToInt32(((HiddenField)lst.FindControl("hidShippingChargeId")).Value); CheckBox chkDelete = (CheckBox)lst.FindControl("chkDelete"); if (chkDelete.Checked) { deleteList.Add(id); } else { TextBox txtKey = (TextBox)lst.FindControl("txtKey"); TextBox txtCost = (TextBox)lst.FindControl("txtCost"); TextBox txtLabel = (TextBox)lst.FindControl("txtLabel"); ShippingCharge shippingCharge = context.ShippingCharges.Single(p => p.ShippingChargeId == id); shippingCharge.Key = txtKey.Text; shippingCharge.Cost = Convert.ToDecimal(txtCost.Text); shippingCharge.FriendlyLabel = txtLabel.Text; context.SubmitChanges(); } } } } if (deleteList.Count > 0) { foreach (int id in deleteList) { CSBusiness.Shipping.ShippingManager.RemoveShippingCharge(id); } } } lblCancel.Visible = false; lblSuccess.Visible = true; } //end of Save Command else { PopulateControls(); lblCancel.Visible = true; lblSuccess.Visible = false; } // Response.Redirect("Main.aspx"); }
public ActionResult Index() { var loadCartRequest = new LoadCartRequest("CommerceEngineDefaultStorefront", "Default", "1234"); var loadCartResult = _cartServiceProvider.LoadCart(loadCartRequest); var cart = loadCartResult.Cart as CommerceCart; var lines = new List <CartLine>(); var cartLine = new CommerceCartLine("Habitat_Master", "6042567", "56042567", 1.0M); lines.Add(cartLine); var addLinesRequest = new AddCartLinesRequest(cart, lines); var addLinesResult = _cartServiceProvider.AddCartLines(addLinesRequest); // Add a shipping address CommerceParty shippingAddress = new CommerceParty(); shippingAddress.ExternalId = "Shipping"; shippingAddress.PartyId = shippingAddress.ExternalId; shippingAddress.Name = "Shipping"; shippingAddress.Address1 = "Barbara Strozzilaan 201"; shippingAddress.Company = "Sitecore"; shippingAddress.Country = "Canada"; shippingAddress.State = "ON"; // State is checked by commerce engine: you can configure it in Commerce shippingAddress.CountryCode = "CA"; // Country is checked by commerce engine shippingAddress.LastName = "Werkman"; shippingAddress.FirstName = "Erwin"; shippingAddress.City = "Amsterdam"; shippingAddress.ZipPostalCode = "1030AC"; var cartParties = cart.Parties.ToList(); cartParties.Add(shippingAddress); cart.Parties = cartParties; ShippingOptionType shippingOptionType = ShippingOptionType.ShipToAddress; ICollection <CommerceShippingInfo> shippingInfoList = new List <CommerceShippingInfo>(); var commerceShippingInfo = new CommerceShippingInfo(); commerceShippingInfo.ShippingOptionType = ShippingOptionType.ShipToAddress; commerceShippingInfo.PartyID = shippingAddress.ExternalId; commerceShippingInfo.ShippingMethodID = "B146622D-DC86-48A3-B72A-05EE8FFD187A"; // Ship Items > Ground commerceShippingInfo.ShippingMethodName = "Ground"; // Method id and name have to match what is configured in Sitecore Commerce Control Panel shippingInfoList.Add(commerceShippingInfo); var csShippingInfoList = new List <ShippingInfo>(); foreach (var shippingInfo in shippingInfoList) { csShippingInfoList.Add(shippingInfo); } // Add a shipping address and shipping method var addShippingInfoRequest = new Sitecore.Commerce.Engine.Connect.Services.Carts.AddShippingInfoRequest(cart, csShippingInfoList, shippingOptionType); var result = _cartServiceProvider.AddShippingInfo(addShippingInfoRequest); cart = result.Cart as CommerceCart; // Add billing address CommerceParty billingAddress = new CommerceParty(); billingAddress.ExternalId = "Billing"; // This should correspond to the PartyId you are setting for the payment info billingAddress.PartyId = billingAddress.ExternalId; billingAddress.Name = "Billing"; billingAddress.Address1 = "Dorpsstraat 50"; billingAddress.Company = "Sitecore"; billingAddress.Country = "Canada"; billingAddress.State = "ON"; // State is checked: you can configure it in Commerce billingAddress.CountryCode = "CA"; billingAddress.LastName = "Werkman"; billingAddress.FirstName = "Erwin"; billingAddress.City = "Amsterdam"; billingAddress.ZipPostalCode = "1234AK"; cart.Parties.Add(billingAddress); // Add a payment address and payment method var payments = new List <PaymentInfo>(); var simplePaymentInfo = new SimplePaymentInfo(); simplePaymentInfo.PaymentMethodID = "9B110CC3-C7C8-4492-8FCF-0CDE5D3E0EB0"; simplePaymentInfo.Amount = cart.Total.Amount; payments.Add(simplePaymentInfo); /* * var giftCardPaymentInfo = new GiftCardPaymentInfo(); * giftCardPaymentInfo.PaymentMethodID = "B5E5464E-C851-4C3C-8086-A4A874DD2DB0"; // GiftCard * giftCardPaymentInfo.Amount = cart.Total.Amount; * giftCardPaymentInfo.ExternalId = "GC1000000"; // This is the number of the giftcard * giftCardPaymentInfo.PartyID = billingAddress.ExternalId; // For a gift card this is not really necessary and not recorded * * payments.Add(giftCardPaymentInfo); */ var addPaymentInfoRequest = new AddPaymentInfoRequest(cart, payments); var addPaymentInfoResult = _cartServiceProvider.AddPaymentInfo(addPaymentInfoRequest); return(View("Cart", addPaymentInfoResult)); }
public ActionResult BasketToOrder() { var shopName = "CommerceEngineDefaultStorefront"; // Better use a configured store, not CommerceEngineDefaultStorefront as it's not really configured var cartName = "Default"; var userId = "Entity-Customer-34d758ae2d2d472d89014954d0cc4440"; var domain = Context.User.Domain; // Get a cart var loadCartRequest = new LoadCartByNameRequest(shopName, cartName, userId); var cartResult = _cartServiceProvider.LoadCart(loadCartRequest); Assert.IsTrue(cartResult.Success, String.Join("|", cartResult.SystemMessages.Select(e => e.Message))); var cart = cartResult.Cart; var quantity = 0.0M; // Get initial quantity if (cart.Lines.Count > 0) { quantity = cart.Lines[0].Quantity; } // Add a cart line: note that adding a line for the same product twice will update the quantity, not add a line: this is configured in commerce engine (look for RollupCartLinesPolicy) var lines = new List <CartLine>(); var cartLine = new CommerceCartLine("Neu", "47838_aus_allen_sternen_liebe_cd", "", 1.0M); lines.Add(cartLine); var addLinesRequest = new AddCartLinesRequest(cart, lines); var addLinesResult = _cartServiceProvider.AddCartLines(addLinesRequest); Assert.IsTrue(addLinesResult.Success, String.Join("|", addLinesResult.SystemMessages.Select(e => e.Message))); var updatedCart = addLinesResult.Cart; Assert.IsTrue(updatedCart.Lines.Count > 0, "Updated cart should have at least one line"); Assert.IsTrue(quantity + 1 == updatedCart.Lines[0].Quantity, "new quantity should be one more than before"); var reloadCartRequest = new LoadCartByNameRequest(shopName, cartName, userId); var reloadedCartResult = _cartServiceProvider.LoadCart(reloadCartRequest); Assert.IsTrue(reloadedCartResult.Success, String.Join("|", reloadedCartResult.SystemMessages.Select(e => e.Message))); var reloadedCart = reloadedCartResult.Cart; Assert.IsTrue(reloadedCart.Lines.Count > 0, "Reloaded cart should have at least one line"); Assert.IsTrue(quantity + 1 == reloadedCart.Lines[0].Quantity, "reloaded cart quantity should be one more than before"); // Switching cart :-) cart = reloadedCart; // Add a shipping address CommerceParty shippingAddress = new CommerceParty(); shippingAddress.ExternalId = "Shipping"; shippingAddress.PartyId = shippingAddress.ExternalId; shippingAddress.Name = "Shipping"; shippingAddress.Address1 = "Barbara Strozzilaan 201"; shippingAddress.Company = "Sitecore"; shippingAddress.Country = "Canada"; shippingAddress.State = "ON"; // State is checked by commerce engine: you can configure it in Commerce shippingAddress.CountryCode = "CA"; // Country is checked by commerce engine shippingAddress.LastName = "Werkman"; shippingAddress.FirstName = "Erwin"; shippingAddress.City = "Amsterdam"; shippingAddress.ZipPostalCode = "1030AC"; var cartParties = cart.Parties.ToList(); cartParties.Add(shippingAddress); cart.Parties = cartParties; ShippingOptionType shippingOptionType = ShippingOptionType.ShipToAddress; ICollection <CommerceShippingInfo> shippingInfoList = new List <CommerceShippingInfo>(); var commerceShippingInfo = new CommerceShippingInfo(); commerceShippingInfo.ShippingOptionType = ShippingOptionType.ShipToAddress; commerceShippingInfo.PartyID = shippingAddress.ExternalId; commerceShippingInfo.ShippingMethodID = "B146622D-DC86-48A3-B72A-05EE8FFD187A"; // Ship Items > Ground commerceShippingInfo.ShippingMethodName = "Ground"; // Method id and name have to match what is configured in Sitecore Commerce Control Panel shippingInfoList.Add(commerceShippingInfo); var csShippingInfoList = new List <ShippingInfo>(); foreach (var shippingInfo in shippingInfoList) { csShippingInfoList.Add(shippingInfo); } // Add a shipping address and shipping method var addShippingInfoRequest = new Sitecore.Commerce.Engine.Connect.Services.Carts.AddShippingInfoRequest(cart, csShippingInfoList, shippingOptionType); var result = _cartServiceProvider.AddShippingInfo(addShippingInfoRequest); Assert.IsTrue(result.Success, String.Join("|", result.SystemMessages.Select(e => e.Message))); // Reload the cart so we have the latest information on how much we need to pay reloadedCartResult = _cartServiceProvider.LoadCart(reloadCartRequest); Assert.IsTrue(reloadedCartResult.Success, String.Join("|", reloadedCartResult.SystemMessages.Select(e => e.Message))); cart = reloadedCartResult.Cart; // Add billing address CommerceParty billingAddress = new CommerceParty(); billingAddress.ExternalId = "Billing"; // This should correspond to the PartyId you are setting for the payment info billingAddress.PartyId = billingAddress.ExternalId; billingAddress.Name = "Billing"; billingAddress.Address1 = "Dorpsstraat 50"; billingAddress.Company = "Sitecore"; billingAddress.Country = "Canada"; billingAddress.State = "ON"; // State is checked: you can configure it in Commerce billingAddress.CountryCode = "CA"; billingAddress.LastName = "Werkman"; billingAddress.FirstName = "Erwin"; billingAddress.City = "Amsterdam"; billingAddress.ZipPostalCode = "1234AK"; cart.Parties.Add(billingAddress); // Add a payment address and payment method var payments = new List <PaymentInfo>(); /* * For federated payment info to work, you need to set up the Braintree integration * var federatedPaymentInfo = new FederatedPaymentInfo(); * * federatedPaymentInfo.PartyID = billingAddress.ExternalId; * federatedPaymentInfo.PaymentMethodID = "0CFFAB11-2674-4A18-AB04-228B1F8A1DEC"; // Federated Payment * federatedPaymentInfo.Amount = cart.Total.Amount; // Total payment (of all payment methods for a cart) should always be the same as the total amount of the order * federatedPaymentInfo.CardToken = "payment-nonce"; // This should be valid b * * payments.Add(federatedPaymentInfo); */ var giftCardPaymentInfo = new GiftCardPaymentInfo(); giftCardPaymentInfo.PaymentMethodID = "B5E5464E-C851-4C3C-8086-A4A874DD2DB0"; // GiftCard giftCardPaymentInfo.Amount = cart.Total.Amount; giftCardPaymentInfo.ExternalId = "GC1000000"; // This is the number of the giftcard giftCardPaymentInfo.PartyID = billingAddress.ExternalId; payments.Add(giftCardPaymentInfo); var addPaymentInfoRequest = new AddPaymentInfoRequest(cart, payments); var addPaymentInfoResult = _cartServiceProvider.AddPaymentInfo(addPaymentInfoRequest); Assert.IsTrue(addPaymentInfoResult.Success, String.Join("|", addPaymentInfoResult.SystemMessages.Select(e => e.Message))); var freshCartRequest = new LoadCartByNameRequest(shopName, cartName, userId); var freshCartResult = _cartServiceProvider.LoadCart(reloadCartRequest); Assert.IsTrue(freshCartResult.Success, String.Join("|", freshCartResult.SystemMessages.Select(e => e.Message))); cart.Email = "*****@*****.**"; // This is necessary otherwise the cart will not become an order // Save the cart as an order var submitVisitorOrderRequest = new SubmitVisitorOrderRequest(cart); var submitVisitorOrderResult = _orderServiceProvider.SubmitVisitorOrder(submitVisitorOrderRequest); Assert.IsTrue(submitVisitorOrderResult.Success, String.Join("|", submitVisitorOrderResult.SystemMessages.Select(e => e.Message))); return(View("Cart", freshCartResult)); }
/// <summary> /// Save Command Operation /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSave_Command(object sender, System.Web.UI.WebControls.CommandEventArgs e) { if (e.CommandName == "Save") { ShippingOptionType option = ShippingOptionType.SiteLevelPref; ShippingOptionType optionRush = ShippingOptionType.SiteLevelPref; int?stateId = null; int countryId; if (DropDownListState.SelectedItem.Value.Length > 0) { stateId = Convert.ToInt32(DropDownListState.SelectedItem.Value); } countryId = Convert.ToInt32(DropDownListCountry.SelectedItem.Value); if (PrefId == 0) //New Region Defined in the system { //Check User Creating same Custom Shipping again or not if (!ShippingDAL.IsValidShippingRegion(countryId, stateId)) { using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection())) { ShippingPref item = new ShippingPref { flatShipping = (pnlFlat.Visible) ? Convert.ToDecimal(txtFlat.Text) : 0, RushShippingCost = (pnlRushFlat.Visible) ? Convert.ToDecimal(txtRushFlat.Text) : 0, RushOptionId = (int)optionRush, OptionId = (int)option, InCludeRushShipping = cbRushShippingOption.Checked, IsCustomized = true }; context.ShippingPrefs.InsertOnSubmit(item); context.SubmitChanges(); PrefId = item.PrefId; //Associate PrefId to Region Table ShippingRegion newRegion = new ShippingRegion { CountryId = countryId, StateId = stateId, PrefId = PrefId }; context.ShippingRegions.InsertOnSubmit(newRegion); context.SubmitChanges(); } } else { //fire Existing Item Message } } if (PrefId > 0) { if (pnlOrderVal.Visible) { option = ShippingOptionType.TotalAmount; if (this.rptItems.Items.Count > 0) { using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection())) { foreach (RepeaterItem lst in rptItems.Items) { if ((lst.ItemType == ListItemType.Item) || (lst.ItemType == ListItemType.AlternatingItem)) { int Id = Convert.ToInt32(((Label)lst.FindControl("lblShippingId")).Text); TextBox txtOrderVal = (TextBox)lst.FindControl("txtOrderItem"); TextBox txtCostVal = (TextBox)lst.FindControl("txtCostItem"); ShippingOrderValue order = context.ShippingOrderValues.Single(p => p.ShippingId == Id); if (order != null) { order.OrderTotal = Convert.ToDecimal(txtOrderVal.Text); order.Cost = Convert.ToDecimal(txtCostVal.Text); order.PrefId = PrefId; context.SubmitChanges(); } } } } } } //end if for Shipping OrderValue if (pnlWeight.Visible) { option = ShippingOptionType.Weight; if (this.rptOrderWeight.Items.Count > 0) { using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection())) { foreach (RepeaterItem lst in rptOrderWeight.Items) { if ((lst.ItemType == ListItemType.Item) || (lst.ItemType == ListItemType.AlternatingItem)) { int Id = Convert.ToInt32(((Label)lst.FindControl("lblShippingId")).Text); TextBox txtOrderVal = (TextBox)lst.FindControl("txtOrderItem"); TextBox txtCostVal = (TextBox)lst.FindControl("txtCostItem"); ShippingOrderValue order = context.ShippingOrderValues.Single(p => p.ShippingId == Id); if (order != null) { order.OrderTotal = Convert.ToDecimal(txtOrderVal.Text); order.Cost = Convert.ToDecimal(txtCostVal.Text); order.PrefId = PrefId; context.SubmitChanges(); } } } } } }//end if for Shipping OrderWeight if (pnlSkuItem.Visible) { option = ShippingOptionType.SkuBased; if (this.rptSkuItem.Items.Count > 0) { using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection())) { foreach (RepeaterItem lst in rptSkuItem.Items) { if ((lst.ItemType == ListItemType.Item) || (lst.ItemType == ListItemType.AlternatingItem)) { int Id = Convert.ToInt32(((Label)lst.FindControl("lblSkuId")).Text); TextBox txtCostVal = (TextBox)lst.FindControl("txtPercentage"); SkuShipping order = context.SkuShippings.FirstOrDefault(p => (p.SkuId == Id) && (p.IncludeRushShipping == false) && (p.PrefId == PrefId)); if (order != null) { order.Cost = Convert.ToDecimal(txtCostVal.Text); context.SubmitChanges(); } else { SkuShipping item = new SkuShipping(); item.SkuId = Id; item.Cost = Convert.ToDecimal(txtCostVal.Text); item.IncludeRushShipping = false; item.PrefId = PrefId; context.SkuShippings.InsertOnSubmit(item); context.SubmitChanges(); } } } } } }//end if for Shipping SkuItem level if (pnlFlat.Visible) { option = ShippingOptionType.Flat; } if (cbSitePref.Checked) { option = ShippingOptionType.SiteLevelPref; } if (cbRushShippingOption.Checked) { if (pnlRushOrderTotal.Visible) { optionRush = ShippingOptionType.TotalAmount; if (this.rptRushOrderTotal.Items.Count > 0) { using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection())) { foreach (RepeaterItem lst in rptRushOrderTotal.Items) { if ((lst.ItemType == ListItemType.Item) || (lst.ItemType == ListItemType.AlternatingItem)) { int Id = Convert.ToInt32(((Label)lst.FindControl("lblShippingId")).Text); TextBox txtOrderVal = (TextBox)lst.FindControl("txtOrderItem"); TextBox txtCostVal = (TextBox)lst.FindControl("txtCostItem"); ShippingOrderValue order = context.ShippingOrderValues.Single(p => p.ShippingId == Id); if (order != null) { order.OrderTotal = Convert.ToDecimal(txtOrderVal.Text); order.Cost = Convert.ToDecimal(txtCostVal.Text); order.PrefId = PrefId; context.SubmitChanges(); } } } } } } if (pnlRushOrderweight.Visible) { optionRush = ShippingOptionType.Weight; if (this.rptRushOrderWeight.Items.Count > 0) { using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection())) { foreach (RepeaterItem lst in rptRushOrderWeight.Items) { if ((lst.ItemType == ListItemType.Item) || (lst.ItemType == ListItemType.AlternatingItem)) { int Id = Convert.ToInt32(((Label)lst.FindControl("lblShippingId")).Text); TextBox txtOrderVal = (TextBox)lst.FindControl("txtOrderItem"); TextBox txtCostVal = (TextBox)lst.FindControl("txtCostItem"); ShippingOrderValue order = context.ShippingOrderValues.Single(p => p.ShippingId == Id); if (order != null) { order.OrderTotal = Convert.ToDecimal(txtOrderVal.Text); order.Cost = Convert.ToDecimal(txtCostVal.Text); order.PrefId = PrefId; context.SubmitChanges(); } } } } } } if (pnlRushSkuItem.Visible) { optionRush = ShippingOptionType.SkuBased; if (this.rptRushSkuItem.Items.Count > 0) { using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection())) { foreach (RepeaterItem lst in rptRushSkuItem.Items) { if ((lst.ItemType == ListItemType.Item) || (lst.ItemType == ListItemType.AlternatingItem)) { int Id = Convert.ToInt32(((Label)lst.FindControl("lblSkuId")).Text); TextBox txtCostVal = (TextBox)lst.FindControl("txtPercentage"); SkuShipping order = context.SkuShippings.FirstOrDefault(p => (p.SkuId == Id) && (p.IncludeRushShipping == true) && (p.PrefId == PrefId)); if (order != null) { order.Cost = Convert.ToDecimal(txtCostVal.Text); context.SubmitChanges(); } else { SkuShipping item = new SkuShipping(); item.SkuId = Id; item.Cost = Convert.ToDecimal(txtCostVal.Text); item.IncludeRushShipping = true; item.PrefId = PrefId; context.SkuShippings.InsertOnSubmit(item); context.SubmitChanges(); } } } } } } } if (pnlRushFlat.Visible) { optionRush = ShippingOptionType.Flat; } if (cbRushSitePref.Checked) { optionRush = ShippingOptionType.SiteLevelPref; } using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection())) { ShippingPref Val = context.ShippingPrefs.FirstOrDefault(x => x.PrefId == PrefId); if (Val != null) { if (pnlFlat.Visible) { Val.flatShipping = Convert.ToDecimal(txtFlat.Text); } if (pnlRushFlat.Visible) { Val.RushShippingCost = Convert.ToDecimal(txtRushFlat.Text); } if (cbRushShippingOption.Checked) { Val.RushOptionId = (int)optionRush; } Val.OptionId = (int)option; Val.InCludeRushShipping = cbRushShippingOption.Checked; context.SubmitChanges(); } } }// prefId check // save additional charges if (this.rptShippingCharges.Items.Count > 0) { List <int> deleteList = new List <int>(); using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection())) { foreach (RepeaterItem lst in rptShippingCharges.Items) { if ((lst.ItemType == ListItemType.Item) || (lst.ItemType == ListItemType.AlternatingItem)) { int id = Convert.ToInt32(((HiddenField)lst.FindControl("hidShippingChargeId")).Value); CheckBox chkDelete = (CheckBox)lst.FindControl("chkDelete"); if (chkDelete.Checked) { deleteList.Add(id); } else { TextBox txtKey = (TextBox)lst.FindControl("txtKey"); TextBox txtCost = (TextBox)lst.FindControl("txtCost"); TextBox txtLabel = (TextBox)lst.FindControl("txtLabel"); ShippingCharge shippingCharge = context.ShippingCharges.Single(p => p.ShippingChargeId == id); shippingCharge.Key = txtKey.Text; shippingCharge.Cost = Convert.ToDecimal(txtCost.Text); shippingCharge.FriendlyLabel = txtLabel.Text; context.SubmitChanges(); } } } } if (deleteList.Count > 0) { foreach (int id in deleteList) { CSBusiness.Shipping.ShippingManager.RemoveShippingCharge(id); } } } }//end of save Response.Redirect("CustomShippingList.aspx"); }
/// <summary> /// Adds shipping info to a cart /// </summary> /// <param name="cart">The cart.</param> /// <param name="orderShippingPreferenceType">Type of the order shipping preference.</param> /// <param name="shipments">The shipments.</param> /// <returns> /// the updated cart /// </returns> protected virtual AddShippingInfoResult AddShippingInfoToCart([NotNull] CommerceCart cart, [NotNull] ShippingOptionType orderShippingPreferenceType, [NotNull] IEnumerable <ShippingInfo> shipments) { Assert.ArgumentNotNull(cart, "cart"); Assert.ArgumentNotNull(orderShippingPreferenceType, "orderShippingPreferenceType"); Assert.ArgumentNotNull(shipments, "shipments"); var request = new AddShippingInformationRequest(cart, shipments.ToList(), orderShippingPreferenceType); var result = this.CartServiceProvider.AddShippingInfo(request); if (!result.Success) { Helpers.LogSystemMessages(result.SystemMessages, result); } return(result); }