Skip to content

Commit

Permalink
packaged version 4.36.0 (#398)
Browse files Browse the repository at this point in the history
  • Loading branch information
MlKilderkin committed Nov 30, 2022
1 parent 81e37b8 commit a0610d2
Show file tree
Hide file tree
Showing 18 changed files with 150 additions and 68 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion bigcommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion build-timestamp.php
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<?php
define('BIGCOMMERCE_ASSETS_BUILD_TIMESTAMP', '3.47.10.10.2022');
define('BIGCOMMERCE_ASSETS_BUILD_TIMESTAMP', '2.42.10.24.2022');
6 changes: 3 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
=== BigCommerce For WordPress ===
Contributors: bigcommerce, moderntribe, jbrinley, becomevocal, vincentlistrani, jbirthler, kdiplas, iliabaum, joshliston, nickioa, fernando22, mr_speer, geoffgraham, yuenvision, xwp, karenpwhite
Contributors: bigcommerce, moderntribe, jbrinley, becomevocal, vincentlistrani, jbirthler, kdiplas, iliabaum, joshliston, nickioa, fernando22, mr_speer, geoffgraham, yuenvision, xwp, karenpwhite, mlkilderkin
Tags: ecommerce, online store, sell online, storefront, retail, online shop, bigcommerce, big commerce, e-commerce, physical products, buy buttons, commerce, shopping cart, checkout, cart, shop, headless commerce, shipping, payments, fulfillment
Requires at least: 5.2
Tested up to: 5.9.2
Stable tag: 4.35.0
Tested up to: 6.0.3
Stable tag: 4.36.0
Requires PHP: 7.4.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Expand Down
2 changes: 1 addition & 1 deletion src/BigCommerce/Cart/Cart_Mapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ private function prepare_gift_certificate_item( ItemGiftCertificate $item ) {
*/
private function calculate_total_tax( $cart_amount, $discount_amount, $coupons_discount_amount, $items ) {
$item_sum = array_sum( array_map( function ( $item ) {
return isset( $item[ 'total_list_price' ][ 'raw' ] ) ? $item[ 'total_list_price' ][ 'raw' ] : 0;
return isset( $item[ 'total_sale_price' ][ 'raw' ] ) ? $item[ 'total_sale_price' ][ 'raw' ] : 0;
}, $items ) );

return $cart_amount + $discount_amount + $coupons_discount_amount - $item_sum;
Expand Down
6 changes: 3 additions & 3 deletions src/BigCommerce/Container/Pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function register( Container $container ) {
$container[ self::CHECKOUT_PAGE ] = function ( Container $container ) {
return new Checkout_Page();
};

$container[ self::CHECKOUT_COMPLETE_PAGE ] = function ( Container $container ) {
return new Checkout_Complete_Page();
};
Expand Down Expand Up @@ -155,6 +155,6 @@ public function register( Container $container ) {
}
}
return $content;
} ) );
} ), 5, 1 );
}
}
}
44 changes: 33 additions & 11 deletions src/BigCommerce/Customizer/Sections/Product_Single.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,20 @@
class Product_Single {
const NAME = 'bigcommerce_product_single';

const RELATED_COUNT = 'bigcommerce_max_related_products';
const DEFAULT_IMAGE = 'bigcommerce_default_image_id';
const PRICE_DISPLAY = 'bigcommerce_default_price_display';
const INVENTORY_DISPLAY = 'bigcommerce_inventory_display';
const VARIANTS_DISABLED = 'bigcommerce_variants_disabled';
const META_DESC_DISABLE = 'bigcommerce_meta_description_disabled';
const GALLERY_SIZE = 'bigcommerce_gallery_image_size';
const ENABLE_ZOOM = 'bigcommerce_enable_zoom';
const ENABLE_PRICE_NONCE = 'bigcommerce_enable_zoom';
const SIZE_DEFAULT = 'default';
const SIZE_LARGE = 'large';
const RELATED_COUNT = 'bigcommerce_max_related_products';
const DEFAULT_IMAGE = 'bigcommerce_default_image_id';
const PRICE_DISPLAY = 'bigcommerce_default_price_display';
const INVENTORY_DISPLAY = 'bigcommerce_inventory_display';
const VARIANTS_DISABLED = 'bigcommerce_variants_disabled';
const META_DESC_DISABLE = 'bigcommerce_meta_description_disabled';
const GALLERY_SIZE = 'bigcommerce_gallery_image_size';
const HEADLESS_IMAGE_SIZE = 'bigcommerce_gallery_headless_image_size';
const ENABLE_ZOOM = 'bigcommerce_enable_zoom';
const ENABLE_PRICE_NONCE = 'bigcommerce_enable_price_nonce';
const SIZE_DEFAULT = 'default';
const SIZE_LARGE = 'large';
const SIZE_CDN_STD = 'standard';
const SIZE_CDN_THUMB = 'thumbnail';

/**
* @param \WP_Customize_Manager $wp_customize
Expand All @@ -35,6 +38,7 @@ public function register( $wp_customize ) {
$this->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 );
Expand Down Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions src/BigCommerce/Import/Image_Importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/BigCommerce/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace BigCommerce;

class Plugin {
const VERSION = '4.35.0';
const VERSION = '4.36.0';

protected static $_instance;

Expand Down
30 changes: 30 additions & 0 deletions src/BigCommerce/Post_Types/Product/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -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( '<img src="%s" class="%s" %s />', $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 );

Expand Down
12 changes: 10 additions & 2 deletions src/BigCommerce/Proxy/Proxy_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

/**
Expand Down
42 changes: 28 additions & 14 deletions src/BigCommerce/Templates/CDN_Images.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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,
];
}
}
Expand All @@ -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 => '',
];
}

Expand Down
6 changes: 4 additions & 2 deletions src/BigCommerce/Templates/Product_Featured_Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion templates/public/amp/components/cart/cart-items.php
Original file line number Diff line number Diff line change
Expand Up @@ -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})"
>
<input type="hidden" name="cartId" value="CLIENT_ID(<?php echo Cart::CART_COOKIE; ?>)" data-amp-replace="CLIENT_ID" />
<input type="hidden" name="cartId" value="<?php echo sprintf( 'CLIENT_ID(%s)', Cart::CART_COOKIE ) ?>" data-amp-replace="CLIENT_ID" />
<button
class="bc-link bc-cart-item__remove-button"
type="submit"
Expand Down
23 changes: 8 additions & 15 deletions templates/public/components/products/product-gallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,10 @@
use BigCommerce\Import\Image_Importer;
use BigCommerce\Post_Types\Product\Product;

$headless = $context['product']->is_headless();
if ( $headless ) {
$item_count = count( $cdn_images );
} else {
$item_count = count( $image_ids ) + count( $youtube_videos );
}


$headless = $context['product']->is_headless();
$item_count = $headless ? count( $cdn_images ) : count( $image_ids ) + count( $youtube_videos );
$gallery_classes = $item_count > 1 ? 'swiper-container bc-product-gallery--has-carousel' : 'swiper-container';

$has_zoom = $zoom ? 'bc-product-image-zoom' : '';
$has_zoom = $zoom ? 'bc-product-image-zoom' : '';
?>

<!-- data-js="bc-product-gallery" is required -->
Expand All @@ -48,13 +41,13 @@
$index = 0;
if ( $headless && ! empty( $cdn_images ) ) {
foreach ( $cdn_images as $image) {
$image_full = $zoom ? sprintf( 'data-zoom="%s"', $image['url'] ) : '';
$image_full = $zoom && ! empty( $image[ Image_Importer::URL_ZOOM ] ) ? sprintf( 'data-zoom="%s"', $image[ Image_Importer::URL_ZOOM ] ) : '';
?>
<!-- class="swiper-slide" is required -->
<div class="swiper-slide bc-product-gallery__image-slide" data-index="<?php echo $index++; ?>">
<img
src="<?php echo esc_url( $image['url'] ); ?>" <?php echo $image_full; ?>
alt="<?php echo esc_attr( trim( strip_tags( $image['alt'] ) ) ); ?>"
src="<?php echo esc_url( $image[ Image_Importer::URL_THUMB ] ); ?>" <?php echo $image_full; ?>
alt="<?php echo esc_attr( trim( strip_tags( $image[ Image_Importer::IMAGE_ALT ] ) ) ); ?>"
>
</div>
<?php }
Expand Down Expand Up @@ -112,15 +105,15 @@ class="swiper-slide bc-product-gallery__video-slide"
$index = 0;
if ( $headless && ! empty( $cdn_images ) ) {
foreach ( $cdn_images as $image) {
$image_full = $zoom ? sprintf( 'data-zoom="%s"', $image['url'] ) : '';
$image_full = $zoom && ! empty( $image[ Image_Importer::URL_ZOOM ] ) ? sprintf( 'data-zoom="%s"', $image[ Image_Importer::URL_ZOOM ] ) : '';
?>
<!-- class="swiper-slide" and data-js="bc-gallery-thumb-trigger" are required -->
<button class="swiper-slide bc-product-gallery__thumb-slide"
data-js="bc-gallery-thumb-trigger"
data-index="<?php echo $index++; ?>"
aria-label="<?php _e( 'mark as featured image', 'stellar' ) ?>"
>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>"
<img src="<?php echo $image[ Image_Importer::URL_THUMB ]; ?>" alt="<?php echo $image[ Image_Importer::IMAGE_ALT ]; ?>"
>
</button>
<?php }
Expand Down
2 changes: 1 addition & 1 deletion vendor/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInitbc47ae46b55b55c82ca9433553970f53::getLoader();
return ComposerAutoloaderInit99810156f222fdb0f3daf1575e98b282::getLoader();
Loading

0 comments on commit a0610d2

Please sign in to comment.