Plugin Directory

Changeset 2887672


Ignore:
Timestamp:
03/27/2023 02:41:16 PM (3 years ago)
Author:
bigcommerce
Message:

Update to version 5.0.2 from GitHub

Location:
bigcommerce
Files:
50 edited
1 copied

Legend:

Unmodified
Added
Removed
  • bigcommerce/tags/5.0.2/CHANGELOG.md

    r2866539 r2887672  
    11# Changelog
     2
     3## [5.0.2]
     4
     5### Added
     6- Add ability to use original image proportion on product single page. Go to Apperance → Bigcommerce → Product Single and change image size to original.
     7
     8### Changed
     9- Show variant SKU if product SKU is not added or missing
     10
     11### Fixed
     12- Prevent import fail on Analytics Settings retrieval due to outdated API use
     13- Fix search issue with product widget block while using fast(headless) import. Allow searching by SKU, name
    214
    315## [5.0.1]
     
    18781890
    18791891
     1892[5.0.2]: https://github.com/bigcommerce/bigcommerce-for-wordpress/compare/5.0.1...5.0.2
    18801893[5.0.1]: https://github.com/bigcommerce/bigcommerce-for-wordpress/compare/5.0.0...5.0.1
    18811894[5.0.0]: https://github.com/bigcommerce/bigcommerce-for-wordpress/compare/4.37.0...5.0.0
  • bigcommerce/tags/5.0.2/bigcommerce.php

    r2866539 r2887672  
    44Description:  Scale your ecommerce business with WordPress on the front-end and BigCommerce on the back end. Free up server resources from things like catalog management, processing payments, and managing fulfillment logistics.
    55Author:       BigCommerce
    6 Version:      5.0.1
     6Version:      5.0.2
    77Author URI:   https://www.bigcommerce.com/wordpress
    88Requires PHP: 7.4.0
  • bigcommerce/tags/5.0.2/build-timestamp.php

    r2866539 r2887672  
    11<?php
    2 define('BIGCOMMERCE_ASSETS_BUILD_TIMESTAMP', '4.11.02.16.2023');
     2define('BIGCOMMERCE_ASSETS_BUILD_TIMESTAMP', '3.41.03.24.2023');
  • bigcommerce/tags/5.0.2/readme.txt

    r2866539 r2887672  
    44Requires at least: 5.2
    55Tested up to: 6.0.3
    6 Stable tag: 5.0.1
     6Stable tag: 5.0.2
    77Requires PHP: 7.4.0
    88License: GPLv2 or later
  • bigcommerce/tags/5.0.2/src/BigCommerce/Api/Store_Api.php

    r2626896 r2887672  
    102102        try {
    103103            $settings = $this->getCollection( '/settings/analytics' );
     104
     105            if ( empty( $settings ) ) {
     106                return [];
     107            }
    104108            $settings = array_map( function ( Resource $resource ) {
    105109                return get_object_vars( $resource->getUpdateFields() );
    106110            }, $settings );
    107         } catch ( \Exception $e ) {
     111        } catch ( \Throwable $e ) {
    108112            $settings = [];
    109113        }
  • bigcommerce/tags/5.0.2/src/BigCommerce/Container/Import.php

    r2865940 r2887672  
    235235
    236236        $container[ self::STORE ] = function ( Container $container ) {
    237             return new Processors\Store_Settings( $container[ Api::FACTORY ]->store(), $container[ self::CUSTOMER_DEFAULT_GROUP ], $container[ self::MSF_STOREFRONT_PROCESSOR ] );
     237            return new Processors\Store_Settings( $container[ Api::FACTORY ]->store(), $container[ self::CUSTOMER_DEFAULT_GROUP ], $container[ self::MSF_STOREFRONT_PROCESSOR ], $container[ Api::FACTORY ]->storefront_settings() );
    238238        };
    239239
  • bigcommerce/tags/5.0.2/src/BigCommerce/Container/Settings.php

    r2742415 r2887672  
    441441    private function analytics( Container $container ) {
    442442        $container[ self::ANALYTICS_SECTION ] = function ( Container $container ) {
    443             return new Analytics_Settings( $container[ Api::FACTORY ]->store() );
     443            return new Analytics_Settings( $container[ Api::FACTORY ]->store(), $container[ Api::FACTORY ]->storefront_settings() );
    444444        };
    445445
  • bigcommerce/tags/5.0.2/src/BigCommerce/Customizer/Sections/Product_Single.php

    r2826745 r2887672  
    2222    const SIZE_DEFAULT        = 'default';
    2323    const SIZE_LARGE          = 'large';
     24    const SIZE_ORIGINAL       = 'original';
    2425    const SIZE_CDN_STD        = 'standard';
    2526    const SIZE_CDN_THUMB      = 'thumbnail';
     
    9697            'label'       => __( 'Image Gallery Size', 'bigcommerce' ),
    9798            'choices'     => [
    98                 self::SIZE_DEFAULT => __( 'Default', 'bigcommerce' ),
    99                 self::SIZE_LARGE   => __( 'Large', 'bigcommerce' ),
     99                self::SIZE_DEFAULT  => __( 'Default', 'bigcommerce' ),
     100                self::SIZE_LARGE    => __( 'Large', 'bigcommerce' ),
     101                self::SIZE_ORIGINAL => __( 'Original', 'bigcommerce' ),
    100102            ],
    101103        ] );
  • bigcommerce/tags/5.0.2/src/BigCommerce/Editor/Editor_Dialog_Template.php

    r2108438 r2887672  
    66use BigCommerce\Customizer\Sections\Product_Archive;
    77use BigCommerce\Exceptions\Channel_Not_Found_Exception;
     8use BigCommerce\Import\Import_Type;
    89use BigCommerce\Rest\Products_Controller;
    910use BigCommerce\Rest\Shortcode_Controller;
     
    105106        return $this->render_template( 'query-builder.php', [
    106107            'featured'   => $featured,
    107             'sale'       => $sale,
     108            'sale'       => Import_Type::is_traditional_import() && $sale,
    108109            'brands'     => $brand_choices,
    109110            'categories' => $category_choices,
  • bigcommerce/tags/5.0.2/src/BigCommerce/Import/Processors/Store_Settings.php

    r2865940 r2887672  
    77use Bigcommerce\Api\Client;
    88use BigCommerce\Api\Store_Api;
     9use BigCommerce\Api\v3\Api\SettingsApi;
    910use BigCommerce\Api\v3\ApiException;
    1011use BigCommerce\Import\Runner\Status;
     
    1213use BigCommerce\Post_Types\Product\Product;
    1314use BigCommerce\Settings;
     15use BigCommerce\Taxonomies\Channel\Channel;
     16use BigCommerce\Taxonomies\Channel\Connections;
    1417
    1518class Store_Settings implements Import_Processor {
     
    4043    private $storefront_processor;
    4144
    42     public function __construct( Store_Api $store_api, Default_Customer_Group $default_customer_group, Storefront_Processor $storefront_processor ) {
     45    /**
     46     * @var \BigCommerce\Api\v3\Api\SettingsApi
     47     */
     48    private $api_v3;
     49
     50    public function __construct( Store_Api $store_api, Default_Customer_Group $default_customer_group, Storefront_Processor $storefront_processor, SettingsApi $api ) {
    4351        $this->store_api              = $store_api;
     52        $this->api_v3                 = $api;
    4453        $this->default_customer_group = $default_customer_group;
    4554        $this->storefront_processor   = $storefront_processor;
     
    7685
    7786            if ( get_option( Settings\Sections\Analytics::SYNC_ANALYTICS, 1 ) ) {
    78                 $analytics                                                 = $this->store_api->get_analytics_settings();
    79                 $settings[ Settings\Sections\Analytics::FACEBOOK_PIXEL ]   = $this->extract_facebook_pixel_id( $analytics );
    80                 $settings[ Settings\Sections\Analytics::GOOGLE_ANALYTICS ] = $this->extract_google_analytics_id( $analytics );
     87                $connections  = new Connections();
     88                $channel      = $connections->current();
     89                $analytics    = $this->api_v3->getStoreAnalyticsSettings( (int) get_term_meta( $channel->term_id, Channel::CHANNEL_ID, true ));
     90
     91                if ( ! empty( $analytics->data ) ) {
     92                    $analytics                                                  = json_decode( json_encode( $analytics->data ), true );
     93                    $settings[ Settings\Sections\Analytics::FACEBOOK_PIXEL ]   = $this->extract_facebook_pixel_id( $analytics );
     94                    $settings[ Settings\Sections\Analytics::GOOGLE_ANALYTICS ] = $this->extract_google_analytics_id( $analytics );
     95                }
     96
    8197            }
    8298
  • bigcommerce/tags/5.0.2/src/BigCommerce/Import/Task_Manager.php

    r2860929 r2887672  
    101101            do_action( 'bigcommerce/log', Error_Log::NOTICE, __( 'No handler found for current import state', 'bigcommerce' ), [
    102102                'state'     => $state,
     103                'import'    => Import_Type::is_traditional_import() ? 'full' : 'headless',
    103104            ] );
    104105            do_action( 'bigcommerce/log', Error_Log::DEBUG, $e->getTraceAsString(), [] );
  • bigcommerce/tags/5.0.2/src/BigCommerce/Plugin.php

    r2866539 r2887672  
    55
    66class Plugin {
    7     const VERSION = '5.0.1';
     7    const VERSION = '5.0.2';
    88
    99    protected static $_instance;
  • bigcommerce/tags/5.0.2/src/BigCommerce/Rest/Products_Controller.php

    r2742415 r2887672  
    7070
    7171    protected function get_items_headless( $request ) {
    72         $container = bigcommerce()->container();
    73 
    74         if ( ! empty( $request['slug'] ) ) {
    75             return $this->get_items_graphql( $container, $request );
     72        $container    = bigcommerce()->container();
     73        $request_data = $request->get_params();
     74
     75        if ( ! empty( $request_data['slug'] ) ) {
     76            return $this->get_items_graphql( $container, $request_data );
    7677        }
    7778
     
    8182        try {
    8283            $params = [
    83                     'page'    => $request['page'],
    84                     'limit'   => $request['per_page'],
    85                     'include' => [ 'variants', 'custom_fields', 'images', 'bulk_pricing_rules', 'options', 'modifiers' ],
     84                'page'    => $request_data['page'],
     85                'limit'   => $request_data['per_page'],
     86                'include' => [ 'variants', 'custom_fields', 'images', 'bulk_pricing_rules', 'options', 'modifiers' ],
    8687            ];
    8788
    88             if ( ! empty( $request['bigcommerce_brand'] ) ) {
    89                 $params['brand_id'] = $request['bigcommerce_brand'];
    90             }
    91 
    92             if ( ! empty( $request['bigcommerce_category'] ) ) {
    93                 $params['categories:in'] = $request['bigcommerce_category'];
    94             }
    95 
    96             if ( ! empty( $request['bcid'] ) ) {
    97                 $params['id'] = $request['bcid'];
     89            if ( ! empty( $request_data['bigcommerce_brand'] ) ) {
     90                $params['brand_id'] = $this->get_term_bc_id( $request_data['bigcommerce_brand'] );
     91            }
     92
     93            if ( ! empty( $request_data['bigcommerce_flag'] ) )  {
     94                $term_ids = $request_data['bigcommerce_flag'];
     95
     96
     97                foreach ( $term_ids as $id ) {
     98                    $flag = get_term( $id, Flag::NAME );
     99
     100                    if ( empty( $flag ) || is_wp_error( $flag ) ) {
     101                        continue;
     102                    }
     103
     104                    if ( $flag->name === Flag::FEATURED ) {
     105                        $params['is_featured'] = 1;
     106                    }
     107                }
     108
     109            }
     110
     111            if ( ! empty( $request_data['bigcommerce_category'] ) ) {
     112                $params['categories:in'] = $this->get_term_bc_id( $request_data['bigcommerce_category'] );
     113            }
     114
     115            if ( ! empty( $request_data['bcid'] ) ) {
     116                $params['id'] = $request_data['bcid'];
     117            }
     118
     119            if ( ! empty( $request_data['search'] ) ) {
     120                $params['keyword'] = $request_data['search'];
    98121            }
    99122
    100123            $response = $catalog->getProducts( $params );
    101124
    102             return $this->parse_result( $response, $client );
     125            $result = $this->parse_result( $response, $client, false );
     126            if ( empty( $result ) ) {
     127                return rest_ensure_response( [] );
     128            }
     129
     130            return $this->convert_to_wp_response( $request, $result );
    103131        } catch ( ApiException $e ) {
    104             do_action( 'bigcommerce/log', Error_Log::DEBUG, $e->getTraceAsString(), [ 'request' => $request ], 'rest' );
     132            do_action( 'bigcommerce/log', Error_Log::DEBUG, $e->getTraceAsString(), [ 'request' => $request_data ], 'rest' );
    105133
    106134            $error = new \WP_Error( 'api_error', sprintf(
     
    111139            return $error;
    112140        }
     141    }
     142
     143    private function convert_to_wp_response( $request,  $result ) {
     144        $mapper = new Query_Mapper();
     145        $args   = $mapper->map_rest_args_to_query( $request->get_params() );
     146
     147        // We don't have required data in WP db. Instead, we will use result from remote
     148        if ( ! empty( $args['s'] ) ) {
     149            unset( $args['s'] );
     150        }
     151        $args['bigcommerce_id__in'] = [];
     152
     153        array_walk( $result, function ( $item ) use ( &$args ) {
     154            if ( empty( $item ) ) {
     155                return;
     156            }
     157
     158            $args['bigcommerce_id__in'][] = $item->id;
     159        } );
     160
     161        $args['post_type']      = Product::NAME;
     162        $args['post_status']    = 'publish';
     163        $args['posts_per_page'] = 12;
     164        if ( ! empty( $args['bigcommerce_id__in'] ) ) {
     165            $args['posts_per_page'] = - 1;
     166        }
     167
     168        $posts_query  = new \WP_Query();
     169        $query_result = $posts_query->query( $args );
     170        $posts        = [];
     171
     172        foreach ( $query_result as $post_id ) {
     173            $bcid = get_post_meta( $post_id, Product::BIGCOMMERCE_ID, true );
     174            $data = $this->prepare_item_for_response( get_post( $post_id ), $request );
     175            // ensure that we only have one result per BCID, no matter how many channels it's in
     176            $posts[ $bcid ] = $this->prepare_response_for_collection( $data );
     177        }
     178
     179        return $this->retrieve_rest_response( $posts, $request, $args, $posts_query, null, true );
     180    }
     181
     182    /**
     183     * @param      $posts
     184     * @param      $request
     185     * @param      $query_args
     186     * @param      $posts_query
     187     * @param null $channel_filter
     188     * @param bool $always_fetch
     189     *
     190     * @return \WP_Error|\WP_HTTP_Response|\WP_REST_Response
     191     */
     192    private function retrieve_rest_response( $posts, $request, $query_args, $posts_query, $channel_filter = null, $always_fetch = false ) {
     193        $page        = (int) $query_args['paged'];
     194        $total_posts = $posts_query->found_posts;
     195
     196        if ( $total_posts < 1 ) {
     197            // Out-of-bounds, run the query again without LIMIT for total count.
     198            unset( $query_args['paged'] );
     199
     200            $count_query = new \WP_Query();
     201            $count_query->query( $query_args );
     202            $total_posts = $count_query->found_posts;
     203        }
     204
     205        if ( $channel_filter ) {
     206            remove_action( 'pre_get_posts', $channel_filter, 9 );
     207        }
     208
     209        if ( $posts_query->query_vars['posts_per_page'] === - 1 ) {
     210            $max_pages = 1;
     211        } else {
     212            $max_pages = ceil( $total_posts / (int) $posts_query->query_vars['posts_per_page'] );
     213        }
     214
     215        if ( $page > $max_pages && $total_posts > 0 && ! $always_fetch ) {
     216            return new \WP_Error( 'rest_post_invalid_page_number', __( 'The page number requested is larger than the number of pages available.', 'bigcommerce' ), [ 'status' => 400 ] );
     217        }
     218
     219        $response = rest_ensure_response( array_values( $posts ) );
     220
     221        $response->header( 'X-WP-Total', (int) $total_posts );
     222        $response->header( 'X-WP-TotalPages', (int) $max_pages );
     223
     224        $request_params = $request->get_query_params();
     225        $base           = add_query_arg( $request_params, rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ) );
     226
     227        if ( $page > 1 ) {
     228            $prev_page = $page - 1;
     229
     230            if ( $prev_page > $max_pages ) {
     231                $prev_page = $max_pages;
     232            }
     233
     234            $prev_link = add_query_arg( 'page', $prev_page, $base );
     235            $response->link_header( 'prev', $prev_link );
     236        }
     237        if ( $max_pages > $page || $always_fetch ) {
     238            $next_page = $page + 1;
     239            $next_link = add_query_arg( 'page', $next_page, $base );
     240
     241            $response->link_header( 'next', $next_link );
     242        }
     243
     244        return $response;
    113245    }
    114246
     
    137269
    138270        if ( ! Import_Type::is_traditional_import() ) {
    139             return $this->get_items_headless( $request_data );
     271            return $this->get_items_headless( $request );
    140272        }
    141273        $mapper = new Query_Mapper();
     
    171303            $posts[ $bcid ] = $this->prepare_response_for_collection( $data );
    172304        }
    173 
    174         $page        = (int) $query_args['paged'];
    175         $total_posts = $posts_query->found_posts;
    176 
    177         if ( $total_posts < 1 ) {
    178             // Out-of-bounds, run the query again without LIMIT for total count.
    179             unset( $query_args['paged'] );
    180 
    181             $count_query = new \WP_Query();
    182             $count_query->query( $query_args );
    183             $total_posts = $count_query->found_posts;
    184         }
    185 
    186         remove_action( 'pre_get_posts', $channel_filter, 9 );
    187 
    188         if ( $posts_query->query_vars['posts_per_page'] === - 1 ) {
    189             $max_pages = 1;
    190         } else {
    191             $max_pages = ceil( $total_posts / (int) $posts_query->query_vars['posts_per_page'] );
    192         }
    193 
    194         if ( $page > $max_pages && $total_posts > 0 ) {
    195             return new \WP_Error( 'rest_post_invalid_page_number', __( 'The page number requested is larger than the number of pages available.', 'bigcommerce' ), [ 'status' => 400 ] );
    196         }
    197 
    198         $response = rest_ensure_response( array_values( $posts ) );
    199 
    200         $response->header( 'X-WP-Total', (int) $total_posts );
    201         $response->header( 'X-WP-TotalPages', (int) $max_pages );
    202 
    203         $request_params = $request->get_query_params();
    204         $base           = add_query_arg( $request_params, rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ) );
    205 
    206         if ( $page > 1 ) {
    207             $prev_page = $page - 1;
    208 
    209             if ( $prev_page > $max_pages ) {
    210                 $prev_page = $max_pages;
    211             }
    212 
    213             $prev_link = add_query_arg( 'page', $prev_page, $base );
    214             $response->link_header( 'prev', $prev_link );
    215         }
    216         if ( $max_pages > $page ) {
    217             $next_page = $page + 1;
    218             $next_link = add_query_arg( 'page', $next_page, $base );
    219 
    220             $response->link_header( 'next', $next_link );
    221         }
    222 
    223         return $response;
     305        do_action( 'bigcommerce/log', Error_Log::ERROR, __( 'Product debug', 'bigcommerce' ), [
     306            'args'  => $query_args,
     307        ] );
     308
     309        return $this->retrieve_rest_response( $posts, $request, $query_args, $posts_query, $channel_filter );
    224310    }
    225311
     
    720806    }
    721807
     808    private function get_term_bc_id( $data ) {
     809        $bc_ids = [];
     810        foreach ( $data as $id ) {
     811            $bc_id = get_term_meta( $id, 'bigcommerce_id', true );
     812            if ( empty( $bc_id ) ) {
     813                continue;
     814            }
     815
     816            $bc_ids[] = $bc_id;
     817        }
     818
     819        return $bc_ids;
     820    }
     821
    722822}
  • bigcommerce/tags/5.0.2/src/BigCommerce/Rest/Rest_Controller.php

    r2742415 r2887672  
    3232    }
    3333
    34     protected function parse_result( $response, $client ) {
     34    protected function parse_result( $response, $client, $rest_response = true ) {
    3535        $result['data'] = json_decode( '[' . $client->getSerializer()->serializeCollection( $response->getData(), 'multi' ) . ']' );
    3636        $result['meta'] = json_decode( '[' . $response->getMeta()->__toString() . ']' );
     
    4040        }
    4141
     42        if ( ! $rest_response ) {
     43            return $result['data'];
     44        }
     45
    4246        return rest_ensure_response( $result );
    4347    }
  • bigcommerce/tags/5.0.2/src/BigCommerce/Settings/Import_Status.php

    r2742415 r2887672  
    137137        }
    138138
    139         $current_task = $this->get_current_task( $current['status'] );
     139        try {
     140            $current_task = $this->get_current_task( $current['status'] );
     141        } catch ( \Throwable $exception ) {
     142            $current_task = null;
     143            $import_stuck = true;
     144        }
     145
     146        if ( isset( $import_stuck ) ) {
     147            $response_message = esc_attr__( 'Import has been stuck. Please abort current import and try again. Enable plugin logs and check any potential issues there', 'bigcommerce' );
     148            return [
     149                'message'  => $response_message,
     150                'status'   => $current[ 'status' ],
     151                'previous' => Status::FAILED,
     152                'products' => [
     153                    'total'     => 0,
     154                    'completed' => 0,
     155                    'status'    => $response_message,
     156                ],
     157                'aborted'  => true,
     158            ];
     159        }
     160
    140161
    141162        $total     = (int) get_option( self::IMPORT_TOTAL_PRODUCTS, 0 );
     
    230251                'state' => $state,
    231252            ] );
    232             do_action( 'bigcommerce/log', Error_Log::DEBUG, $e->getTraceAsString(), [] );
     253            do_action( 'bigcommerce/log', Error_Log::DEBUG, __( 'Could not process the task', 'bigcommerce' ), [
     254                'code'    => $e->getCode(),
     255                'message' => $e->getMessage(),
     256                'trace'   => $e->getTraceAsString(),
     257            ] );
    233258
    234259            return null;
  • bigcommerce/tags/5.0.2/src/BigCommerce/Settings/Sections/Analytics.php

    r2722893 r2887672  
    66
    77use BigCommerce\Api\Store_Api;
     8use BigCommerce\Api\v3\Api\SettingsApi;
    89use BigCommerce\Settings\Screens\Settings_Screen;
     10use BigCommerce\Taxonomies\Channel\Channel;
     11use BigCommerce\Taxonomies\Channel\Connections;
    912
    1013class Analytics extends Settings_Section {
     
    2629    private $api;
    2730
    28     public function __construct( Store_Api $api ) {
    29         $this->api = $api;
     31    /**
     32     * @var SettingsApi
     33     */
     34    private $api_v3;
     35
     36    public function __construct( Store_Api $api, SettingsApi $api_v3 ) {
     37        $this->api    = $api;
     38        $this->api_v3 = $api_v3;
    3039    }
    3140
     
    149158            return;
    150159        }
    151         $settings = $this->api->get_analytics_settings();
     160        $connections = new Connections();
     161        $channel     = $connections->current();
     162        $settings    = $this->api_v3->getStoreAnalyticsSettings( (int) get_term_meta( $channel->term_id, Channel::CHANNEL_ID, true ) );
     163
     164        if ( empty( $settings ) || empty( $settings->data ) ) {
     165            return;
     166        }
     167
     168        $settings = json_decode( json_encode( $settings->data ), true );
     169
    152170        foreach ( $settings as &$account ) {
    153171            if ( $account['name'] == self::FACEBOOK_PIXEL_NAME ) {
     
    173191            return;
    174192        }
    175         $settings = $this->api->get_analytics_settings();
     193        $connections = new Connections();
     194        $channel     = $connections->current();
     195        $settings    = $this->api_v3->getStoreAnalyticsSettings( (int) get_term_meta( $channel->term_id, Channel::CHANNEL_ID, true ) );
     196
     197        if ( empty( $settings ) || empty( $settings->data ) ) {
     198            return;
     199        }
     200
     201        $settings = json_decode( json_encode( $settings->data ), true );
     202
    176203        foreach ( $settings as &$account ) {
    177204            if ( $account['name'] == self::GOOGLE_ANALYTICS_NAME ) {
  • bigcommerce/tags/5.0.2/src/BigCommerce/Templates/Product_Gallery.php

    r2742415 r2887672  
    4343                $size = Image_Sizes::BC_EXTRA_MEDIUM;
    4444                break;
     45            case Customizer::SIZE_ORIGINAL:
     46                $size = Image_Sizes::BC_CATEGORY_IMAGE;
     47                break;
    4548            case Customizer::SIZE_DEFAULT:
    4649            default:
     
    6265            case Customizer::SIZE_LARGE:
    6366                $size = Image_Sizes::BC_THUMB_LARGE;
     67                break;
     68            case Customizer::SIZE_ORIGINAL:
     69                $size = 'full';
    6470                break;
    6571            case Customizer::SIZE_DEFAULT:
  • bigcommerce/tags/5.0.2/src/BigCommerce/Templates/Product_Options.php

    r2785458 r2887672  
    236236                $size = Image_Sizes::BC_EXTRA_MEDIUM;
    237237                break;
     238            case Customizer::SIZE_ORIGINAL:
     239                $size = 'full';
     240                break;
    238241            case Customizer::SIZE_DEFAULT:
    239242            default:
  • bigcommerce/tags/5.0.2/src/BigCommerce/Templates/Product_Sku.php

    r2141486 r2887672  
    2727        return [
    2828            self::PRODUCT => $product,
    29             self::SKU     => $product->sku(),
     29            self::SKU     => $this->get_sku( $product ),
    3030        ];
    3131    }
     32
     33    /**
     34     * @param \BigCommerce\Post_Types\Product\Product $product
     35     *
     36     * @return string
     37     */
     38    private function get_sku( Product $product ) {
     39        $sku = $product->sku();
     40
     41        if ( ! empty( $sku ) ) {
     42            return $sku;
     43        }
     44
     45        $data = $product->get_source_data();
     46
     47        if ( empty( $data->variants ) ) {
     48            return '';
     49        }
     50
     51        return $data->variants[0]->sku ?? '';
     52    }
    3253}
  • bigcommerce/tags/5.0.2/templates/admin/query-builder.php

    r2342514 r2887672  
    1212 */
    1313
     14use BigCommerce\Import\Import_Type;
    1415use BigCommerce\Taxonomies\Brand\Brand;
    1516use BigCommerce\Taxonomies\Channel\Channel;
     
    3435
    3536    <ul class="bc-shortcode-ui__query-builder-list" data-js="bcqb-list">
    36         <li class="bc-shortcode-ui__query-builder-list-item">
    37             <a
    38                 href="#"
    39                 class="bc-shortcode-ui__query-builder-anchor"
    40                 data-key="recent"
    41                 data-value="1"
    42                 data-slug="<?php esc_html_e( 'recent', 'bigcommerce' ); ?>"
    43                 data-depth="0"
    44             ><?php esc_html_e( 'Recent', 'bigcommerce' ); ?></a>
    45         </li>
     37        <?php if ( Import_Type::is_traditional_import() ) : ?>
     38            <li class="bc-shortcode-ui__query-builder-list-item">
     39                <a
     40                    href="#"
     41                    class="bc-shortcode-ui__query-builder-anchor"
     42                    data-key="recent"
     43                    data-value="1"
     44                    data-slug="<?php esc_html_e( 'recent', 'bigcommerce' ); ?>"
     45                    data-depth="0"
     46                ><?php esc_html_e( 'Recent', 'bigcommerce' ); ?></a>
     47            </li>
     48        <?php endif; ?>
    4649        <?php if ( $featured ) { ?>
    4750            <li class="bc-shortcode-ui__query-builder-list-item">
  • bigcommerce/tags/5.0.2/vendor/autoload.php

    r2866539 r2887672  
    55require_once __DIR__ . '/composer/autoload_real.php';
    66
    7 return ComposerAutoloaderInit3a8e1eb94f496d635fd89a7cc1cbcd65::getLoader();
     7return ComposerAutoloaderInit9f56a5c2911017136344a43be2570fff::getLoader();
  • bigcommerce/tags/5.0.2/vendor/composer/autoload_real.php

    r2866539 r2887672  
    33// autoload_real.php @generated by Composer
    44
    5 class ComposerAutoloaderInit3a8e1eb94f496d635fd89a7cc1cbcd65
     5class ComposerAutoloaderInit9f56a5c2911017136344a43be2570fff
    66{
    77    private static $loader;
     
    2020        }
    2121
    22         spl_autoload_register(array('ComposerAutoloaderInit3a8e1eb94f496d635fd89a7cc1cbcd65', 'loadClassLoader'), true, true);
     22        spl_autoload_register(array('ComposerAutoloaderInit9f56a5c2911017136344a43be2570fff', 'loadClassLoader'), true, true);
    2323        self::$loader = $loader = new \Composer\Autoload\ClassLoader();
    24         spl_autoload_unregister(array('ComposerAutoloaderInit3a8e1eb94f496d635fd89a7cc1cbcd65', 'loadClassLoader'));
     24        spl_autoload_unregister(array('ComposerAutoloaderInit9f56a5c2911017136344a43be2570fff', 'loadClassLoader'));
    2525
    2626        $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
     
    2828            require_once __DIR__ . '/autoload_static.php';
    2929
    30             call_user_func(\Composer\Autoload\ComposerStaticInit3a8e1eb94f496d635fd89a7cc1cbcd65::getInitializer($loader));
     30            call_user_func(\Composer\Autoload\ComposerStaticInit9f56a5c2911017136344a43be2570fff::getInitializer($loader));
    3131        } else {
    3232            $classMap = require __DIR__ . '/autoload_classmap.php';
     
    4040
    4141        if ($useStaticLoader) {
    42             $includeFiles = Composer\Autoload\ComposerStaticInit3a8e1eb94f496d635fd89a7cc1cbcd65::$files;
     42            $includeFiles = Composer\Autoload\ComposerStaticInit9f56a5c2911017136344a43be2570fff::$files;
    4343        } else {
    4444            $includeFiles = require __DIR__ . '/autoload_files.php';
    4545        }
    4646        foreach ($includeFiles as $fileIdentifier => $file) {
    47             composerRequire3a8e1eb94f496d635fd89a7cc1cbcd65($fileIdentifier, $file);
     47            composerRequire9f56a5c2911017136344a43be2570fff($fileIdentifier, $file);
    4848        }
    4949
     
    5252}
    5353
    54 function composerRequire3a8e1eb94f496d635fd89a7cc1cbcd65($fileIdentifier, $file)
     54function composerRequire9f56a5c2911017136344a43be2570fff($fileIdentifier, $file)
    5555{
    5656    if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
  • bigcommerce/tags/5.0.2/vendor/composer/autoload_static.php

    r2866539 r2887672  
    55namespace Composer\Autoload;
    66
    7 class ComposerStaticInit3a8e1eb94f496d635fd89a7cc1cbcd65
     7class ComposerStaticInit9f56a5c2911017136344a43be2570fff
    88{
    99    public static $files = array (
     
    11851185    {
    11861186        return \Closure::bind(function () use ($loader) {
    1187             $loader->prefixLengthsPsr4 = ComposerStaticInit3a8e1eb94f496d635fd89a7cc1cbcd65::$prefixLengthsPsr4;
    1188             $loader->prefixDirsPsr4 = ComposerStaticInit3a8e1eb94f496d635fd89a7cc1cbcd65::$prefixDirsPsr4;
    1189             $loader->prefixesPsr0 = ComposerStaticInit3a8e1eb94f496d635fd89a7cc1cbcd65::$prefixesPsr0;
    1190             $loader->classMap = ComposerStaticInit3a8e1eb94f496d635fd89a7cc1cbcd65::$classMap;
     1187            $loader->prefixLengthsPsr4 = ComposerStaticInit9f56a5c2911017136344a43be2570fff::$prefixLengthsPsr4;
     1188            $loader->prefixDirsPsr4 = ComposerStaticInit9f56a5c2911017136344a43be2570fff::$prefixDirsPsr4;
     1189            $loader->prefixesPsr0 = ComposerStaticInit9f56a5c2911017136344a43be2570fff::$prefixesPsr0;
     1190            $loader->classMap = ComposerStaticInit9f56a5c2911017136344a43be2570fff::$classMap;
    11911191
    11921192        }, null, ClassLoader::class);
  • bigcommerce/tags/5.0.2/vendor/composer/installed.json

    r2865940 r2887672  
    121121    {
    122122        "name": "moderntribe/bigcommerce-api-php-v3",
    123         "version": "v2.3.3",
    124         "version_normalized": "2.3.3.0",
     123        "version": "v2.3.4",
     124        "version_normalized": "2.3.4.0",
    125125        "source": {
    126126            "type": "git",
    127127            "url": "git@github.com:moderntribe/bigcommerce-api-php-v3.git",
    128             "reference": "860eb3be09c623dc0c8b53f506abed72a882f399"
    129         },
    130         "dist": {
    131             "type": "zip",
    132             "url": "https://api.github.com/repos/moderntribe/bigcommerce-api-php-v3/zipball/860eb3be09c623dc0c8b53f506abed72a882f399",
    133             "reference": "860eb3be09c623dc0c8b53f506abed72a882f399",
     128            "reference": "054f0c7bc188560bdcad24c7ace908def11a5c9e"
     129        },
     130        "dist": {
     131            "type": "zip",
     132            "url": "https://api.github.com/repos/moderntribe/bigcommerce-api-php-v3/zipball/054f0c7bc188560bdcad24c7ace908def11a5c9e",
     133            "reference": "054f0c7bc188560bdcad24c7ace908def11a5c9e",
    134134            "shasum": ""
    135135        },
     
    145145            "squizlabs/php_codesniffer": "~2.6"
    146146        },
    147         "time": "2022-08-17T17:15:47+00:00",
     147        "time": "2023-03-15T21:18:15+00:00",
    148148        "type": "library",
    149149        "installation-source": "dist",
  • bigcommerce/tags/5.0.2/vendor/moderntribe/bigcommerce-api-php-v3/src/Api/SettingsApi.php

    r2865940 r2887672  
    110110        return $response;
    111111    }
     112
     113    public function getStoreAnalyticsSettings( $channel_id = 0 ) {
     114        list( $response ) = $this->getStorefrontHttpInfo( '/settings/analytics', $channel_id );
     115
     116        return $response;
     117    }
    112118
    113119    /**
  • bigcommerce/trunk/CHANGELOG.md

    r2866539 r2887672  
    11# Changelog
     2
     3## [5.0.2]
     4
     5### Added
     6- Add ability to use original image proportion on product single page. Go to Apperance → Bigcommerce → Product Single and change image size to original.
     7
     8### Changed
     9- Show variant SKU if product SKU is not added or missing
     10
     11### Fixed
     12- Prevent import fail on Analytics Settings retrieval due to outdated API use
     13- Fix search issue with product widget block while using fast(headless) import. Allow searching by SKU, name
    214
    315## [5.0.1]
     
    18781890
    18791891
     1892[5.0.2]: https://github.com/bigcommerce/bigcommerce-for-wordpress/compare/5.0.1...5.0.2
    18801893[5.0.1]: https://github.com/bigcommerce/bigcommerce-for-wordpress/compare/5.0.0...5.0.1
    18811894[5.0.0]: https://github.com/bigcommerce/bigcommerce-for-wordpress/compare/4.37.0...5.0.0
  • bigcommerce/trunk/bigcommerce.php

    r2866539 r2887672  
    44Description:  Scale your ecommerce business with WordPress on the front-end and BigCommerce on the back end. Free up server resources from things like catalog management, processing payments, and managing fulfillment logistics.
    55Author:       BigCommerce
    6 Version:      5.0.1
     6Version:      5.0.2
    77Author URI:   https://www.bigcommerce.com/wordpress
    88Requires PHP: 7.4.0
  • bigcommerce/trunk/build-timestamp.php

    r2866539 r2887672  
    11<?php
    2 define('BIGCOMMERCE_ASSETS_BUILD_TIMESTAMP', '4.11.02.16.2023');
     2define('BIGCOMMERCE_ASSETS_BUILD_TIMESTAMP', '3.41.03.24.2023');
  • bigcommerce/trunk/readme.txt

    r2866539 r2887672  
    44Requires at least: 5.2
    55Tested up to: 6.0.3
    6 Stable tag: 5.0.1
     6Stable tag: 5.0.2
    77Requires PHP: 7.4.0
    88License: GPLv2 or later
  • bigcommerce/trunk/src/BigCommerce/Api/Store_Api.php

    r2626896 r2887672  
    102102        try {
    103103            $settings = $this->getCollection( '/settings/analytics' );
     104
     105            if ( empty( $settings ) ) {
     106                return [];
     107            }
    104108            $settings = array_map( function ( Resource $resource ) {
    105109                return get_object_vars( $resource->getUpdateFields() );
    106110            }, $settings );
    107         } catch ( \Exception $e ) {
     111        } catch ( \Throwable $e ) {
    108112            $settings = [];
    109113        }
  • bigcommerce/trunk/src/BigCommerce/Container/Import.php

    r2865940 r2887672  
    235235
    236236        $container[ self::STORE ] = function ( Container $container ) {
    237             return new Processors\Store_Settings( $container[ Api::FACTORY ]->store(), $container[ self::CUSTOMER_DEFAULT_GROUP ], $container[ self::MSF_STOREFRONT_PROCESSOR ] );
     237            return new Processors\Store_Settings( $container[ Api::FACTORY ]->store(), $container[ self::CUSTOMER_DEFAULT_GROUP ], $container[ self::MSF_STOREFRONT_PROCESSOR ], $container[ Api::FACTORY ]->storefront_settings() );
    238238        };
    239239
  • bigcommerce/trunk/src/BigCommerce/Container/Settings.php

    r2742415 r2887672  
    441441    private function analytics( Container $container ) {
    442442        $container[ self::ANALYTICS_SECTION ] = function ( Container $container ) {
    443             return new Analytics_Settings( $container[ Api::FACTORY ]->store() );
     443            return new Analytics_Settings( $container[ Api::FACTORY ]->store(), $container[ Api::FACTORY ]->storefront_settings() );
    444444        };
    445445
  • bigcommerce/trunk/src/BigCommerce/Customizer/Sections/Product_Single.php

    r2826745 r2887672  
    2222    const SIZE_DEFAULT        = 'default';
    2323    const SIZE_LARGE          = 'large';
     24    const SIZE_ORIGINAL       = 'original';
    2425    const SIZE_CDN_STD        = 'standard';
    2526    const SIZE_CDN_THUMB      = 'thumbnail';
     
    9697            'label'       => __( 'Image Gallery Size', 'bigcommerce' ),
    9798            'choices'     => [
    98                 self::SIZE_DEFAULT => __( 'Default', 'bigcommerce' ),
    99                 self::SIZE_LARGE   => __( 'Large', 'bigcommerce' ),
     99                self::SIZE_DEFAULT  => __( 'Default', 'bigcommerce' ),
     100                self::SIZE_LARGE    => __( 'Large', 'bigcommerce' ),
     101                self::SIZE_ORIGINAL => __( 'Original', 'bigcommerce' ),
    100102            ],
    101103        ] );
  • bigcommerce/trunk/src/BigCommerce/Editor/Editor_Dialog_Template.php

    r2108438 r2887672  
    66use BigCommerce\Customizer\Sections\Product_Archive;
    77use BigCommerce\Exceptions\Channel_Not_Found_Exception;
     8use BigCommerce\Import\Import_Type;
    89use BigCommerce\Rest\Products_Controller;
    910use BigCommerce\Rest\Shortcode_Controller;
     
    105106        return $this->render_template( 'query-builder.php', [
    106107            'featured'   => $featured,
    107             'sale'       => $sale,
     108            'sale'       => Import_Type::is_traditional_import() && $sale,
    108109            'brands'     => $brand_choices,
    109110            'categories' => $category_choices,
  • bigcommerce/trunk/src/BigCommerce/Import/Processors/Store_Settings.php

    r2865940 r2887672  
    77use Bigcommerce\Api\Client;
    88use BigCommerce\Api\Store_Api;
     9use BigCommerce\Api\v3\Api\SettingsApi;
    910use BigCommerce\Api\v3\ApiException;
    1011use BigCommerce\Import\Runner\Status;
     
    1213use BigCommerce\Post_Types\Product\Product;
    1314use BigCommerce\Settings;
     15use BigCommerce\Taxonomies\Channel\Channel;
     16use BigCommerce\Taxonomies\Channel\Connections;
    1417
    1518class Store_Settings implements Import_Processor {
     
    4043    private $storefront_processor;
    4144
    42     public function __construct( Store_Api $store_api, Default_Customer_Group $default_customer_group, Storefront_Processor $storefront_processor ) {
     45    /**
     46     * @var \BigCommerce\Api\v3\Api\SettingsApi
     47     */
     48    private $api_v3;
     49
     50    public function __construct( Store_Api $store_api, Default_Customer_Group $default_customer_group, Storefront_Processor $storefront_processor, SettingsApi $api ) {
    4351        $this->store_api              = $store_api;
     52        $this->api_v3                 = $api;
    4453        $this->default_customer_group = $default_customer_group;
    4554        $this->storefront_processor   = $storefront_processor;
     
    7685
    7786            if ( get_option( Settings\Sections\Analytics::SYNC_ANALYTICS, 1 ) ) {
    78                 $analytics                                                 = $this->store_api->get_analytics_settings();
    79                 $settings[ Settings\Sections\Analytics::FACEBOOK_PIXEL ]   = $this->extract_facebook_pixel_id( $analytics );
    80                 $settings[ Settings\Sections\Analytics::GOOGLE_ANALYTICS ] = $this->extract_google_analytics_id( $analytics );
     87                $connections  = new Connections();
     88                $channel      = $connections->current();
     89                $analytics    = $this->api_v3->getStoreAnalyticsSettings( (int) get_term_meta( $channel->term_id, Channel::CHANNEL_ID, true ));
     90
     91                if ( ! empty( $analytics->data ) ) {
     92                    $analytics                                                  = json_decode( json_encode( $analytics->data ), true );
     93                    $settings[ Settings\Sections\Analytics::FACEBOOK_PIXEL ]   = $this->extract_facebook_pixel_id( $analytics );
     94                    $settings[ Settings\Sections\Analytics::GOOGLE_ANALYTICS ] = $this->extract_google_analytics_id( $analytics );
     95                }
     96
    8197            }
    8298
  • bigcommerce/trunk/src/BigCommerce/Import/Task_Manager.php

    r2860929 r2887672  
    101101            do_action( 'bigcommerce/log', Error_Log::NOTICE, __( 'No handler found for current import state', 'bigcommerce' ), [
    102102                'state'     => $state,
     103                'import'    => Import_Type::is_traditional_import() ? 'full' : 'headless',
    103104            ] );
    104105            do_action( 'bigcommerce/log', Error_Log::DEBUG, $e->getTraceAsString(), [] );
  • bigcommerce/trunk/src/BigCommerce/Plugin.php

    r2866539 r2887672  
    55
    66class Plugin {
    7     const VERSION = '5.0.1';
     7    const VERSION = '5.0.2';
    88
    99    protected static $_instance;
  • bigcommerce/trunk/src/BigCommerce/Rest/Products_Controller.php

    r2742415 r2887672  
    7070
    7171    protected function get_items_headless( $request ) {
    72         $container = bigcommerce()->container();
    73 
    74         if ( ! empty( $request['slug'] ) ) {
    75             return $this->get_items_graphql( $container, $request );
     72        $container    = bigcommerce()->container();
     73        $request_data = $request->get_params();
     74
     75        if ( ! empty( $request_data['slug'] ) ) {
     76            return $this->get_items_graphql( $container, $request_data );
    7677        }
    7778
     
    8182        try {
    8283            $params = [
    83                     'page'    => $request['page'],
    84                     'limit'   => $request['per_page'],
    85                     'include' => [ 'variants', 'custom_fields', 'images', 'bulk_pricing_rules', 'options', 'modifiers' ],
     84                'page'    => $request_data['page'],
     85                'limit'   => $request_data['per_page'],
     86                'include' => [ 'variants', 'custom_fields', 'images', 'bulk_pricing_rules', 'options', 'modifiers' ],
    8687            ];
    8788
    88             if ( ! empty( $request['bigcommerce_brand'] ) ) {
    89                 $params['brand_id'] = $request['bigcommerce_brand'];
    90             }
    91 
    92             if ( ! empty( $request['bigcommerce_category'] ) ) {
    93                 $params['categories:in'] = $request['bigcommerce_category'];
    94             }
    95 
    96             if ( ! empty( $request['bcid'] ) ) {
    97                 $params['id'] = $request['bcid'];
     89            if ( ! empty( $request_data['bigcommerce_brand'] ) ) {
     90                $params['brand_id'] = $this->get_term_bc_id( $request_data['bigcommerce_brand'] );
     91            }
     92
     93            if ( ! empty( $request_data['bigcommerce_flag'] ) )  {
     94                $term_ids = $request_data['bigcommerce_flag'];
     95
     96
     97                foreach ( $term_ids as $id ) {
     98                    $flag = get_term( $id, Flag::NAME );
     99
     100                    if ( empty( $flag ) || is_wp_error( $flag ) ) {
     101                        continue;
     102                    }
     103
     104                    if ( $flag->name === Flag::FEATURED ) {
     105                        $params['is_featured'] = 1;
     106                    }
     107                }
     108
     109            }
     110
     111            if ( ! empty( $request_data['bigcommerce_category'] ) ) {
     112                $params['categories:in'] = $this->get_term_bc_id( $request_data['bigcommerce_category'] );
     113            }
     114
     115            if ( ! empty( $request_data['bcid'] ) ) {
     116                $params['id'] = $request_data['bcid'];
     117            }
     118
     119            if ( ! empty( $request_data['search'] ) ) {
     120                $params['keyword'] = $request_data['search'];
    98121            }
    99122
    100123            $response = $catalog->getProducts( $params );
    101124
    102             return $this->parse_result( $response, $client );
     125            $result = $this->parse_result( $response, $client, false );
     126            if ( empty( $result ) ) {
     127                return rest_ensure_response( [] );
     128            }
     129
     130            return $this->convert_to_wp_response( $request, $result );
    103131        } catch ( ApiException $e ) {
    104             do_action( 'bigcommerce/log', Error_Log::DEBUG, $e->getTraceAsString(), [ 'request' => $request ], 'rest' );
     132            do_action( 'bigcommerce/log', Error_Log::DEBUG, $e->getTraceAsString(), [ 'request' => $request_data ], 'rest' );
    105133
    106134            $error = new \WP_Error( 'api_error', sprintf(
     
    111139            return $error;
    112140        }
     141    }
     142
     143    private function convert_to_wp_response( $request,  $result ) {
     144        $mapper = new Query_Mapper();
     145        $args   = $mapper->map_rest_args_to_query( $request->get_params() );
     146
     147        // We don't have required data in WP db. Instead, we will use result from remote
     148        if ( ! empty( $args['s'] ) ) {
     149            unset( $args['s'] );
     150        }
     151        $args['bigcommerce_id__in'] = [];
     152
     153        array_walk( $result, function ( $item ) use ( &$args ) {
     154            if ( empty( $item ) ) {
     155                return;
     156            }
     157
     158            $args['bigcommerce_id__in'][] = $item->id;
     159        } );
     160
     161        $args['post_type']      = Product::NAME;
     162        $args['post_status']    = 'publish';
     163        $args['posts_per_page'] = 12;
     164        if ( ! empty( $args['bigcommerce_id__in'] ) ) {
     165            $args['posts_per_page'] = - 1;
     166        }
     167
     168        $posts_query  = new \WP_Query();
     169        $query_result = $posts_query->query( $args );
     170        $posts        = [];
     171
     172        foreach ( $query_result as $post_id ) {
     173            $bcid = get_post_meta( $post_id, Product::BIGCOMMERCE_ID, true );
     174            $data = $this->prepare_item_for_response( get_post( $post_id ), $request );
     175            // ensure that we only have one result per BCID, no matter how many channels it's in
     176            $posts[ $bcid ] = $this->prepare_response_for_collection( $data );
     177        }
     178
     179        return $this->retrieve_rest_response( $posts, $request, $args, $posts_query, null, true );
     180    }
     181
     182    /**
     183     * @param      $posts
     184     * @param      $request
     185     * @param      $query_args
     186     * @param      $posts_query
     187     * @param null $channel_filter
     188     * @param bool $always_fetch
     189     *
     190     * @return \WP_Error|\WP_HTTP_Response|\WP_REST_Response
     191     */
     192    private function retrieve_rest_response( $posts, $request, $query_args, $posts_query, $channel_filter = null, $always_fetch = false ) {
     193        $page        = (int) $query_args['paged'];
     194        $total_posts = $posts_query->found_posts;
     195
     196        if ( $total_posts < 1 ) {
     197            // Out-of-bounds, run the query again without LIMIT for total count.
     198            unset( $query_args['paged'] );
     199
     200            $count_query = new \WP_Query();
     201            $count_query->query( $query_args );
     202            $total_posts = $count_query->found_posts;
     203        }
     204
     205        if ( $channel_filter ) {
     206            remove_action( 'pre_get_posts', $channel_filter, 9 );
     207        }
     208
     209        if ( $posts_query->query_vars['posts_per_page'] === - 1 ) {
     210            $max_pages = 1;
     211        } else {
     212            $max_pages = ceil( $total_posts / (int) $posts_query->query_vars['posts_per_page'] );
     213        }
     214
     215        if ( $page > $max_pages && $total_posts > 0 && ! $always_fetch ) {
     216            return new \WP_Error( 'rest_post_invalid_page_number', __( 'The page number requested is larger than the number of pages available.', 'bigcommerce' ), [ 'status' => 400 ] );
     217        }
     218
     219        $response = rest_ensure_response( array_values( $posts ) );
     220
     221        $response->header( 'X-WP-Total', (int) $total_posts );
     222        $response->header( 'X-WP-TotalPages', (int) $max_pages );
     223
     224        $request_params = $request->get_query_params();
     225        $base           = add_query_arg( $request_params, rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ) );
     226
     227        if ( $page > 1 ) {
     228            $prev_page = $page - 1;
     229
     230            if ( $prev_page > $max_pages ) {
     231                $prev_page = $max_pages;
     232            }
     233
     234            $prev_link = add_query_arg( 'page', $prev_page, $base );
     235            $response->link_header( 'prev', $prev_link );
     236        }
     237        if ( $max_pages > $page || $always_fetch ) {
     238            $next_page = $page + 1;
     239            $next_link = add_query_arg( 'page', $next_page, $base );
     240
     241            $response->link_header( 'next', $next_link );
     242        }
     243
     244        return $response;
    113245    }
    114246
     
    137269
    138270        if ( ! Import_Type::is_traditional_import() ) {
    139             return $this->get_items_headless( $request_data );
     271            return $this->get_items_headless( $request );
    140272        }
    141273        $mapper = new Query_Mapper();
     
    171303            $posts[ $bcid ] = $this->prepare_response_for_collection( $data );
    172304        }
    173 
    174         $page        = (int) $query_args['paged'];
    175         $total_posts = $posts_query->found_posts;
    176 
    177         if ( $total_posts < 1 ) {
    178             // Out-of-bounds, run the query again without LIMIT for total count.
    179             unset( $query_args['paged'] );
    180 
    181             $count_query = new \WP_Query();
    182             $count_query->query( $query_args );
    183             $total_posts = $count_query->found_posts;
    184         }
    185 
    186         remove_action( 'pre_get_posts', $channel_filter, 9 );
    187 
    188         if ( $posts_query->query_vars['posts_per_page'] === - 1 ) {
    189             $max_pages = 1;
    190         } else {
    191             $max_pages = ceil( $total_posts / (int) $posts_query->query_vars['posts_per_page'] );
    192         }
    193 
    194         if ( $page > $max_pages && $total_posts > 0 ) {
    195             return new \WP_Error( 'rest_post_invalid_page_number', __( 'The page number requested is larger than the number of pages available.', 'bigcommerce' ), [ 'status' => 400 ] );
    196         }
    197 
    198         $response = rest_ensure_response( array_values( $posts ) );
    199 
    200         $response->header( 'X-WP-Total', (int) $total_posts );
    201         $response->header( 'X-WP-TotalPages', (int) $max_pages );
    202 
    203         $request_params = $request->get_query_params();
    204         $base           = add_query_arg( $request_params, rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ) );
    205 
    206         if ( $page > 1 ) {
    207             $prev_page = $page - 1;
    208 
    209             if ( $prev_page > $max_pages ) {
    210                 $prev_page = $max_pages;
    211             }
    212 
    213             $prev_link = add_query_arg( 'page', $prev_page, $base );
    214             $response->link_header( 'prev', $prev_link );
    215         }
    216         if ( $max_pages > $page ) {
    217             $next_page = $page + 1;
    218             $next_link = add_query_arg( 'page', $next_page, $base );
    219 
    220             $response->link_header( 'next', $next_link );
    221         }
    222 
    223         return $response;
     305        do_action( 'bigcommerce/log', Error_Log::ERROR, __( 'Product debug', 'bigcommerce' ), [
     306            'args'  => $query_args,
     307        ] );
     308
     309        return $this->retrieve_rest_response( $posts, $request, $query_args, $posts_query, $channel_filter );
    224310    }
    225311
     
    720806    }
    721807
     808    private function get_term_bc_id( $data ) {
     809        $bc_ids = [];
     810        foreach ( $data as $id ) {
     811            $bc_id = get_term_meta( $id, 'bigcommerce_id', true );
     812            if ( empty( $bc_id ) ) {
     813                continue;
     814            }
     815
     816            $bc_ids[] = $bc_id;
     817        }
     818
     819        return $bc_ids;
     820    }
     821
    722822}
  • bigcommerce/trunk/src/BigCommerce/Rest/Rest_Controller.php

    r2742415 r2887672  
    3232    }
    3333
    34     protected function parse_result( $response, $client ) {
     34    protected function parse_result( $response, $client, $rest_response = true ) {
    3535        $result['data'] = json_decode( '[' . $client->getSerializer()->serializeCollection( $response->getData(), 'multi' ) . ']' );
    3636        $result['meta'] = json_decode( '[' . $response->getMeta()->__toString() . ']' );
     
    4040        }
    4141
     42        if ( ! $rest_response ) {
     43            return $result['data'];
     44        }
     45
    4246        return rest_ensure_response( $result );
    4347    }
  • bigcommerce/trunk/src/BigCommerce/Settings/Import_Status.php

    r2742415 r2887672  
    137137        }
    138138
    139         $current_task = $this->get_current_task( $current['status'] );
     139        try {
     140            $current_task = $this->get_current_task( $current['status'] );
     141        } catch ( \Throwable $exception ) {
     142            $current_task = null;
     143            $import_stuck = true;
     144        }
     145
     146        if ( isset( $import_stuck ) ) {
     147            $response_message = esc_attr__( 'Import has been stuck. Please abort current import and try again. Enable plugin logs and check any potential issues there', 'bigcommerce' );
     148            return [
     149                'message'  => $response_message,
     150                'status'   => $current[ 'status' ],
     151                'previous' => Status::FAILED,
     152                'products' => [
     153                    'total'     => 0,
     154                    'completed' => 0,
     155                    'status'    => $response_message,
     156                ],
     157                'aborted'  => true,
     158            ];
     159        }
     160
    140161
    141162        $total     = (int) get_option( self::IMPORT_TOTAL_PRODUCTS, 0 );
     
    230251                'state' => $state,
    231252            ] );
    232             do_action( 'bigcommerce/log', Error_Log::DEBUG, $e->getTraceAsString(), [] );
     253            do_action( 'bigcommerce/log', Error_Log::DEBUG, __( 'Could not process the task', 'bigcommerce' ), [
     254                'code'    => $e->getCode(),
     255                'message' => $e->getMessage(),
     256                'trace'   => $e->getTraceAsString(),
     257            ] );
    233258
    234259            return null;
  • bigcommerce/trunk/src/BigCommerce/Settings/Sections/Analytics.php

    r2722893 r2887672  
    66
    77use BigCommerce\Api\Store_Api;
     8use BigCommerce\Api\v3\Api\SettingsApi;
    89use BigCommerce\Settings\Screens\Settings_Screen;
     10use BigCommerce\Taxonomies\Channel\Channel;
     11use BigCommerce\Taxonomies\Channel\Connections;
    912
    1013class Analytics extends Settings_Section {
     
    2629    private $api;
    2730
    28     public function __construct( Store_Api $api ) {
    29         $this->api = $api;
     31    /**
     32     * @var SettingsApi
     33     */
     34    private $api_v3;
     35
     36    public function __construct( Store_Api $api, SettingsApi $api_v3 ) {
     37        $this->api    = $api;
     38        $this->api_v3 = $api_v3;
    3039    }
    3140
     
    149158            return;
    150159        }
    151         $settings = $this->api->get_analytics_settings();
     160        $connections = new Connections();
     161        $channel     = $connections->current();
     162        $settings    = $this->api_v3->getStoreAnalyticsSettings( (int) get_term_meta( $channel->term_id, Channel::CHANNEL_ID, true ) );
     163
     164        if ( empty( $settings ) || empty( $settings->data ) ) {
     165            return;
     166        }
     167
     168        $settings = json_decode( json_encode( $settings->data ), true );
     169
    152170        foreach ( $settings as &$account ) {
    153171            if ( $account['name'] == self::FACEBOOK_PIXEL_NAME ) {
     
    173191            return;
    174192        }
    175         $settings = $this->api->get_analytics_settings();
     193        $connections = new Connections();
     194        $channel     = $connections->current();
     195        $settings    = $this->api_v3->getStoreAnalyticsSettings( (int) get_term_meta( $channel->term_id, Channel::CHANNEL_ID, true ) );
     196
     197        if ( empty( $settings ) || empty( $settings->data ) ) {
     198            return;
     199        }
     200
     201        $settings = json_decode( json_encode( $settings->data ), true );
     202
    176203        foreach ( $settings as &$account ) {
    177204            if ( $account['name'] == self::GOOGLE_ANALYTICS_NAME ) {
  • bigcommerce/trunk/src/BigCommerce/Templates/Product_Gallery.php

    r2742415 r2887672  
    4343                $size = Image_Sizes::BC_EXTRA_MEDIUM;
    4444                break;
     45            case Customizer::SIZE_ORIGINAL:
     46                $size = Image_Sizes::BC_CATEGORY_IMAGE;
     47                break;
    4548            case Customizer::SIZE_DEFAULT:
    4649            default:
     
    6265            case Customizer::SIZE_LARGE:
    6366                $size = Image_Sizes::BC_THUMB_LARGE;
     67                break;
     68            case Customizer::SIZE_ORIGINAL:
     69                $size = 'full';
    6470                break;
    6571            case Customizer::SIZE_DEFAULT:
  • bigcommerce/trunk/src/BigCommerce/Templates/Product_Options.php

    r2785458 r2887672  
    236236                $size = Image_Sizes::BC_EXTRA_MEDIUM;
    237237                break;
     238            case Customizer::SIZE_ORIGINAL:
     239                $size = 'full';
     240                break;
    238241            case Customizer::SIZE_DEFAULT:
    239242            default:
  • bigcommerce/trunk/src/BigCommerce/Templates/Product_Sku.php

    r2141486 r2887672  
    2727        return [
    2828            self::PRODUCT => $product,
    29             self::SKU     => $product->sku(),
     29            self::SKU     => $this->get_sku( $product ),
    3030        ];
    3131    }
     32
     33    /**
     34     * @param \BigCommerce\Post_Types\Product\Product $product
     35     *
     36     * @return string
     37     */
     38    private function get_sku( Product $product ) {
     39        $sku = $product->sku();
     40
     41        if ( ! empty( $sku ) ) {
     42            return $sku;
     43        }
     44
     45        $data = $product->get_source_data();
     46
     47        if ( empty( $data->variants ) ) {
     48            return '';
     49        }
     50
     51        return $data->variants[0]->sku ?? '';
     52    }
    3253}
  • bigcommerce/trunk/templates/admin/query-builder.php

    r2342514 r2887672  
    1212 */
    1313
     14use BigCommerce\Import\Import_Type;
    1415use BigCommerce\Taxonomies\Brand\Brand;
    1516use BigCommerce\Taxonomies\Channel\Channel;
     
    3435
    3536    <ul class="bc-shortcode-ui__query-builder-list" data-js="bcqb-list">
    36         <li class="bc-shortcode-ui__query-builder-list-item">
    37             <a
    38                 href="#"
    39                 class="bc-shortcode-ui__query-builder-anchor"
    40                 data-key="recent"
    41                 data-value="1"
    42                 data-slug="<?php esc_html_e( 'recent', 'bigcommerce' ); ?>"
    43                 data-depth="0"
    44             ><?php esc_html_e( 'Recent', 'bigcommerce' ); ?></a>
    45         </li>
     37        <?php if ( Import_Type::is_traditional_import() ) : ?>
     38            <li class="bc-shortcode-ui__query-builder-list-item">
     39                <a
     40                    href="#"
     41                    class="bc-shortcode-ui__query-builder-anchor"
     42                    data-key="recent"
     43                    data-value="1"
     44                    data-slug="<?php esc_html_e( 'recent', 'bigcommerce' ); ?>"
     45                    data-depth="0"
     46                ><?php esc_html_e( 'Recent', 'bigcommerce' ); ?></a>
     47            </li>
     48        <?php endif; ?>
    4649        <?php if ( $featured ) { ?>
    4750            <li class="bc-shortcode-ui__query-builder-list-item">
  • bigcommerce/trunk/vendor/autoload.php

    r2866539 r2887672  
    55require_once __DIR__ . '/composer/autoload_real.php';
    66
    7 return ComposerAutoloaderInit3a8e1eb94f496d635fd89a7cc1cbcd65::getLoader();
     7return ComposerAutoloaderInit9f56a5c2911017136344a43be2570fff::getLoader();
  • bigcommerce/trunk/vendor/composer/autoload_real.php

    r2866539 r2887672  
    33// autoload_real.php @generated by Composer
    44
    5 class ComposerAutoloaderInit3a8e1eb94f496d635fd89a7cc1cbcd65
     5class ComposerAutoloaderInit9f56a5c2911017136344a43be2570fff
    66{
    77    private static $loader;
     
    2020        }
    2121
    22         spl_autoload_register(array('ComposerAutoloaderInit3a8e1eb94f496d635fd89a7cc1cbcd65', 'loadClassLoader'), true, true);
     22        spl_autoload_register(array('ComposerAutoloaderInit9f56a5c2911017136344a43be2570fff', 'loadClassLoader'), true, true);
    2323        self::$loader = $loader = new \Composer\Autoload\ClassLoader();
    24         spl_autoload_unregister(array('ComposerAutoloaderInit3a8e1eb94f496d635fd89a7cc1cbcd65', 'loadClassLoader'));
     24        spl_autoload_unregister(array('ComposerAutoloaderInit9f56a5c2911017136344a43be2570fff', 'loadClassLoader'));
    2525
    2626        $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
     
    2828            require_once __DIR__ . '/autoload_static.php';
    2929
    30             call_user_func(\Composer\Autoload\ComposerStaticInit3a8e1eb94f496d635fd89a7cc1cbcd65::getInitializer($loader));
     30            call_user_func(\Composer\Autoload\ComposerStaticInit9f56a5c2911017136344a43be2570fff::getInitializer($loader));
    3131        } else {
    3232            $classMap = require __DIR__ . '/autoload_classmap.php';
     
    4040
    4141        if ($useStaticLoader) {
    42             $includeFiles = Composer\Autoload\ComposerStaticInit3a8e1eb94f496d635fd89a7cc1cbcd65::$files;
     42            $includeFiles = Composer\Autoload\ComposerStaticInit9f56a5c2911017136344a43be2570fff::$files;
    4343        } else {
    4444            $includeFiles = require __DIR__ . '/autoload_files.php';
    4545        }
    4646        foreach ($includeFiles as $fileIdentifier => $file) {
    47             composerRequire3a8e1eb94f496d635fd89a7cc1cbcd65($fileIdentifier, $file);
     47            composerRequire9f56a5c2911017136344a43be2570fff($fileIdentifier, $file);
    4848        }
    4949
     
    5252}
    5353
    54 function composerRequire3a8e1eb94f496d635fd89a7cc1cbcd65($fileIdentifier, $file)
     54function composerRequire9f56a5c2911017136344a43be2570fff($fileIdentifier, $file)
    5555{
    5656    if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
  • bigcommerce/trunk/vendor/composer/autoload_static.php

    r2866539 r2887672  
    55namespace Composer\Autoload;
    66
    7 class ComposerStaticInit3a8e1eb94f496d635fd89a7cc1cbcd65
     7class ComposerStaticInit9f56a5c2911017136344a43be2570fff
    88{
    99    public static $files = array (
     
    11851185    {
    11861186        return \Closure::bind(function () use ($loader) {
    1187             $loader->prefixLengthsPsr4 = ComposerStaticInit3a8e1eb94f496d635fd89a7cc1cbcd65::$prefixLengthsPsr4;
    1188             $loader->prefixDirsPsr4 = ComposerStaticInit3a8e1eb94f496d635fd89a7cc1cbcd65::$prefixDirsPsr4;
    1189             $loader->prefixesPsr0 = ComposerStaticInit3a8e1eb94f496d635fd89a7cc1cbcd65::$prefixesPsr0;
    1190             $loader->classMap = ComposerStaticInit3a8e1eb94f496d635fd89a7cc1cbcd65::$classMap;
     1187            $loader->prefixLengthsPsr4 = ComposerStaticInit9f56a5c2911017136344a43be2570fff::$prefixLengthsPsr4;
     1188            $loader->prefixDirsPsr4 = ComposerStaticInit9f56a5c2911017136344a43be2570fff::$prefixDirsPsr4;
     1189            $loader->prefixesPsr0 = ComposerStaticInit9f56a5c2911017136344a43be2570fff::$prefixesPsr0;
     1190            $loader->classMap = ComposerStaticInit9f56a5c2911017136344a43be2570fff::$classMap;
    11911191
    11921192        }, null, ClassLoader::class);
  • bigcommerce/trunk/vendor/composer/installed.json

    r2865940 r2887672  
    121121    {
    122122        "name": "moderntribe/bigcommerce-api-php-v3",
    123         "version": "v2.3.3",
    124         "version_normalized": "2.3.3.0",
     123        "version": "v2.3.4",
     124        "version_normalized": "2.3.4.0",
    125125        "source": {
    126126            "type": "git",
    127127            "url": "git@github.com:moderntribe/bigcommerce-api-php-v3.git",
    128             "reference": "860eb3be09c623dc0c8b53f506abed72a882f399"
    129         },
    130         "dist": {
    131             "type": "zip",
    132             "url": "https://api.github.com/repos/moderntribe/bigcommerce-api-php-v3/zipball/860eb3be09c623dc0c8b53f506abed72a882f399",
    133             "reference": "860eb3be09c623dc0c8b53f506abed72a882f399",
     128            "reference": "054f0c7bc188560bdcad24c7ace908def11a5c9e"
     129        },
     130        "dist": {
     131            "type": "zip",
     132            "url": "https://api.github.com/repos/moderntribe/bigcommerce-api-php-v3/zipball/054f0c7bc188560bdcad24c7ace908def11a5c9e",
     133            "reference": "054f0c7bc188560bdcad24c7ace908def11a5c9e",
    134134            "shasum": ""
    135135        },
     
    145145            "squizlabs/php_codesniffer": "~2.6"
    146146        },
    147         "time": "2022-08-17T17:15:47+00:00",
     147        "time": "2023-03-15T21:18:15+00:00",
    148148        "type": "library",
    149149        "installation-source": "dist",
  • bigcommerce/trunk/vendor/moderntribe/bigcommerce-api-php-v3/src/Api/SettingsApi.php

    r2865940 r2887672  
    110110        return $response;
    111111    }
     112
     113    public function getStoreAnalyticsSettings( $channel_id = 0 ) {
     114        list( $response ) = $this->getStorefrontHttpInfo( '/settings/analytics', $channel_id );
     115
     116        return $response;
     117    }
    112118
    113119    /**
Note: See TracChangeset for help on using the changeset viewer.