Exemple #1
0
        /// <summary>
        /// Adds the items from an EA order to a Cart in Magento.
        /// If an item on the order cannot be found in Magento an exception is thrown.
        /// </summary>
        /// <param name="orderId">Order to get items for</param>
        /// <param name="cartId">Cart to add items to</param>
        public void AddOrderItemsToCart(string orderId, int cartId)
        {
            Guid result;

            if (!Guid.TryParse(orderId, out result))
            {
                throw new ArgumentException("Argument must be a valid Guid.", nameof(orderId));
            }
            IEnumerable <OrderItemResource> orderItems = _eaOrderController.GetOrderItems(orderId);

            foreach (var orderItem in orderItems)
            {
                CatalogItemResource catalogItem = _eaCatalogsController.GetCatalogItem(orderItem.ProductId);
                ProductResource     product     = _magentoProductController.SearchForProducts(ConfigReader.MappingCode, catalogItem.Slug,
                                                                                              ConfigReader.MagentoEqualsCondition).items.FirstOrDefault();

                if (product == null)
                {
                    throw new Exception(string.Format("Magento product could not be found for product {0} on order {1} with mapping code {2}",
                                                      orderItem.SKU, orderId, catalogItem.Slug));
                }

                CartAddItemResource cartAddItem = new CartAddItemResource(cartId, product.sku, orderItem.Quantity);
                _magentoCartController.AddItemToCart(cartId, cartAddItem);
            }
        }
Exemple #2
0
        /**
         * This function adds a product to your Catalog in EA given a slug
         *
         * @param   slug            Slug of a Product in EA
         *
         * @return  string          Identifier of a created CatalogItem
         */
        public string AddProductToEndlessAisle(string slug)
        {
            var catalogItem = new CatalogItemResource
            {
                Slug = slug
            };

            return(_eaCatalogController.CreateCatalogItem(catalogItem).CatalogItemId.ToString());
        }
Exemple #3
0
        /**
         * Creates a Catalog Item
         *
         * @param   CatalogItemResource       Object representing CatalogItem to be created
         * @return  CatalogItemResource       CatalogItemResource that was created, if sucessful
         */
        public CatalogItemResource CreateCatalogItem(CatalogItemResource catalogItem)
        {
            var endpoint = UrlFormatter.EndlessAisleCreateCatalogUrl();

            var client  = new RestClient(endpoint);
            var request = new RestRequest(Method.POST);

            request.AddHeader("Authorization", string.Format("Bearer {0}", AuthToken));
            request.AddHeader("Accept", "application/json");
            request.AddHeader("Content-Type", "application/json");

            request.AddJsonBody(catalogItem);

            var response = client.Execute(request);

            //Ensure we get the right code
            CheckStatusCode(response.StatusCode);

            return(JsonConvert.DeserializeObject <CatalogItemResource>(response.Content));
        }
Exemple #4
0
 public CatalogClient(HttpClient client)
 {
     Item = new CatalogItemResource(new BaseClient(client, client.BaseAddress.ToString()));
 }