public IActionResult Orders([FromBody] Bukimedia.PrestaSharp.Entities.order order)
        {
            // order olustururken her bir product icin orderDetail olusturmak gerekiyor
            // fakat orderdetail ayni zamanda order_id tutuyor, daha order olusturmadan orderdetail'e nasil
            // order id'si verebiliriz ki?

            //int cartId = (int) order.id_cart;
            //Bukimedia.PrestaSharp.Entities.cart cart = cartFactory.Get(cartId);


            //foreach (Bukimedia.PrestaSharp.Entities.cart_row cart_row in cart.associations.cart_rows)
            //{
            //    // sepetteki urunun idsi ile product cekiyoruz
            //    Bukimedia.PrestaSharp.Entities.product prd = productFactory.Get((int) cart_row.id_product);


            //    Bukimedia.PrestaSharp.Entities.order_detail od = new Bukimedia.PrestaSharp.Entities.order_detail();

            //    od.product_name = prd.name[0].Value;

            //}


            orderFactory.Add(order);

            return(Ok(order));
        }
Beispiel #2
0
 public void AddMethodInOrderFactoryThrowsExceptionForWrongAddressData()
 {
     Assert.Throws <ArgumentException>(() =>
     {
         var orderFactory = new OrderFactory();
         orderFactory.Add("Customer 1", "");
     });
 }
Beispiel #3
0
        public void CanAddOrderWithFactoryInstance()
        {
            var orders = new OrderFactory();

            orders.Add("Customer 1", "Address 1");

            Assert.NotEmpty(orders.Get());
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                UserModel userInfo = this.LoginUser;
                string    orderno  = HYRequest.GetQueryString("orderno");

                CartOrder = OrderFactory.Get(orderno);

                //需要判断是否选中所有产品,如不是,则新增加一个订单作为购物车,保留未选中的产品;
                if (CartOrder != null && CartOrder.orderstatus == 1) //购物车订单
                {
                    if (!CartOrder.selectallproduct)
                    {
                        OrderModel om = new OrderModel();
                        om.orderstatus  = 1;                 //购物车
                        om.address      = userInfo.address;  //CartOrder.address;
                        om.createtime   = CartOrder.createtime;
                        om.customername = userInfo.fullname; //CartOrder.customername;
                        om.tel          = userInfo.tel;
                        om.uid          = CartOrder.uid;
                        om.orderno      = Utils.GenerateOutTradeNo(CartOrder.uid);

                        foreach (OrderProduct op in CartOrder.productlist)
                        {
                            if (!op.isselected)
                            {
                                om.productlist.Add(op);
                            }
                        }

                        foreach (OrderProduct op in om.productlist)
                        {
                            CartOrder.productlist.Remove(op);
                        }

                        CartOrder.orderstatus = 2; //更新为已下单
                        CartOrder.createtime  = DateTime.Now;
                        OrderFactory.Update(CartOrder);

                        OrderFactory.Add(om);
                    }
                }

                //if (CartOrder != null && CartOrder.orderstatus == 1) //购物车订单
                //    OrderFactory.UpdateStatus(2, CartOrder.orderid);//更新为已下单

                this.txtaddress.Value      = userInfo.address; //CartOrder.address;
                this.txtcustomername.Value = userInfo.fullname;
                this.txttel.Value          = userInfo.tel;
                this.txtordermessage.Value = CartOrder.ordermessage;

                //this.ltlPostAge.Text = vsconfig.PostAge.ToString();
            }
        }
Beispiel #5
0
        /// <summary>
        /// Procedimiento de Pedido: Actualizar Nro de Guia por Prestashop WebService
        /// </summary>
        /// <param name="id_orden">Id de Orden</param>
        /// <param name="serie_guia">Numero de Guia</param>
        /// <returns>Verdadero/Falso</returns>
        //public static bool ActualizarGuia(int id_orden, string serie_guia)
        //{
        //    bool result = false;
        //    try
        //    {
        //        OrderFactory of = new OrderFactory(BaseUrl, Account, Password);

        //        // Actualizar Orden
        //        order orden = of.Get(id_orden);
        //        orden.shipping_number = serie_guia;
        //        orden.current_state = 4; // Pedido Enviado (Shipped)
        //        of.Update(orden);

        //        // Actualizar Orden_Carrier
        //        // Filtro
        //        Dictionary<string, string> dtn = new Dictionary<string, string>();
        //        dtn.Add("id_order", id_orden.ToString());

        //        OrderCarrierFactory ocf = new OrderCarrierFactory(BaseUrl, Account, Password);
        //        order_carrier orden_trans = ocf.GetByFilter(dtn,null,null).FirstOrDefault();
        //        if (orden_trans != null)
        //        {
        //            orden_trans.tracking_number = serie_guia;
        //            ocf.Update(orden_trans);
        //            //Console.WriteLine(String.Format("{0}, {1}, {2}, {3}", orden_trans.id, orden_trans.id_carrier, orden_trans.id_order, orden_trans.id_order_invoice));
        //            //Console.ReadLine();
        //        }
        //        result = true;
        //    }
        //    catch (Exception)
        //    {
        //        result = false;
        //    }
        //    return result;
        //}



        public static bool ActualizarGuia(int id_orden, string serie_guia)
        {
            bool result           = false;
            int  ID_CLIENTE       = 20;
            int  ID_PRODUCTO_1    = 8092950;
            int  ID_PRODUCTO_2    = 8899998;
            int  STOCK_ACTUAL     = 10;
            int  CANTIDAD_COMPRA  = 2;
            int  DIRECCION_ENVIO  = 30;
            int  ID_TRANSPORTISTA = 16;

            for (int i = 1; i <= 200; i++)
            {
                try
                {
                    // Obtener los productos
                    Dictionary <string, string> dtn = new Dictionary <string, string>();
                    dtn.Add("id", ID_PRODUCTO_1.ToString());
                    product pro1 = pf.GetByFilter(dtn, null, null).FirstOrDefault();


                    // Agregar Stock a Producto = 10
                    dtn = new Dictionary <string, string>();
                    dtn.Add("id_product", pro1.id.ToString());
                    dtn.Add("id_product_attribute", pro1.associations.combinations.FirstOrDefault().id.ToString());
                    stock_available osa = sf.GetByFilter(dtn, null, null).FirstOrDefault();
                    osa.quantity = STOCK_ACTUAL;
                    sf.Update(osa);

                    dtn = new Dictionary <string, string>();
                    dtn.Add("id", ID_PRODUCTO_2.ToString());
                    product pro2 = pf.GetByFilter(dtn, null, null).FirstOrDefault();

                    dtn = new Dictionary <string, string>();
                    dtn.Add("id_product", pro2.id.ToString());
                    dtn.Add("id_product_attribute", pro2.associations.combinations.FirstOrDefault().id.ToString());
                    osa          = sf.GetByFilter(dtn, null, null).FirstOrDefault();
                    osa.quantity = STOCK_ACTUAL;
                    sf.Update(osa);

                    // Agregar Carrito
                    cart carrito = new cart();
                    carrito.id_shop_group       = 1;
                    carrito.id_shop             = 1;
                    carrito.id_carrier          = ID_TRANSPORTISTA;
                    carrito.delivery_option     = "a:1:{i:13;s:3:\"16,\";}";
                    carrito.id_lang             = 1;
                    carrito.id_address_delivery = 30;
                    carrito.id_address_invoice  = 30;
                    carrito.id_currency         = 1;
                    carrito.id_customer         = ID_CLIENTE;
                    carrito.id_guest            = 254;

                    // Agregar Detalle Carrito
                    cart_row cr = new cart_row();
                    cr.id_product           = ID_PRODUCTO_1;
                    cr.id_product_attribute = pro1.associations.combinations.FirstOrDefault().id;
                    cr.quantity             = CANTIDAD_COMPRA;
                    cr.id_address_delivery  = DIRECCION_ENVIO;
                    carrito.associations.cart_rows.Add(cr);

                    cr                      = new cart_row();
                    cr.id_product           = ID_PRODUCTO_2;
                    cr.id_product_attribute = pro2.associations.combinations.FirstOrDefault().id;
                    cr.quantity             = CANTIDAD_COMPRA;
                    cr.id_address_delivery  = DIRECCION_ENVIO;
                    carrito.associations.cart_rows.Add(cr);

                    carrito = oc.Add(carrito);

                    // Agregar Orden
                    order orden = new order();
                    orden.id_shop_group       = 1;
                    orden.id_shop             = 1;
                    orden.id_carrier          = ID_TRANSPORTISTA;
                    orden.id_lang             = 1;
                    orden.id_customer         = ID_CLIENTE;
                    orden.id_cart             = carrito.id;
                    orden.id_currency         = 1;
                    orden.id_address_delivery = DIRECCION_ENVIO;
                    orden.id_address_invoice  = DIRECCION_ENVIO;
                    orden.current_state       = 2;
                    orden.payment             = "Cash on delivery (COD)";
                    orden.conversion_rate     = 1.0M;
                    orden.module                   = "cashondelivery";
                    orden.recyclable               = 0;
                    orden.gift                     = 0;
                    orden.gift_message             = "";
                    orden.mobile_theme             = 0;
                    orden.shipping_number          = "";
                    orden.total_discounts          = 0M;
                    orden.total_discounts_tax_incl = 0M;
                    orden.total_discounts_tax_excl = 0M;
                    orden.total_paid               = 363.400M;
                    orden.total_paid_tax_incl      = 363.400M;
                    orden.total_paid_tax_excl      = 290.713M;
                    orden.total_paid_real          = 0M;
                    orden.total_products           = 284.413M;
                    orden.total_products_wt        = 115.900M;
                    orden.total_shipping           = 0M;
                    orden.total_shipping_tax_incl  = 0M;
                    orden.total_shipping_tax_excl  = 0M;
                    orden.carrier_tax_rate         = 18M;
                    orden.total_wrapping           = 0M;
                    orden.total_wrapping_tax_incl  = 0M;
                    orden.total_wrapping_tax_excl  = 0M;
                    orden.invoice_number           = 0;
                    orden.delivery_number          = 11;
                    orden.valid                    = 1;
                    orden.date_add                 = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    orden.date_upd                 = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

                    order_row or = new order_row();
                    or.product_id           = pro1.id;
                    or.product_attribute_id = pro1.associations.combinations.FirstOrDefault().id;
                    or.product_ean13        = "";
                    or.product_name         = pro1.description.ToString();
                    or.product_quantity     = 1;
                    or.product_price        = 46.525424M;
                    or.product_reference    = pro1.reference;
                    or.product_upc          = "";
                    or.unit_price_tax_excl  = 37.203391M;
                    or.unit_price_tax_incl  = 43.900001M;
                    orden.associations.order_rows.Add(or);

                    or                      = new order_row();
                    or.product_id           = pro2.id;
                    or.product_attribute_id = pro2.associations.combinations.FirstOrDefault().id;
                    or.product_ean13        = "";
                    or.product_name         = pro2.description.ToString();
                    or.product_quantity     = 1;
                    or.product_price        = 76.186441M;
                    or.product_reference    = pro2.reference;
                    or.product_upc          = "";
                    or.unit_price_tax_excl  = 60.932204M;
                    or.unit_price_tax_incl  = 71.900001M;
                    orden.associations.order_rows.Add(or);

                    order ok = new order();
                    ok = of.Add(orden);

                    ok.current_state = 2;
                    of.Update(ok);

                    /*
                     * Dictionary<string, string> dtn = new Dictionary<string, string>();
                     * dtn.Add("id", id_orden.ToString());
                     *
                     * OrderFactory ocf = new OrderFactory(BaseUrl, Account, Password);
                     * order o = ocf.GetByFilter(dtn, null, null).FirstOrDefault();
                     *
                     * of.Add(o);
                     */

                    result = true;
                    Console.WriteLine(String.Format("Se agrego la Orden Nro {0}", ok.id));
                }
                catch (PrestaSharpException ex)
                {
                    result = false;
                    Console.Write(ex.Message);
                    Console.ReadKey();
                }
                catch (Exception ex)
                {
                    result = false;
                    Console.Write(ex.Message);
                    Console.ReadKey();
                }
            }



            return(result);
        }
Beispiel #6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                UserModel  userInfo = this.LoginUser;
                OrderModel myorder  = OrderFactory.GetCartOrder(userInfo.uid);

                int    pid      = HYRequest.GetQueryInt("pid", 0);
                int    itemflag = HYRequest.GetQueryInt("itemflag", 0);
                string action   = HYRequest.GetQueryString("action");

                if (action == "add") //添加商品
                {
                    OrderModel myof = myorder;
                    if (myof == null)
                    {
                        myof              = new OrderModel();
                        myof.orderno      = Utils.GenerateOutTradeNo(userInfo.uid); //Utils.GetRandomOrderNo();
                        myof.uid          = userInfo.uid;
                        myof.customername = userInfo.fullname;
                        myof.tel          = userInfo.tel;
                        myof.address      = userInfo.address;
                    }

                    ProductModel p  = ProductFactory.Get(pid);
                    OrderProduct op = new OrderProduct();
                    op.count       = 1;
                    op.productinfo = p;
                    op.price       = p.price;

                    //判断是否有属性
                    if (itemflag > 0)
                    {
                        int tmpflag = 1;
                        foreach (KeyValuePair <string, decimal> kvp in p.itempricelist)
                        {
                            if (itemflag == tmpflag)
                            {
                                op.item  = kvp.Key;
                                op.price = kvp.Value;
                                break;
                            }
                            tmpflag++;
                        }
                    }

                    CheckIsAdd(myof.productlist, op);

                    if (myorder == null)
                    {
                        OrderFactory.Add(myof);
                    }
                    else
                    {
                        OrderFactory.Update(myof);
                    }

                    Response.Redirect("cart.aspx");
                }
                else if (action == "del")
                {
                    OrderModel   myof = myorder;
                    ProductModel p    = ProductFactory.Get(pid);

                    OrderProduct op = new OrderProduct();
                    op.productinfo = p;
                    op.item        = HYRequest.GetQueryString("item");

                    CheckIsDel(myof.productlist, op);

                    OrderFactory.Update(myof);
                    Response.Redirect("cart.aspx");
                }
                else if (action == "ajaxupdate")   //更新数量
                {
                    int    goods_selected = HYRequest.GetInt("goods_selected", 1);
                    int    goods_number   = HYRequest.GetInt("goods_number", 1);
                    int    rec_id         = HYRequest.GetInt("rec_id", 0);
                    string item           = HYRequest.GetString("item");

                    OrderModel   myof = myorder;
                    ProductModel p    = ProductFactory.Get(rec_id);
                    OrderProduct op   = new OrderProduct();
                    op.isselected  = (goods_selected == 1) ? true : false;
                    op.count       = goods_number;
                    op.item        = item;
                    op.productinfo = p;
                    CheckIsUpdate(myof.productlist, op);

                    OrderFactory.Update(myof);

                    string json = "{\"rec_id\":" + rec_id + ",\"goods_number\":" + goods_number + ",\"total_number\":" + myof.productcount + ",\"total_desc\":" + myof.productprice.ToString() + ",\"postage\":" + myof.postage.ToString() + ",\"error\":0}";
                    Response.Write(json);
                    Response.Flush();
                    Response.End();
                    return;
                }
                else if (action == "ajaxupdateall")  //全选状态处理
                {
                    int        goods_selected = HYRequest.GetInt("goods_selected", 1);
                    int        rec_id         = HYRequest.GetInt("rec_id", 0);
                    OrderModel myof           = myorder;
                    foreach (OrderProduct o in myof.productlist)
                    {
                        o.isselected = (goods_selected == 1) ? true : false;
                    }

                    OrderFactory.Update(myof);

                    string json = "{\"rec_id\":" + rec_id + ",\"total_number\":" + myof.productcount + ",\"total_desc\":" + myof.productprice.ToString() + ",\"postage\":" + myof.postage.ToString() + ",\"error\":0}";
                    Response.Write(json);
                    Response.Flush();
                    Response.End();
                    return;
                }

                if (myorder != null && myorder.productcount > 0)
                {
                    this.phNoProduct.Visible = false;
                    CartOrder = myorder;
                }
                else
                {
                    this.phNoProduct.Visible = true;
                }
            }
        }
Beispiel #7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                string action = HYRequest.GetQueryString("action");

                UserModel  userInfo = this.LoginUser;
                OrderModel myorder  = OrderFactory.GetCartOrder(userInfo.uid);



                if (action == "addtocart")       //添加到购物车
                {
                    #region ==addtocart==
                    int pid      = HYRequest.GetFormInt("pid", 0);
                    int buycount = HYRequest.GetFormInt("buycount", 0);
                    int itemflag = HYRequest.GetFormInt("itemflag", 0);

                    OrderModel myof = myorder;
                    if (myof == null)
                    {
                        myof              = new OrderModel();
                        myof.orderno      = Utils.GenerateOutTradeNo(this.LoginUser.uid);
                        myof.uid          = userInfo.uid;
                        myof.customername = userInfo.fullname;
                        myof.tel          = userInfo.tel;
                        myof.address      = userInfo.address;
                    }

                    ProductModel p  = ProductFactory.Get(pid);
                    OrderProduct op = new OrderProduct();
                    op.count       = buycount;
                    op.productinfo = p;
                    op.price       = p.price;

                    //判断是否有属性
                    if (itemflag > 0)
                    {
                        int tmpflag = 1;
                        foreach (KeyValuePair <string, decimal> kvp in p.itempricelist)
                        {
                            if (itemflag == tmpflag)
                            {
                                op.item  = kvp.Key;
                                op.price = kvp.Value;
                                break;
                            }
                            tmpflag++;
                        }
                    }

                    CheckIsAdd(myof.productlist, op);

                    if (myorder == null)
                    {
                        OrderFactory.Add(myof);
                    }
                    else
                    {
                        OrderFactory.Update(myof);
                    }

                    string json = "{\"shopcount\":" + myof.productlist.Count + ",\"error\":0}";
                    Response.Write(json);
                    Response.Flush();
                    Response.End();
                    return;

                    #endregion
                }
                else if (action == "addtofav")   //添加到收藏夹
                {
                    #region ==addtofav==
                    int  pid   = HYRequest.GetFormInt("pid", 0);
                    bool isfav = FavoriteFactory.IsFavorite(this.LoginUser.uid, pid);
                    if (!isfav)
                    {
                        FavoriteModel fm = new FavoriteModel();
                        fm.product   = ProductFactory.Get(pid);
                        fm.uid       = this.LoginUser.uid;
                        fm.productid = pid;

                        FavoriteFactory.Add(fm);
                    }
                    string json = "{\"favtip\":\"已收藏\",\"error\":0}";
                    Response.Write(json);
                    Response.Flush();
                    Response.End();
                    return;

                    #endregion
                }
                else if (action == "delfav")     //删除收藏夹
                {
                    int fid = HYRequest.GetFormInt("fid", 0);
                    FavoriteFactory.Delete(fid);
                }
            }
        }