Update Product in custom Plugin not updating

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
7 years ago
Using NopCommerce 3.8, Visual Studio 2015 proff.

I have created a plugin that is responsible for making restful calls to my Web API that exposes a different DB to that of Nop.

The process is run via a nop Task, it succesfully pulls the data back and i can step through and manipulate as i see fit, no issues so far.

Issue comes when i try to update a record on the product table, i perform the update... but nothing happens no change, no error.

I beleive this is due to the Context having no idea about my newly instantiated product object, however I'm drawing a blank on what i need to do in relation to my particular example.

Similar questions usually reference a "model" object that is part of the paramter of the method call, "model" has the method "ToEntity" which seems to be the asnwer in similar question in stack.

However my example doesnt have the ToEntity class/method possibly because my paramter is actually a list of products. To Clarigy heres my code.

Method in RestClient.cs

public async Task<List<T>> GetAsync()
    {
        try
        {
            var httpClient = new HttpClient();

            var json = await httpClient.GetStringAsync(ApiControllerURL);

            var taskModels = JsonConvert.DeserializeObject<List<T>>(json);

            return taskModels;
        }
        catch (Exception e)
        {
            return null;
        }
    }


Method in my Service Class

public async Task<List<MWProduct>> GetProductsAsync()
    {
        RestClient<MWProduct> restClient = new RestClient<MWProduct>(ApiConst.Products);
        var productsList = await restClient.GetAsync();

        InsertSyncProd(productsList.Select(x => x).ToList());
        return productsList;
    }
private void InsertSyncProd(List<MWProduct> inserted)
    {
        var model = inserted.Select(x =>
        {
            switch (x.AD_Action)
            {
                case "I":
                    //_productService.InsertProduct(row);
                    break;
                case "U":
                    UpdateSyncProd(inserted);
                  .....


Then the method to bind and update

private void UpdateSyncProd(List<MWProduct> inserted)
    {
        var me = inserted.Select(x =>
        {
            var productEnt = _productRepos.Table.FirstOrDefault(ent => ent.Sku == x.Sku.ToString());
            if(productEnt != null)
            {
                productEnt.Sku = x.Sku.ToString();
                productEnt.ShortDescription = x.ShortDescription;
                productEnt.FullDescription = x.FullDescription;
                productEnt.Name = x.Name;
                productEnt.Height = x.Pd_height != null ? Convert.ToDecimal(x.Pd_height) : 0;
                productEnt.Width = x.Pd_width != null ? Convert.ToDecimal(x.Pd_width) : 0;
                productEnt.Length = x.Pd_depth != null ? Convert.ToDecimal(x.Pd_depth) : 0;
                productEnt.UpdatedOnUtc = DateTime.UtcNow;
            }
            //TODO: set to entity so context nows and can update
            _productService.UpdateProduct(productEnt);

            return productEnt;
        });

    }


So as you can see, i get the data, i pass data through to certain method based on a result. From that list in the method i iterate over, i then pull the the entity from the table, then update via the product service using that manipulated entity.

So what am i missing here, I'm sure its 1 step, and i think it may be iether be because 1) The context still has no idea about the entity in question, or 2) Its Incorrect calls.

Summary
Update is not updateing, possibly due to context having no knowledge OR my methodolgy is wrong. (probably both).

question also available on http://stackoverflow.com/questions/41609158/nopcommerce-update-entity-issue
7 years ago
Is my implimentation ok?
7 years ago
Still no luck after debugging, is it because what im doing is inside a task would that have any effect?
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.