Beispiel #1
0
        /**
         * This function creates a master product
         *
         * @param  productMapping          Mapping value, can be null
         * @param  eaCategoryId            Identifier for a category in EA
         * @param  eaClassificationTreeId  Identifier for a classification tree in ea
         * @param  eaManufacturerId        Identifier for a manufacturer in EA
         * @param  fields                  Fields representing changes to product details
         * @param  assets                  Assets for product
         *
         * @return int                     Identifier of a product document in EA
         */
        public int UpsertMasterProduct(string productMapping, int eaCategoryId, int eaClassificationTreeId, int?eaManufacturerId, List <FieldResource> fields, List <AssetResource> assets)
        {
            var productDocumentId = -1;

            if (productMapping != null)
            {
                var slug = _eaCatalogController.GetCatalogItem(productMapping).Slug;

                productDocumentId = _eaProductController.UpdateMasterProduct(GetProductDocumentIdFromSlug(slug),
                                                                             new RevisionEditResource
                {
                    FieldValues       = fields,
                    Assets            = assets,
                    IdentifierGroups  = null,
                    ColorDefinitionId = null
                });
            }
            else
            {
                var requestBody = new ProductDocumentResource
                {
                    Classification = new ProductClassificationRefResource
                    {
                        Id     = eaCategoryId,
                        TreeId = eaClassificationTreeId
                    },
                    OwnerEntityId = ConfigReader.EaCompanyId,
                    RootRevision  = new RootRevisionResource
                    {
                        FieldValues = fields,
                        Assets      = assets
                    }
                };

                if (eaManufacturerId != null)
                {
                    requestBody.Manufacturer = new EntityRefResource {
                        Id = (int)eaManufacturerId
                    };
                }

                productDocumentId = _eaProductController.CreateMasterProduct(requestBody).Id;
            }

            return(productDocumentId);
        }
Beispiel #2
0
        /**
         * Creates a Master Product
         *
         * @param   ProductDocumentResource       Object representing Master product to be created
         * @return  ProductDocumentResource       ProductDocumentResource that was created, if sucessful
         */
        public ProductDocumentResource CreateMasterProduct(ProductDocumentResource product)
        {
            var endpoint = UrlFormatter.EndlessAisleCreateProductUrl();

            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(product);

            var response = client.Execute(request);

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

            return(JsonConvert.DeserializeObject <ProductDocumentResource>(response.Content));
        }