private MiniShoppingCartModel PrepareMiniShoppingCartModel()
        {
            var cart = _workContext.CurrentCustomer.GetCartItems();

            var lstPost = new List <Post>();

            if (cart.IsAny())
            {
                ViewBag.CurrentOrderItem = cart.FirstOrDefault(x => x.CreatedDate >= DateTime.UtcNow.AddSeconds(-2));

                foreach (var item in cart)
                {
                    var objPost = _postService.GetById(item.PostId, false);
                    lstPost.Add(objPost);
                }
            }

            var model = new MiniShoppingCartModel
            {
                Items         = lstPost,
                ShoppingCarts = cart,
                SubTotal      = _shoppingCartItemService.GetCurrentCartSubTotal(cart)
            };

            return(model);
        }
Exemple #2
0
        /// <summary>
        /// Get Cart theo khách hàng
        /// </summary>
        /// <returns></returns>
        private MiniShoppingCartModel GetCartByCustomer()
        {
            //Get Cart by customer
            var cart    = _workContext.CurrentCustomer.GetCartItems();
            var lstPost = new List <Post>();

            if (cart.IsAny())
            {
                foreach (var item in cart)
                {
                    var objPost = _postService.GetById(item.PostId);
                    lstPost.Add(objPost);
                }
            }
            var miniShopping = new MiniShoppingCartModel
            {
                Items         = lstPost,
                ShoppingCarts = cart,
                SubTotal      = _shoppingCartItemService.GetCurrentCartSubTotal(cart)
            };

            HttpContext.Session["OrderPaymentInfo"] = miniShopping;

            return(miniShopping);
        }
Exemple #3
0
        public virtual PlaceOrderResult PlaceOrder(
            ProcessPaymentRequest processPaymentRequest,
            Dictionary <string, string> extraData)
        {
            var result = new PlaceOrderResult();
            var utcNow = DateTime.UtcNow;

            if (processPaymentRequest == null)
            {
                throw new AggregateException("processPaymentRequest");
            }

            if (processPaymentRequest.OrderGuid == Guid.Empty)
            {
                processPaymentRequest.OrderGuid = Guid.NewGuid();
            }

            try
            {
                var customer = _customerService.GetById(processPaymentRequest.CustomerId, false);
                var cart     = customer.GetCartItems();

                //Order total
                decimal?orderTotal = null;
                if (cart != null)
                {
                    var subTotal = _shoppingCartItemService.GetCurrentCartSubTotal(cart);
                    orderTotal = subTotal;
                }

                //BillingAddress
                var billingAddress = customer.BillingAddress;

                //Shiping method
                var shippingMethod = customer.GetAttribute("Customer", SystemCustomerAttributeNames.SelectedShippingOption, _genericAttributeService);

                var order = new Order
                {
                    StoreId                           = processPaymentRequest.StoreId,
                    OrderGuid                         = processPaymentRequest.OrderGuid,
                    CustomerId                        = customer.Id,
                    CustomerLanguageId                = 1,                                                           // Draft code
                    CustomerTaxDisplayTypeId          = 0,                                                           //Draft code
                    CustomerIp                        = "172.0.0.0",                                                 //Draft code
                    OrderSubtotalInclTax              = 0,                                                           //Draft code
                    OrderSubtotalExclTax              = _orderTotalCalculationService.GetShoppingCartSubTotal(cart), //Draft code
                    OrderSubTotalDiscountInclTax      = decimal.Zero,                                                //Draft code
                    OrderSubTotalDiscountExclTax      = decimal.Zero,                                                //Draft code
                    OrderShippingInclTax              = decimal.Zero,                                                //Draft code
                    OrderShippingExclTax              = decimal.Zero,                                                //Draft code
                    OrderShippingTaxRate              = decimal.Zero,                                                //Draft code
                    PaymentMethodAdditionalFeeInclTax = decimal.Zero,                                                //Draft code
                    PaymentMethodAdditionalFeeExclTax = decimal.Zero,                                                //Draft code
                    PaymentMethodAdditionalFeeTaxRate = decimal.Zero,                                                //Draft code
                    TaxRates                          = string.Empty,                                                //Draft code
                    OrderTax                          = decimal.Zero,                                                //Draft code
                    BillingAddress                    = billingAddress,
                    PaidDateUtc                       = utcNow,
                    CreatedOnUtc                      = utcNow,
                    UpdatedOnUtc                      = utcNow,
                    PaymentMethodSystemName           = processPaymentRequest.PaymentMethodSystemName,
                    CustomerCurrencyCode              = "VNĐ",
                    CurrencyRate                      = decimal.Zero,
                    OrderTotal                        = orderTotal.Value,
                    ShippingMethod                    = shippingMethod,
                    ShippingStatus                    = ShippingStatus.ShippingNotRequired,
                    OrderStatus                       = OrderStatus.Pending,
                    PaymentStatus                     = PaymentStatus.Pending
                };

                _orderService.Create(order);

                result.PlacedOrder = order;

                //Insert OrderItem
                foreach (var sc in cart)
                {
                    var scSubTotal        = _priceCalculationService.GetSubTotal(sc, true);
                    var scSubTotalInclTax = scSubTotal;

                    var orderItem = new OrderItem
                    {
                        OrderItemGuid    = Guid.NewGuid(),
                        Order            = order,
                        PostId           = sc.PostId,
                        Quantity         = sc.Quantity,
                        UnitPriceInclTax = sc.CustomerEnteredPrice,
                        UnitPriceExclTax = decimal.Zero,
                        PriceExclTax     = decimal.Zero,
                        PriceInclTax     = scSubTotalInclTax,
                        //Post = _postService.GetById(sc.PostId),
                        ItemWeight            = decimal.Zero,
                        DiscountAmountInclTax = decimal.Zero,
                        DiscountAmountExclTax = decimal.Zero
                    };

                    order.OrderItems.Add(orderItem);
                    _orderService.Update(order);
                }

                if (result.Success)
                {
                    //Delete
                    cart.ToList().ForEach(cr => _shoppingCartItemService.DeleteShoppingCartItem(cr, false));

                    _customerService.ResetCheckoutData(customer, 1, false, true);

                    #region Notifications, notes and attribute

                    //send email notifications
                    var msg = _messageFactory.SendOrderPlacedStoreOwnerNotification(order, 1);
                    msg = _messageFactory.SendOrderPlacedCustomerNotification(order, order.CustomerLanguageId);

                    #endregion
                }
            }
            catch (Exception ex)
            {
                string msg = ex.Message;
                // ignored
            }

            return(result);
        }