Ejemplo n.º 1
0
        /// <summary>
        /// don't forget to call UpdateDiscountPrice
        /// </summary>
        /// <param name="row"></param>
        /// <param name="trackInventory"></param>
        /// <param name="viewerid"></param>
        /// <returns></returns>
        public static Cart ToLiquidModel(this cart row, long?viewerid)
        {
            var cart = new Cart();

            cart.items          = row.cartitems.ToLiquidModel(viewerid).ToList();
            cart.item_count     = cart.items.Count;
            cart.subtotal_price = cart.items.Sum(x => x.total_price);
            cart.note           = row.note;
            cart.coupon_code    = row.coupon;
            if (!string.IsNullOrEmpty(row.coupon))
            {
                cart.discount_amount = row.ToDiscountAmount(cart.subtotal_price);
                cart.total_price     = cart.subtotal_price - cart.discount_amount;
            }
            else
            {
                cart.total_price = cart.subtotal_price;
            }

            return(cart);
        }
Ejemplo n.º 2
0
        public static CheckoutViewModel ToViewModel(this cart c, BaseViewModel baseviewmodel, long?viewerid)
        {
            var model = new CheckoutViewModel(baseviewmodel);

            model.subdomainid = c.subdomainid;
            model.store_url   = c.MASTERsubdomain.ToHostName().ToDomainUrl();

            foreach (var entry in c.cartitems)
            {
                var citem = entry.product_variant.ToCheckoutItem(entry.quantity, viewerid);
                model.CartItems.Add(citem);
            }

            model.sub_total       = model.CartItems.Sum(x => x.subTotal);
            model.coupon          = c.coupon;
            model.discount_amount = c.ToDiscountAmount(model.sub_total);
            model.total           = model.sub_total - model.discount_amount;
            model.currency        = c.MASTERsubdomain.currency.ToCurrency();

            model.isLoggedIn     = viewerid.HasValue;
            model.isDigitalOrder = c.isDigitalOrder();

            return(model);
        }