You are here:  » Pre Import Feed Scanning


Pre Import Feed Scanning

Submitted by Keeop on Tue, 2014-02-11 16:31 in

Hi David,

After another helpful piece of code please! Would it be possible to have a drop-down and text box on the admin page where you could select any field from the data feed, pre import, and generate a list of the values for display in the text box? It's just that sometimes I only want to import a very limited set of products, say from a merchant category field, and at the moment that's only possible after either importing the whole feed and assigning that field to a PT field (even if I don't want to use it on the site) or scanning through the XML file by hand.

Cheers.
Keeop

Submitted by support on Wed, 2014-02-12 08:47

Hi Keeop,

Here's something quick and easy to try. In admin/feeds_register_step2.php look for the following code at line 259:

  print "<th class='key'>".widget_safe($k)."</th>";

...and REPLACE with:

  print "<th class='key'><a target='_BLANK' href='feeds_register_inspect.php?filename=".urlencode($filename)."&format=".urlencode($format)."&field=".urlencode($k)."'>".widget_safe($k)."</a></th>";

Now create a new file admin/feeds_register_inspect.php as follows:

<?php
  
@set_time_limit(0);
  
header("Content-Type: text/plain");
  require(
"../includes/common.php");
  require(
"../includes/MagicParser.php");
  
$filename $_GET["filename"];
  
$format $_GET["format"];
  
$field $_GET["field"];
  
$values = array();
  function 
myRecordHandler($record)
  {
    global 
$field;
    global 
$values;
    
$values[$record[$field]] = 1;
  }
  
MagicParser_parse($config_feedDirectory.$filename,"myRecordHandler",$format);
  foreach(
$values as $value => $v)
  {
    print 
$value."\n";
  }
?>

With that in place, from Feed Registration Step 2, each field name in the sample data table will be a link to the new script (opening in new window) which will display the complete list of unique values for that field...

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by Keeop on Wed, 2014-02-12 09:38

Hi David,

Thanks. Sounds like a good idea. It doesn't seem to work correctly though. It prints a load of '1's before the field list and clicking on those fields just opens a blank page. Would this be caused by my hotch-potch of PT versioned code?! What would also make this better if that on the new screen a 'helper' could be incorporated too so that I could then highlight one of the values from the generated list and get a list of any products associated with it. Guess this might be a bit tricky though!

Cheers.
Keeop

Submitted by support on Wed, 2014-02-12 10:06

Sorry Keep there was a superfluous extra "print" statement in the replacement line - corrected above...

Cheers,
David.
--
PriceTapestry.com

Submitted by Keeop on Wed, 2014-02-12 10:20

Hi David,

Still nothing showing up in the newly opened window though!

Cheers.
Keeop

Submitted by Keeop on Wed, 2014-02-12 10:32

Sorted - didn't have the config.advanced file in that version! So, what do you reckon about the feasibility of putting a 'helper' in there to display any products? Guess the associated 'name' field for each item listed in the new window, whatever it may be?

Cheers.
Keeop

Submitted by support on Wed, 2014-02-12 12:07

Hi Keeop,

Would an "Inspect" process _after_ a feed has been registered work for you - as the product name field can then be picked up from the `pt_feeds` record?

Cheers,
David.
--
PriceTapestry.com

Submitted by Keeop on Wed, 2014-02-12 15:45

Hi David,

Yes that would work I reckon. I can always manually change around the registered fields in the feed table anyway should a scan/inspection reveal a better field to use for a particular thing. It's mainly for categories really, when there is a merchant category field and a network category field - to find which one is best suited.

Cheers.
Keeop

Submitted by support on Wed, 2014-02-12 17:34

Hi Keeop,

I'll give this a go on my test server and follow up by email for you...

Cheers,
David.
--
PriceTapestry.com

Submitted by Convergence on Thu, 2014-02-27 17:53

Hi David,

Will this work on our heavily modified version 12/10B?

Thanks!

Submitted by support on Thu, 2014-02-27 18:06

Hi Convergence,

You might want to check out the Insepector tool posted just the other week which i've coded it to let you view custom field A-Z lists as well as the default fieldset but the initial code above should work fine with 12/10B if you're after inspecting field values before the first registration, but I know your installation is heavily customised so if any problems just let me know and I'll check it out for you...

Cheers,
David.
--
PriceTapestry.com

Submitted by BobL on Fri, 2014-08-01 01:30

Bob L.

Hi David,
Hope all is well.
What modifications would be needed to get this to work on version 14/06.
I've changed line #120 in feeds_register_step2.php and it creates the hyperlinks to feeds_register_inspect.php,but all I get is a blank page.

Thank you in advance and for your great support here.

Submitted by support on Fri, 2014-08-01 08:44

Hello Bob,

The equivalent code in 14/06A is within a function so $filename and $format need to be declared global. Full modification as follows;

In admin/feeds_register_step2.php look for the following code at line 114:

  global $productRecord;

...and REPLACE with:

    global $productRecord;
    global $filename;
    global $format;

And then look for the following code at line 123:

  print "<th class='pta_key'>".widget_safe($k)."</th>";

...and REPLACE with:

  print "<th class='pta_key'><a href='feeds_register_inspect.php?filename=".urlencode($filename)."&format=".urlencode($format)."&field=".urlencode($k)."'>".widget_safe($k)."</a></th>";

FYI, I have also just posted a version of the Inspector tool for 14/06A - see downloads / this page for more info.

Cheers,
David.
--
PriceTapestry.com