Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion includes/ProductSync/ProductValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,8 @@ protected function validate_product_sync_field() {
/**
* This check will run for background jobs like sync all and feeds
*/
$parent_sync = $this->product_parent->get_meta( Products::get_product_sync_meta_key() ) || null;
// Check if product_parent exists before calling get_meta() to prevent "Call to a member function get_meta() on null" error
$parent_sync = $this->product_parent ? $this->product_parent->get_meta( Products::get_product_sync_meta_key() ) : null;

if ( 'yes' === $parent_sync ) {
return;
Expand Down
29 changes: 29 additions & 0 deletions includes/Products/Sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

namespace WooCommerce\Facebook\Products;

use WooCommerce\Facebook\Framework\Logger;

defined( 'ABSPATH' ) || exit;

/**
Expand Down Expand Up @@ -56,6 +58,9 @@ public function add_hooks() {
// stock update actions
add_action( 'woocommerce_product_set_stock', array( $this, 'handle_stock_update' ) );
add_action( 'woocommerce_variation_set_stock', array( $this, 'handle_stock_update' ) );

// product import handling
add_action( 'woocommerce_product_import_inserted_product_object', array( $this, 'handle_product_import_update' ), 10, 2 );
}


Expand Down Expand Up @@ -173,6 +178,30 @@ public function handle_stock_update( \WC_Product $product ) {
}


/**
* Handles product imports from WooCommerce import functionality.
*
* @since 3.5.8
*
* @param \WC_Product $product The product object that was imported
* @param array $data The import data
*/
public function handle_product_import_update( $product, $data ) {

// bail if not connected
if ( ! facebook_for_woocommerce()->get_connection_handler()->is_connected() ) {
return;
}

// Process ALL products (both new and updates) during import
try {
facebook_for_woocommerce()->get_product_sync_validator( $product )->validate();
$this->create_or_update_products( array( $product->get_id() ) );
} catch ( \Exception $e ) {
return;
}
}

/**
* Creates a background job to sync the products in the requests array.
*
Expand Down
Loading