You are here:  » Set merchant based on other field


Set merchant based on other field

Submitted by sirmanu on Sat, 2018-12-29 19:21 in

Hi David.

I have a merchant which have a marketplace. Let say it is called "Amachon". So they offer two feeds: one for their offers, and other for third party.

1) amachon_retail.csv
2) amachon_marketplace.csv

On (1) I am using the the name Amachon for merchant name, and for (2), just Amachon Marketplace.

The problem is that sometimes, they put products which should be amachon_retail.csv into amachon_marketplace.csv

In each feed, I have the field itemMerchantName. On (1) this value is always is always Amachon. In (2), this value is changing constantly, depending on the name of the third party. The thing is that sometimes this value is Amachon.

So what I want to do (maybe with a filter?), is to set the merchant name on amachon_marketplace.csv to Amachon rather than Amachon Marketplace if the field itemMerchantName is equals to Amachon.

I have the filter scan and set regexp, if it helps.

I hope you have understood the problem.

Thank you.

Submitted by support on Mon, 2018-12-31 10:19

Hi,

A modified version of Scan and Set Field filter from this thread but changed to pass the field to scan as a parameter, and set values which can be different to the corresponding scan values, and return the value unaltered if none of the scan values are matched should do the trick - add the following code to includes/filter.php:

  /*************************************************/
  /* scanSetField */
  /*************************************************/
  $filter_names["scanSetField"] = "Scan and Set Field";
  function filter_scanSetFieldConfigure($filter_data)
  {
    print "Field:<br />";
    print "<input type='text' name='field' value='".widget_safe($filter_data["field"])."' />";
    widget_errorGet("field");
    print "Scan Values:<br />";
    print "<input type='text' name='scan' value='".widget_safe($filter_data["scan"])."' />";
    widget_errorGet("scan");
    print "Set Values:<br />";
    print "<input type='text' name='set' value='".widget_safe($filter_data["set"])."' />";
    widget_errorGet("values");
  }
  function filter_scanSetFieldValidate($filter_data)
  {
    if (!$filter_data["field"])
    {
      widget_errorSet("field","required field");
    }
    if (!$filter_data["scan"])
    {
      widget_errorSet("scan","required field");
    }
    if (!$filter_data["set"])
    {
      widget_errorSet("set","required field");
    }
  }
  function filter_scanSetFieldExec($filter_data,$text)
  {
    global $filter_record;
    $scans = explode(",",$filter_data["scan"]);
    $sets = explode(",",$filter_data["set"]);
    foreach($scans as $k => $scan)
    {
      if (stripos($filter_record[$filter_data["field"]],trim($scan))!==FALSE) return $sets[$k];
    }
    return $text;
  }

However, by default filters can't be attached to the Merchant field so a small modification is required to both admin/feeds_filters.php and admin/feeds_filters_configure.php. In both files, look for the following code at line 2:

  require("../includes/common.php");

...and REPLACE with:

  require("../includes/common.php");
  $config_fieldSet["merchant"] = "Merchant";

With that in place; you should then be able to add a Scan and Set Field filter to the Merchant field for amachon_marketplace.csv configured as follows;

Field:
itemMerchantName

Scan:
Amachon

Set:
Amachon

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by sirmanu on Mon, 2018-12-31 12:26

Excellent David. It seems to be working.
...

I have added to feed_register_step2.php

$config_fieldSet["merchant"] = "Merchant";

Because I was having undefined offset. Is it right?

Submitted by support on Mon, 2018-12-31 13:01

Hi,

There isn't any filter specific functionality on Feed Registration Step 2 so that shouldn't be required however if you have previous modifications in place that do then yes, that same modification would be needed - if anything not working as expected as a result of course let me know and I'll check it out further with you...

Cheers,
David.
--
PriceTapestry.com

Submitted by sirmanu on Mon, 2018-12-31 13:11

You are right. It was a modification from other thread to display filters on that page. Sorry!