/// <summary> /// Upserts an EA availability / quantity record for a catalog product. EA requires products to have availability /// before they can show up. /// /// Availability is set at the COMPANY level in EA /// /// NOTE: /// By default, this function creates an availability record of 1 for a product across the company /// Allowing a product to appear in EA, passing the "do not display out of stock products" rule. /// </summary> /// <param name="catalogItemId">Item ID for EA catalog</param> /// <param name="quantity">Quantity to set for the item. Defaults to 1 if not set.</param> public void UpsertAvailabilityForCatalogItem(string catalogItemId, int quantity = 1) { if (catalogItemId == null) { throw new Exception("A catalog item ID must be provided."); } var availability = new AvailabilityResource { Id = new Guid(catalogItemId), EntityId = ConfigReader.EaCompanyId, Quantity = quantity }; _eaAvailabilityController.CreateCatalogItem(availability); }
/** * Creates an Availability resource * * @param AvailabilityResource Object representing Availability to be created * @return AvailabilityResource AvailabilityResource that was created, if sucessful */ public AvailabilityResource CreateCatalogItem(AvailabilityResource availability) { var endpoint = UrlFormatter.EndlessAisleCreateAvailabilityUrl(); 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(availability); var response = client.Execute(request); //Ensure we get the right code CheckStatusCode(response.StatusCode, System.Net.HttpStatusCode.Created); return(JsonConvert.DeserializeObject <AvailabilityResource>(response.Content)); }