You are here:  » Importing only specific categories from feed

Support Forum



Importing only specific categories from feed

Submitted by mchinery on Fri, 2007-05-25 16:49 in

Hi,

I am quite new to PT and I wanted to find out if there was a way to only import specific categories from a merchants data feed.

As an example I have a data feed for Comet and my website only relates to some of there product categories. I could use the Drop Record in Filters but out of a category list of a few hundred I only need say 20 categories. That is a lot of individual filters to create!

Is there a way to import only the 20 categories I need and not the hundreds of other I do not need? This would be a great function to have if it is not already in PT and would be very useful for more niche sites that still want to offer products for the larger merchants such as Comet in the example?

I really hope someone can help with this.

Many thanks

Martin

Submitted by support on Sat, 2007-05-26 15:44

Hi Martin,

If a particular site is only going to be valid for certain categories it will be quickest to modify the import record handler to abandon records that are not part of the category list for this site. It's quite easy to do. In includes/admin.php, look for the following code, starting at line 220:

    /* apply category mappings */
    if (isset($admin_importCategoryMappings[$category]))
    {
      $category = $admin_importCategoryMappings[$category];
    }

This will apply category mappings if required (you might need it for some feeds on the site) and then you can add the following code immediately afterwards:

    $valid_categories = array("Category 1","Category 2","Category 3");
    // see if $category is in $valid_categories, return false if not
    if (!isset($valid_categories[$category])) return false;

Simply edit and expand the valid categories list (Category 1, Category 2 etc.) as required...

Hope this helps!
Cheers,
David.

Submitted by mchinery on Thu, 2007-05-31 20:30

Thanks very much for this David.

Submitted by support on Thu, 2007-05-31 21:32

Hello Martin,

My apologies - in the array setup line, the entries need to be given a value for the isset() function to return true. The line would need to look like this:

$valid_categories = array("All in ones"=>1,"All-In-One Printers"=>1,"All-In-Ones"=>1);

That should do the trick. I also notice that these are very similar sounding category names that you are using, so you might still want to use category mapping, which is applied before this check and would convert these variations to a single category name...

Cheers,
David.

Submitted by chrisstaunton on Tue, 2009-01-27 13:08

Hi David,

Similarly to the post above, I'd like to limit the products imported into my db via feeds to those of a few specific categories. Feeds from Comet etc contain thousands of products yet for my niche site I'm only interested in 50 - 100.

I believe your solution above will do what I'm after, however I'd like to alter it to only import products from the categories that I assign in the mapping, rather than having to edit a list manually (I'm likely to forget if I add a new category).
e.g. If I have 6 categories mapped, can I import products that only fall into those 6 categories?

Is it as simple as adding an else statement to the original includes/admin.php code - line 220 - to return false if no mapped category is found?

Thanks for your excellent support.

Chris

Submitted by support on Tue, 2009-01-27 13:11

Hi Chris,

Yes - almost. I take it you mean after the mapping has been applied, in which case, look for the following code beginning at line 222 of includes/admin.php

    /* apply category mappings */
    if (isset($admin_importCategoryMappings[$category]))
    {
      $category = $admin_importCategoryMappings[$category];
    }

...and on the next line, add:

     if (!isset($admin_importCategoryMappings[$category])) return;

Cheers,
David.