Skip to content

Commit

Permalink
packaged version 4.4.0 (#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
vladanost committed Nov 18, 2020
1 parent 4e3d5dc commit a305b22
Show file tree
Hide file tree
Showing 28 changed files with 274 additions and 45 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## [4.4.0]

### Added
- Added a new customizer option to hide search bar from product archive
- Added ability to embed iframe in Product description
- Added option to never sync products
- Added new sort options on Product Archive: by SKU and by Inventory Count


## [4.3.1]

### Fixed
Expand Down Expand Up @@ -1305,6 +1314,7 @@
in fact, reset postdata, so far as Gutenberg 3.2.0 is concerned.


[4.4.0]: https://github.com/bigcommerce/bigcommerce-for-wordpress/compare/4.3.1...4.4.0
[4.3.1]: https://github.com/bigcommerce/bigcommerce-for-wordpress/compare/4.3.0...4.3.1
[4.3.0]: https://github.com/bigcommerce/bigcommerce-for-wordpress/compare/4.2.0...4.3.0
[4.2.0]: https://github.com/bigcommerce/bigcommerce-for-wordpress/compare/4.1.0...4.2.0
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ As with any WordPress plugin, upload the plugin ZIP file to the

### System Requirements

* PHP: 5.6+ (7.2+ recommended)
* PHP: 7.2+
* MySQL: 5.5+ (5.6+ recommended)
* WordPress: 5.2+
* SSL
Expand Down
5 changes: 4 additions & 1 deletion assets/css/bc-gutenberg.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/css/bc-gutenberg.min.css

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion assets/css/master-amp.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/css/master-amp.min.css

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion assets/css/master.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/css/master.min.css

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions assets/pcss/content/components/_refinery.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@

@media (--viewport-large) {
margin-left: 10px;

.bc-refinery--no-search & {
margin-left: 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.3.1
Version: 4.4.0
Author URI: https://www.bigcommerce.com/wordpress
Requires PHP: 7.2.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', '6.46.10.13.2020');
define('BIGCOMMERCE_ASSETS_BUILD_TIMESTAMP', '5.51.11.04.2020');
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: bigcommerce, moderntribe, jbrinley, becomevocal, vincentlistrani,
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.5
Stable tag: 4.3.1
Stable tag: 4.4.0
Requires PHP: 7.2.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Expand Down
23 changes: 23 additions & 0 deletions src/BigCommerce/Container/Util.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php


namespace BigCommerce\Container;


use BigCommerce\Util\Kses;
use Pimple\Container;

class Util extends Provider {
const KSES = 'util.kses';

public function register( Container $container ) {
$container[ self::KSES ] = function ( Container $container ) {
return new Kses();
};

add_action( 'wp_kses_allowed_html', $this->create_callback( 'kses_allowed_html', function ( $allowed_tags, $context ) use ( $container ) {
return $container[ self::KSES ]->product_description_allowed_html( $allowed_tags, $context );
} ), 10, 2 );
}

}
55 changes: 39 additions & 16 deletions src/BigCommerce/Customizer/Sections/Product_Archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,24 @@ class Product_Archive {
const CATEGORY_SLUG = 'bigcommerce_category_archive_slug';
const BRAND_SLUG = 'bigcommerce_brand_archive_slug';

const SORT_FEATURED = 'featured';
const SORT_DATE = 'date';
const SORT_SALES = 'sales';
const SORT_TITLE_ASC = 'title_asc';
const SORT_TITLE_DESC = 'title_desc';
const SORT_REVIEWS = 'reviews';
const SORT_PRICE_ASC = 'price_asc';
const SORT_PRICE_DESC = 'price_desc';
const SORT_FEATURED = 'featured';
const SORT_DATE = 'date';
const SORT_SALES = 'sales';
const SORT_TITLE_ASC = 'title_asc';
const SORT_TITLE_DESC = 'title_desc';
const SORT_REVIEWS = 'reviews';
const SORT_PRICE_ASC = 'price_asc';
const SORT_PRICE_DESC = 'price_desc';
const SORT_INVENTORY_COUNT = 'inventory_count';
const SORT_SKU = 'sku';

const FILTER_CATEGORY = Product_Category::NAME;
const FILTER_BRAND = Brand::NAME;
const PER_PAGE_DEFAULT = 24;
const PER_PAGE = 'bigcommerce_products_per_page';
const GRID_COLUMNS = 'bigcommerce_catalog_grid_columns';
const QUICK_VIEW = 'bigcommerce_enable_quick_view';
const SEARCH_FIELD = 'bigcommerce_catalog_enable_search_field';

/**
* @param \WP_Customize_Manager $wp_customize
Expand All @@ -57,6 +60,7 @@ public function register( $wp_customize ) {
$this->columns( $wp_customize );
$this->per_page( $wp_customize );
$this->quick_view( $wp_customize );
$this->search_field( $wp_customize );
}

private function title( \WP_Customize_Manager $wp_customize ) {
Expand Down Expand Up @@ -141,14 +145,16 @@ private function sorting( \WP_Customize_Manager $wp_customize ) {

public static function sort_choices() {
$choices = [
self::SORT_FEATURED => __( 'Featured', 'bigcommerce' ),
self::SORT_DATE => __( 'Newest', 'bigcommerce' ),
self::SORT_SALES => __( 'Best Selling', 'bigcommerce' ),
self::SORT_TITLE_ASC => __( 'Product Title A–Z', 'bigcommerce' ),
self::SORT_TITLE_DESC => __( 'Product Title Z–A', 'bigcommerce' ),
self::SORT_REVIEWS => __( 'Reviews', 'bigcommerce' ),
self::SORT_PRICE_ASC => __( 'Price (low to high)', 'bigcommerce' ),
self::SORT_PRICE_DESC => __( 'Price (high to low)', 'bigcommerce' ),
self::SORT_FEATURED => __( 'Featured', 'bigcommerce' ),
self::SORT_DATE => __( 'Newest', 'bigcommerce' ),
self::SORT_SALES => __( 'Best Selling', 'bigcommerce' ),
self::SORT_TITLE_ASC => __( 'Product Title A–Z', 'bigcommerce' ),
self::SORT_TITLE_DESC => __( 'Product Title Z–A', 'bigcommerce' ),
self::SORT_REVIEWS => __( 'Reviews', 'bigcommerce' ),
self::SORT_PRICE_ASC => __( 'Price (low to high)', 'bigcommerce' ),
self::SORT_PRICE_DESC => __( 'Price (high to low)', 'bigcommerce' ),
self::SORT_INVENTORY_COUNT => __( 'Inventory Count', 'bigcommerce' ),
self::SORT_SKU => __( 'SKU', 'bigcommerce' ),
];

/**
Expand Down Expand Up @@ -285,4 +291,21 @@ private function quick_view( \WP_Customize_Manager $wp_customize ) {
],
] );
}

private function search_field( \WP_Customize_Manager $wp_customize ) {
$wp_customize->add_setting( new \WP_Customize_Setting( $wp_customize, self::SEARCH_FIELD, [
'type' => 'option',
'default' => 'yes',
'transport' => 'refresh',
] ) );
$wp_customize->add_control( self::SEARCH_FIELD, [
'section' => self::NAME,
'type' => 'radio',
'label' => __( 'Search Field', 'bigcommerce' ),
'choices' => [
'yes' => __( 'Enabled', 'bigcommerce' ),
'no' => __( 'Disabled', 'bigcommerce' ),
],
] );
}
}
2 changes: 1 addition & 1 deletion src/BigCommerce/Import/Import_Strategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace BigCommerce\Import;

interface Import_Strategy {
const VERSION = '4.0.0';
const VERSION = '4.4.0';

/**
* @return int The imported post ID
Expand Down
57 changes: 56 additions & 1 deletion src/BigCommerce/Import/Importers/Products/Product_Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ private function get_post_content() {
}

private function sanitize_content( $content ) {
return wp_kses_post( $content );
$content = html_entity_decode( $content );

return wp_kses( $content, 'bigcommerce/product_description' );
}

private function get_post_slug() {
Expand Down Expand Up @@ -389,6 +391,7 @@ public function build_post_meta() {
$meta[ Product::IMPORTER_VERSION_META_KEY ] = Import_Strategy::VERSION;
$meta[ Product::BIGCOMMERCE_ID ] = $this->sanitize_int( $this->product['id'] );
$meta[ Product::SKU ] = $this->sanitize_string( $this->product['sku'] );
$meta[ Product::SKU_NORMALIZED ] = $this->normalize_sku( $this->product['sku'] );
$meta[ Product::RATING_META_KEY ] = $this->get_avg_rating();
$meta[ Product::REVIEW_COUNT_META_KEY ] = $this->sanitize_int( $this->product[ 'reviews_rating_sum' ] );
$meta[ Product::RATING_SUM_META_KEY ] = $this->sanitize_int( $this->product[ 'reviews_count' ] );
Expand All @@ -401,6 +404,58 @@ public function build_post_meta() {
return $meta;
}

private function normalize_sku( $sku ) {
$num_of_characters = apply_filters( 'bigcommerce/sku/normalized/segment/num_of_characters', 10 );
if ( empty( $sku ) ) {
return apply_filters( 'bigcommerce/sku/normalized/empty', str_repeat( 'z', $num_of_characters ) );
}

return apply_filters( 'bigcommerce/sku/normalized', $this->normalize_sku_segments( $this->segment_sku( $sku ), $num_of_characters ), $sku );
}

private function segment_sku( $sku ) {
$sku = preg_replace( "/[^A-Za-z0-9 ]/", '', $sku );

// Group characters by type
$previous_type = 'alpha';
$segments = [[]];
foreach ( str_split( $sku ) as $char ) {
end( $segments );
$key = key( $segments );

$current_type = 'num';

if ( ctype_alpha( $char ) ) {
$current_type = 'alpha';
}

if ( $current_type !== $previous_type ) {
$key++;
$segments[ $key ] = [];
}
$segments[ $key ][] = $char;

$previous_type = $current_type;
}

// Flatten segments
return array_map( function( $segment ) {
return implode( '', $segment );
}, $segments );
}

private function normalize_sku_segments( $segments, $num_of_characters ) {
$segments = array_map( function( $segment ) use ( $num_of_characters ) {
$pad_type = STR_PAD_LEFT;
if ( ctype_alpha( $segment[0] ) ) {
$pad_type = STR_PAD_RIGHT;
}
return str_pad( $segment, $num_of_characters, '0', $pad_type );
}, $segments );

return implode( '-', $segments );
}

private function get_avg_rating() {
$sum = $this->sanitize_int( $this->product[ 'reviews_rating_sum' ] );
$count = $this->sanitize_int( $this->product[ 'reviews_count' ] );
Expand Down
2 changes: 2 additions & 0 deletions src/BigCommerce/Import/Importers/Products/Product_Saver.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ public function do_import() {
*/
protected function save_wp_post( Product_Builder $builder ) {
$postarr = $this->get_post_array( $builder );
kses_remove_filters();
wp_update_post( $postarr );
kses_init();
}

/**
Expand Down
10 changes: 8 additions & 2 deletions src/BigCommerce/Import/Runner/Cron_Scheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ class Cron_Scheduler {
* @return void
*/
public function schedule_next_import() {
$frequency = get_option( Import::OPTION_FREQUENCY, Import::DEFAULT_FREQUENCY );
if ( $frequency === Import::FREQUENCY_NEVER ) {
wp_unschedule_hook( Cron_Runner::START_CRON );
return;
}

$status = new Status();
$previous = $status->previous_status();

Expand All @@ -24,8 +30,8 @@ public function schedule_next_import() {
return;
}

$last = (int) $previous[ 'timestamp' ];
$frequency = get_option( Import::OPTION_FREQUENCY, Import::DEFAULT_FREQUENCY );
$last = (int) $previous[ 'timestamp' ];

switch ( $frequency ) {
case Import::FREQUENCY_HOURLY:
$offset = HOUR_IN_SECONDS;
Expand Down
3 changes: 2 additions & 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.3.1';
const VERSION = '4.4.0';

protected static $_instance;

Expand Down Expand Up @@ -80,6 +80,7 @@ private function load_service_providers() {
$this->providers[ 'templates' ] = new Container\Templates();
$this->providers[ 'widgets' ] = new Container\Widgets();
$this->providers[ 'webhooks' ] = new Container\Webhooks();
$this->providers[ 'util' ] = new Container\Util();


/**
Expand Down
1 change: 1 addition & 0 deletions src/BigCommerce/Post_Types/Product/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Product {
const BIGCOMMERCE_ID = 'bigcommerce_id';
const LISTING_ID = 'bigcommerce_listing_id';
const SKU = 'bigcommerce_sku';
const SKU_NORMALIZED = 'bigcommerce_sku_normalized';
const SOURCE_DATA_META_KEY = 'bigcommerce_source_data';
const LISTING_DATA_META_KEY = 'bigcommerce_listing_data';
const MODIFIER_DATA_META_KEY = 'bigcommerce_modifier_data';
Expand Down
31 changes: 31 additions & 0 deletions src/BigCommerce/Post_Types/Product/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,37 @@ public function filter_queries( \WP_Query $query ) {
};
add_filter( 'posts_orderby', $orderby_filter, 10, 2 );
break;

case Product_Archive::SORT_INVENTORY_COUNT:
$meta_query = $query->get( 'meta_query' ) ?: [];

$meta_query['bigcommerce_inventory_level'] = [
'key' => Product::INVENTORY_META_KEY,
'compare' => 'EXISTS',
'type' => 'NUMERIC'
];

$meta_query['bigcommerce_id'] = [
'key' => Product::BIGCOMMERCE_ID,
'type' => 'NUMERIC'
];

$query->set( 'meta_query', $meta_query );
$query->set( 'orderby', [ 'bigcommerce_inventory_level' => 'DESC', 'bigcommerce_id' => 'DESC' ] );
break;

case Product_Archive::SORT_SKU:
$meta_query = $query->get( 'meta_query' ) ?: [];

$meta_query['bigcommerce_sku_normalized'] = [
'key' => Product::SKU_NORMALIZED,
'compare' => 'EXISTS',
];

$query->set( 'meta_query', $meta_query );
$query->set( 'orderby', [ 'bigcommerce_sku_normalized' => 'ASC'] );

break;
default:
do_action( 'bigcommerce/query/sort', $query );
break;
Expand Down
2 changes: 2 additions & 0 deletions src/BigCommerce/Settings/Sections/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Import extends Settings_Section {
const FREQUENCY_DAILY = 'daily';
const FREQUENCY_WEEKLY = 'weekly';
const FREQUENCY_MONTHLY = 'monthly';
const FREQUENCY_NEVER = 'never';

const DEFAULT_FREQUENCY = self::FREQUENCY_FIVE;

Expand Down Expand Up @@ -168,6 +169,7 @@ public function frequency_select() {
self::FREQUENCY_DAILY => __( 'Day', 'bigcommerce' ),
self::FREQUENCY_WEEKLY => __( 'Week', 'bigcommerce' ),
self::FREQUENCY_MONTHLY => __( 'Month', 'bigcommerce' ),
self::FREQUENCY_NEVER => __( 'Never', 'bigcommerce' ),
];

$select = sprintf( '<select id="field-%s" name="%s" class="regular-text bc-field-choices">', esc_attr( self::OPTION_FREQUENCY ), esc_attr( self::OPTION_FREQUENCY ) );
Expand Down
Loading

0 comments on commit a305b22

Please sign in to comment.