Exemplo n.º 1
0
        private void CreateRemoteCheckoutFromLocalState(CompletionCallback callback)
        {
            MutationQuery query = new MutationQuery();

            List <CheckoutLineItemInput> newLineItemInput = CartLineItems.ConvertToCheckoutLineItemInput(LineItems.All());

            DefaultQueries.checkout.Create(query, newLineItemInput);

            Client.Mutation(query, (Mutation response, ShopifyError error) => {
                if (error != null)
                {
                    callback(error);
                    return;
                }

                if (UpdateState(response.checkoutCreate().checkout(), response.checkoutCreate().userErrors()))
                {
                    if (CurrentCheckout.ready())
                    {
                        callback(null);
                    }
                    else
                    {
                        PollCheckoutAndUpdate(PollCheckoutReady, callback);
                    }
                }
                else
                {
                    HandleUserError(callback);
                }
            });
        }
Exemplo n.º 2
0
        //By not making it public I make it easier to ensure that no cart line items are created with non-existing variants before a foreign key error is thrown
        private void AddVariant(string variantId, int count = 1)
        {
            Guid cartLineItemId;
            var  existingCartLineItem = CartLineItems.SingleOrDefault(item => item.VariantId == variantId);

            if (existingCartLineItem != null)
            {
                cartLineItemId = existingCartLineItem.Id;
                existingCartLineItem.IncreaseCount(count);
                DomainEvents.Raise(new CartLineItemUpdatedEvent(Id, cartLineItemId, variantId, existingCartLineItem.Count));
            }
            else
            {
                cartLineItemId = Guid.NewGuid();
                CartLineItems.Add(new CartLineItem(cartLineItemId, Id, variantId));
                DomainEvents.Raise(new CartLineItemAddedEvent(Id, cartLineItemId, variantId));
            }
        }
Exemplo n.º 3
0
        public void RemoveVariant(string variantId)
        {
            var existingCartLineItem = CartLineItems.SingleOrDefault(item => item.VariantId == variantId);

            if (existingCartLineItem == null)
            {
                throw new VariantNotExistingInCartException(Id, variantId);
            }

            existingCartLineItem.DecreaseCount();
            if (existingCartLineItem.Count == 0)
            {
                DeleteCartLineItem(existingCartLineItem);
            }
            else
            {
                DomainEvents.Raise(new CartLineItemUpdatedEvent(Id, existingCartLineItem.Id, variantId, existingCartLineItem.Count));
            }
        }
Exemplo n.º 4
0
        private void UpdateRemoteCheckoutFromLocalState(CompletionCallback callback)
        {
            MutationQuery query = new MutationQuery();

            // remove all line items them add them
            List <string> lineItemsToRemove = CartLineItems.ConvertToLineItemIds(LineItems.All());

            lineItemsToRemove.AddRange(DeletedLineItems);

            List <CheckoutLineItemInput> lineItemsToAdd = CartLineItems.ConvertToCheckoutLineItemInput(LineItems.All());

            DefaultQueries.checkout.LineItemsRemove(query, CurrentCheckout.id(), lineItemsToRemove);
            DefaultQueries.checkout.LineItemsAdd(query, CurrentCheckout.id(), lineItemsToAdd);

            Client.Mutation(query, (Mutation response, ShopifyError error) => {
                if (error != null)
                {
                    callback(error);
                    return;
                }

                DeletedLineItems.Clear();

                if (UpdateState(response.checkoutLineItemsAdd().checkout(), response.checkoutLineItemsAdd().userErrors()))
                {
                    if (CurrentCheckout.ready())
                    {
                        callback(null);
                    }
                    else
                    {
                        PollCheckoutAndUpdate(PollCheckoutReady, callback);
                    }
                }
                else
                {
                    HandleUserError(callback);
                }
            });
        }
Exemplo n.º 5
0
 public CartState(ShopifyClient client)
 {
     Client               = client;
     _LineItems           = new CartLineItems();
     _LineItems.OnChange += OnLineItemChange;
 }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            #region Variable declaration
            string        idstring           = string.Empty;
            int           id                 = 0;
            int           numberofitems      = 0;
            string        userinput          = string.Empty;
            string        quantitystring     = string.Empty;
            int           quantity           = 0;
            bool          cartstatus         = false;
            int           discountcount      = 0;
            int           discountincremwnrt = 1;
            string        couponcode         = string.Empty;
            string        discontinput       = string.Empty;
            List <string> coupencodearray    = new List <string>();
            string        modeofpayment      = string.Empty;
            decimal       grandtotal         = 0;
            #endregion
            try
            {
                Console.WriteLine("Welcome to Shopping Cart\n");
                #region To Display lsit of items
                display displayitems = new display();
                numberofitems = displayitems.displayproduct();
                #endregion

                #region To Add item to the cart
                CartLineItems additem = new CartLineItems();
                while (true)
                {
                    Console.WriteLine("Please enter the id of the product to be added to the cart");
                    idstring = Console.ReadLine();
                    id       = Convert.ToInt32(idstring);
                    if (id <= numberofitems)
                    {
                        Console.WriteLine("Enter the Quantity");
                        quantitystring = Console.ReadLine();
                        quantity       = Convert.ToInt32(quantitystring);
                        cartstatus     = additem.additems(id, quantity);
                        if (cartstatus)
                        {
                            Console.WriteLine("Item Added to Cart Successfully.Do you want to add more items to the cart? Y/N");
                        }
                        else
                        {
                            Console.WriteLine("Please try adding again");
                        }
                        userinput = Console.ReadLine();
                        if (userinput == "y" || userinput == "Y")
                        {
                            continue;
                        }
                        else
                        {
                            break;
                        }
                    }
                    else
                    {
                        Console.WriteLine("Item Id does not exist. Please enter the valid id ");
                    }
                }

                #endregion

                #region To Display the items in the cart and applying discount
                displayitems.displaycartlineitems();
                discountcount = displayitems.displaydiscount();
                if (discountcount > 0)
                {
                    Console.WriteLine("Please enter the coupon code of the discount you need to apply");
                    couponcode = Console.ReadLine();
                    coupencodearray.Add(couponcode);
                    displayitems.updatecart(couponcode);
                    while (discountcount > discountincremwnrt)
                    {
                        Console.WriteLine("Do you want to add another Code? If Yes enter the Offer Code else press N");
                        couponcode = Console.ReadLine();
                        if (couponcode == "n" || couponcode == "N")
                        {
                            grandtotal = displayitems.displayfinalcart();
                        }
                        else if (coupencodearray != null && coupencodearray.Contains(couponcode))
                        {
                            Console.WriteLine("Coupon already applied");
                        }
                        else
                        {
                            displayitems.updatecart(couponcode);
                        }
                        discountincremwnrt++;
                    }
                }
                grandtotal = displayitems.displayfinalcart();
                #endregion

                #region Payment Section
                Console.WriteLine("Please select the mode of payment");
                displayitems.displaymodeofpayments();
                modeofpayment = Console.ReadLine();
                displayitems.finalpage(modeofpayment, grandtotal);
                #endregion
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error in program.cs," + ex.Message);
            }
        }
Exemplo n.º 7
0
 private void DeleteCartLineItem(CartLineItem cartLineItem)
 {
     cartLineItem.TrackingState = TrackingState.Deleted;
     CartLineItems.Remove(cartLineItem);
     DomainEvents.Raise(new CartLineItemDeletedEvent(Id, cartLineItem.Id, cartLineItem.VariantId));
 }
Exemplo n.º 8
0
        public void Clear()
        {
            var elementsToDelete = CartLineItems.Select(e => e).ToList();

            elementsToDelete.ForEach(DeleteCartLineItem);
        }