Пример #1
0
        public void CompleteShipment(int purchaseOrderId)
        {
            PurchaseOrder order = OrderContext.Current.GetPurchaseOrderById(purchaseOrderId);

            if (order == null || order.OrderForms.Count == 0)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound));
            }

            if (order.OrderForms.Count > 1)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotImplemented)
                {
                    ReasonPhrase = "Orderform contains more than one form, this is not supported by the API."
                });
            }

            ShipmentCollection shipments = order.OrderForms[0].Shipments;

            if (shipments.Count > 1)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotImplemented)
                {
                    ReasonPhrase = "Orderform contains more than one shipment, this is not supported by the API."
                });
            }

            // Set status and run workflows
            OrderStatusManager.CompleteOrderShipment(shipments[0]);

            // Workflows could have changed the order
            order.AcceptChanges();
        }
Пример #2
0
        public PurchaseOrderModel QuickBuyOrder(QuickBuyModel model, Guid customerId)
        {
            var cart = _orderRepository.LoadOrCreateCart <Cart>(customerId, Constants.Order.Cartname.Quickbuy);
            var item = _orderGroupFactory.CreateLineItem(model.Sku, cart);

            item.Quantity = 1;


            cart.GetFirstShipment().LineItems.Add(item);
            cart.GetFirstShipment().ShippingAddress = CreateAddress(model, cart, "Shipping");

            if (!string.IsNullOrEmpty(model.CouponCode))
            {
                cart.GetFirstForm().CouponCodes.Add(model.CouponCode);
            }

            cart.ValidateOrRemoveLineItems(ProcessValidationIssue);
            cart.UpdatePlacedPriceOrRemoveLineItems(ProcessValidationIssue);
            cart.UpdateInventoryOrRemoveLineItems(ProcessValidationIssue);
            _promotionEngine.Run(cart);


            cart.GetFirstForm().Payments.Add(CreateQuickBuyPayment(model, cart));
            cart.GetFirstForm().Payments.FirstOrDefault().BillingAddress = CreateAddress(model, cart, "Billing");

            cart.ProcessPayments();

            cart.OrderNumberMethod = cart1 => GetInvoiceNumber();

            var orderRef = _orderRepository.SaveAsPurchaseOrder(cart);

            var order = _orderRepository.Load <PurchaseOrder>(orderRef.OrderGroupId);

            order[Constants.Metadata.PurchaseOrder.Frequency]      = model.Frequency.ToString();
            order[Constants.Metadata.PurchaseOrder.LatestDelivery] = DateTime.Now.AddDays(5);

            OrderStatusManager.CompleteOrderShipment(order.GetFirstShipment() as Shipment);

            _orderRepository.Save(order);

            return(MapToModel(order));
        }