Listing_Fetcher::run()
Summary
No summary available.Source
File: src/BigCommerce/Import/Processors/Listing_Fetcher.php
public function run() { $status = new Status(); $status->set_status( Status::FETCHING_LISTINGS . '-' . $this->channel_term->term_id ); $channel_id = get_term_meta( $this->channel_term->term_id, Channel::CHANNEL_ID, true ); if ( empty( $channel_id ) ) { do_action( 'bigcommerce/import/error', __( 'Channel ID is not set. Product import canceled.', 'bigcommerce' ) ); return; } $modified_product_ids = []; $import_type = get_option( Import_Type::IMPORT_TYPE ); if ( $import_type === Import_Type::IMPORT_TYPE_PARTIAL ) { /** * Filters modified product ids. * * @param array $modified_product_ids Product ids. */ $modified_product_ids = apply_filters( 'bigcommerce_modified_product_ids', [] ); if ( empty( $modified_product_ids ) ) { $status->set_status( Status::FETCHED_LISTINGS . '-' . $this->channel_term->term_id ); $this->clear_state(); $this->update_option( self::PRODUCT_LISTING_MAP, [], false ); return; } } $id_map = $this->get_option( self::PRODUCT_LISTING_MAP, [] ) ?: []; $next = $this->get_next(); do_action( 'bigcommerce/log', Error_Log::DEBUG, __( 'Retrieving listings', 'bigcommerce' ), [ 'limit' => $this->limit, 'after' => $next ?: null, ] ); try { $response = $this->channels->listChannelListings( $channel_id, [ 'product_id:in' => $modified_product_ids, 'limit' => $this->limit, 'after' => $next ?: null, ] ); } 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(), [] ); return; } foreach ( $response->getData() as $listing ) { if ( $listing->getState() === 'deleted' ) { continue; } $data = ObjectSerializer::sanitizeForSerialization( $listing ); $id_map[ (int) $listing->getProductId() ][ $this->channel_term->term_id ] = wp_json_encode( $data ); } $this->update_option( self::PRODUCT_LISTING_MAP, $id_map, false ); $next = $this->extract_next_from_response( $response ); if ( $next ) { do_action( 'bigcommerce/log', Error_Log::DEBUG, __( 'Ready for next page of listings', 'bigcommerce' ), [ 'next' => $next, ] ); $this->set_next( $next ); } else { $status->set_status( Status::FETCHED_LISTINGS . '-' . $this->channel_term->term_id ); $this->clear_state(); } }