Hi there,
The merchants I deal don't structure their data feeds correctly when it comes to categories, but in order for my site to work I do need them.
The only unique identifier I can find in their feed that would indicate it's category is a string within their URL structure.
So for example, the 'superWidget' product is available in two different formats/categories; 'redWidgets' & 'blueWidgets'. The URLs on the data feed are as follows:
http://example/redWidgets/superWidget
http://example/blueWidgets/superWidget
Is it possible you could suggest a way of parsing the datafeed for a given string within the url (for e.g. 'blueWidgets') and mapping it to a category accordingly? Is this something that has been asked for before?
Cheers,
Matt
Thanks David this is a great help.
Just so I understand it, what is the purpose of the return index value in this instance? I.e. why should it be set to '3' for the example above?
The identifier that exists in the url varies for each merchant so I'm just making sure I fully understand how this works..
Hi,
The filter basically uses PHP's explode() function to split the input value up into an array of parts using the separator charater - in this case "/" - and then the return index specifies which of the split up parts you want, but as PHP arrays are zero based so is the required parameter for the return index in the filter. For example if the input was:
aaa/bbb/ccc
...a return index of 0 would give aaa and 1 would give bbb (when using an explode character or string of "/").
Note that a URL contains a double // after the http: so these have to be taken into acount, it will result in an empty value because there is nothing between them rather than being treated as a single delimiter...
Hope this helps!
Cheers,
David.
--
PriceTapestry.com
I've just come across a potential complication here. I had one huge feed from AW which includes all merchants / products that I require. For approx 50% of the merchants, there is a category that exists as it should do on the feed. For the other 50% I would have to use the above explode method. This causes complications when setting the url (as above) to the category field during feed registration.
Do you think it's best to separate the merchants that don't have a category as standard into a different data feed and use the method above?
Also, one more question - if I change the string in /includes/admin.php - will I still be able to import as normal for products that have a category assigned as normal?
Thanks in advance,
Matt
Hi Matt,
Whilst something could be worked out in code I would say yes, if it is easy enough to separate out the merchants that need a more creative mapping into their own feed that would be the best solution...
Cheers,
David.
--
PriceTapestry.com
Hello Matt,
If the format is totally predictable then based on the above examples you could extract the category using an Explode filter. Firstly however, a small code change will be required to prevent the character that the filter would need to work on being removed during "normalisation". To do this, look for the following code around line 189 in includes/admin.php:
$importRecord["category"] = tapestry_normalise($importRecord["category"]);
...and REPLACE with:
$importRecord["category"] = tapestry_normalise($importRecord["category"],"\/");
With that in place, on Feed Registration Step 2, register the URL as the Category. After registering the feed, click Filters alongside the feed from the /admin/ home page and add a new Explode filter to the category field. On the configuration page for the filter enter as the Explode Character or String "/" (without the quotes), and use a return index of 3.
This should generate category values of "redWidgets" and "blueWidgets" respectively based on the example URLs; so to finalise these could be tidied up with Category Mapping by creating the desired names for each as a new Category Mapping e.g. "Red Widgets" and in the alternatives box on the configuration page enter the value as extracted from the URL e.g. "redWidgets". Don't forget to re-import after creating / modifying category mappings as the transformations are only applied at import time...
Hope this helps!
Cheers,
David.
--
PriceTapestry.com