Skip to content

Commit

Permalink
Merge pull request #413 from moderntribe/release/5.0.0
Browse files Browse the repository at this point in the history
packaged version 5.0.0
  • Loading branch information
MlKilderkin committed Feb 15, 2023
2 parents b78dea3 + da6045d commit 8e11122
Show file tree
Hide file tree
Showing 120 changed files with 3,793 additions and 560 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

## [5.0.0]

### Added
- Added support for Multi Storefront(MSF) functionality:
- Pull products, product categories and brands that belongs to specified channel
- Retrieve and save currencies during the import. They can be used in `Currency Switch` widget. You can add widget in Appearance -> Widgets. Just drop widget to registered widget area. After that each user can switch to required currency on the frontend
- Apply channel settings(hide prices, hide reviews etc.) set in Bigcommerce Channel Manager to WordPress e-commerce pages.
- Retrieve customer groups existed in Bigcommerce. If it is possible set default customer group for all new customer

### Changed
- Creation of new channel for MSF stores won't create active channel in Bigcommerce anymore. Instead of that channel with pre-launch status will be created. Usual WordPres pages will be still accessible by regular users. However, any e-commerce pages(checkout, product single page and etc) won't be visible for anyone, except site administrator, and return 404 error. To make it visible please enable webhooks and go to Bigcommerce Channel Manager. Change channel status to active. After that e-commerce pages will become visible for everyone.

## [4.37.0]

### Added
Expand Down Expand Up @@ -1860,6 +1872,7 @@
in fact, reset postdata, so far as Gutenberg 3.2.0 is concerned.


[5.0.0]: https://github.com/bigcommerce/bigcommerce-for-wordpress/compare/4.37.0...5.0.0
[4.37.0]: https://github.com/bigcommerce/bigcommerce-for-wordpress/compare/4.36.0...4.37.0
[4.36.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
Expand Down
34 changes: 33 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.

38 changes: 33 additions & 5 deletions 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.

6 changes: 3 additions & 3 deletions assets/js/dist/admin/gutenberg/scripts.js

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions assets/js/dist/admin/gutenberg/scripts.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/js/dist/scripts.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/js/dist/scripts.min.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { GUTENBERG_PRODUCT_COMPONENTS as BLOCK } from '../../config/gutenberg-se
import ProductId from './productId';
import ProductComponentType from './productComponentType';

const { InspectorControls } = wp.editor;
const { InspectorControls } = wp.blockEditor;
const { PanelRow, PanelBody, BaseControl } = wp.components;
const { Component, Fragment } = wp.element;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { GUTENBERG_PRODUCT_REVIEWS as BLOCK } from '../../config/gutenberg-settings';
import ShortcodeInput from './shortcodeInput';

const { InspectorControls } = wp.editor;
const { InspectorControls } = wp.blockEditor;
const { PanelRow, PanelBody, BaseControl } = wp.components;
const { withInstanceId } = wp.compose;
const { Fragment } = wp.element;
Expand Down
2 changes: 1 addition & 1 deletion assets/js/src/admin/gutenberg/blocks/products/inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { trigger } from '../../../../utils/events';
import shortcodeState from '../../../config/shortcode-state';

const { Component } = wp.element;
const { InspectorControls } = wp.editor;
const { InspectorControls } = wp.blockEditor;
const { PanelRow, PanelBody, Button } = wp.components;

export default class Inspector extends Component {
Expand Down
8 changes: 7 additions & 1 deletion assets/js/src/public/page/dynamicStateField.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,13 @@ const parseCountryObject = (selectedCountry = '', stateControlContainer = '') =>
const storeInitialFieldStates = () => {
const countryControl = tools.getNodes('bc-dynamic-country-select')[0];
const stateControl = tools.getNodes('bc-dynamic-state-control')[0];
const stateFieldType = stateControl.tagName.toLowerCase();
let stateFieldType = '';

if (!stateControl || !countryControl) {
return;
}

stateFieldType = stateControl.tagName.toLowerCase();

if (stateFieldType === 'select') {
countryState.initialStateValue = stateControl.options[stateControl.selectedIndex].value;
Expand Down
1 change: 1 addition & 0 deletions assets/pcss/content/components/_all.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@
@import "images";
@import "wish-lists";
@import "banner";
@import "currency-widget";
29 changes: 29 additions & 0 deletions assets/pcss/content/components/_currency-widget.pcss
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
.bc-currency-switcher {
padding: 0;
margin: 0;

.bc-form {
display: flex;
flex-direction: row;
flex-wrap: wrap;
align-items: flex-end;
}

.bc-form__control {
margin-bottom: 0;

select {
padding-right: 20px;
}
}

.bc-form__actions {
margin-top: 0;
width: auto;
margin-left: 16px;

.bc-btn {
border: 1px solid transparent;
}
}
}
5 changes: 0 additions & 5 deletions assets/pcss/wp-themes/_twenty-twenty-theme.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,6 @@
}
}

/* Case: All BC related buttons should inherit the bc styles from the customizer. */
button:not(.toggle) {
background-color: inherit;
}

label.bc-product-form__quantity-label {
font-size: inherit;
}
Expand Down
57 changes: 49 additions & 8 deletions bigcommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
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.37.0
Version: 5.0.0
Author URI: https://www.bigcommerce.com/wordpress
Requires PHP: 7.4.0
Text Domain: bigcommerce
License: GPLv2 or later
*/

use BigCommerce\Pages\Login_Page;
use BigCommerce\Taxonomies\Channel\BC_Status;

define( 'BIGCOMMERCE_PHP_MINIMUM_VERSION', '7.0' );
define( 'BIGCOMMERCE_PHP_OPTIMAL_VERSION', '7.4' );
define( 'BIGCOMMERCE_WP_MINIMUM_VERSION', '4.8' );
Expand Down Expand Up @@ -43,14 +46,17 @@
*/
function bigcommerce_init() {
// Don't load on frontend for non-active channel status
if ( ! defined( 'WP_CLI' )
&& ! is_admin()
&& bigcommerce_get_primary_channel_status() !== null
&& bigcommerce_get_primary_channel_status() !== \BigCommerce\Taxonomies\Channel\BC_Status::STATUS_ACTIVE
) {
$channel_status = bigcommerce_get_primary_channel_status();
$is_front_page = ! defined( 'WP_CLI' ) && ! is_admin() && $channel_status !== null;
// Don't load on frontend for non-active channel status
if ( $is_front_page && ! in_array( $channel_status, [ BC_Status::STATUS_ACTIVE, BC_Status::STATUS_PRE_LAUNCH ] ) ) {
return;
}

if ( ! defined( 'DOING_CRON' ) && $is_front_page && $channel_status === BC_Status::STATUS_PRE_LAUNCH && ! current_user_can( 'publish_posts' ) ) {
handle_404_redirect_in_prelaunch();
return;
}
$container = new \Pimple\Container( [ 'plugin_file' => __FILE__ ] );
$plugin = \BigCommerce\Plugin::instance( $container );
$plugin->init();
Expand All @@ -66,6 +72,41 @@ function bigcommerce_init() {
return $plugin;
}

function handle_404_redirect_in_prelaunch() {
// We have to do that here because we don't initialize the plugin in case of prelaunch status
add_filter( 'pre_handle_404', function ( $preempt ) {
if ( is_admin() || ! ( is_page() && is_main_query() ) ) {
return $preempt;
}

$plugin_pages = [
\BigCommerce\Pages\Account_Page::SLUG,
\BigCommerce\Pages\Address_Page::SLUG,
\BigCommerce\Pages\Cart_Page::SLUG,
\BigCommerce\Pages\Check_Balance_Page::SLUG,
\BigCommerce\Pages\Checkout_Complete_Page::SLUG,
\BigCommerce\Pages\Checkout_Page::SLUG,
\BigCommerce\Pages\Login_Page::SLUG,
\BigCommerce\Pages\Gift_Certificate_Page::SLUG,
\BigCommerce\Pages\Orders_Page::SLUG,
\BigCommerce\Pages\Registration_Page::SLUG,
\BigCommerce\Pages\Shipping_Returns_Page::SLUG,
\BigCommerce\Pages\Wishlist_Page::SLUG
];

if ( ! in_array( get_queried_object()->post_name, $plugin_pages ) ) {
return $preempt;
}

global $wp_query;
$wp_query->set_404();
status_header( 404 );
nocache_headers();

return '';
}, 10, 1 );
}

function bigcommerce() {
try {
return \BigCommerce\Plugin::instance();
Expand Down Expand Up @@ -100,7 +141,7 @@ function bigcommerce_get_env( $key ) {
function bigcommerce_get_primary_channel_status() {
$cache_key = 'bigcommerce_primary_channel_status';
$status = wp_cache_get( $cache_key );
if ( $status === false ) {
if ( empty( $status ) ) {
global $wpdb;

$sql = "SELECT tm.meta_value
Expand All @@ -110,7 +151,7 @@ function bigcommerce_get_primary_channel_status() {

$status = $wpdb->get_var( $wpdb->prepare(
$sql,
\BigCommerce\Taxonomies\Channel\BC_Status::STATUS,
BC_Status::STATUS,
\BigCommerce\Taxonomies\Channel\Channel::STATUS,
\BigCommerce\Taxonomies\Channel\Channel::STATUS_PRIMARY
) );
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.11.02.06.2023');
define('BIGCOMMERCE_ASSETS_BUILD_TIMESTAMP', '6.15.02.15.2023');
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: 6.0.3
Stable tag: 4.37.0
Stable tag: 5.0.0
Requires PHP: 7.4.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Expand Down
43 changes: 40 additions & 3 deletions src/BigCommerce/Accounts/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
use Bigcommerce\Api\Resources\Address;
use Bigcommerce\Api\Resources\Order;
use Bigcommerce\Api\Resources\OrderProduct;
use BigCommerce\Import\Processors\Default_Customer_Group;
use BigCommerce\Logging\Error_Log;
use BigCommerce\Settings\Sections\Troubleshooting_Diagnostics;
use BigCommerce\Taxonomies\Channel\Channel;
use BigCommerce\Taxonomies\Channel\Connections;

/**
* Class Customer
Expand Down Expand Up @@ -335,10 +339,12 @@ public function set_customer_id( $customer_id ) {
public function get_group_id() {
$customer_id = is_user_logged_in() || defined( 'DOING_CRON' ) ? get_user_option( self::CUSTOMER_ID_META, $this->wp_user_id ) : 0;
if ( ! $customer_id ) {
$default_guest_group = $this->get_guests_default_group();
$default_guest_group = ! empty( $default_guest_group ) ? reset( $default_guest_group ) : null;
/**
* This filter is documented in src/BigCommerce/Accounts/Customer.php
*/
return apply_filters( 'bigcommerce/customer/group_id', null, $this );
return apply_filters( 'bigcommerce/customer/group_id', $default_guest_group ?: null, $this );
}
$transient_key = sprintf( 'bccustomergroup%d', $customer_id );
$group_id = get_transient( $transient_key );
Expand All @@ -349,14 +355,17 @@ public function get_group_id() {
$group_id = isset( $profile['customer_group_id'] ) ? absint( $profile['customer_group_id'] ) : 0;
$expiration = get_option( Troubleshooting_Diagnostics::USERS_TRANSIENT, 12 * HOUR_IN_SECONDS ); // TODO: a future webhook to flush this cache when the customer's group changes
if ( $group_id === 0 ) {
set_transient( $transient_key, 'zero', $expiration ); // workaround for storing empty values in cache
$default_group = get_option( Default_Customer_Group::DEFAULT_GROUP, 0 );
$value = $default_group ?: 'zero';

set_transient( $transient_key, $value, $expiration ); // workaround for storing empty values in cache
} else {
set_transient( $transient_key, $group_id, $expiration );
}
}

if ( $group_id === 'zero' ) {
$group_id = 0;
$group_id = get_option( Default_Customer_Group::DEFAULT_GROUP, 0 );
}

/**
Expand All @@ -370,6 +379,34 @@ public function get_group_id() {
return absint( $group_id );
}

/**
* @return array|null
*/
public function get_guests_default_group() {
$args = [
'is_group_for_guests' => true,
];
$query = '?' . http_build_query( $args );

$customer_groups = Client::getCustomerGroups( $query );

if ( empty( $customer_groups ) ) {
do_action( 'bigcommerce/log', Error_Log::INFO, __( 'Customer groups are empty', 'bigcommerce' ), [] );
return null;
}
$connections = new Connections();
$channel = $connections->current();
$channel_id = get_term_meta( $channel->term_id, Channel::CHANNEL_ID, true );
return array_filter( array_map( function ( $group ) use ( $channel_id ) {
// Exit if group is not default
if ( ( int ) $group->channel_id !== ( int ) $channel_id ) {
return;
}

return $group->id;
}, $customer_groups ) );
}

/**
* Get the customer group associated with this customer
*
Expand Down
Loading

0 comments on commit 8e11122

Please sign in to comment.