Ejemplo n.º 1
0
 void CheckingOut(object sender, CheckingOutEventArgs e)
 {
     //MAKE SURE WE HAVE VALIDATED THIS FORM
     Page.Validate("OPC");
     //IF ANYTHING WAS INVALID CANCEL CHECKOUT
     if (!Page.IsValid)
     {
         e.Cancel = true;
     }
     //MAKE SURE THE SHIPPING MESSAGE IS SET
     if (!e.Cancel)
     {
         int shipmentIndex = 0;
         foreach (RepeaterItem item in ShipmentList.Items)
         {
             BasketShipment shipment    = _Basket.Shipments[shipmentIndex];
             TextBox        shipMessage = (TextBox)item.FindControl("ShipMessage");
             if (shipMessage != null)
             {
                 shipment.ShipMessage = StringHelper.Truncate(shipMessage.Text, 200);
                 shipment.Save();
             }
             shipmentIndex++;
         }
     }
 }
        protected BasketShipment GetShipment(int warehouseId, int addressId, bool create)
        {
            Basket    basket    = _Basket;
            Warehouse warehouse = WarehouseDataSource.Load(warehouseId);
            Address   address   = AddressDataSource.Load(addressId);

            foreach (BasketShipment shipment in basket.Shipments)
            {
                if ((shipment.Warehouse.Id == warehouseId) || (shipment.Warehouse.Id == 0))
                {
                    if ((shipment.Address.Id == addressId) || (shipment.Address.Id == 0))
                    {
                        shipment.Warehouse = warehouse;
                        shipment.Address   = address;
                        return(shipment);
                    }
                }
            }
            if (!create)
            {
                return(null);
            }

            //IF WE COME THIS FAR, AN EXISTING SHIPMENT WAS NOT AVAILABLE
            //ADD A NEW SHIPMENT
            BasketShipment newShipment = new BasketShipment();

            newShipment.Basket    = basket;
            newShipment.Warehouse = warehouse;
            newShipment.Address   = address;
            basket.Shipments.Add(newShipment);
            newShipment.Save();
            return(newShipment);
        }
Ejemplo n.º 3
0
        protected void ShipMethods_Databound(object sender, EventArgs e)
        {
            DropDownList ddl = (DropDownList)sender;

            if (ddl != null)
            {
                int            shipmentId = AlwaysConvert.ToInt(ddl.Attributes["ShipmentId"]);
                BasketShipment shipment   = _basket.Shipments.Find(a => a.Id == shipmentId);
                if (shipment != null)
                {
                    if (shipment.ShipMethod != null)
                    {
                        ListItem item = ddl.Items.FindByValue(shipment.ShipMethodId.ToString());
                        if (item != null)
                        {
                            item.Selected = true;
                        }
                    }
                    else
                    {
                        if (ddl.Items.Count > 0)
                        {
                            var shipMethod = ShipMethodDataSource.Load(AlwaysConvert.ToInt(ddl.Items[0].Value));
                            if (shipMethod != null)
                            {
                                shipment.ShipMethod = shipMethod;
                                shipment.Save();
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        private void RecalculateBasket(bool rebindPaymentForms)
        {
            //UPDATE SHIPPING RATES
            if (DelieveryMethodsPanel.Visible)
            {
                int shipmentIndex = 0;
                foreach (RepeaterItem item in ShipmentsRepeater.Items)
                {
                    BasketShipment shipment       = _basket.Shipments[shipmentIndex];
                    DropDownList   ShipMethodList = (DropDownList)item.FindControl("ShipMethodList");
                    if (ShipMethodList != null)
                    {
                        shipment.ShipMethodId = AlwaysConvert.ToInt(ShipMethodList.SelectedValue);
                        shipment.Save();
                    }
                    shipmentIndex++;
                }
            }
            //RECALCULATE SHIPPING, TAXES, DISCOUNTS, ETC.
            _basketService.Recalculate(_basket);
            _CurrentBasketHash = _basket.GetContentHash(OrderItemType.Product);

            if (rebindPaymentForms)
            {
                PaymentWidget.DataBind();
            }
        }
Ejemplo n.º 5
0
        protected List <ListItem> GetShipMethodList(BasketShipment shipment, bool forceRecalcualte)
        {
            List <ListItem> methodList  = new List <ListItem>();
            bool            hasSelected = false;

            if (shipment != null)
            {
                IShipRateQuoteCalculator  shippingCalculator = AbleContext.Resolve <IShipRateQuoteCalculator>();
                List <LocalShipRateQuote> localQuotes        = null;
                _SavedShipRates.TryGetValue(shipment.Id, out localQuotes);
                if (forceRecalcualte || localQuotes == null)
                {
                    //RECALCULATE THE RATES
                    localQuotes = new List <LocalShipRateQuote>();
                    ICollection <ShipRateQuote> rateQuotes = shippingCalculator.QuoteForShipment(shipment);
                    foreach (ShipRateQuote quote in rateQuotes)
                    {
                        decimal totalRate     = TaxHelper.GetShopPrice(quote.TotalRate, quote.ShipMethod.TaxCodeId, null, new TaxAddress(shipment.Address));
                        string  formattedRate = totalRate.LSCurrencyFormat("ulc");
                        string  methodName    = (totalRate > 0) ? quote.Name + ": " + formattedRate : quote.Name;
                        localQuotes.Add(new LocalShipRateQuote(quote.ShipMethodId, methodName, formattedRate));
                    }
                    _SavedShipRates[shipment.Id] = localQuotes;
                }

                foreach (LocalShipRateQuote quote in localQuotes)
                {
                    ListItem item = new ListItem(quote.Name, quote.ShipMethodId.ToString());
                    if (shipment.ShipMethodId != 0 && shipment.ShipMethodId == quote.ShipMethodId)
                    {
                        item.Selected = true;
                        hasSelected   = true;
                    }
                    methodList.Add(item);
                }

                if (!hasSelected)
                {
                    if (methodList.Count > 0)
                    {
                        methodList[0].Selected = true;
                        shipment.ShipMethodId  = AlwaysConvert.ToInt(methodList[0].Value);
                        shipment.Save();
                    }
                }
            }

            return(methodList);
        }