• Resolved wortep

    (@wortep)


    Hi there, How can we detect the very first import of a file?

    We have an inventory feed with products (several thousands products). Periodically our suppliers update the file with new products, how can we execute the function on repeat import, to see if any new products appeared.

    We know about ‘wp_all_import_is_post_to_create’ hook, but the problem with it is that it runs on every single import, while we need to execute code only when update happened.

    Thanks in advance.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author WP All Import

    (@wpallimport)

    Hi @wortep

    We know about ‘wp_all_import_is_post_to_create’ hook, but the problem with it is that it runs on every single import, while we need to execute code only when update happened.

    I am not sure if I understand why the wp_all_import_is_post_to_create hook wouldn’t work. It will only run when new products are present in the feed and are about to be created, which would indicate that it’s the first run with a new (updated) file.

    Can you elaborate on why it wouldn’t work and what you need to do? are you trying to detect that the file is different before the import starts?

    Thread Starter wortep

    (@wortep)

    Thanks for your reply @wpallimport !

    We have several vendor files. To fill the site with goods, initially each file is imported once.

    After a while, the vendor file is updated and new products are added.

    We need to identify these new products in the second and subsequent import of goods. We must add new status to new products. Now it turns out that at the first boot all of our products have a novelty.

    How can we determine the first import of goods to a site? So that the status of a novelty is added to new products. Now the new status is added to all goods, including the very first import. The first goods must be imported without a novelty.

    If we import goods the first time, then they are all new and our database of goods on the site consists only of new goods. The first import should be filled with goods no new..

    Thread Starter wortep

    (@wortep)

    @wpallimport ,

    An idea came up to solve this problem. Add a checkbox to each import in the settings.

    page=pmxi-admin-manage

    https://joxi.ru/MAjBbMnUxjydYA

    If checked we we will include the assignment of a new status to the goods that have just been created. If not checked, then we do not apply the new status for the goods.

    How we can add our checkbox for set new product status ?

    Plugin Author WP All Import

    (@wpallimport)

    Hi @wortep

    How can we determine the first import of goods to a site? So that the status of a novelty is added to new products. Now the new status is added to all goods, including the very first import. The first goods must be imported without a novelty.

    I am not sure where you’re storing the new status, but couldn’t you just leave it out when you first create the import? After the first run you can edit the import template and add the new status, then go to the import settings and use the “Choose which data to update” option to disable the field that you’re adding the new status in. This way it’s only imported for new products on subsequent runs.

    If you want to do it all automatically, then you could use the pmxi_saved_post hook: https://github.com/soflyy/wp-all-import-action-reference/blob/master/all-import/pmxi_saved_post.php. Example code:

    function my_saved_post( $post_id, $xml_node, $is_update ) {
    	global $wpdb;
         $import_id = ( isset( $_GET['id'] ) ? $_GET['id'] : ( isset( $_GET['import_id'] ) ? $_GET['import_id'] : 'new' ) );
    	if ( $import = $wpdb->get_row( $wpdb->prepare( "SELECT <code>iteration</code> FROM <code>&quot; . $wpdb->prefix . &quot;pmxi_imports</code> WHERE <code>id</code> = '%d'", $import_id ) ) ) {
    		if ( $import->iteration > 1 && ! $is_update ) {
    			// $post_id is a new post and this is not the first run of the import
    			// add novelty to the post programmatically here
    			// e.g.: update_post_meta( $post_id, '_is_new_product', 'true' );
    		}
    	}
    }
    add_action('pmxi_saved_post', 'my_saved_post', 10, 3);

    How we can add our checkbox for set new product status ?

    Unfortunately there’s no way to add a checkbox in the location your screenshot shows, but you could write an add-on with a radio option in the import template: https://www.wpallimport.com/documentation/addon-dev/overview/.

    Plugin Author WP All Import

    (@wpallimport)

    Hi @wortep

    I’m marking this as resolved since we haven’t heard back. Let me know if you still have questions regarding this issue. Anyone else, please open a new thread.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘detect the very first import of a file’ is closed to new replies.