From a0610d295f272b752aa6b89a76088c5ba55c27fb Mon Sep 17 00:00:00 2001 From: MlKilderkin Date: Wed, 30 Nov 2022 19:21:48 +0200 Subject: [PATCH] packaged version 4.36.0 (#398) --- CHANGELOG.md | 12 +++++ bigcommerce.php | 2 +- build-timestamp.php | 2 +- readme.txt | 6 +-- src/BigCommerce/Cart/Cart_Mapper.php | 2 +- src/BigCommerce/Container/Pages.php | 6 +-- .../Customizer/Sections/Product_Single.php | 44 ++++++++++++++----- src/BigCommerce/Import/Image_Importer.php | 1 + src/BigCommerce/Plugin.php | 2 +- .../Post_Types/Product/Product.php | 30 +++++++++++++ src/BigCommerce/Proxy/Proxy_Controller.php | 12 ++++- src/BigCommerce/Templates/CDN_Images.php | 42 ++++++++++++------ .../Templates/Product_Featured_Image.php | 6 ++- .../public/amp/components/cart/cart-items.php | 2 +- .../components/products/product-gallery.php | 23 ++++------ vendor/autoload.php | 2 +- vendor/composer/autoload_real.php | 14 +++--- vendor/composer/autoload_static.php | 10 ++--- 18 files changed, 150 insertions(+), 68 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 55e34458..6fb52afb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ # Changelog +## [4.36.0] + +### Added +- Added ability to choose default product image size while ‘Fast Headless’ import is on. You can choose between 2 sizes: standard and thumbnail. Since Bigcommerce API provides standard images without compressing page load speed may reduce. To avoid the such problem you can choose thumbnail size to load in Wordpress customizer: Appearance → Customize → Bigcommerce → Product Single → Image Size(headless) + +### Fixed +- Fixed 'Image Zoom'(Appearance → Customizer → Bigcommerce → Product Single → Image Zoom) option. Allow using image zoom when ‘Fast Headless’ import is on +- Fixed compatibility with the Elementor plugin. Do not duplicate shortcodes on required pages, if shortcode is added already on the page +- Prevent situation when cart shows negative taxes values +- Fixed AMP cart template issue when you can't delete last item from cart + ## [4.35.0] ### Added @@ -1841,6 +1852,7 @@ in fact, reset postdata, so far as Gutenberg 3.2.0 is concerned. +[4.35.0]: https://github.com/bigcommerce/bigcommerce-for-wordpress/compare/4.35.0...4.36.0 [4.35.0]: https://github.com/bigcommerce/bigcommerce-for-wordpress/compare/4.34.0...4.35.0 [4.34.0]: https://github.com/bigcommerce/bigcommerce-for-wordpress/compare/4.33.0...4.34.0 [4.33.0]: https://github.com/bigcommerce/bigcommerce-for-wordpress/compare/4.32.0...4.33.0 diff --git a/bigcommerce.php b/bigcommerce.php index 009a49dc..ff3c7a06 100644 --- a/bigcommerce.php +++ b/bigcommerce.php @@ -3,7 +3,7 @@ Plugin Name: BigCommerce for WordPress Description: 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. Author: BigCommerce -Version: 4.35.0 +Version: 4.36.0 Author URI: https://www.bigcommerce.com/wordpress Requires PHP: 7.4.0 Text Domain: bigcommerce diff --git a/build-timestamp.php b/build-timestamp.php index 8efbae4f..5b2f711b 100644 --- a/build-timestamp.php +++ b/build-timestamp.php @@ -1,2 +1,2 @@ related( $wp_customize ); $this->default_image( $wp_customize ); $this->gallery_size( $wp_customize ); + $this->headless_cdn_image_size( $wp_customize ); $this->zoom( $wp_customize ); $this->pricing( $wp_customize ); $this->pricing_nonce( $wp_customize ); @@ -97,6 +101,24 @@ private function gallery_size( \WP_Customize_Manager $wp_customize ) { ] ); } + private function headless_cdn_image_size( \WP_Customize_Manager $wp_customize ) { + $wp_customize->add_setting( new \WP_Customize_Setting( $wp_customize, self::HEADLESS_IMAGE_SIZE, [ + 'type' => 'option', + 'transport' => 'refresh', + 'default' => self::SIZE_CDN_STD, + ] ) ); + $wp_customize->add_control( self::HEADLESS_IMAGE_SIZE, [ + 'section' => self::NAME, + 'type' => 'radio', + 'label' => __( 'Image Size(headless)', 'bigcommerce' ), + 'choices' => [ + self::SIZE_CDN_STD => __( 'Standard', 'bigcommerce' ), + self::SIZE_CDN_THUMB => __( 'Thumbnail', 'bigcommerce' ), + ], + 'description' => __( 'Toggle size of images while headless import is on', 'bigcommerce' ), + ] ); + } + private function zoom( \WP_Customize_Manager $wp_customize ) { $wp_customize->add_setting( new \WP_Customize_Setting( $wp_customize, self::ENABLE_ZOOM, [ 'type' => 'option', diff --git a/src/BigCommerce/Import/Image_Importer.php b/src/BigCommerce/Import/Image_Importer.php index b9f5185c..e718f445 100644 --- a/src/BigCommerce/Import/Image_Importer.php +++ b/src/BigCommerce/Import/Image_Importer.php @@ -18,6 +18,7 @@ class Image_Importer { const URL_STD = 'url_standard'; const URL_THUMB = 'url_thumbnail'; const URL_TINY = 'url_tiny'; + const IMAGE_ALT = 'image_alt'; const FULL_IMAGE_IMPORT = 'bigcommerce_allow_full_image_import'; const CDN_IMAGE_IMPORT = 'bigcommerce_allow_cdn_image_import'; const DISABLE_IMAGE_IMPORT = 'bigcommerce_disable_image_import'; diff --git a/src/BigCommerce/Plugin.php b/src/BigCommerce/Plugin.php index 36dee088..52c5e924 100644 --- a/src/BigCommerce/Plugin.php +++ b/src/BigCommerce/Plugin.php @@ -4,7 +4,7 @@ namespace BigCommerce; class Plugin { - const VERSION = '4.35.0'; + const VERSION = '4.36.0'; protected static $_instance; diff --git a/src/BigCommerce/Post_Types/Product/Product.php b/src/BigCommerce/Post_Types/Product/Product.php index 56f52375..6970cb3c 100644 --- a/src/BigCommerce/Post_Types/Product/Product.php +++ b/src/BigCommerce/Post_Types/Product/Product.php @@ -633,6 +633,36 @@ public function get_gallery_ids() { return apply_filters( 'bigcommerce/product/gallery', $gallery ); } + /** + * @param string $size + * + * @return string|null + */ + public function get_headless_featured_image( $size = '80' ) { + $source = $this->get_source_data(); + + if ( empty( $source->images ) ) { + return null; + } + $is_standard_img = get_option( Product_Single::HEADLESS_IMAGE_SIZE, Product_Single::SIZE_CDN_STD ) === Product_Single::SIZE_CDN_STD; + + if ( ! $is_standard_img ) { + $thumb = array_reduce( $source->images, static function( $found, $item ) { + return $item->is_thumbnail ? $item : $found; + } ); + } + + if ( empty( $thumb ) ) { + $thumb = $source->images[0]; + } + + $class = 'attachment-thumbnail size-thumbnail wp-post-image'; + $width = ! empty( $size ) ? sprintf( 'width="%s"', $size ) : ''; + + return sprintf( '', $is_standard_img ? $thumb->url_standard : $thumb->url_thumbnail, $class, $width ); + + } + public static function get_thumb_from_cdn( $post_ID, $format = 'html', $size = '80' ) { $data = get_post_meta( $post_ID, Product::GALLERY_META_KEY, true ); diff --git a/src/BigCommerce/Proxy/Proxy_Controller.php b/src/BigCommerce/Proxy/Proxy_Controller.php index 0e791888..534dc466 100644 --- a/src/BigCommerce/Proxy/Proxy_Controller.php +++ b/src/BigCommerce/Proxy/Proxy_Controller.php @@ -227,9 +227,17 @@ public function update_cart_item( $request ) { $args['body'] = wp_json_encode( $body ); } - $response = wp_remote_request( $route, $args ); + $response = wp_remote_request( $route, $args ); + $body_response = json_decode( wp_remote_retrieve_body( $response ), true ) ; + + if ( empty( $body_response ) ) { + return rest_ensure_response( [ + 'data' => [], + 'meta' => [] + ] ); + } - return rest_ensure_response( json_decode( wp_remote_retrieve_body( $response ), true ) ); + return rest_ensure_response( $body_response ); } /** diff --git a/src/BigCommerce/Templates/CDN_Images.php b/src/BigCommerce/Templates/CDN_Images.php index 5a174342..e21dada0 100644 --- a/src/BigCommerce/Templates/CDN_Images.php +++ b/src/BigCommerce/Templates/CDN_Images.php @@ -3,6 +3,8 @@ namespace BigCommerce\Templates; use BigCommerce\Import\Image_Importer; +use BigCommerce\Post_Types\Product\Product; +use \BigCommerce\Customizer\Sections\Product_Single; trait CDN_Images { @@ -22,33 +24,43 @@ public function get_images_cdn_url( $images_ids = [] ) { foreach ( $images_ids as $image_id ) { $cdn_images[ $image_id ] = [ - Image_Importer::URL_ZOOM => get_post_meta( $image_id, Image_Importer::SOURCE_URL, true ), - Image_Importer::URL_THUMB => get_post_meta( $image_id, Image_Importer::URL_THUMB, true ), - Image_Importer::URL_STD => get_post_meta( $image_id, Image_Importer::URL_STD, true ), + Image_Importer::URL_ZOOM => get_post_meta( $image_id, Image_Importer::SOURCE_URL, true ), + Image_Importer::URL_THUMB => get_post_meta( $image_id, Image_Importer::URL_THUMB, true ), + Image_Importer::URL_STD => get_post_meta( $image_id, Image_Importer::URL_STD, true ), ]; } return $cdn_images; } - public function get_headless_images( $product ) { + /** + * @param \BigCommerce\Post_Types\Product\Product $product + * + * @return array|array[] + */ + public function get_headless_images( Product $product ) { $images = []; - $source = $product->get_source_data(); - $default_images = []; - $main_image = []; + $source = $product->get_source_data(); + $default_images = []; + $main_image = []; + $is_standard_img = get_option( Product_Single::HEADLESS_IMAGE_SIZE, Product_Single::SIZE_CDN_STD ) === Product_Single::SIZE_CDN_STD; if ( ! empty( $source->images ) ) { foreach ( $source->images as $image ) { if ( $image->is_thumbnail ) { $main_image = [ - 'url' => $image->url_standard, - 'alt' => $image->description, + Image_Importer::URL_STD => $image->url_standard, + Image_Importer::URL_ZOOM => $image->url_zoom ?? null, + Image_Importer::URL_THUMB => $is_standard_img ? $image->url_standard : $image->url_thumbnail ?? null, + Image_Importer::IMAGE_ALT => $image->description, ]; continue; } $default_images[] = [ - 'url' => $image->url_zoom, - 'alt' => $image->description, + Image_Importer::URL_STD => $image->url_standard, + Image_Importer::URL_ZOOM => $image->url_zoom ?? null, + Image_Importer::URL_THUMB => $is_standard_img ? $image->url_standard : $image->url_thumbnail ?? null, + Image_Importer::IMAGE_ALT => $image->description, ]; } } @@ -60,13 +72,15 @@ public function get_headless_images( $product ) { continue; } - if ( !empty( $main_image ) && $main_image['url'] === $image) { + if ( ! empty( $main_image ) && $main_image[ Image_Importer::URL_STD ] === $image ) { continue; } $images[] = [ - 'url' => $image, - 'alt' => '', + Image_Importer::URL_STD => $image, + Image_Importer::URL_ZOOM => $image, + Image_Importer::URL_THUMB => $image, + Image_Importer::IMAGE_ALT => '', ]; } diff --git a/src/BigCommerce/Templates/Product_Featured_Image.php b/src/BigCommerce/Templates/Product_Featured_Image.php index 3d55d340..8f2a00f2 100644 --- a/src/BigCommerce/Templates/Product_Featured_Image.php +++ b/src/BigCommerce/Templates/Product_Featured_Image.php @@ -52,8 +52,10 @@ public function get_data() { } protected function get_attachment_id( Product $product ) { - if ( Image_Importer::should_load_from_cdn() ) { - $this->cdn_image = Product::get_thumb_from_cdn( $product->post_id(), 'html', null ); + if ( Image_Importer::should_load_from_cdn() || $product->is_headless() ) { + $this->cdn_image = $product->is_headless() + ? $product->get_headless_featured_image( null ) + : Product::get_thumb_from_cdn( $product->post_id(), 'html', null ); return $this->cdn_image; } diff --git a/templates/public/amp/components/cart/cart-items.php b/templates/public/amp/components/cart/cart-items.php index d0e8c8a0..012ae236 100644 --- a/templates/public/amp/components/cart/cart-items.php +++ b/templates/public/amp/components/cart/cart-items.php @@ -51,7 +51,7 @@ class="bc-cart-body" method="post" on="submit:AMP.setState({savingItem: true});submit-success:product-list.refresh,subtotal.refresh,AMP.setState({savingItem: false})" > - + = 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded()); if ($useStaticLoader) { require_once __DIR__ . '/autoload_static.php'; - call_user_func(\Composer\Autoload\ComposerStaticInitbc47ae46b55b55c82ca9433553970f53::getInitializer($loader)); + call_user_func(\Composer\Autoload\ComposerStaticInit99810156f222fdb0f3daf1575e98b282::getInitializer($loader)); } else { $classMap = require __DIR__ . '/autoload_classmap.php'; if ($classMap) { @@ -39,19 +39,19 @@ public static function getLoader() $loader->register(true); if ($useStaticLoader) { - $includeFiles = Composer\Autoload\ComposerStaticInitbc47ae46b55b55c82ca9433553970f53::$files; + $includeFiles = Composer\Autoload\ComposerStaticInit99810156f222fdb0f3daf1575e98b282::$files; } else { $includeFiles = require __DIR__ . '/autoload_files.php'; } foreach ($includeFiles as $fileIdentifier => $file) { - composerRequirebc47ae46b55b55c82ca9433553970f53($fileIdentifier, $file); + composerRequire99810156f222fdb0f3daf1575e98b282($fileIdentifier, $file); } return $loader; } } -function composerRequirebc47ae46b55b55c82ca9433553970f53($fileIdentifier, $file) +function composerRequire99810156f222fdb0f3daf1575e98b282($fileIdentifier, $file) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { require $file; diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 57fa25bf..168d5f82 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -4,7 +4,7 @@ namespace Composer\Autoload; -class ComposerStaticInitbc47ae46b55b55c82ca9433553970f53 +class ComposerStaticInit99810156f222fdb0f3daf1575e98b282 { public static $files = array ( '5255c38a0faeba867671b61dfda6d864' => __DIR__ . '/..' . '/paragonie/random_compat/lib/random.php', @@ -1163,10 +1163,10 @@ class ComposerStaticInitbc47ae46b55b55c82ca9433553970f53 public static function getInitializer(ClassLoader $loader) { return \Closure::bind(function () use ($loader) { - $loader->prefixLengthsPsr4 = ComposerStaticInitbc47ae46b55b55c82ca9433553970f53::$prefixLengthsPsr4; - $loader->prefixDirsPsr4 = ComposerStaticInitbc47ae46b55b55c82ca9433553970f53::$prefixDirsPsr4; - $loader->prefixesPsr0 = ComposerStaticInitbc47ae46b55b55c82ca9433553970f53::$prefixesPsr0; - $loader->classMap = ComposerStaticInitbc47ae46b55b55c82ca9433553970f53::$classMap; + $loader->prefixLengthsPsr4 = ComposerStaticInit99810156f222fdb0f3daf1575e98b282::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInit99810156f222fdb0f3daf1575e98b282::$prefixDirsPsr4; + $loader->prefixesPsr0 = ComposerStaticInit99810156f222fdb0f3daf1575e98b282::$prefixesPsr0; + $loader->classMap = ComposerStaticInit99810156f222fdb0f3daf1575e98b282::$classMap; }, null, ClassLoader::class); }