normal How to add filter for new items

6 years 1 day ago #4067 by sakattack
How to add filter for new items was created 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


  • Posts: 42
  • Thank you received: 0

  • Gender: Unknown
  • Birthdate: Unknown
  • Please Log in or Create an account to join the conversation.

    5 years 11 months ago - 5 years 11 months ago #4068 by bram
    Replied by bram on topic How to add filter for new items
    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:
    item['md5']=md5($item['feed'].$item['menu_18'].item['menu_color']);


  • Posts: 1421
  • Thank you received: 234

  • Gender: Unknown
  • Birthdate: Unknown
  • Last edit: 5 years 11 months ago by bram.

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

    Time to create page: 0.117 seconds