You are here:  » Merchant specific duplicate checking


Merchant specific duplicate checking

Submitted by ChrisNBC on Wed, 2015-05-13 14:45 in

Hi David,

Hope all is going well. I wondered if you might be able to give me some advice re duplicate checking. I know I can alter the duplicate checking criteria globally but I wondered if you could suggest if there is a simple way I could create a specific duplicate check criteria for an individual merchant?

Thanks in advance.

Regards
Chris

Submitted by support on Wed, 2015-05-13 16:30

Hi Chris,

A merchant specific derivation of $dupe_key - the value which is hashed to create the dupe_hash field against which there is a unique key on the database would be straightforward to override on a per merchant basis, with reference to either raw (feed values) or process ($config_fieldSet values).

In includes/admin.php locate the default version of the code as follows:

    /* create dupe_hash value */
    $dupe_key = $importRecord["merchant"];
    $dupe_key .= $searchName;

A switch statement could be used at this point to work out the value differently depending on the merchant name in $importRecord["merchant"]. This point in the code as access to the raw feed data (unaffected by filters) via $record and the import prepared versions (affected by filters and mapping) via $importRecord.

Keys to $record are as per the field name values shown in the Sample Data displayed below the form on Feed Registration Step 2.

Keys to $importRecord are as per $config_fieldSet in config.advanced.php.

So let's say you have a particular merchant, Merchant 1, and you wanted to base duplicate prevention on the raw feed fields "field1" and "field2", a replacement for the above code would be as follows:

    /* create dupe_hash value */
    switch($importRecord["merchant"])
    {
      case "Merchant 1":
        $dupe_key = $record["field1"].$record["field2"];
        break;
      default:
        $dupe_key = $importRecord["merchant"];
        $dupe_key .= $searchName;
        break;
    }

Additional cases for other merchants can be added, e.g. for Merchant 2 that you wish to de-dupe via field3 and field4, use:

    /* create dupe_hash value */
    switch($importRecord["merchant"])
    {
      case "Merchant 1":
        $dupe_key = $record["field1"].$record["field2"];
        break;
      case "Merchant 2":
        $dupe_key = $record["field3"].$record["field4"];
        break;
      default:
        $dupe_key = $importRecord["merchant"];
        $dupe_key .= $searchName;
        break;
    }

Any merchant not listed specifically in the CASE statement continue to work as normal via the default: case.

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by ChrisNBC on Thu, 2015-05-14 12:59

Wow! ..thanks David, the above sounds perfect, I'm going to give this a whirl later today on my test server.

Best regards
Chris