Beispiel #1
0
        void grid_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
        {
            if (e.Item is Telerik.Web.UI.GridDataItem)
            {
                Telerik.Web.UI.GridDataItem item = (Telerik.Web.UI.GridDataItem)e.Item;

                Literal litAttributes = (Literal)item.FindControl("litAttributes");
                if (litAttributes != null)
                {
                    int    productId     = Convert.ToInt32(item.GetDataKeyValue("ProductId"));
                    string attributesXml = item.GetDataKeyValue("AttributesXml").ToString();
                    string results       = string.Empty;

                    if (!string.IsNullOrEmpty(attributesXml))
                    {
                        var attributes = ProductAttributeParser.ParseProductAttributeMappings(customFields, attributesXml);
                        if (attributes.Count > 0)
                        {
                            foreach (var a in attributes)
                            {
                                var values = ProductAttributeParser.ParseValues(attributesXml, a.CustomFieldId);
                                if (values.Count > 0)
                                {
                                    productProperties.ForEach(property =>
                                    {
                                        if (property.ProductId == productId &&
                                            property.CustomFieldId == a.CustomFieldId &&
                                            values.Contains(property.CustomFieldOptionId))
                                        {
                                            results += string.Format("<div><span>{0}</span>: {1}</div>", a.Name, property.OptionName);
                                        }
                                    });
                                }
                            }
                        }
                    }

                    if (results.Length > 0)
                    {
                        litAttributes.Text = string.Format("<div class='attributes'>{0}</div>", results);
                    }
                }
            }
        }
Beispiel #2
0
        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);
        }