Developer forum

Forum » Integration » DataIntegration - Remove missing products from multiple shops (9.12.10)

DataIntegration - Remove missing products from multiple shops (9.12.10)

Gunnar Örn Baldursson
Reply

Hi, 

we have a client using the "Remove missing rows after import" setting on a data integration job to import products from an XMLProvider. After they've added some of their products to PIM, the client feels the option is no longer working since it's only removing "some" products or, specifically, products not added to the PIM shop.

I found a similar case here (https://doc.dynamicweb.com/forum/integration/integration/dw-9-13-2-ecom-provider-remove-missing-rows-after-import-not-working) on the forum where the proposed solution is to set the Shop option to 'None' and remove missing products from all shops. Our client is using one non-integrated shop which they maintain manually so I can't set the shop to None if it means that shop gets cleared.

Can you advise on how to handle this scenario? Would you perhaps consider changing the option to allow me to select multiple shops instead of one or none?


Replies

 
Morten Snedker Dynamicweb Employee
Morten Snedker
Reply
This post has been marked as an answer

Hi Gunnar,

A data integration job triggers a "JobFinishedNotification" that you may subscribe to, in order to provide your own logic.

Example:

using Dynamicweb.DataIntegration.Integration;
using Dynamicweb.Extensibility.Notifications;
using Dynamicweb.DataIntegration.Integration.Notifications;

namespace Ecom
{
    [Subscribe(Integration.JobFinished)]
    public class JobFinishedObserver1 : NotificationSubscriber
    {
        public override void OnNotify(string notification, NotificationArgs args)
        {
            var integrationArgs = args as Integration.JobFinishedIntegrationArgs;
            if (args is null)
                return;

            if (integrationArgs.Job.Name.ToLower() == "job1")
            {
                // your logic
            }
        }
    }
}

Your logic could be re-reading the source xml to get a hold of ProductId/ProductNumber or what-ever key you may want, and put it to a list that is kept in session. And then use that list to compare with existing products. Alternatively you can use TableScript to build the list, as you are processing each row anyway:

using System.Linq;
using System.Collections.Generic;
using Dynamicweb.DataIntegration.Integration;
namespace T3
{
    public class ExampleTableScript1 : TableScript
    {
        public override string ScriptingName
        {
            get
            {
                return "Sample input processing script";
            }
        }

        public override void ProcessInputRow(Mapping mapping, Dictionary<string, object> row)
        {
            if (mapping.SourceTable != null)
            {
                var column = mapping.SourceTable.Columns.FirstOrDefault(c => c != null && c.Name.ToLower() == "ProductNumber".ToLower());
                if (column != null && row.ContainsKey(column.ProductNumber))
                {
                    someList.Add(row[column.ProductNumber].ToString());
                }
            }
        }
    }
}

And then use this list in your jobfinished observer.

Hope the above may be useful.

 

BR
Snedker

Votes for this answer: 1
 
Gunnar Örn Baldursson
Reply

Alright-y, I'll try those methods, thanks for the tip! :) 

 

You must be logged in to post in the forum