_productService.UpdateProduct() doesn't seem to be working

Hace 5 meses
I'm working on a service in NopCommerce 4.3 that will insert new products into the catalog and will update existing products. So far inserting products works well. Updating products doesn't seem to be working.

How can I get this method to work? Is there a different method that I should be using?


            Product testProduct = new Product();
            testProduct = products[0];

            var _productRepository = EngineContext.Current.Resolve<IRepository<Product>>();
            var _productService = EngineContext.Current.Resolve<IProductService>();

            var skuFound = _productService.GetProductBySku(testProduct.Sku);

            if (skuFound.Sku != null)
            {
                _productService.UpdateProduct(testProduct);
            }
            else
            {
                _productRepository.Insert(testProduct);
            }
Hace 5 meses
You cannot pass a new product to the "UpdateProduct" methods. It should be inserted first.

I presume you want to update "skuFound" (not "testProduct") in your example
Hace 5 meses
a.m. wrote:
You cannot pass a new product to the "UpdateProduct" methods. It should be inserted first.

I presume you want to update "skuFound" (not "testProduct") in your example


You are correct. I wasn't using the product that already exists in the catalog (ie. skuFound).

With those changes the product now updates as expected. Thank you!