Product_Updater::update( int $product_id )
Summary
Re-import a previously imported product.
Parameters
- $product_id
-
(int) (Required)
Return
(void)
Source
File: src/BigCommerce/Webhooks/Product_Updater.php
public function update( $product_id ) { $connections = new Connections(); $channels = $connections->active(); if ( empty( $channels ) ) { do_action( 'bigcommerce/import/error', __( 'No channels connected. Product import canceled.', 'bigcommerce' ) ); return; } try { /* * Listings should not be updated when saving a product on import. * * Create our own callback instead of __return_false() so that * we don't inadvertently unhook someone else's filter later */ $empty = function () { return false; }; add_filter( 'bigcommerce/channel/listing/should_update', $empty, 10, 0 ); add_filter( 'bigcommerce/channel/listing/should_delete', $empty, 10, 0 ); $product = $this->catalog->getProductById( $product_id, [ 'include' => [ 'variants', 'custom_fields', 'images', 'videos', 'bulk_pricing_rules', 'options', 'modifiers' ], ] )->getData(); foreach ( $channels as $channel ) { $this->update_for_channel( $product, $channel ); } } catch ( ApiException $e ) { do_action( 'bigcommerce/import/error', $e->getMessage(), [ 'response' => $e->getResponseBody(), 'headers' => $e->getResponseHeaders(), ] ); do_action( 'bigcommerce/log', Error_Log::DEBUG, $e->getTraceAsString(), [] ); } finally { // unhook the filters we added at the start remove_filter( 'bigcommerce/channel/listing/should_update', $empty, 10 ); remove_filter( 'bigcommerce/channel/listing/should_delete', $empty, 10 ); } }