コード例 #1
0
        protected void ShipmentCommand(object sender, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "Recalc")
            {
                int itemId = AlwaysConvert.ToInt(e.CommandArgument);
                int index  = _Order.Shipments.IndexOf(itemId);
                if (index > -1)
                {
                    OrderShipment shipment   = _Order.Shipments[index];
                    ShipMethod    shipMethod = shipment.ShipMethod;
                    if (shipMethod != null)
                    {
                        ShipRateQuote rate = shipMethod.GetShipRateQuote(shipment);
                        if (rate != null)
                        {
                            // REMOVE OLD SHIPPING CHARGES FOR THIS SHIPMENT
                            for (int i = _Order.Items.Count - 1; i >= 0; i--)
                            {
                                OrderItem item = _Order.Items[i];
                                if (item.OrderShipmentId == shipment.Id)
                                {
                                    if (item.OrderItemType == OrderItemType.Shipping || item.OrderItemType == OrderItemType.Handling)
                                    {
                                        _Order.Items.DeleteAt(i);
                                    }
                                }
                            }

                            // ADD NEW SHIPPING LINE ITEMS TO THE ORDER
                            OrderItem shipRateLineItem = new OrderItem();
                            shipRateLineItem.OrderId         = _Order.Id;
                            shipRateLineItem.OrderItemType   = OrderItemType.Shipping;
                            shipRateLineItem.OrderShipmentId = shipment.Id;
                            shipRateLineItem.Name            = shipMethod.Name;
                            shipRateLineItem.Price           = rate.Rate;
                            shipRateLineItem.Quantity        = 1;
                            shipRateLineItem.TaxCodeId       = shipMethod.TaxCodeId;
                            _Order.Items.Add(shipRateLineItem);
                            if (rate.Surcharge > 0)
                            {
                                shipRateLineItem                 = new OrderItem();
                                shipRateLineItem.OrderId         = _Order.Id;
                                shipRateLineItem.OrderItemType   = OrderItemType.Handling;
                                shipRateLineItem.OrderShipmentId = shipment.Id;
                                shipRateLineItem.Name            = shipMethod.Name;
                                shipRateLineItem.Price           = rate.Surcharge;
                                shipRateLineItem.Quantity        = 1;
                                shipRateLineItem.TaxCodeId       = shipMethod.TaxCodeId;
                                _Order.Items.Add(shipRateLineItem);
                            }
                            _Order.Save(true, false);
                            BindGrids();
                            ShippingRecalculatedMessage.Visible = true;
                        }
                    }
                }
            }
        }
コード例 #2
0
 /// <summary>
 /// Apply a ship method to this basket shipment
 /// </summary>
 /// <param name="shipMethod">The ship method to apply</param>
 public void ApplyShipMethod(ShipMethod shipMethod)
 {
     if (shipMethod == null) throw new ArgumentNullException("shipMethod");
     //WIPE OUT ANY SHIPPING CHARGES CURRENTLY IN THIS SHIPMENT
     this.ShipMethodId = shipMethod.ShipMethodId;
     this._ShipMethod = shipMethod;
     BasketItem item;
     BasketItemCollection basketItems = this.Basket.Items;
     for (int i = basketItems.Count - 1; i >= 0; i--)
     {
         item = basketItems[i];
         if (item.BasketShipmentId.Equals(this.BasketShipmentId) && ((item.OrderItemType == OrderItemType.Shipping || item.OrderItemType == OrderItemType.Handling)))
         {
             basketItems.DeleteAt(i);
         }
     }
     ShipRateQuote quote = shipMethod.GetShipRateQuote(this);
     if (quote == null) throw new ArgumentException("The specified shipping method is not valid for these items.", "shipMethod");
     item = new BasketItem();
     item.BasketId = this.BasketId;
     item.BasketShipmentId = this.BasketShipmentId;
     item.Name = quote.ShipMethod.Name;
     item.OrderItemType = OrderItemType.Shipping;
     item.Price = quote.Rate;
     item.Weight = 0;
     item.Quantity = 1;
     basketItems.Add(item);
     if (quote.Surcharge > 0)
     {
         item = new BasketItem();
         item.BasketId = this.BasketId;
         item.BasketShipmentId = this.BasketShipmentId;
         item.Name = quote.ShipMethod.Name;
         item.OrderItemType = OrderItemType.Handling;
         item.Price = quote.Surcharge;
         item.Weight = 0;
         item.Quantity = 1;
         basketItems.Add(item);
     }
     basketItems.Save();
     this.Save();
 }
コード例 #3
0
        private ShipRateQuote GetShipRateQuote(Basket basket, ShipMethod shipMethod)
        {
            GoogleBasketShipment shipment = new GoogleBasketShipment(basket, shipMethod);

            return(shipMethod.GetShipRateQuote(shipment));
        }
コード例 #4
0
        protected void ChangeShipMethodOKButton_Click(object source, EventArgs e)
        {
            int shipmentId = AlwaysConvert.ToInt(Request.Form[ChangeShipMethodShipmentId.UniqueID]);
            int index      = _Order.Shipments.IndexOf(shipmentId);

            if (index > -1)
            {
                // WE FOUND THE TARGET SHIPMENT. REMOVE OLD SHIPPING LINE ITEMS
                OrderShipment shipment = _Order.Shipments[index];
                for (int i = shipment.OrderItems.Count - 1; i >= 0; i--)
                {
                    OrderItemType itemType = shipment.OrderItems[i].OrderItemType;
                    if (itemType == OrderItemType.Shipping || itemType == OrderItemType.Handling)
                    {
                        shipment.OrderItems.DeleteAt(i);
                    }
                }

                // SEE IF WE HAVE A NEW SELECTED SHIPMETHOD
                int        shipMethodId = AlwaysConvert.ToInt(Request.Form[NewShipMethod.UniqueID]);
                ShipMethod shipMethod   = ShipMethodDataSource.Load(shipMethodId);
                if (shipMethod != null)
                {
                    ShipRateQuote rate = shipMethod.GetShipRateQuote(shipment);
                    if (rate != null)
                    {
                        // ADD NEW SHIPPING LINE ITEMS TO THE ORDER
                        OrderItem shipRateLineItem = new OrderItem();
                        shipRateLineItem.OrderId         = _Order.Id;
                        shipRateLineItem.OrderItemType   = OrderItemType.Shipping;
                        shipRateLineItem.OrderShipmentId = shipmentId;
                        shipRateLineItem.Name            = shipMethod.Name;
                        shipRateLineItem.Price           = rate.Rate;
                        shipRateLineItem.Quantity        = 1;
                        shipRateLineItem.TaxCodeId       = shipMethod.TaxCodeId;
                        shipRateLineItem.Save();
                        shipment.OrderItems.Add(shipRateLineItem);
                        if (rate.Surcharge > 0)
                        {
                            shipRateLineItem                 = new OrderItem();
                            shipRateLineItem.OrderId         = _Order.Id;
                            shipRateLineItem.OrderItemType   = OrderItemType.Handling;
                            shipRateLineItem.OrderShipmentId = shipmentId;
                            shipRateLineItem.Name            = shipMethod.Name;
                            shipRateLineItem.Price           = rate.Surcharge;
                            shipRateLineItem.Quantity        = 1;
                            shipRateLineItem.TaxCodeId       = shipMethod.TaxCodeId;
                            shipRateLineItem.Save();
                            shipment.OrderItems.Add(shipRateLineItem);
                        }

                        //Add the Tracking Number
                        ShipGateway shipGateway = shipMethod.ShipGateway;
                        foreach (TrackingNumber tn in shipment.TrackingNumbers)
                        {
                            tn.ShipGateway = shipGateway;
                        }
                    }
                }

                // UPDATE THE SHIPMENT WITH NEW METHOD ASSOCIATION
                shipment.ShipMethodId   = shipMethodId;
                shipment.ShipMethodName = (shipMethod != null ? shipMethod.Name : string.Empty);
                shipment.Save();

                // RELOAD ORDER AND REBIND THE PAGE FOR UPDATED INFO
                _Order = OrderDataSource.Load(_Order.Id);
                BindShipmentsGrid();
            }
        }