How to add filter for new items

7 years 2 months ago #4067 by sakattack
Hello again

Is it possible to add something like "new product" in a Select field when there is a new addition in the database?

If the product is already in the database then it doesn't get the "new product" field, regardless if it was updated with new info or not. If, however, on successful import of a datafeed, a product is being added that wasn't there before, then it gets the "new product" field. Am I making sense? Is this possible and how?

Thank you for your time and this excellent component

Please Log in or Create an account to join the conversation.

7 years 2 months ago - 7 years 2 months ago #4068 by bram
During impot a field 'adddate' is populated with the well the date that the item is added for the first time. You can use this field to order items on your website. However it is not possible to check on this value directly during import. You can't tell whether or not a item is new.

However the import script allows to execute a function after a feed is imported, here you can execute a mysql command for example updating your item status as you like:
#goes into feeds.php function feedcron_on_success($feed) { global $db_table; #$q='UPDATe ' .$db_table .' SET Select17="" WHERE feed_id='.(int)$feed; $q='UPDATE ' .$db_table .' SET Select17="OLD" WHERE `adddate` < (CURDATE()- INTERVAL 3 DAY) AND feed_id='.(int)$feed; echo db_query($q); $q='UPDATE ' .$db_table .' SET Select17="NEW" WHERE `adddate` >= (CURDATE()- INTERVAL 3 DAY) AND feed_id='.(int)$feed; echo db_query($q); }

I picked Select17 as your 'new' field and set the interval to 3 days, adjust as you like.

But what is 'new'

The keep track of unique items the import script calculates a hash based on the item fields. Whenever a field changes the hash changes and the imported sees the item as new. For example if a merchant changes the title by just a single character the item is considered new.

However it is easy to redefine the way a hash is calculated and make your 'new' versus 'updated' might get a bit more stable and accurate.

For example for feeds with ean codes. You could put the ean code in for example Select18 and then:
function myimport_cb(&$item) { generic_cb($item); $item['md5']=md5($item['feed'].$item['menu_18']); }

For feeds without ean code you could put the href/clicklink into the Select18 field. Some networks have a relative stable product-id

Feeds are messy, I have a feed with 20-and-more items with the same ean/sku but different colors/sizes and different clicklink. The code above would give me just a single item or 20+ if I use the clicklink. But I want to keep the colors AND not the sizes so my md5 got:
Last edit: 7 years 2 months ago by bram.

Please Log in or Create an account to join the conversation.

Time to create page: 0.166 seconds