You are here:  » New Import Filter


New Import Filter

Submitted by Keeop on Fri, 2013-11-01 13:13 in

Hi David,

Hoping you can help me with a new global import filter. On a lot of feeds where the merchant uses model names and brand fields separately - so I then use a standard 'Text Before' filter to plonk prep-end the name field with the brand value - they also slip in a few records with the brand name already in the 'model' field. So, I'm looking for a neat way (a new filter) to automatically de-dupe the name field of a double brand name.

e.g.

After a text before, we are left with: 'Breville Breville SX200' where 'Breville' is the brand value.

Would love a filter that removed that second brand name instance automatically rather than me having to keep an eye out for it after each import!

Cheers.
Keeop

Submitted by support on Fri, 2013-11-01 13:56

Hi Keeop,

In this comment you'll find a mod to the Search and Replace filter that enables you to use the %fieldname% placeholders in the Search field. With this in place, in sequence _before_ your Text Before filter if you add a Search and Replace filter with %brand% and leave the Replace box empty, that should do the trick!

In %brand%, "brand" should match exactly the field name as it appears in the sample data shown on Feed Registration Step 2.

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by Keeop on Tue, 2013-11-05 10:40

Hi David,

That's the thing. Different feeds have different values for %brand% so I can't set one filter to cover them all - which is what I'm after. I can, of course, set up multiple instances but I was after a 'fire and forget' solution as if I add another feed with a different %brand% value, it will slip through. Hmm, I think the best way is to probably add some search and replace code in to includes/admin.php and do it there.

Cheers.
Keeop

Submitted by support on Tue, 2013-11-05 11:35

Hi Keeop,

Sure - no problem, in includes.admin.php look for the following comment around line 218:

  /* apply user filters */

...so to remove the brand name from the product name, immediately before the above line add the following new code:

  $importRecord["name"] = trim(str_replace($importRecord["brand"],"",$importRecord["name"]));

Cheers,
David.
--
PriceTapestry.com

Submitted by Keeop on Thu, 2013-11-07 11:08

Thanks David.

Hoping you can also help with something else. It's getting to the point were the 'backfilling reviews' function is taking an age to complete. Can you think of a faster, more efficient way of carrying out this process?

Cheers.
Keeop

Submitted by support on Thu, 2013-11-07 16:35

Hi Keeop,

The main purpose of the backfill process is so that products can be ordered by rating but that's certainly not the most used of functions - if you didn't mind removing that sort option from your site then review data can be pulled into search results direct from the reviews table. If that would be OK, if you would like to email me your search.php and products.php I'll check that out on my test server and patch your latest versions for you...

Cheers,
David.
--
PriceTapestry.com

Submitted by Keeop on Fri, 2013-11-08 09:00

Hi David,

I do use that feature so I'll have to keep it as-is. I was just wondering if there was a more efficient way of performing the backfill function?

Cheers.
Keeop

Submitted by support on Fri, 2013-11-08 09:43

Hi Keeop,

Sure - I'll check some options out on my test server and get back to you...

Cheers,
David.
--
PriceTapestry.com

Submitted by Keeop on Mon, 2013-11-11 23:17

Thanks David.

I'm also starting to have troubles with the UIDMAP script - I think that it's timing out. If you have any suggestions on altering that, it would be great.

Cheers.
Keeop

Submitted by support on Tue, 2013-11-12 09:19

Hi Keeop,

As the uidmap process is normally chained in sequence with the import.php/cron.php it sounds like they're related issues - possibly the job is not even reaching uidmap.

What hosting do you have - standard shared, or do you have dedicated, VPS or cloud server on which it would be possible to adjust PHP's timeout settings? If you could also confirm the actual CRON commmands that you have scheduled (i'll remove any domains/usernames before publishing your reply) that will help...

Cheers,
David.
--
PriceTapestry.com

Submitted by Keeop on Fri, 2013-11-15 09:34

Hi David,

It's a dedicated server. Yes, I have an import routine for each web site that runs several php scripts in order. It just seems to be the uidmap that's not completing. It's definitely running but not getting all the way through. I expect it's similar to the 'SQL dropped connections' we were getting when you were trying to rewrite my quality.php script to use the same sort of logic as the uidmap script - that kept losing connection if you remember. So, I guess the uidmap script needs to be rewritten to use the old methods of creating connections to the SQL server - as is used by the rest of the PT script. Can you help with that please or did you ever find a solution to the 'dropped connection' problem - I never did!

Cheers.
Keeop

Submitted by Keeop on Fri, 2013-11-15 10:26

Hi David,

OK very weird. If I run the uidmap script from a web page, it all seems to work. Running it from a command line gives it problems. i.e., the php-cgi executable is handling it fine, but the php.exe isn't! Any ideas?!

Cheers.
Keeop

Submitted by support on Fri, 2013-11-15 10:58

Hi Keeop,

I haven't as yet experienced the "MySQL Server Has Gone Away" issue with the mysqli library, so if you would like to give that a go you can download the patch here (more info). If that doesn't do the trick, or is not convenient, let me know and I'll look into what's required to apply the work-around to uidmap.php for you...

Cheers,
David.
--
PriceTapestry.com

Submitted by Keeop on Sat, 2013-11-16 21:57

Hi David,

I had set the uidmap script time-outs to 90000 - think this caused the problems. Set them back to 900 and it worked again. Will have a play with the time-outs and have a look at the mysqli stuff again!

As an aside, but related to SKU/EAN stuff, I've noticed some merchants are stuffing zeros at the beginning of some of their EANs. Could you help me with a filter (assuming a regex job) that will strip either the first 00 or 0 from the EAN?

Thanks!
Keeop

Submitted by support on Sun, 2013-11-17 10:22

Hi Keeop,

If you don't already have it, there is a Search and Replace RegExp filter in this comment. With that in place, add an instance of the new filter to the EAN field, and in the Search box, enter the expression:

/^(0{0,2})/

...and leave the Replace box empty - that should do the trick!

Cheers,
David.
--
PriceTapestry.com

Submitted by Keeop on Tue, 2013-11-19 22:26

Thanks David.

Filter works like a charm and I've got the other scripts working again after tampering with the timeout values. Still need to try and speed the review imports up though so if you've any ideas..........

Cheers.
Keeop

Submitted by Keeop on Tue, 2013-11-26 17:45

Hi David,

Slowly working through upgrading some of my code...........!

Can you please help me with some voucher stuff? I have an older style, highly customised voucher_codes_edit.php which I'm trying to update to use the voucher feeds and helper code. The main thing with this is it's a centralised voucher management system that manages all of my sites. So, the main addition is a list of all my databases so I can then select the correct one to find the correct merchant. I'm having all sorts of problems with trying to get field values to populate when already known, values not being passed to the helper etc. Without the extra DB selector, it would be fine but this thing is causing me problems. I have tried using Ajax to populate the 'merchant' drop-down based on the selection made in the 'database' drop-down and it sort of works sometimes - I have now tinkered with the file a bit too much and made it unusable! So, really, I'd like it as-is but with the addition of being able to select the database and hence the merchant, but I'd like the database value passed to the 'helper' and read/written from the 'vouchers' table where applicable.

Is this something you can knock up, or shall I send to my existing file - bearing in mind it is now a total mess?!

Cheers.
Keeop

Submitted by support on Wed, 2013-11-27 11:04

Hi Keeop,

In admin/voucher_codes_edit.php, first add a hidden field to the form by looking for the following code at line 24:

  print "<form method='post'>";

...and REPLACE with:

  print "<form method='post'>";
  print "<input id='database_name' name='database_name' value='' />";

And then at the top of the script, use this to override $config_databaseName (if set) by looking for the following code at line 2:

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

...and REPLACE with:

  require("../includes/common.php");
  if (isset($_POST["database_name"]))
  {
    $config_databaseName = $_POST["database_name"];
  }

It sounds like you already have a "Database" drop down in your modified admin/voucher_codes_edit.php so first make sure it has an id field e.g

  id='database_name'

Then look for the following code at line 479:

  helper_document.getElementById(that.id).value = that.value;

...and REPLACE with:

  helper_document.getElementById('database_name').value = document.getElementById('database_name');
  helper_document.getElementById(that.id).value = that.value;

That will update the hidden field in the helper tool whenever it is set (or loaded) on the main edit form....

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by Keeop on Wed, 2013-11-27 14:56

Hi David,

Thanks. Doesn't seem to make any difference though. I added a 'hidden' attribute to hide the text box but other than that, I've put everything in. The Helper just doesn't get updated! Do I need to add an 'onchange' event to the drop down?

Cheers.
Keeop

Submitted by Keeop on Wed, 2013-11-27 14:59

Ah, to answer my own question, that does seem to work when changing that value but not populating the helper when loaded. Also, I need another 'onchange' script for that field anyway to kick off the Ajax call to populate the second dropdown, so I don't think I can call both?

Cheers.
Keeop

Submitted by support on Wed, 2013-11-27 16:18

Hi Keeop,

You can chain multiple function calls in a single onchange event, separate by semi-colon e.g.

onchange='JavaScript:onchange1();onchange2();'

...but you're correct - an onchange handler to update database_name in the iframe will be required, so if you add a new function to the JavaScript section in admin/voucher_codes_edit.php:

  function database_nameOnChange()
  {
    helper = document.getElementById("helper");
    helper_document = (helper.contentDocument || helper.contentWindow.document || helper.document);
    helper_document.getElementById('database_name').value = document.getElementById('database_name');
  }

...and add database_nameOnChange() as one of the functions called in the onchange attribute of the database_name field (or of course you can just add your own code to the above function and contain it all in one place...)

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by Keeop on Wed, 2014-01-08 09:32

Hi David,

I'm having troubles with the UIDMAP script again - it just doesn't complete half the time. Any chance you could rewrite it to use the standard db.php functions etc. which don't have these session timeout variables, connections and such like?

Cheers.
Keeop

Submitted by support on Wed, 2014-01-08 12:08

Hello Keeop,

I don't believe I've forwarded a MySQLi version of uidmap.php to try, so I'll email to you in just a moment...

Cheers,
David.
--
PriceTapestry.com

Submitted by Keeop on Sun, 2014-01-12 11:52

Hi David,

Seems to suffer similar problems in that 'Phase 1' will complete at a different number of records each time it is run and 'Phase 2' isn't running at all! I've no idea what's going on here but would love some more help please!

Cheers.
Keeop

Submitted by support on Mon, 2014-01-13 11:25

Hi Keeop,

I've just forward to you a version of the mysqli_ patched uidmap.php with debugging enabled, so assuming there is a database error at the point at which it aborts that should indicate the problem - if you could let me know what is displayed when the script exists I'll check it out further...

Thanks,
David.
--
PriceTapestry.com