void grid_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e) { bool isApplied = gridPersister.IsAppliedSortFilterOrGroup; int iCount = ShoppingCartItem.GetCount(siteSettings.SiteId, Convert.ToInt32(ddlCartType.SelectedValue)); int startRowIndex = isApplied ? 1 : grid.CurrentPageIndex + 1; int maximumRows = isApplied ? iCount : grid.PageSize; grid.VirtualItemCount = iCount; grid.AllowCustomPaging = !isApplied; grid.PagerStyle.EnableSEOPaging = !isApplied; List <ShoppingCartItem> list = ShoppingCartItem.GetPage( siteSettings.SiteId, Convert.ToInt32(ddlCartType.SelectedValue), startRowIndex, maximumRows); if (ProductConfiguration.EnableShoppingCartAttributes) { var lstProductIds = list.Select(x => x.ProductId).Distinct().ToList(); customFields = CustomField.GetActiveForCart(siteSettings.SiteId, Product.FeatureGuid); if (customFields.Count > 0 && lstProductIds.Count > 0) { productProperties = ProductProperty.GetPropertiesByProducts(lstProductIds); } } grid.DataSource = list; }
private bool SaveOrderSummary(Order order, List <ShoppingCartItem> cartList) { List <Product> lstProductsInCart = Product.GetByShoppingCart(siteSettings.SiteId, CartHelper.GetCartSessionGuid(siteSettings.SiteId)); List <CustomField> customFields = new List <CustomField>(); List <ProductProperty> productProperties = new List <ProductProperty>(); if (ProductConfiguration.EnableShoppingCartAttributes && ProductConfiguration.EnableAttributesPriceAdjustment) { List <int> lstProductIds = lstProductsInCart.Select(x => x.ProductId).Distinct().ToList(); productProperties = ProductProperty.GetPropertiesByProducts(lstProductIds); if (productProperties.Count > 0) { var customFieldIds = productProperties.Select(x => x.CustomFieldId).Distinct().ToList(); customFields = CustomField.GetByOption(CustomField.GetActiveByFields(siteSettings.SiteId, Product.FeatureGuid, customFieldIds), CustomFieldOptions.EnableShoppingCart); } } //List<CouponAppliedToItem> lstAppliedItems = new List<CouponAppliedToItem>(); //Coupon coupon = null; //if (CartHelper.CouponCodeInput.Length > 0) // lstAppliedItems = CartHelper.GetAppliedItems(siteSettings.SiteId, cartList, lstProductsInCart, out coupon); decimal totalDiscount = decimal.Zero; List <OrderItem> lstOrderItem = new List <OrderItem>(); foreach (ShoppingCartItem itm in cartList) { Product product = ProductHelper.GetProductFromList(lstProductsInCart, itm.ProductId); if (product != null) { decimal discount = decimal.Zero; decimal price = ProductHelper.GetPrice(product); //if (lstAppliedItems.Count > 0) //{ // CouponAppliedToItem appliedToItem = CouponAppliedToItem.FindFromList(lstAppliedItems, product.ZoneId, (int)CouponAppliedType.ToCategories); // if (appliedToItem == null) // appliedToItem = CouponAppliedToItem.FindFromList(lstAppliedItems, product.ProductId, (int)CouponAppliedType.ToProducts); // if (appliedToItem != null) // { // int totalRemain = 0; // if (coupon.MaximumQtyDiscount > 0) // { // int totalQty = OrderItem.GetTotalItemsByCoupon(product.ProductId, coupon.CouponCode); // totalRemain = coupon.MaximumQtyDiscount - totalQty; // if (totalRemain <= 0) // totalRemain = -1; // } // if (totalRemain >= 0) // { // int qtyApplied = Math.Min(coupon.DiscountQtyStep, itm.Quantity); // if (totalRemain > 0) // qtyApplied = Math.Min(qtyApplied, totalRemain); // if (appliedToItem.Discount > 0) // { // if (appliedToItem.UsePercentage) // discount = (appliedToItem.Discount * product.Price * qtyApplied) / 100; // else // discount = appliedToItem.Discount * qtyApplied; // } // else // { // if (coupon.DiscountType == (int)CouponDiscountType.PercentagePerProduct) // discount = (coupon.Discount * product.Price * qtyApplied) / 100; // else // discount = coupon.Discount * qtyApplied; // } // totalDiscount += discount; // } // } //} if (!string.IsNullOrEmpty(itm.AttributesXml)) { var attributes = ProductAttributeParser.ParseProductAttributeMappings(customFields, itm.AttributesXml); if (attributes.Count > 0) { foreach (var a in attributes) { var values = ProductAttributeParser.ParseValues(itm.AttributesXml, a.CustomFieldId); if (values.Count > 0) { productProperties.ForEach(property => { if (property.ProductId == product.ProductId && property.CustomFieldId == a.CustomFieldId && values.Contains(property.CustomFieldOptionId)) { price += property.OverriddenPrice; } }); } } } } OrderItem orderItem = new OrderItem(); orderItem.OrderId = order.OrderId; orderItem.Price = price; orderItem.DiscountAmount = discount; orderItem.ProductId = itm.ProductId; orderItem.Quantity = itm.Quantity; orderItem.AttributesXml = itm.AttributesXml; orderItem.AttributeDescription = itm.CreatedFromIP; totalDiscount += discount; orderItem.Save(); lstOrderItem.Add(orderItem); } ShoppingCartItem.Delete(itm.Guid); } decimal shippingPrice = decimal.Zero; if (order.ShippingMethod > 0) { decimal orderSubTotal = cartList.GetSubTotal(lstProductsInCart); decimal orderWeight = cartList.GetTotalWeights(lstProductsInCart); int productTotalQty = cartList.GetTotalProducts(); string geoZoneGuids = ProductHelper.GetShippingGeoZoneGuidsByOrderSession(order); shippingPrice = ProductHelper.GetShippingPrice(order.ShippingMethod, orderSubTotal, orderWeight, productTotalQty, geoZoneGuids); } decimal subTotal = cartList.GetSubTotal(lstProductsInCart); //order.UserPoint = 0; //order.UserPointDiscount = 0; //int point = 0; //string currentPoint = GetPostValue("hdfCurrentPoint", "0"); //int.TryParse(currentPoint, out point); //if (point >= 0 && Request.IsAuthenticated) //{ // SiteUser siteUser = SiteUtils.GetCurrentSiteUser(); // if (siteUser != null && siteUser.UserId > 0 && point <= siteUser.TotalPosts) // { // order.UserPoint = point; // order.UserPointDiscount = ProductHelper.GetDiscountByPoint(point); // int bonusPoint = Convert.ToInt32(Math.Round(subTotal / 1000)); // SiteUserEx.UpdateUserPoints(siteUser.UserGuid, (siteUser.TotalPosts - point) + bonusPoint); // } //} decimal total = CartHelper.GetCartTotal(subTotal: subTotal, shippingTotal: shippingPrice, pointDiscount: order.UserPointDiscount); order.OrderDiscount = totalDiscount; order.OrderSubtotal = subTotal; order.OrderShipping = shippingPrice; order.OrderTotal = total; //if (lstAppliedItems.Count > 0 && coupon != null) //{ // order.CouponCode = coupon.CouponCode; // var history = new CouponUsageHistory(); // history.OrderId = order.OrderId; // history.CouponId = coupon.CouponId; // history.Save(); //} order.Save(); string billingProvinceName = string.Empty; string billingDistrictName = string.Empty; string shippingProvinceName = string.Empty; string shippingDistrictName = string.Empty; if (order.BillingProvinceGuid != Guid.Empty) { var province = new GeoZone(order.BillingProvinceGuid); if (province != null && province.Guid != Guid.Empty) { billingProvinceName = province.Name; } } if (order.BillingDistrictGuid != Guid.Empty) { var province = new GeoZone(order.BillingDistrictGuid); if (province != null && province.Guid != Guid.Empty) { billingDistrictName = province.Name; } } if (order.ShippingProvinceGuid != Guid.Empty) { var province = new GeoZone(order.ShippingProvinceGuid); if (province != null && province.Guid != Guid.Empty) { shippingProvinceName = province.Name; } } if (order.ShippingDistrictGuid != Guid.Empty) { var province = new GeoZone(order.ShippingDistrictGuid); if (province != null && province.Guid != Guid.Empty) { shippingDistrictName = province.Name; } } string toEmail = order.BillingEmail.Trim(); if ( order.ShippingEmail.Length > 0 && !string.Equals(toEmail, order.ShippingEmail, StringComparison.CurrentCultureIgnoreCase) ) { toEmail += "," + order.ShippingEmail; } //ProductHelper.SendOrderPlacedNotification(siteSettings, order, lstProductsInCart, lstOrderItem, "OrderPlacedCustomerNotification", billingProvinceName, billingDistrictName, shippingProvinceName, shippingDistrictName, toEmail); ProductHelper.SendOrderPlacedNotification(siteSettings, order, lstProductsInCart, lstOrderItem, "OrderPlacedStoreOwnerNotification", billingProvinceName, billingDistrictName, shippingProvinceName, shippingDistrictName); WebTaskManager.StartOrResumeTasks(); return(true); }
private XmlDocument GetPageXml(int zoneId, int pageNumber, int pageSize, out int totalPages) { XmlDocument doc = new XmlDocument(); doc.LoadXml("<ProductList></ProductList>"); XmlElement root = doc.DocumentElement; XmlHelper.AddNode(doc, root, "ModuleTitle", this.moduleTitle); XmlHelper.AddNode(doc, root, "ZoneTitle", basePage.CurrentZone.Name); XmlHelper.AddNode(doc, root, "ZoneDescription", basePage.CurrentZone.Description); XmlHelper.AddNode(doc, root, "ViewMore", ProductResources.ViewMoreLabel); XmlHelper.AddNode(doc, root, "SiteUrl", siteRoot); XmlHelper.AddNode(doc, root, "ZoneUrl", SiteUtils.GetCurrentZoneUrl()); if (module != null && module.ResourceFileDef.Length > 0 && module.ResourceKeyDef.Length > 0) { List <string> lstResourceKeys = module.ResourceKeyDef.SplitOnCharAndTrim(';'); foreach (string item in lstResourceKeys) { XmlHelper.AddNode(doc, root, item, ResourceHelper.GetResourceString(module.ResourceFileDef, item)); } } //Render view mode BuildViewModeXml(doc, root); //Render sort mode BuildSortModeXml(doc, root); int languageId = WorkingCulture.LanguageId; List <Product> lstProducts = new List <Product>(); string propertyCondition = string.Empty; string andClause = " "; int numberGroup = 0; List <CustomField> lstCustomFields = CustomFieldHelper.GetCustomFieldsFromContext(siteSettings.SiteId, Product.FeatureGuid, basePage.CurrentZone.ZoneGuid, languageId); foreach (CustomField field in lstCustomFields) { if ( field.DataType == (int)CustomFieldDataType.CheckBox || field.DataType == (int)CustomFieldDataType.SelectBox ) { if (field.FilterType == (int)CustomFieldFilterType.ByValue) { string paramName = ProductHelper.QueryStringFilterSingleParam + field.CustomFieldId.ToString(); int optionValue = WebUtils.ParseInt32FromQueryString(paramName, -1); if (optionValue > 0) { propertyCondition += andClause + "(CustomFieldID=" + field.CustomFieldId + " AND CustomFieldOptionID=" + optionValue.ToString() + ")"; andClause = " OR "; numberGroup += 1; } } else { string paramName = ProductHelper.QueryStringFilterMultiParam + field.CustomFieldId.ToString(); string optionValues = WebUtils.ParseStringFromQueryString(paramName, string.Empty); // Split and validate data List <int> lstValues = new List <int>(); optionValues.SplitOnCharAndTrim('/').ForEach(s => { int value = -1; if (int.TryParse(s, out value)) { lstValues.Add(value); } }); if (lstValues.Count > 0) { propertyCondition += andClause + "(CustomFieldID=" + field.CustomFieldId + " AND CustomFieldOptionID IN (" + string.Join(",", lstValues.ToArray()) + "))"; andClause = " OR "; numberGroup += 1; } } } } if (numberGroup > 0) { propertyCondition = "(SELECT COUNT(DISTINCT CustomFieldID) FROM gb_ProductProperties WHERE ProductID=p.ProductID AND (" + propertyCondition + ")) = " + numberGroup.ToString(); } string keyword = null; if (config.EnableKeywordFiltering) { keyword = WebUtils.ParseStringFromQueryString(ProductHelper.QueryStringKeywordParam, null); } int sort = WebUtils.ParseInt32FromQueryString(ProductHelper.QueryStringSortModeParam, 0); decimal?priceMin; decimal?priceMax; ProductHelper.GetPriceFromQueryString(out priceMin, out priceMax); int totalRows = 0; if (numberGroup > 0 || priceMin != null || priceMax != null || sort > 0 || !string.IsNullOrEmpty(keyword) ) { string rangeZoneIds = null; if (ProductConfiguration.FilterProductByTopLevelParentZones) { var topLevelNode = SiteUtils.GetTopLevelParentNode(SiteUtils.GetSiteMapNodeByZoneId(zoneId)); if (topLevelNode != null) { rangeZoneIds = ProductHelper.GetRangeZoneIdsToSemiColonSeparatedString(siteSettings.SiteId, topLevelNode.ZoneId); } } else { if (config.ZoneIds.Length == 0) { rangeZoneIds = ProductHelper.GetRangeZoneIdsToSemiColonSeparatedString(siteSettings.SiteId, zoneId); } else { rangeZoneIds = config.ZoneIds; } } totalRows = Product.GetCountBySearch(siteSettings.SiteId, rangeZoneIds, 1, languageId, -1, -1, priceMin, priceMax, -1, -1, propertyCondition, null, keyword); if (pageSize == -1) { pageSize = totalRows; } totalPages = CaculateTotalPages(pageSize, totalRows); lstProducts = Product.GetPageBySearch(pageNumber, pageSize, siteSettings.SiteId, rangeZoneIds, 1, languageId, -1, -1, priceMin, priceMax, -1, -1, propertyCondition, null, keyword, false, null, sort); } else { if (config.ZoneIds.Length == 0) { if (config.ShowAllProducts) { string rangeZoneIds = ProductHelper.GetRangeZoneIdsToSemiColonSeparatedString(siteSettings.SiteId, zoneId); totalRows = Product.GetCountByListZone(siteSettings.SiteId, rangeZoneIds, languageId, -1); if (pageSize == -1) { pageSize = totalRows; } totalPages = CaculateTotalPages(pageSize, totalRows); lstProducts = Product.GetPageByListZone(siteSettings.SiteId, rangeZoneIds, languageId, -1, pageNumber, pageSize); } else { totalRows = Product.GetCount(siteSettings.SiteId, zoneId, languageId, -1); if (pageSize == -1) { pageSize = totalRows; } totalPages = CaculateTotalPages(pageSize, totalRows); lstProducts = Product.GetPage(siteSettings.SiteId, zoneId, languageId, -1, pageNumber, pageSize); } } else { totalRows = Product.GetCountByListZone(siteSettings.SiteId, config.ZoneIds, languageId, -1); if (pageSize == -1) { pageSize = totalRows; } totalPages = CaculateTotalPages(pageSize, totalRows); lstProducts = Product.GetPageByListZone(siteSettings.SiteId, config.ZoneIds, languageId, -1, pageNumber, pageSize); } } XmlHelper.AddNode(doc, root, "TotalProducts", totalRows.ToString()); BuildPageSizeXml(doc, root); List <int> productIds = new List <int>(); if (ProductConfiguration.EnableComparing) { productIds = ProductHelper.GetCompareProductsIds(); XmlHelper.AddNode(doc, root, "CompareProductsCount", productIds.Count.ToString()); XmlHelper.AddNode(doc, root, "CompareListUrl", siteRoot + "/Product/Compare.aspx"); List <Product> compareProducts = ProductHelper.GetCompareProducts(); foreach (Product product in compareProducts) { XmlElement productXml = doc.CreateElement("Compared"); root.AppendChild(productXml); ProductHelper.BuildProductDataXml(doc, productXml, product, timeZone, timeOffset, ProductHelper.BuildEditLink(product, basePage, userCanUpdate, currentUser)); } } List <ProductProperty> productProperties = new List <ProductProperty>(); List <CustomField> customFields = new List <CustomField>(); if (config.ShowCustomFieldsInProductList) { List <int> lstProductIds = new List <int>(); foreach (Product product in lstProducts) { lstProductIds.Add(product.ProductId); } if (lstProductIds.Count > 0) { productProperties = ProductProperty.GetPropertiesByProducts(lstProductIds); } if (productProperties.Count > 0) { var customFieldIds = new List <int>(); foreach (var property in productProperties) { if (!customFieldIds.Contains(property.CustomFieldId)) { customFieldIds.Add(property.CustomFieldId); } } var tmp = CustomField.GetActiveByFields(basePage.SiteId, Product.FeatureGuid, customFieldIds, languageId); customFields = CustomField.GetByOption(tmp, CustomFieldOptions.ShowInCatalogPages); } } foreach (Product product in lstProducts) { XmlElement productXml = doc.CreateElement("Product"); root.AppendChild(productXml); ProductHelper.BuildProductDataXml(doc, productXml, product, timeZone, timeOffset, ProductHelper.BuildEditLink(product, basePage, userCanUpdate, currentUser), productIds); if (config.ShowCustomFieldsInProductList) { BuildCustomFieldsXml(doc, productXml, product.ProductId, customFields, productProperties); } } if (pageNumber < totalPages) { string pageUrl = ProductHelper.BuildFilterUrlLeaveOutPageNumber(Request.RawUrl); if (pageUrl.Contains("?")) { pageUrl += "&" + ProductHelper.QueryStringPageNumberParam + "=" + (pageNumber + 1).ToString(); } else { pageUrl += "?" + ProductHelper.QueryStringPageNumberParam + "=" + (pageNumber + 1).ToString(); } XmlHelper.AddNode(doc, root, "NextPageUrl", pageUrl); } return(doc); }