Skip to content

Commit a513fdc

Browse files
authored
packaged version 4.30.0 (#363)
1 parent 79462ad commit a513fdc

27 files changed

+297
-42
lines changed

CHANGELOG.md

+13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# Changelog
22

3+
## [4.30.0]
4+
5+
### Added
6+
- Allow creating customers from WordPress admin. To add new customer go to wp-admin panel Users -> Add New and create new user with Customer role
7+
8+
### Changed
9+
- Allow using embedded checkout when cart page is disabled. If embedded checkout is enabled customers will proceed to embedded checkout page
10+
- Show inventory level according to selected variant instead of show inventory for whole product. Inventory show option can be enabled via Customizer -> Single product -> Inventory Level setting
11+
12+
### Fixed
13+
- Create customer account on Bigcommerce side during registration process and store customer address
14+
315
## [4.29.0]
416

517
### Added
@@ -1783,6 +1795,7 @@
17831795
in fact, reset postdata, so far as Gutenberg 3.2.0 is concerned.
17841796

17851797

1798+
[4.30.0]: https://github.com/bigcommerce/bigcommerce-for-wordpress/compare/4.29.0...4.30.0
17861799
[4.29.0]: https://github.com/bigcommerce/bigcommerce-for-wordpress/compare/4.28.0...4.29.0
17871800
[4.28.0]: https://github.com/bigcommerce/bigcommerce-for-wordpress/compare/4.27.1...4.28.0
17881801
[4.27.1]: https://github.com/bigcommerce/bigcommerce-for-wordpress/compare/4.27.0...4.27.1

assets/css/bc-gutenberg.css

+5-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/css/bc-gutenberg.min.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/css/master.css

+5-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/css/master.min.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/js/dist/scripts.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/js/dist/scripts.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/js/src/public/product/variants.js

+19
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,24 @@ const setProductURLParameter = () => {
444444
window.history.replaceState(null, null, updateQueryVar('sku', state.sku));
445445
};
446446

447+
/**
448+
* @function setProductVariantInventory
449+
* @description Update inventory level html for selected variant
450+
*/
451+
const setProductVariantInventory = () => {
452+
if (!state.variantID || !state.sku || !el.singleWrapper || state.singleVariant) {
453+
return;
454+
}
455+
456+
const node = tools.getNodes('.bc-product__inventory-number', true, document, true)[0];
457+
458+
if (!node) {
459+
return;
460+
}
461+
462+
node.textContent = state.maxInventory;
463+
};
464+
447465
/**
448466
* @function validateTextArea
449467
* @description Listen for key presses and validate that the text meets the textarea's restrictions.
@@ -526,6 +544,7 @@ const handleSelections = (e, node = '') => {
526544
buildSelectionArray(instances.selections[productID], optionsContainer);
527545
parseVariants(instances.product[productID], instances.selections[productID]);
528546
setProductURLParameter();
547+
setProductVariantInventory();
529548
setVariantIDHiddenField(formWrapper);
530549
setSelectedVariantPrice(metaWrapper);
531550
setVariantSKU(metaWrapper);

assets/pcss/content/components/_wish-lists.pcss

+4
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,10 @@
350350
margin-bottom: 4px;
351351
}
352352

353+
.bc-wish-list-product-row__title {
354+
font-size: 1.6rem;
355+
}
356+
353357
.bc-wish-list-product-row__delete {
354358
font-size: var(--font-size-content-xs);
355359
order: 1;

bigcommerce.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Plugin Name: BigCommerce for WordPress
44
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.
55
Author: BigCommerce
6-
Version: 4.29.0
6+
Version: 4.30.0
77
Author URI: https://www.bigcommerce.com/wordpress
88
Requires PHP: 7.4.0
99
Text Domain: bigcommerce

build-timestamp.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
<?php
2-
define('BIGCOMMERCE_ASSETS_BUILD_TIMESTAMP', '6.50.06.06.2022');
2+
define('BIGCOMMERCE_ASSETS_BUILD_TIMESTAMP', '4.11.06.20.2022');

readme.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Contributors: bigcommerce, moderntribe, jbrinley, becomevocal, vincentlistrani,
33
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
44
Requires at least: 5.2
55
Tested up to: 5.9.2
6-
Stable tag: 4.29.0
6+
Stable tag: 4.30.0
77
Requires PHP: 7.4.0
88
License: GPLv2 or later
99
License URI: https://www.gnu.org/licenses/gpl-2.0.html

src/BigCommerce/Accounts/Register.php

+149
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
<?php
2+
3+
namespace BigCommerce\Accounts;
4+
5+
use BigCommerce\Api_Factory;
6+
use BigCommerce\Logging\Error_Log;
7+
use BigCommerce\Taxonomies\Channel\Channel;
8+
use BigCommerce\Taxonomies\Channel\Connections;
9+
10+
/**
11+
* Handles customer creation
12+
* @class Bigcommerce\Accounts\Register
13+
*/
14+
class Register {
15+
16+
/**
17+
* @var \BigCommerce\Api_Factory
18+
*/
19+
private $factory;
20+
21+
/**
22+
* @var \BigCommerce\Taxonomies\Channel\Connections
23+
*/
24+
private $connections;
25+
26+
public function __construct( Api_Factory $api_factory, Connections $connections ) {
27+
$this->factory = $api_factory;
28+
$this->connections = $connections;
29+
}
30+
31+
/**
32+
* Create customer if it doesn't exist on Bigcommerce
33+
*
34+
* @param $user_id
35+
* @param $userdata
36+
*/
37+
public function maybe_create_new_customer( $user_id, $userdata ) {
38+
if ( empty( $userdata['role'] ) || $userdata['role'] !== \BigCommerce\Accounts\Roles\Customer::NAME ) {
39+
return;
40+
}
41+
42+
$customer_id = get_user_meta( $user_id, Customer::CUSTOMER_ID_META, true );
43+
44+
// Customer already connected
45+
if ( ! empty( $customer_id ) ) {
46+
return;
47+
}
48+
49+
$customer_id = $this->is_customer_mail_in_use( $userdata['user_email'] );
50+
51+
if ( $customer_id ) {
52+
// Connect existing customer
53+
$customer = new Customer( $user_id );
54+
$customer->set_customer_id( $customer_id );
55+
return;
56+
}
57+
58+
$this->register_new_customer( $user_id, $userdata );
59+
}
60+
61+
/**
62+
* Check if customer email is already owned
63+
*
64+
* @param $email
65+
*
66+
* @return bool
67+
*/
68+
protected function is_customer_mail_in_use( $email ) {
69+
try {
70+
$customer_api = $this->factory->customer();
71+
$matches = $customer_api->getCustomers( [
72+
'email' => $email,
73+
] );
74+
75+
if ( ! empty( $matches ) ) {
76+
$found_customer = reset( $matches );
77+
return $found_customer->id;
78+
}
79+
80+
return false;
81+
} catch( \Exception $exception ) {
82+
do_action( 'bigcommerce/log', Error_Log::DEBUG, __( 'Could not check if user exists.', 'bigcommerce' ), [
83+
'user_email' => $email,
84+
] );
85+
do_action( 'bigcommerce/log', Error_Log::DEBUG, $exception->getMessage() , [
86+
'trace' => $exception->getTraceAsString(),
87+
] );
88+
// We are not able to check and due to this we should avoid customer creation
89+
return true;
90+
}
91+
}
92+
93+
/**
94+
* Create new customer with V3 API and associate primary channel
95+
*
96+
* @param $user_id
97+
* @param $userdata
98+
*
99+
* @return int
100+
*/
101+
protected function register_new_customer( $user_id, $userdata ) {
102+
try {
103+
$customer_api = $this->factory->customers();
104+
$channel = $this->connections->primary();
105+
$channel_id = get_term_meta( $channel->term_id, Channel::CHANNEL_ID, true );
106+
107+
$new_customer_data = [
108+
'first_name' => $userdata['first_name'] ?: $userdata['user_login'],
109+
'last_name' => $userdata['last_name'] ?: __( 'User', 'bigcommerce' ),
110+
'email' => $userdata['user_email'],
111+
'customer_group_id' => 0,
112+
'authentication' => [
113+
'force_password_reset' => true,
114+
'new_password' => $userdata['user_pass']
115+
],
116+
'origin_channel_id' => ( int ) $channel_id,
117+
'channels_ids' => [ ( int ) $channel_id ],
118+
];
119+
120+
/**
121+
* Filters customer create arguments.
122+
*
123+
* @param array $new_customer_data Customer data.
124+
*/
125+
$new_customer_data = apply_filters( 'bigcommerce/customer/create/args', $new_customer_data );
126+
127+
$response = $customer_api->customersPost( [ $new_customer_data ] );
128+
129+
if ( $response && ! empty( $response->id ) ) {
130+
$customer = new Customer( $user_id);
131+
$customer->set_customer_id( $response->id );
132+
133+
return $response->id;
134+
}
135+
} catch ( \Exception $exception ) {
136+
do_action( 'bigcommerce/log', Error_Log::DEBUG, __( 'Unable to create customer.', 'bigcommerce' ), [
137+
'user_id' => $user_id,
138+
'userdata' => $userdata,
139+
] );
140+
do_action( 'bigcommerce/log', Error_Log::DEBUG, $exception->getMessage() , [
141+
'trace' => $exception->getTraceAsString(),
142+
] );
143+
144+
}
145+
146+
return 0;
147+
}
148+
149+
}

src/BigCommerce/Cart/Buy_Now.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
namespace BigCommerce\Cart;
55

66
use BigCommerce\Api\v3\ApiException;
7+
use BigCommerce\Pages\Checkout_Page;
8+
use BigCommerce\Settings\Sections\Cart as Cart_Settings;
79

810
/**
911
* Class Buy_Now
@@ -24,6 +26,11 @@ class Buy_Now extends Add_To_Cart {
2426
* @return void
2527
*/
2628
protected function handle_response( $response, Cart $cart, $post_id, $product_id, $variant_id ) {
29+
if ( get_option( Cart_Settings::OPTION_EMBEDDED_CHECKOUT, true ) ) {
30+
wp_safe_redirect( esc_url( home_url( '/bigcommerce/checkout/' . $response->getId() ) ), 303 );
31+
exit();
32+
}
33+
2734
$checkout_url = $cart->get_checkout_url( $response->getId() );
2835
wp_redirect( $checkout_url, 303 );
2936
exit();
@@ -57,4 +64,4 @@ protected function handle_exception( ApiException $e, $cart ) {
5764
}
5865
do_action( 'bigcommerce/form/error', $error, $_POST, $cart->get_cart_url() );
5966
}
60-
}
67+
}

src/BigCommerce/Cart/Cart.php

+11-6
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function __construct( CartApi $api ) {
4343
public function get_cart_id() {
4444
$cart_id = '';
4545
$cookie = filter_input( INPUT_COOKIE, self::CART_COOKIE, FILTER_SANITIZE_STRING );
46-
if ( $cookie && get_option( Settings\Sections\Cart::OPTION_ENABLE_CART, true ) ) {
46+
if ( $cookie ) {
4747
$cart_id = $cookie;
4848
}
4949

@@ -107,12 +107,17 @@ public function add_line_item( $product_id, $options = [], $quantity = 1, $modif
107107
] );
108108
}
109109

110+
$line_request_data = [
111+
'quantity' => $quantity,
112+
'product_id' => $product_id,
113+
];
114+
115+
if ( ! empty( $option_selections ) ) {
116+
$line_request_data['option_selections'] = $option_selections;
117+
}
118+
110119
$request_data->setLineItems( [
111-
new LineItemRequestData( [
112-
'quantity' => $quantity,
113-
'product_id' => $product_id,
114-
'option_selections' => $option_selections,
115-
] ),
120+
new LineItemRequestData( $line_request_data ),
116121
] );
117122
$request_data->setGiftCertificates( [] );
118123

src/BigCommerce/Container/Accounts.php

+10
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use BigCommerce\Accounts\Customer_Group_Proxy;
99
use BigCommerce\Accounts\Nav_Menu;
1010
use BigCommerce\Accounts\Password_Reset;
11+
use BigCommerce\Accounts\Register;
1112
use BigCommerce\Accounts\Wishlists\Actions as Wishlist_Actions;
1213
use BigCommerce\Accounts\Wishlists\Add_Item_View;
1314
use BigCommerce\Accounts\Wishlists\Wishlist_Request_Parser;
@@ -26,6 +27,7 @@
2627
*/
2728
class Accounts extends Provider {
2829
const LOGIN = 'accounts.login';
30+
const REGISTER = 'accounts.register';
2931
const COUNTRIES = 'accounts.countries';
3032
const COUNTRIES_PATH = 'accounts.countries.path';
3133
const DELETE_ADDRESS = 'accounts.delete_address';
@@ -66,6 +68,10 @@ private function login( Container $container ) {
6668
return new Login( $container[ Api::FACTORY ] );
6769
};
6870

71+
$container[ self::REGISTER ] = function ( Container $container ) {
72+
return new Register( $container[ Api::FACTORY ], new Connections() );
73+
};
74+
6975
add_action( 'wp_login', $this->create_callback( 'connect_customer_id', function ( $username, $user ) use ( $container ) {
7076
$container[ self::LOGIN ]->connect_customer_id( $username, $user );
7177
} ), 10, 2 );
@@ -114,6 +120,10 @@ private function login( Container $container ) {
114120

115121
return $match;
116122
} ), 10, 4 );
123+
124+
add_action( 'user_register', $this->create_callback( 'create_customer_from_admin', function ( $user_id, $userdata ) use ( $container ) {
125+
$container[ self::REGISTER ]->maybe_create_new_customer( $user_id, $userdata );
126+
} ), 10, 2 );
117127
}
118128

119129
/**

src/BigCommerce/Container/Forms.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ private function actions( Container $container ) {
7171
} ), 10, 1 );
7272

7373
$container[ self::REGISTER ] = function ( Container $container ) {
74-
return new Registration_Handler( $container[ Compatibility::SPAM_CHECKER ] );
74+
return new Registration_Handler( $container[ Compatibility::SPAM_CHECKER ], $container[ Accounts::LOGIN] );
7575
};
7676
add_action( 'bigcommerce/form/action=' . Registration_Handler::ACTION, $this->create_callback( 'register', function ( $submission ) use ( $container ) {
7777
return $container[ self::REGISTER ]->handle_request( $submission );
@@ -142,4 +142,4 @@ private function messaging( Container $container ) {
142142
return $container[ self::MESSAGING ]->render_messages( $messages );
143143
} ), 10, 1 );
144144
}
145-
}
145+
}

src/BigCommerce/Forms/Registration_Handler.php

+12-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55

66

77
use BigCommerce\Accounts\Customer;
8+
use BigCommerce\Accounts\Login;
89
use BigCommerce\Accounts\Roles\Customer as Customer_Role;
910
use BigCommerce\Accounts\User_Profile_Settings;
11+
use BigCommerce\Container\Accounts;
1012
use BigCommerce\Pages\Account_Page;
1113
use BigCommerce\Compatibility\Spam_Checker;
1214
use BigCommerce\Settings\Sections\Account_Settings;
@@ -20,8 +22,14 @@ class Registration_Handler implements Form_Handler {
2022
*/
2123
private $spam_checker;
2224

23-
public function __construct( Spam_Checker $spam_checker ) {
25+
/**
26+
* @var \BigCommerce\Accounts\Login
27+
*/
28+
private $login;
29+
30+
public function __construct( Spam_Checker $spam_checker, Login $login ) {
2431
$this->spam_checker = $spam_checker;
32+
$this->login = $login;
2533
}
2634

2735
public function handle_request( $submission ) {
@@ -107,8 +115,9 @@ public function handle_request( $submission ) {
107115
// all future password validation will be against the API for this user
108116
update_user_meta( $user_id, User_Profile_Settings::SYNC_PASSWORD, true );
109117

110-
wp_set_current_user( $user_id );
111-
118+
/** Create customer profile */
119+
// TODO: Add connection via V3 and channels
120+
$this->login->connect_customer_id( $submission[ 'bc-register' ][ 'email' ], $user );
112121
$customer = new Customer( $user_id );
113122
$customer->add_address( $address );
114123

0 commit comments

Comments
 (0)