Ejemplo n.º 1
0
        /// <summary>
        /// Processes an shipment shipped event
        /// </summary>
        /// <param name="shipment">The shipment that has been shipped</param>
        public static void ShipmentShipped(OrderShipment shipment)
        {
            Order order = shipment.Order;

            UpdateOrderStatus(StoreEvent.ShipmentShipped, order);
            Hashtable parameters = new Hashtable();

            parameters["order"]    = order;
            parameters["payments"] = order.Payments;
            parameters["customer"] = order.User;
            parameters["shipment"] = shipment;
            ProcessEmails(StoreEvent.ShipmentShipped, parameters);
            //A PAYMENT HAS BEEN COMPLETED, SO DETERMINE WHICH ORDER PAID EVENT TO TRIGGER
            int unshippedItems = CountUnshippedItems(order);

            if (unshippedItems == 0)
            {
                OrderShipped(order);
            }
            else
            {
                OrderShippedPartial(order, unshippedItems);
            }
        }
Ejemplo n.º 2
0
 protected void Page_PreRender(object sender, EventArgs e)
 {
     if (_OrderItem != null)
     {
         Product product = _OrderItem.Product;
         if (product != null)
         {
             string productName = _OrderItem.Name;
             if (!string.IsNullOrEmpty(_OrderItem.VariantName))
             {
                 string variantName = string.Format(" ({0})", _OrderItem.VariantName);
                 if (!productName.EndsWith(variantName))
                 {
                     productName += variantName;
                 }
             }
             if (this.LinkProducts)
             {
                 ProductLink.NavigateUrl = "~/Admin/Products/EditProduct.aspx?ProductId=" + product.Id.ToString();
                 ProductLink.Text        = productName;
                 ProductName.Visible     = false;
             }
             else
             {
                 ProductName.Text    = productName;
                 ProductLink.Visible = false;
             }
             //SHOW INPUTS
             if (_OrderItem.Inputs.Count > 0)
             {
                 InputList.DataSource = _OrderItem.Inputs;
                 InputList.DataBind();
             }
             else
             {
                 InputList.Visible = false;
             }
             //SHOW KIT PRODUCTS IF AVAILABLE, AND THE PRODUCT DOES NOT USE ITEMIZED DISPLAY
             if (!string.IsNullOrEmpty(_OrderItem.KitList) && !_OrderItem.ItemizeChildProducts)
             {
                 IList <OrderItem> kitProductList = GetKitProducts(_OrderItem);
                 if (kitProductList.Count > 0)
                 {
                     KitProductPanel.Visible       = true;
                     KitProductRepeater.DataSource = kitProductList;
                     KitProductRepeater.DataBind();
                 }
             }
             //SET THE KIT MEMBER LABEL
             if (_OrderItem.OrderItemType == OrderItemType.Product && _OrderItem.IsChildItem)
             {
                 OrderItem parentItem = _OrderItem.GetParentItem(true);
                 if (parentItem != null &&
                     (parentItem.ItemizeChildProducts ||
                      _OrderItem.OrderShipmentId != parentItem.OrderShipmentId))
                 {
                     //SET THE WISHLIST NAME
                     KitMemberLabel.Visible = true;
                     KitMemberLabel.Text    = string.Format(KitMemberLabel.Text, parentItem.Name);
                 }
             }
             //SET THE WISHLIST LABEL
             WishlistLabel.Visible = (_OrderItem.WishlistItem != null);
             if (WishlistLabel.Visible)
             {
                 //SET THE WISHLIST NAME
                 WishlistLabel.Text = string.Format(WishlistLabel.Text, GetWishlistName(_OrderItem.WishlistItem.Wishlist));
             }
             //SET THE SHIPS TO PANEL
             Order         basket   = _OrderItem.Order;
             OrderShipment shipment = _OrderItem.OrderShipment;
             ShipsToPanel.Visible = this.ShowShipTo;
             if (ShipsToPanel.Visible)
             {
                 ShipsTo.Text = shipment.ShipToFullName;
             }
             //SHOW GIFT WRAP
             GiftWrapPanel.Visible = (_OrderItem.WrapStyle != null);
             if (GiftWrapPanel.Visible)
             {
                 GiftWrap.Text         = _OrderItem.WrapStyle.Name;
                 GiftWrapPrice.Visible = (_OrderItem.WrapStyle.Price != 0);
                 GiftWrapPrice.Text    = string.Format("&nbsp;({0})", _OrderItem.WrapStyle.Price);
             }
             //SHOW GIFT MESSAGE
             GiftMessagePanel.Visible = (!string.IsNullOrEmpty(_OrderItem.GiftMessage));
             if (GiftMessagePanel.Visible)
             {
                 GiftMessage.Text = _OrderItem.GiftMessage;
             }
             //SHOW ASSETS
             List <AbleCommerce.Code.ProductAssetWrapper> assets = AbleCommerce.Code.ProductHelper.GetAssets(this.Page, _OrderItem.Product, _OrderItem.OptionList, _OrderItem.KitList, "~/Members/MyOrder.aspx?OrderNumber=" + _OrderItem.Order.OrderNumber.ToString());
             AssetsPanel.Visible = (this.ShowAssets && assets.Count > 0);
             if (AssetsPanel.Visible)
             {
                 AssetLinkList.DataSource = assets;
                 AssetLinkList.DataBind();
             }
         }
         else
         {
             ProductLink.Visible      = false;
             ProductName.Text         = _OrderItem.Name;
             InputList.Visible        = false;
             KitProductPanel.Visible  = false;
             WishlistLabel.Visible    = false;
             ShipsToPanel.Visible     = false;
             GiftWrapPanel.Visible    = false;
             GiftMessagePanel.Visible = false;
             AssetsPanel.Visible      = false;
         }
     }
     else
     {
         //NO ITEM TO DISPLAY
         this.Controls.Clear();
     }
 }
Ejemplo n.º 3
0
 public object Post(OrderShipment order)
 {
     return(new { success = "No implemented" });
 }
        private void SetAddress(OrderShipment newShipment)
        {
            string selectedValue = AddressList.SelectedItem.Value;

            //USE EXISTING ADDRESS
            if (selectedValue.StartsWith("B_"))
            {
                //USE ORDER BILLING ADDRESS
                newShipment.ShipToFirstName   = _Order.BillToFirstName;
                newShipment.ShipToLastName    = _Order.BillToLastName;
                newShipment.ShipToAddress1    = _Order.BillToAddress1;
                newShipment.ShipToAddress2    = _Order.BillToAddress2;
                newShipment.ShipToCity        = _Order.BillToCity;
                newShipment.ShipToProvince    = _Order.BillToProvince;
                newShipment.ShipToPostalCode  = _Order.BillToPostalCode;
                newShipment.ShipToCountryCode = _Order.BillToCountryCode;
                newShipment.ShipToPhone       = _Order.BillToPhone;
                newShipment.ShipToCompany     = _Order.BillToCompany;
                newShipment.ShipToFax         = _Order.BillToFax;
                newShipment.ShipToResidence   = true;
            }
            else if (selectedValue.StartsWith("S_"))
            {
                //USE SHIPPING ADDRESS
                int shipmentId = AlwaysConvert.ToInt(AddressList.SelectedItem.Value.Split('_')[1]);
                int index      = _Order.Shipments.IndexOf(shipmentId);
                if (index > -1)
                {
                    OrderShipment shipment = _Order.Shipments[index];
                    newShipment.ShipToFirstName   = shipment.ShipToFirstName;
                    newShipment.ShipToLastName    = shipment.ShipToLastName;
                    newShipment.ShipToAddress1    = shipment.ShipToAddress1;
                    newShipment.ShipToAddress2    = shipment.ShipToAddress2;
                    newShipment.ShipToCity        = shipment.ShipToCity;
                    newShipment.ShipToProvince    = shipment.ShipToProvince;
                    newShipment.ShipToPostalCode  = shipment.ShipToPostalCode;
                    newShipment.ShipToCountryCode = shipment.ShipToCountryCode;
                    newShipment.ShipToPhone       = shipment.ShipToPhone;
                    newShipment.ShipToCompany     = shipment.ShipToCompany;
                    newShipment.ShipToFax         = shipment.ShipToFax;
                    newShipment.ShipToResidence   = shipment.ShipToResidence;
                }
            }
            else
            {
                //USE ADDRESS FROM ADDRESS BOOK
                int     addressId = AlwaysConvert.ToInt(selectedValue);
                Address address   = AddressDataSource.Load(addressId);
                newShipment.ShipToFirstName   = address.FirstName;
                newShipment.ShipToLastName    = address.LastName;
                newShipment.ShipToAddress1    = address.Address1;
                newShipment.ShipToAddress2    = address.Address2;
                newShipment.ShipToCity        = address.City;
                newShipment.ShipToProvince    = address.Province;
                newShipment.ShipToPostalCode  = address.PostalCode;
                newShipment.ShipToCountryCode = address.CountryCode;
                newShipment.ShipToPhone       = address.Phone;
                newShipment.ShipToCompany     = address.Company;
                newShipment.ShipToFax         = address.Fax;
                newShipment.ShipToResidence   = address.Residence;
            }
        }
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            IList <OrderItem> orderItems = GetOrderItems();

            if ((orderItems != null) && (orderItems.Count > 0))
            {
                int shipmentId;
                if (_OrderShipment == null)
                {
                    shipmentId = AlwaysConvert.ToInt(ShipmentsList.SelectedValue);
                }
                else
                {
                    shipmentId = _OrderShipmentId;
                }

                // create a new shipment if required
                if (shipmentId == -1)
                {
                    _OrderShipment = new OrderShipment(_Order);

                    _OrderShipment.Order       = _Order;
                    _OrderShipment.WarehouseId = AlwaysConvert.ToInt(ShipFrom.SelectedValue);
                    SetAddress(_OrderShipment);
                    if (ShipMethodList.SelectedIndex > -1)
                    {
                        _OrderShipment.ShipMethodId   = AlwaysConvert.ToInt(ShipMethodList.SelectedItem.Value);
                        _OrderShipment.ShipMethodName = ShipMethodList.SelectedItem.Text;
                    }

                    // ADD TO ORDER, SAVE AND RECALCULATE
                    _Order.Shipments.Add(_OrderShipment);
                    _Order.Save(true, false);

                    _OrderShipmentId = _OrderShipment.Id;
                    shipmentId       = _OrderShipmentId;
                }

                // JIRA: AC8-2949: FIX THE OrderBy issue
                short nextOrderBy = OrderItemDataSource.GetNextOrderBy(_OrderId);

                foreach (OrderItem item in orderItems)
                {
                    item.Order           = _Order;
                    item.OrderShipmentId = shipmentId;

                    // JIRA: AC8-2949: FIX THE OrderBy issue
                    item.OrderBy = nextOrderBy++;

                    _Order.Items.Add(item);
                }
                _Order.Save(true, false);

                // IF IT IS A GIFT CERTIFICATE PRODUCT ITEM, GENERATE GIFT CERTIFICATES
                //NOTE: HAVE TO DO IT AFTER (ADDING THE ORDER ITEM TO ORDER + SAVING THE ORDER)
                foreach (OrderItem item in orderItems)
                {
                    if (item.Product != null && item.Product.IsGiftCertificate)
                    {
                        item.GenerateGiftCertificates(false);
                        item.Save();
                    }

                    //GENERATE (BUT DO NOT ACTIVATE) SUBSCRIPTIONS (IF THERE ARE ANY)
                    if (item.OrderItemType == OrderItemType.Product && item.Product != null)
                    {
                        Product product = item.Product;
                        if (product.IsSubscription)
                        {
                            SubscriptionPlan plan = product.SubscriptionPlan;
                            if (!plan.IsOptional)
                            {
                                item.IsSubscription = true;
                                item.Frequency      = plan.PaymentFrequency;
                                item.FrequencyUnit  = plan.PaymentFrequencyUnit;
                                item.GenerateSubscriptions(false);
                            }
                        }
                    }
                }
            }

            if (_OrderShipment == null)
            {
                Response.Redirect("~/Admin/Orders/Edit/EditOrderItems.aspx?OrderNumber=" + _Order.OrderNumber.ToString());
            }
            else
            {
                Response.Redirect("~/Admin/Orders/Shipments/EditShipment.aspx?OrderShipmentId=" + _OrderShipmentId.ToString());
            }
        }
Ejemplo n.º 6
0
        protected void UpdateButton_Click(object sender, EventArgs e)
        {
            bool          itemFound    = false;
            OrderShipment newShipment  = null;
            OrderShipment moveShipment = null;

            foreach (GridViewRow row in ShipmentItems.Rows)
            {
                HiddenField hf          = (HiddenField)row.FindControl("Id");
                int         orderItemId = AlwaysConvert.ToInt(hf.Value);
                int         index       = _OrderShipment.OrderItems.IndexOf(orderItemId);
                if (index > -1)
                {
                    TextBox      tb  = (TextBox)row.FindControl("MoveQty");
                    short        qty = AlwaysConvert.ToInt16(tb.Text);
                    DropDownList ddl = (DropDownList)row.FindControl("Shipment");
                    string       selectedShipment = Request.Form[ddl.UniqueID];
                    if ((qty > 0) && (!string.IsNullOrEmpty(selectedShipment)))
                    {
                        OrderItem orderItem = _OrderShipment.OrderItems[index];
                        itemFound = true;
                        int shipmentId = AlwaysConvert.ToInt(selectedShipment);
                        moveShipment = OrderShipmentDataSource.Load(shipmentId);
                        if (moveShipment == null)
                        {
                            if (newShipment == null)
                            {
                                newShipment = _OrderShipment.Copy();
                                newShipment.Save();
                            }
                            moveShipment = newShipment;
                        }
                        if (qty < orderItem.Quantity)
                        {
                            //SPLIT PART OF THIS ITEM TO ANOTHER SHIPMENT
                            OrderItem splitItem = OrderItem.Copy(orderItem.Id, false);
                            splitItem.Quantity        = qty;
                            splitItem.OrderShipmentId = moveShipment.Id;
                            splitItem.Save();
                            if (orderItem.ParentItemId == orderItem.Id)
                            {
                                splitItem.ParentItemId = splitItem.Id;
                                splitItem.Save();
                            }
                            moveShipment.OrderItems.Add(splitItem);
                            orderItem.Quantity -= qty;
                            orderItem.Save();
                        }
                        else
                        {
                            //MOVE WHOLE ITEM TO ANOTHER SHIPMENT
                            orderItem.OrderShipmentId = moveShipment.Id;
                            orderItem.Save();
                            _OrderShipment.OrderItems.RemoveAt(index);
                        }
                    }
                }
            }

            if (itemFound)
            {
                Response.Redirect(CancelLink.NavigateUrl);
            }
            else
            {
                CustomValidator quantityError = new CustomValidator();
                quantityError.ErrorMessage = "You must pick at least one item to move.";
                quantityError.Text         = "&nbsp;";
                quantityError.IsValid      = false;
                phQuantityValidation.Controls.Add(quantityError);
            }
        }
Ejemplo n.º 7
0
        protected void Page_PreRender(object sender, EventArgs e)
        {
            if (_OrderItem != null)
            {
                Product product = _OrderItem.Product;
                if (product != null)
                {
                    string productName = _OrderItem.Name;
                    if (!string.IsNullOrEmpty(_OrderItem.VariantName))
                    {
                        string variantName = string.Format(" ({0})", _OrderItem.VariantName);
                        if (!productName.Contains(variantName))
                        {
                            productName += variantName;
                        }
                    }
                    if (this.LinkProducts)
                    {
                        ProductLink.NavigateUrl = UrlGenerator.GetBrowseUrl(product.Id, CatalogNodeType.Product, productName);
                        if (EnableFriendlyFormat)
                        {
                            ProductLink.Text = string.Format("{0} of {1}(<span class='price'>{2}</span>)", _OrderItem.Quantity, productName, _OrderItem.Price.LSCurrencyFormat("ulc"));
                        }
                        else
                        {
                            ProductLink.Text = productName;
                        }
                        ProductName.Visible = false;
                    }
                    else
                    {
                        if (EnableFriendlyFormat)
                        {
                            ProductName.Text = string.Format("{0} of {1}(<span class='price'>{2}</span>)", _OrderItem.Quantity, productName, _OrderItem.Price.LSCurrencyFormat("ulc"));
                        }
                        else
                        {
                            ProductName.Text = productName;
                        }
                        ProductLink.Visible = false;
                    }
                    //SHOW INPUTS
                    if (_OrderItem.Inputs.Count > 0)
                    {
                        InputList.DataSource = _OrderItem.Inputs;
                        InputList.DataBind();
                    }
                    else
                    {
                        InputList.Visible = false;
                    }
                    //SHOW KIT PRODUCTS IF AVAILABLE, AND THE PRODUCT DOES NOT USE ITEMIZED DISPLAY
                    if (!string.IsNullOrEmpty(_OrderItem.KitList) && !_OrderItem.ItemizeChildProducts)
                    {
                        IList <OrderItem> kitProductList = GetKitProducts(_OrderItem);
                        if (kitProductList.Count > 0)
                        {
                            KitProductPanel.Visible       = true;
                            KitProductRepeater.DataSource = kitProductList;
                            KitProductRepeater.DataBind();
                        }
                    }
                    //SET THE KIT MEMBER LABEL
                    if (_OrderItem.OrderItemType == OrderItemType.Product && _OrderItem.IsChildItem)
                    {
                        OrderItem parentItem = _OrderItem.GetParentItem(true);
                        if (parentItem.ItemizeChildProducts ||
                            _OrderItem.Id != parentItem.Id)
                        {
                            //SET THE WISHLIST NAME
                            KitMemberLabel.Visible = true;
                            KitMemberLabel.Text    = string.Format(KitMemberLabel.Text, parentItem.Name);
                        }
                    }
                    //SET THE WISHLIST LABEL
                    WishlistLabel.Visible = (_OrderItem.WishlistItem != null);
                    if (WishlistLabel.Visible)
                    {
                        //SET THE WISHLIST NAME
                        WishlistLabel.Text = string.Format(WishlistLabel.Text, GetWishlistName(_OrderItem.WishlistItem.Wishlist));
                    }
                    //SET THE SHIPS TO PANEL
                    Order         basket   = _OrderItem.Order;
                    OrderShipment shipment = _OrderItem.OrderShipment;
                    ShipsToPanel.Visible = this.ShowShipTo;
                    if (ShipsToPanel.Visible)
                    {
                        ShipsTo.Text = shipment.ShipToFullName;
                    }
                    //SHOW GIFT WRAP
                    GiftWrapPanel.Visible = (_OrderItem.WrapStyle != null);
                    if (GiftWrapPanel.Visible)
                    {
                        GiftWrap.Text         = _OrderItem.WrapStyle.Name;
                        GiftWrapPrice.Visible = (_OrderItem.WrapStyle.Price != 0);
                        GiftWrapPrice.Text    = string.Format("&nbsp;({0})", _OrderItem.WrapStyle.Price.LSCurrencyFormat("ulc"));
                    }
                    //SHOW GIFT MESSAGE
                    GiftMessagePanel.Visible = (!string.IsNullOrEmpty(_OrderItem.GiftMessage));
                    if (GiftMessagePanel.Visible)
                    {
                        GiftMessage.Text = _OrderItem.GiftMessage;
                    }
                    //SHOW ASSETS
                    List <AbleCommerce.Code.ProductAssetWrapper> assets = AbleCommerce.Code.ProductHelper.GetAssets(this.Page, _OrderItem.Product, _OrderItem.OptionList, _OrderItem.KitList, "~/Members/MyOrder.aspx?OrderNumber=" + _OrderItem.Order.OrderNumber.ToString());
                    AssetsPanel.Visible = (this.ShowAssets && assets.Count > 0);
                    if (AssetsPanel.Visible)
                    {
                        AssetLinkList.DataSource = assets;
                        AssetLinkList.DataBind();
                    }

                    //SHOW SUBSCRIPTIONS
                    if (this.ShowSubscription)
                    {
                        SubscriptionPlan sp = _OrderItem.Product.SubscriptionPlan;
                        if (sp != null && _OrderItem.IsSubscription && _OrderItem.Frequency > 0)
                        {
                            // GET THE RECURRING PAYMENT MESSAGE FOR THIS PRODUCT
                            RecurringPaymentMessage.Text = ProductHelper.GetRecurringPaymentMessage(_OrderItem);
                            SubscriptionPanel.Visible    = true;
                        }
                    }
                }
                else
                {
                    ProductLink.Visible       = false;
                    ProductName.Text          = _OrderItem.Name;
                    InputList.Visible         = false;
                    KitProductPanel.Visible   = false;
                    WishlistLabel.Visible     = false;
                    ShipsToPanel.Visible      = false;
                    GiftWrapPanel.Visible     = false;
                    GiftMessagePanel.Visible  = false;
                    AssetsPanel.Visible       = false;
                    SubscriptionPanel.Visible = false;
                }
            }
            else
            {
                //NO ITEM TO DISPLAY
                this.Controls.Clear();
            }
        }
Ejemplo n.º 8
0
        protected void BatchButton_Click(object sender, EventArgs e)
        {
            List <string> messages = new List <string>();
            List <int>    orderIds = GetSelectedOrderIds();

            if (orderIds.Count > 0)
            {
                if (BatchAction.SelectedValue.StartsWith("OS_"))
                {
                    //UPDATE ORDER STATUS REQUESTED
                    int orderStatusId = AlwaysConvert.ToInt(BatchAction.SelectedValue.Substring(3));
                    //VALIDATE STATUS
                    OrderStatus status = OrderStatusDataSource.Load(orderStatusId);
                    if (status != null)
                    {
                        IDatabaseSessionManager database = AbleContext.Current.Database;
                        database.BeginTransaction();
                        foreach (int orderId in orderIds)
                        {
                            Order order = OrderDataSource.Load(orderId);
                            if (order != null)
                            {
                                order.UpdateOrderStatus(status);
                            }
                        }
                        database.CommitTransaction();
                    }
                }
                else
                {
                    switch (BatchAction.SelectedValue)
                    {
                    case "INVOICE":
                        AbleContext.Current.Session.SelectedOrderIds = orderIds;
                        Response.Redirect("Print/Invoices.aspx");
                        break;

                    case "PACKSLIP":
                        AbleContext.Current.Session.SelectedOrderIds = orderIds;
                        Response.Redirect("Print/PackSlips.aspx");
                        break;

                    case "PULLSHEET":
                        AbleContext.Current.Session.SelectedOrderIds = orderIds;
                        Response.Redirect("Print/PullSheet.aspx");
                        break;

                    case "CANCEL":
                        AbleContext.Current.Session.SelectedOrderIds = orderIds;
                        Response.Redirect("Batch/Cancel.aspx");
                        break;

                    case "SHIPOPT":
                        AbleContext.Current.Session.SelectedOrderIds = orderIds;
                        Response.Redirect("Batch/Ship.aspx");
                        break;

                    case "SHIP":
                        AbleContext.Current.Database.BeginTransaction();
                        int shipCount = 0;
                        foreach (int orderId in orderIds)
                        {
                            Order order = OrderDataSource.Load(orderId);
                            if (order != null && order.Shipments != null)
                            {
                                bool shipped       = false;
                                int  shipmentCount = order.Shipments.Count;
                                for (int i = 0; i < shipmentCount; i++)
                                {
                                    OrderShipment shipment = order.Shipments[i];
                                    if (shipment != null && !shipment.IsShipped)
                                    {
                                        shipment.Ship();
                                        shipped = true;
                                    }
                                }
                                if (shipped)
                                {
                                    messages.Add("Order #" + order.OrderNumber + " shipped.");
                                    shipCount++;
                                }
                                else
                                {
                                    messages.Add("Order #" + order.OrderNumber + " did not have any unshipped items.");
                                }
                            }
                        }
                        AbleContext.Current.Database.CommitTransaction();
                        messages.Add(shipCount + " orders shipped.");
                        break;

                    case "PAY":
                        AbleContext.Current.Database.BeginTransaction();
                        int payCount = 0;
                        foreach (int orderId in orderIds)
                        {
                            Order order = OrderDataSource.Load(orderId);
                            if (order != null)
                            {
                                bool paid         = false;
                                int  paymentCount = order.Payments.Count;
                                for (int i = 0; i < paymentCount; i++)
                                {
                                    Payment payment = order.Payments[i];
                                    if (payment.PaymentStatus == PaymentStatus.Authorized)
                                    {
                                        payment.Capture(payment.Amount, true);
                                        paid = true;
                                    }
                                    else if (payment.PaymentStatus == PaymentStatus.Unprocessed)
                                    {
                                        payment.Authorize();
                                        paid = true;
                                    }
                                }
                                if (paid)
                                {
                                    payCount++;
                                    messages.Add("Order " + order.OrderNumber.ToString() + " processed.");
                                }
                                else
                                {
                                    messages.Add("Order " + order.OrderNumber.ToString() + " does not have any payments to be processed.");
                                }
                            }
                        }
                        AbleContext.Current.Database.CommitTransaction();
                        messages.Add(payCount + " orders processed.");
                        break;

                    case "DELETE":
                        if (AbleContext.Current.User.IsSystemAdmin)
                        {
                            IDatabaseSessionManager database = AbleContext.Current.Database;
                            database.BeginTransaction();
                            foreach (int orderId in orderIds)
                            {
                                OrderDataSource.Delete(orderId);
                            }
                            database.CommitTransaction();
                            OrderGrid.DataBind();
                        }
                        break;

                    case "EXPORT":
                        AbleContext.Current.Session.SelectedOrderIds = orderIds;
                        Response.Redirect("../DataExchange/OrdersExport.aspx?type=selected");
                        break;
                    }
                }
            }
            if (messages.Count > 0)
            {
                BatchMessage.Visible = true;
                BatchMessage.Text    = string.Join("<br />", messages.ToArray());
            }
            BatchAction.SelectedIndex = -1;
            OrderGrid.DataBind();
        }
Ejemplo n.º 9
0
        protected bool ShowTracking(object dataItem)
        {
            OrderShipment shipment = (OrderShipment)dataItem;

            return(shipment.TrackingNumbers.Count > 0);
        }
Ejemplo n.º 10
0
        protected bool ShowShipMessage(object dataItem)
        {
            OrderShipment shipment = (OrderShipment)dataItem;

            return(!string.IsNullOrEmpty(shipment.ShipMessage));
        }
Ejemplo n.º 11
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();
            }
        }
Ejemplo n.º 12
0
        protected void EditShipmentsGrid_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "DelShp")
            {
                int shipmentId = AlwaysConvert.ToInt(e.CommandArgument);
                int index      = _Order.Shipments.IndexOf(shipmentId);
                if (index > -1)
                {
                    OrderShipment shipment = _Order.Shipments[index];

                    // DELETE FROM ORDER
                    _Order.Shipments.Remove(shipment);
                    foreach (OrderItem item in shipment.OrderItems)
                    {
                        _Order.Items.Remove(item);
                    }

                    _Order.Save(true, false);
                    BindShipmentsGrid();
                }
            }
            else if (e.CommandName == "ChangeShipMethod")
            {
                int shipmentId = AlwaysConvert.ToInt(e.CommandArgument);
                int index      = _Order.Shipments.IndexOf(shipmentId);
                if (index > -1)
                {
                    // SHOW THE CHANGE SHIPMENT POPUP
                    ChangeShipMethodShipmentId.Value   = shipmentId.ToString();
                    ChangeShipMethodDialogCaption.Text = string.Format(ChangeShipMethodDialogCaption.Text, index + 1);
                    OrderShipment shipment = _Order.Shipments[index];
                    ExistingShipMethod.Text = shipment.ShipMethodName;

                    // GENERATE RATE QUOTES FOR ALL SHIPPING METHODS
                    List <ShipRateQuote> rateQuotes  = new List <ShipRateQuote>();
                    IList <ShipMethod>   shipMethods = ShipMethodDataSource.LoadAll();
                    foreach (ShipMethod method in shipMethods)
                    {
                        ShipRateQuote quote = method.GetShipRateQuote(shipment);
                        if (quote != null)
                        {
                            rateQuotes.Add(quote);
                        }
                    }

                    // GET LIST OF SHIPPING METHODS THAT WOULD BE AVAILABLE TO THE CUSTOMER
                    IList <ShipMethod> customerShipMethods = ShipMethodDataSource.LoadForShipment(shipment);

                    // ADD RATE QUOTES TO THE DROPDOWN
                    foreach (ShipRateQuote quote in rateQuotes)
                    {
                        string name = string.Format("{0} : {1}", quote.Name, quote.Rate.LSCurrencyFormat("lc"));
                        if (customerShipMethods.IndexOf(quote.ShipMethodId) < 0)
                        {
                            // SHOW NOTE IF HIDDEN SHIPPING METHODS ARE AVAIALBLE
                            name = "** " + name;
                            HiddenShipMethodWarning.Visible = true;
                        }
                        NewShipMethod.Items.Add(new ListItem(name, quote.ShipMethodId.ToString()));
                    }
                    ChangeShipMethodPopup.Show();
                }
            }
            else if (e.CommandName == "VoidShp")
            {
                int shipmentId = AlwaysConvert.ToInt(e.CommandArgument);
                int index      = _Order.Shipments.IndexOf(shipmentId);
                if (index > -1)
                {
                    OrderShipment shipment = _Order.Shipments[index];
                    shipment.Void();

                    _Order.Save(true, false);
                    BindShipmentsGrid();
                }
            }
        }
Ejemplo n.º 13
0
        protected void Page_PreRender(object sender, EventArgs e)
        {
            if (_OrderItem != null)
            {
                string productName = _OrderItem.Name;
                if (!string.IsNullOrEmpty(_OrderItem.VariantName))
                {
                    string variantName = string.Format(" ({0})", _OrderItem.VariantName);
                    if (!productName.EndsWith(variantName))
                    {
                        productName += variantName;
                    }
                }

                Product product = _OrderItem.Product;
                if (product != null)
                {
                    if (this.LinkProducts)
                    {
                        ProductLink.NavigateUrl = "~/Admin/Products/EditProduct.aspx?ProductId=" + product.Id.ToString();
                        ProductLink.Text        = productName;
                        ProductName.Visible     = false;
                    }
                    else
                    {
                        ProductName.Text    = productName;
                        ProductLink.Visible = false;
                    }
                    //SHOW INPUTS
                    if (_OrderItem.Inputs.Count > 0)
                    {
                        InputList.DataSource = _OrderItem.Inputs;
                        InputList.DataBind();
                    }
                    else
                    {
                        InputList.Visible = false;
                    }
                    //SET THE WISHLIST LABEL
                    WishlistLabel.Visible = (_OrderItem.WishlistItem != null);
                    if (WishlistLabel.Visible)
                    {
                        //SET THE WISHLIST NAME
                        WishlistLabel.Text = string.Format(WishlistLabel.Text, GetWishlistName(_OrderItem.WishlistItem.Wishlist));
                    }
                    //SET THE SHIPS TO PANEL
                    Order         basket   = _OrderItem.Order;
                    OrderShipment shipment = _OrderItem.OrderShipment;
                    ShipsToPanel.Visible = this.ShowShipTo;
                    if (ShipsToPanel.Visible)
                    {
                        ShipsTo.Text = shipment.ShipToFullName;
                    }
                    //SHOW GIFT WRAP
                    GiftWrapPanel.Visible = (_OrderItem.WrapStyle != null);
                    if (GiftWrapPanel.Visible)
                    {
                        GiftWrap.Text         = _OrderItem.WrapStyle.Name;
                        GiftWrapPrice.Visible = (_OrderItem.WrapStyle.Price != 0);
                        GiftWrapPrice.Text    = string.Format("&nbsp;({0})", _OrderItem.WrapStyle.Price);
                    }
                    //SHOW GIFT MESSAGE
                    GiftMessagePanel.Visible = (!string.IsNullOrEmpty(_OrderItem.GiftMessage));
                    if (GiftMessagePanel.Visible)
                    {
                        GiftMessage.Text = _OrderItem.GiftMessage;
                    }
                    //SHOW ASSETS
                    List <AbleCommerce.Code.ProductAssetWrapper> assets = AbleCommerce.Code.ProductHelper.GetAssets(this.Page, _OrderItem.Product, _OrderItem.OptionList, _OrderItem.KitList, "~/Members/MyOrder.aspx?OrderNumber=" + _OrderItem.Order.OrderNumber.ToString());
                    AssetsPanel.Visible = (this.ShowAssets && assets.Count > 0);
                    if (AssetsPanel.Visible)
                    {
                        AssetLinkList.DataSource = assets;
                        AssetLinkList.DataBind();
                    }

                    //SHOW SUBSCRIPTIONS
                    if (this.ShowSubscription)
                    {
                        SubscriptionPlan sp = _OrderItem.Product.SubscriptionPlan;
                        if (sp != null && _OrderItem.IsSubscription && _OrderItem.Frequency > 0)
                        {
                            // GET THE RECURRING PAYMENT MESSAGE FOR THIS PRODUCT
                            RecurringPaymentMessage.Text = ProductHelper.GetRecurringPaymentMessage(_OrderItem);
                            SubscriptionPanel.Visible    = true;
                        }
                    }
                }
                else
                {
                    ProductLink.Visible      = false;
                    ProductName.Text         = productName;
                    InputList.Visible        = false;
                    WishlistLabel.Visible    = false;
                    ShipsToPanel.Visible     = false;
                    GiftWrapPanel.Visible    = false;
                    GiftMessagePanel.Visible = false;
                    AssetsPanel.Visible      = false;
                }
            }
            else
            {
                //NO ITEM TO DISPLAY
                this.Controls.Clear();
            }
        }
Ejemplo n.º 14
0
        protected void Page_Init(object sender, EventArgs e)
        {
            int shipmentId = AlwaysConvert.ToInt(Request.QueryString["OrderShipmentId"]);

            _OrderShipment = OrderShipmentDataSource.Load(shipmentId);
            if (_OrderShipment == null)
            {
                Response.Redirect("../Default.aspx");
            }
            _Order                   = _OrderShipment.Order;
            Caption.Text             = string.Format(Caption.Text, _Order.OrderNumber);
            ShipmentNumber.Text      = string.Format(ShipmentNumber.Text, _Order.Shipments.IndexOf(_OrderShipment.Id) + 1, _Order.Shipments.Count);
            ShippingMethod.Text      = _OrderShipment.ShipMethodName;
            trShipMessage.Visible    = !string.IsNullOrEmpty(_OrderShipment.ShipMessage);
            ShipMessage.Text         = _OrderShipment.ShipMessage;
            ShipFrom.Text            = _OrderShipment.FormatFromAddress();
            ShipTo.Text              = _OrderShipment.FormatToAddress();
            ShipmentItems.DataSource = GetShipmentItems();
            ShipmentItems.DataBind();

            // check if ship gateway supports shipping feature
            CommerceBuilder.Shipping.ShipGateway shipGateway = _OrderShipment.ShipMethod != null ?_OrderShipment.ShipMethod.ShipGateway : null;
            IShippingProvider shipProvider = null;

            if (shipGateway != null)
            {
                shipProvider = shipGateway.GetProviderInstance();
                _IsProviderSupportShipping = shipProvider != null && shipProvider.IsShippingSupported;
            }

            ShipGateway.DataSource = ShipGatewayDataSource.LoadAll();
            ShipGateway.DataBind();
            if (ShipGateway.Items.Count > 1)
            {
                //TRY TO PRESET THE CORRECT GATEWAY
                if (_OrderShipment.ShipMethod != null)
                {
                    ListItem item = ShipGateway.Items.FindByValue(_OrderShipment.ShipMethod.ShipGatewayId.ToString());
                    if (item != null)
                    {
                        item.Selected = true;
                    }
                }
            }
            else
            {
                ShipGateway.Visible = false;
            }

            if (_IsProviderSupportShipping)
            {
                autoTrackingInputPanel.Visible = true;

                // update the provider name
                ProviderInstructionText.Text    = string.Format(ProviderInstructionText.Text, shipProvider.Name);
                ProviderInstructionText.Visible = true;
            }
            else
            {
                autoTrackingInputPanel.Visible = false;
            }

            CancelButton.NavigateUrl += "?OrderNumber=" + _OrderShipment.Order.OrderNumber.ToString();
        }
Ejemplo n.º 15
0
        private void Ship(bool requestTracking)
        {
            //WE HAVE TO LOOK FOR ANY ITEMS NOT BEING SHIPPED
            //BUILD A DICTIONARY OF QUANTITY TO SHIP
            bool itemFound        = false;
            bool isPartial        = false;
            bool quantityExceeded = false;
            Dictionary <int, short> quantities = new Dictionary <int, short>();

            foreach (GridViewRow row in ShipmentItems.Rows)
            {
                HiddenField hf          = (HiddenField)row.FindControl("Id");
                int         orderItemId = AlwaysConvert.ToInt(hf.Value);
                int         index       = _OrderShipment.OrderItems.IndexOf(orderItemId);
                if (index > -1)
                {
                    TextBox tb  = (TextBox)row.FindControl("Quantity");
                    short   qty = AlwaysConvert.ToInt16(tb.Text);
                    itemFound        = itemFound || (qty > 0);
                    isPartial        = isPartial || (qty < _OrderShipment.OrderItems[index].Quantity);
                    quantityExceeded = quantityExceeded || (qty > _OrderShipment.OrderItems[index].Quantity);
                    quantities.Add(orderItemId, qty);
                }
            }

            if ((itemFound) && (!quantityExceeded))
            {
                try
                {
                    // start transation to do it in single step
                    AbleContext.Current.Database.BeginTransaction();

                    //CHECK IF WE ARE NOT SHIPPING ALL OF THE ITEMS
                    if (isPartial)
                    {
                        //AT LEAST ONE ITEM MUST BE MOVED TO A NEW SHIPMENT
                        //CREATE A COPY OF THIS SHIPMENT
                        OrderShipment newShipment = _OrderShipment.Copy();
                        newShipment.Save();
                        _Order.Shipments.Add(newShipment);
                        //KEEP TRACK OF ITEMS TO REMOVE FROM THE CURRENT SHIPMENT
                        List <int> removeItems = new List <int>();
                        //LOOP THE ITEMS AND DECIDE WHICH TO PUT IN THE NEW SHIPMENT
                        foreach (OrderItem item in _OrderShipment.OrderItems)
                        {
                            int searchItemId = (AlwaysConvert.ToInt(item.ParentItemId) == 0) ? item.Id : AlwaysConvert.ToInt(item.ParentItemId);
                            if (quantities.ContainsKey(searchItemId))
                            {
                                short shipQty = quantities[searchItemId];
                                if (shipQty != item.Quantity)
                                {
                                    if (shipQty > 0)
                                    {
                                        //WE HAVE TO SPLIT THIS ITEM
                                        OrderItem newItem = OrderItem.Copy(item.Id, true);
                                        newItem.Quantity        = (short)(item.Quantity - shipQty);
                                        newItem.OrderShipmentId = newShipment.Id;
                                        newItem.Save();
                                        newShipment.OrderItems.Add(newItem);
                                        //UPDATE THE CURRENT ITEM
                                        item.Quantity = shipQty;
                                        item.Save();
                                    }
                                    else
                                    {
                                        //THIS ITEM JUST NEEDS TO BE MOVED
                                        item.OrderShipmentId = newShipment.Id;
                                        item.Save();
                                        newShipment.OrderItems.Add(item);
                                        removeItems.Add(item.Id);
                                    }
                                }
                            }
                        }
                        //REMOVE ANY ITEMS THAT WERE MOVED TO ANOTHER SHIPMENT
                        foreach (int id in removeItems)
                        {
                            int delIndex = _OrderShipment.OrderItems.IndexOf(id);
                            if (delIndex > -1)
                            {
                                _OrderShipment.OrderItems.RemoveAt(delIndex);
                            }
                        }
                    }

                    //Add the Tracking Number
                    int    shipgwId     = AlwaysConvert.ToInt(ShipGateway.SelectedValue);
                    string trackingData = AddTrackingNumber.Text.Trim();
                    if (!string.IsNullOrEmpty(trackingData))
                    {
                        TrackingNumber tnum = new TrackingNumber();
                        tnum.TrackingNumberData = trackingData;
                        tnum.ShipGatewayId      = shipgwId;
                        tnum.OrderShipmentId    = _OrderShipment.Id;
                        _OrderShipment.TrackingNumbers.Add(tnum);
                    }

                    //SHIP THE CURRENT SHIPMENT
                    _OrderShipment.Ship(requestTracking, LocaleHelper.LocalNow);

                    // end transaction
                    AbleContext.Current.Database.CommitTransaction();

                    //RETURN TO SHIPMENTS PAGE
                    Response.Redirect(CancelButton.NavigateUrl, false);
                }
                catch (Exception ex)
                {
                    AbleContext.Current.Database.RollbackTransaction();
                    Logger.Error(string.Format("An error occurred while trying to confirm shipment to provider: {0}", ex.Message), ex);

                    CustomValidator shipError = new CustomValidator();
                    shipError.Text         = "*";
                    shipError.ErrorMessage = ex.Message;
                    shipError.IsValid      = false;
                    phValidation.Controls.Add(shipError);
                }
            }
            else
            {
                CustomValidator quantityError = new CustomValidator();
                if (quantityExceeded)
                {
                    quantityError.ErrorMessage = "You cannot move more than the existing quantity.";
                }
                else
                {
                    quantityError.ErrorMessage = "You must pick at least one item to move.";
                }
                quantityError.Text    = "&nbsp;";
                quantityError.IsValid = false;
                phValidation.Controls.Add(quantityError);
            }
        }
Ejemplo n.º 16
0
 /// <summary>
 /// Add a shipment, that was created in an external system to an order.
 /// </summary>
 /// <param name="shipment"></param>
 public void AddShipment(OrderShipment shipment)
 {
     post($"/orders/{shipment.OrderId}/shipment", shipment);
 }
        protected string GetShipFromAddress(object dataItem)
        {
            OrderShipment shipment = (OrderShipment)dataItem;

            return(shipment.FormatFromAddress(true));
        }
Ejemplo n.º 18
0
        protected bool ShowLabelLink(object dataItem)
        {
            OrderShipment shipment = (OrderShipment)dataItem;

            return(shipment.LabelImages.Count > 0);
        }