Example #1
0
        /// <summary>
        /// Create a cart draft of some order
        /// </summary>
        /// <param name="orderId">Id of the order</param>
        /// <returns>Cart draft</returns>
        public Task <ProcessedCart> CreateCartOrderDraft(CreateCartOrderDraftParam param)
        {
            if (param == null)
            {
                throw new ArgumentNullException(nameof(param));
            }
            if (param.OrderId == default)
            {
                throw new ArgumentException(GetMessageOfEmpty(nameof(param.OrderId)));
            }
            if (string.IsNullOrWhiteSpace(param.Scope))
            {
                throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.Scope)));
            }
            if (param.CustomerId == null)
            {
                throw new ArgumentException(GetMessageOfNull(nameof(param.CustomerId)));
            }

            var request = new CreateCartOrderDraftRequest
            {
                CultureName = param.CultureInfo.Name,
                CustomerId  = param.CustomerId,
                OrderId     = param.OrderId,
                ScopeId     = param.Scope
            };

            return(OvertureClient.SendAsync(request));
        }
Example #2
0
        public virtual async Task <ProcessedCart> StartEditOrderModeAsync(Overture.ServiceModel.Orders.Order order)
        {
            if (order == null)
            {
                throw new ArgumentNullException(nameof(order));
            }

            Guid          orderId   = Guid.Parse(order.Id);
            ProcessedCart draftCart = null;

            var createOrderDraftParam = new CreateCartOrderDraftParam
            {
                CultureInfo = ComposerContext.CultureInfo,
                OrderId     = orderId,
                Scope       = order.ScopeId,
                CustomerId  = Guid.Parse(order.CustomerId)
            };

            try
            {
                draftCart = await OrderRepository.CreateCartOrderDraft(createOrderDraftParam).ConfigureAwait(false);
            }
            catch (ComposerException ex)
            {
                var ownedBySomeoneElseError   = ex.Errors?.FirstOrDefault(e => e.ErrorCode == Constants.ErrorCodes.IsOwnedBySomeoneElse);
                var ownedByRequestedUserError = ex.Errors?.FirstOrDefault(e => e.ErrorCode == Constants.ErrorCodes.IsOwnedByRequestedUser);
                if (ownedBySomeoneElseError != null)
                {
                    draftCart = await ChangeOwnership(order).ConfigureAwait(false);
                }
                else if (ownedByRequestedUserError != null)
                {
                    draftCart = await CartRepository.GetCartAsync(new GetCartParam
                    {
                        Scope       = order.ScopeId,
                        CartName    = order.Id.GetDraftCartName(),
                        CartType    = CartConfiguration.OrderDraftCartType,
                        CustomerId  = Guid.Parse(order.CustomerId),
                        CultureInfo = ComposerContext.CultureInfo
                    }).ConfigureAwait(false);
                }
                else
                {
                    throw;
                }
            }

            if (draftCart == null)
            {
                throw new InvalidOperationException("Expected draft cart, but received null.");
            }

            //Set Edit Mode
            ComposerContext.EditingCartName = draftCart.Name;

            return(draftCart);
        }