2019-12-03 14:12:46 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2020-08-13 13:24:51 +00:00
|
|
|
import classnames from 'classnames';
|
2019-12-16 14:59:16 +00:00
|
|
|
import { __ } from '@wordpress/i18n';
|
2020-03-04 15:13:38 +00:00
|
|
|
import { InspectorControls } from '@wordpress/block-editor';
|
2020-03-05 13:06:47 +00:00
|
|
|
import {
|
|
|
|
PanelBody,
|
|
|
|
ToggleControl,
|
|
|
|
CheckboxControl,
|
2020-03-06 12:20:17 +00:00
|
|
|
Notice,
|
2020-04-06 15:35:09 +00:00
|
|
|
Disabled,
|
2020-03-05 13:06:47 +00:00
|
|
|
} from '@wordpress/components';
|
2020-03-06 11:43:40 +00:00
|
|
|
import BlockErrorBoundary from '@woocommerce/base-components/block-error-boundary';
|
2020-03-06 12:20:17 +00:00
|
|
|
import {
|
|
|
|
PRIVACY_URL,
|
|
|
|
TERMS_URL,
|
2020-03-16 16:38:24 +00:00
|
|
|
CHECKOUT_PAGE_ID,
|
2020-11-05 02:22:43 +00:00
|
|
|
CHECKOUT_ALLOWS_SIGNUP,
|
2020-03-06 12:20:17 +00:00
|
|
|
} from '@woocommerce/block-settings';
|
2020-12-15 15:10:24 +00:00
|
|
|
import { isWcVersion, getAdminLink } from '@woocommerce/settings';
|
2020-09-26 13:51:21 +00:00
|
|
|
import { createInterpolateElement } from 'wordpress-element';
|
2020-04-22 16:44:12 +00:00
|
|
|
import { useRef } from '@wordpress/element';
|
2020-09-18 10:27:54 +00:00
|
|
|
import {
|
|
|
|
EditorProvider,
|
|
|
|
useEditorContext,
|
|
|
|
StoreNoticesProvider,
|
|
|
|
} from '@woocommerce/base-context';
|
2021-03-19 10:05:42 +00:00
|
|
|
import { CartCheckoutFeedbackPrompt } from '@woocommerce/editor-components/feedback-prompt';
|
2020-09-02 08:21:46 +00:00
|
|
|
import PageSelector from '@woocommerce/editor-components/page-selector';
|
2021-03-19 10:05:42 +00:00
|
|
|
import { CartCheckoutCompatibilityNotice } from '@woocommerce/editor-components/compatibility-notices';
|
2020-04-08 15:03:39 +00:00
|
|
|
import {
|
|
|
|
previewCart,
|
2020-04-15 00:05:01 +00:00
|
|
|
previewSavedPaymentMethods,
|
2020-04-08 15:03:39 +00:00
|
|
|
} from '@woocommerce/resource-previews';
|
2019-12-03 14:12:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import Block from './block.js';
|
2019-12-06 13:18:55 +00:00
|
|
|
import './editor.scss';
|
2019-12-03 14:12:46 +00:00
|
|
|
|
2020-03-16 16:38:24 +00:00
|
|
|
const BlockSettings = ( { attributes, setAttributes } ) => {
|
2020-03-05 13:06:47 +00:00
|
|
|
const {
|
|
|
|
showCompanyField,
|
2020-04-21 10:51:11 +00:00
|
|
|
showApartmentField,
|
2020-03-05 13:06:47 +00:00
|
|
|
showPhoneField,
|
|
|
|
requireCompanyField,
|
|
|
|
requirePhoneField,
|
Support "create account" option in checkout block (https://github.com/woocommerce/woocommerce-blocks/pull/2851)
* prototype 'create account' checkbox in checkout block
* expose store config for generating password/username to blocks:
+ use FILTER_VALIDATE_BOOLEAN instead of hard-coded `yes`
* stub out signup form in checkout block
* context / provider to store checkout signup form data
* revert signup form - checkout block will always generate username etc
* persist signup checkbox in checkout state & pass to checkout API
* add `create_account` param to order API, fix name in client POST
* handle creating user account as part of order (first cut)
* ensure the order is associated with the new customer
* only show 'create account' checkbox when appropriate (guest checkout)
* remove unnecessary username/password variables
* refactor account-creation logic into functions:
- clarify inputs and outputs
- use RouteException for error handling
- use woo options directly, avoid dependency on WC_Checkout
* update "email exists" error message to use existing error message text
* handle all known errors from wc_create_new_customer + use core message
* only show "create account" checkbox to shopper when necessary:
- if guest checkout is disabled, user must create account - not optional
* only show "create account" if account creation is optional:
- fixes incorrect logic in previous commit
- add some comments to clarify
* fix create account logic in API when checkout requires account:
- use correct woo setting option name
- reverse logic to match option = allow guest false means registration required
* strip html tags from create account error messages
* temporarily force enable autogenerate user/pass in new account API
* fix rebase errors
* add new allowCreateAccount attribute in checkout block
* show/hide `Create account` checkbox dependent on block attribute:
- previously was dependent on store setting
* new create user API, with set initial password email (first cut):
- use core register_new_user for creating the user
- this triggers core "set new password" email
- generate username using logic lifted from WC core
- rough cut, lots to tidy/polish here
* remove alternative/unused create account function
* set `Customer` role for signups during checkout
* eslint fix - switch case break
* remove comments that mirror code & might go stale
* tidy func comment
* remove unused function
* use store setting `allow signup` for default value of new block option
* refactor order signup logic to service class first cut:
- new CreateAccount service
- hook up via custom action (for now at least)
- paste over existing create account logic (temporary - will be replaced)
* adapt wc_create_new_customer logic in CreateAccount service (WIP)
* set default_password_nag on new account + throw instead of WP_Error
* rename `createAccount` => `shouldCreateAccount` to clarify meaning
* fix checkout block - renamed `shouldCreateAccount` (missed in prev commit)
* prototype sending alternative email template for checkout signup
* add magic link to set password to blocks new account html email
* tidy up new account email templates - set password link, subject/heading
* use same id so merchant setting tweaks apply to our new improved email
* remove logging
* code tidies in CreateAccount service:
- remove unnecessary constructor
- type-hint in should_create_customer_account
- streamline logic in should_create_customer_account - remove
unnecessary `empty` check
- add comments to illuminate different use-cases handled by should_create_customer_account
* don't provide password to new account email templates (no longer used)
* declare dependencies in root namespace
* code tidies on new account email class:
- correct namespace and camelcase name
- declare class in file, don't instantiate; instantiate in client code
(CreateAccount service) when used
- no require/file import, use `use`
* move CustomerNewEmail to folder matching namespace
* use Package->get_path for email template paths:
- CreateAccount service now depends on Package
- CreateAccount passes Package to email class so it can use `get_path`
- note: CustomerNewAccount is not registered with DI container as it
needs to be instantiated after Woo init (for `WC_Email`)
- shift email templates to {plugin}/templates, consistent with WP
convention
* call CreateAccount::from_order_request directly, no custom hook:
- custom hook is not appropriate as we may not want to allow
extensibility in this way - TBD
* add appropriate margin above create account checkbox
* remove unnecessary direct-access protection
* generalise name of error-handling method
* simplify CustomerNewAccount - instantiate directly, when needed
* remove unused new_account_email member - now instantiated on demand
* numerous fixes and updates due to rebase changes
* fix typo in name of CustomerNewAccount php file (missing `n`)
* experiment - link to lost-password form in my-account (prototype branded screen)
* Revert "experiment - link to lost-password form in my-account (prototype branded screen)"
This reverts commit e1dc6dd5e9f0218ede81da92188d813c2d0856d9.
* feature gate CreateAccount service init to dev build only +
+ remove stale comment
* feature gate front end "Create account" checkbox to feature plugin only
* feature gate editor "allow signup" option to dev build only
* feature gate checkout api create account - dev build only
* tweak feature gating PHP logic so it's robust:
- all PHP feature gating is in the service class
- all publicly-available methods return early if feature gate off
- Checkout rest API transparently calls service - no explicit feature
gate at API level
* ensure frontend/editor features are feature gated (isExperimentalBuild is a function)
* feature gate value of checkoutAllowsSignup - can only be true in feature plugin
* fix a / an typo in comment
Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com>
* remove commented code
* hello world unit test (doesn't test anything yet)
* add a command for running unit tests when container already up:
- this should probably move to another PR/branch
* basic tests of core logic in CreateAccount service
* import isExperimentalBuild direct:
- import from alias package was causing an issue, likely a dependency cycle
* refactor from_order_request to return new user ID so it's easier to test
* test creating a customer from an order + rest request:
- i.e. a full end-to-end integration test
* delete redundant test and tidy comments
* generalise test to provider format
* refactor create-dup-user err test to use same approach as success test
* add test for when user should not be created
* don't hard-code options in "create" test, remove redundant provider in no-account-requested test
* de-generalise "user already signed up" test
* add test for malformed email
* flesh out & comment successful signup tests
* flesh out "invalid email" tests
* clarify no account requested test comment
* remove phpunit:quick - I don't think it's needed
* add comment explaining this is an integration test
* experiment – disable feature flag, is this why the tests are failing?
* revert test commit - restore feature gate (experimental flag)
* skip all tests if CreateAccount is disabled due to feature flag
* d'oh - expose CreateAccount:is_feature_enabled so can be used in tests
* add jsdoc for checkout-state shouldCreateAccount field
* remove unnecessary comment + fix whitespace/indentation
* simulate logged-out user for createaccount signup tests
* use a single, compound if statement for early return (review nitpick)
* don't hide `checkoutAllowsSignup` store setting behind feature flag:
- the feature flag should be used to enable/disable behaviour
- it's dangerous to adjust store settings/options based on feature flag
* rejig tests so they require woocommerce_blocks_phase==3:
- make feature gate method private to avoid exposing
- remove feature flag check & test skip for other builds
- set blocks phase in travis config
* remove redundant user-logout in test setup - cleaner to just require this
* use WP function bracket style (same line)
Co-authored-by: Darren Ethier <darren@roughsmootheng.in>
Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com>
2020-10-01 02:07:16 +00:00
|
|
|
allowCreateAccount,
|
2020-07-31 15:17:01 +00:00
|
|
|
showOrderNotes,
|
2020-03-06 12:20:17 +00:00
|
|
|
showPolicyLinks,
|
2020-03-16 16:38:24 +00:00
|
|
|
showReturnToCart,
|
|
|
|
cartPageId,
|
2020-08-14 11:08:16 +00:00
|
|
|
hasDarkControls,
|
2020-03-05 13:06:47 +00:00
|
|
|
} = attributes;
|
2020-03-16 16:38:24 +00:00
|
|
|
const { currentPostId } = useEditorContext();
|
2020-04-22 16:44:12 +00:00
|
|
|
const { current: savedCartPageId } = useRef( cartPageId );
|
2020-10-15 01:13:49 +00:00
|
|
|
// Checkout signup is feature gated to WooCommerce 4.7 and newer;
|
|
|
|
// uses updated my-account/lost-password screen from 4.7+ for
|
|
|
|
// setting initial password.
|
2020-10-28 21:42:49 +00:00
|
|
|
// Also implicitly gated to feature plugin, because Checkout
|
|
|
|
// block is gated to plugin
|
2020-11-05 02:22:43 +00:00
|
|
|
const showCreateAccountOption =
|
2020-12-15 15:10:24 +00:00
|
|
|
CHECKOUT_ALLOWS_SIGNUP && isWcVersion( '4.7.0', '>=' );
|
2019-12-03 14:12:46 +00:00
|
|
|
return (
|
2020-03-16 16:38:24 +00:00
|
|
|
<InspectorControls>
|
|
|
|
{ currentPostId !== CHECKOUT_PAGE_ID && (
|
|
|
|
<Notice
|
|
|
|
className="wc-block-checkout__page-notice"
|
|
|
|
isDismissible={ false }
|
|
|
|
status="warning"
|
2020-03-05 13:06:47 +00:00
|
|
|
>
|
2020-09-26 13:51:21 +00:00
|
|
|
{ createInterpolateElement(
|
2020-03-16 16:38:24 +00:00
|
|
|
__(
|
|
|
|
'If you would like to use this block as your default checkout you must update your <a>page settings in WooCommerce</a>.',
|
2020-03-05 13:06:47 +00:00
|
|
|
'woo-gutenberg-products-block'
|
2020-03-16 16:38:24 +00:00
|
|
|
),
|
|
|
|
{
|
|
|
|
a: (
|
|
|
|
// eslint-disable-next-line jsx-a11y/anchor-has-content
|
|
|
|
<a
|
|
|
|
href={ getAdminLink(
|
|
|
|
'admin.php?page=wc-settings&tab=advanced'
|
|
|
|
) }
|
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
/>
|
|
|
|
),
|
|
|
|
}
|
|
|
|
) }
|
|
|
|
</Notice>
|
|
|
|
) }
|
|
|
|
<PanelBody
|
2020-05-05 21:25:41 +00:00
|
|
|
title={ __(
|
|
|
|
'Address options',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
2020-03-16 16:38:24 +00:00
|
|
|
>
|
|
|
|
<p className="wc-block-checkout__controls-text">
|
|
|
|
{ __(
|
2020-05-05 21:25:41 +00:00
|
|
|
'Include additional address fields in the checkout form.',
|
2020-03-16 16:38:24 +00:00
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
</p>
|
|
|
|
<ToggleControl
|
|
|
|
label={ __( 'Company', 'woo-gutenberg-products-block' ) }
|
|
|
|
checked={ showCompanyField }
|
|
|
|
onChange={ () =>
|
|
|
|
setAttributes( {
|
|
|
|
showCompanyField: ! showCompanyField,
|
|
|
|
} )
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
{ showCompanyField && (
|
|
|
|
<CheckboxControl
|
2020-03-05 13:06:47 +00:00
|
|
|
label={ __(
|
2020-03-16 16:38:24 +00:00
|
|
|
'Require company name?',
|
2020-03-05 13:06:47 +00:00
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
2020-03-16 16:38:24 +00:00
|
|
|
checked={ requireCompanyField }
|
2020-03-05 13:06:47 +00:00
|
|
|
onChange={ () =>
|
|
|
|
setAttributes( {
|
2020-03-16 16:38:24 +00:00
|
|
|
requireCompanyField: ! requireCompanyField,
|
2020-03-05 13:06:47 +00:00
|
|
|
} )
|
|
|
|
}
|
2020-03-16 16:38:24 +00:00
|
|
|
className="components-base-control--nested"
|
2020-03-05 13:06:47 +00:00
|
|
|
/>
|
2020-03-16 16:38:24 +00:00
|
|
|
) }
|
|
|
|
<ToggleControl
|
|
|
|
label={ __(
|
|
|
|
'Apartment, suite, etc.',
|
|
|
|
'woo-gutenberg-products-block'
|
2020-03-05 13:06:47 +00:00
|
|
|
) }
|
2020-04-21 10:51:11 +00:00
|
|
|
checked={ showApartmentField }
|
2020-03-16 16:38:24 +00:00
|
|
|
onChange={ () =>
|
|
|
|
setAttributes( {
|
2020-04-21 10:51:11 +00:00
|
|
|
showApartmentField: ! showApartmentField,
|
2020-03-16 16:38:24 +00:00
|
|
|
} )
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<ToggleControl
|
|
|
|
label={ __( 'Phone', 'woo-gutenberg-products-block' ) }
|
|
|
|
checked={ showPhoneField }
|
|
|
|
onChange={ () =>
|
|
|
|
setAttributes( {
|
|
|
|
showPhoneField: ! showPhoneField,
|
|
|
|
} )
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
{ showPhoneField && (
|
|
|
|
<CheckboxControl
|
2020-03-05 13:06:47 +00:00
|
|
|
label={ __(
|
2020-03-16 16:38:24 +00:00
|
|
|
'Require phone number?',
|
2020-03-05 13:06:47 +00:00
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
2020-03-16 16:38:24 +00:00
|
|
|
checked={ requirePhoneField }
|
2020-03-05 13:06:47 +00:00
|
|
|
onChange={ () =>
|
|
|
|
setAttributes( {
|
2020-03-16 16:38:24 +00:00
|
|
|
requirePhoneField: ! requirePhoneField,
|
2020-03-05 13:06:47 +00:00
|
|
|
} )
|
|
|
|
}
|
2020-03-16 16:38:24 +00:00
|
|
|
className="components-base-control--nested"
|
2020-03-05 13:06:47 +00:00
|
|
|
/>
|
2020-03-16 16:38:24 +00:00
|
|
|
) }
|
|
|
|
</PanelBody>
|
2020-10-15 01:13:49 +00:00
|
|
|
{ showCreateAccountOption && (
|
Support "create account" option in checkout block (https://github.com/woocommerce/woocommerce-blocks/pull/2851)
* prototype 'create account' checkbox in checkout block
* expose store config for generating password/username to blocks:
+ use FILTER_VALIDATE_BOOLEAN instead of hard-coded `yes`
* stub out signup form in checkout block
* context / provider to store checkout signup form data
* revert signup form - checkout block will always generate username etc
* persist signup checkbox in checkout state & pass to checkout API
* add `create_account` param to order API, fix name in client POST
* handle creating user account as part of order (first cut)
* ensure the order is associated with the new customer
* only show 'create account' checkbox when appropriate (guest checkout)
* remove unnecessary username/password variables
* refactor account-creation logic into functions:
- clarify inputs and outputs
- use RouteException for error handling
- use woo options directly, avoid dependency on WC_Checkout
* update "email exists" error message to use existing error message text
* handle all known errors from wc_create_new_customer + use core message
* only show "create account" checkbox to shopper when necessary:
- if guest checkout is disabled, user must create account - not optional
* only show "create account" if account creation is optional:
- fixes incorrect logic in previous commit
- add some comments to clarify
* fix create account logic in API when checkout requires account:
- use correct woo setting option name
- reverse logic to match option = allow guest false means registration required
* strip html tags from create account error messages
* temporarily force enable autogenerate user/pass in new account API
* fix rebase errors
* add new allowCreateAccount attribute in checkout block
* show/hide `Create account` checkbox dependent on block attribute:
- previously was dependent on store setting
* new create user API, with set initial password email (first cut):
- use core register_new_user for creating the user
- this triggers core "set new password" email
- generate username using logic lifted from WC core
- rough cut, lots to tidy/polish here
* remove alternative/unused create account function
* set `Customer` role for signups during checkout
* eslint fix - switch case break
* remove comments that mirror code & might go stale
* tidy func comment
* remove unused function
* use store setting `allow signup` for default value of new block option
* refactor order signup logic to service class first cut:
- new CreateAccount service
- hook up via custom action (for now at least)
- paste over existing create account logic (temporary - will be replaced)
* adapt wc_create_new_customer logic in CreateAccount service (WIP)
* set default_password_nag on new account + throw instead of WP_Error
* rename `createAccount` => `shouldCreateAccount` to clarify meaning
* fix checkout block - renamed `shouldCreateAccount` (missed in prev commit)
* prototype sending alternative email template for checkout signup
* add magic link to set password to blocks new account html email
* tidy up new account email templates - set password link, subject/heading
* use same id so merchant setting tweaks apply to our new improved email
* remove logging
* code tidies in CreateAccount service:
- remove unnecessary constructor
- type-hint in should_create_customer_account
- streamline logic in should_create_customer_account - remove
unnecessary `empty` check
- add comments to illuminate different use-cases handled by should_create_customer_account
* don't provide password to new account email templates (no longer used)
* declare dependencies in root namespace
* code tidies on new account email class:
- correct namespace and camelcase name
- declare class in file, don't instantiate; instantiate in client code
(CreateAccount service) when used
- no require/file import, use `use`
* move CustomerNewEmail to folder matching namespace
* use Package->get_path for email template paths:
- CreateAccount service now depends on Package
- CreateAccount passes Package to email class so it can use `get_path`
- note: CustomerNewAccount is not registered with DI container as it
needs to be instantiated after Woo init (for `WC_Email`)
- shift email templates to {plugin}/templates, consistent with WP
convention
* call CreateAccount::from_order_request directly, no custom hook:
- custom hook is not appropriate as we may not want to allow
extensibility in this way - TBD
* add appropriate margin above create account checkbox
* remove unnecessary direct-access protection
* generalise name of error-handling method
* simplify CustomerNewAccount - instantiate directly, when needed
* remove unused new_account_email member - now instantiated on demand
* numerous fixes and updates due to rebase changes
* fix typo in name of CustomerNewAccount php file (missing `n`)
* experiment - link to lost-password form in my-account (prototype branded screen)
* Revert "experiment - link to lost-password form in my-account (prototype branded screen)"
This reverts commit e1dc6dd5e9f0218ede81da92188d813c2d0856d9.
* feature gate CreateAccount service init to dev build only +
+ remove stale comment
* feature gate front end "Create account" checkbox to feature plugin only
* feature gate editor "allow signup" option to dev build only
* feature gate checkout api create account - dev build only
* tweak feature gating PHP logic so it's robust:
- all PHP feature gating is in the service class
- all publicly-available methods return early if feature gate off
- Checkout rest API transparently calls service - no explicit feature
gate at API level
* ensure frontend/editor features are feature gated (isExperimentalBuild is a function)
* feature gate value of checkoutAllowsSignup - can only be true in feature plugin
* fix a / an typo in comment
Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com>
* remove commented code
* hello world unit test (doesn't test anything yet)
* add a command for running unit tests when container already up:
- this should probably move to another PR/branch
* basic tests of core logic in CreateAccount service
* import isExperimentalBuild direct:
- import from alias package was causing an issue, likely a dependency cycle
* refactor from_order_request to return new user ID so it's easier to test
* test creating a customer from an order + rest request:
- i.e. a full end-to-end integration test
* delete redundant test and tidy comments
* generalise test to provider format
* refactor create-dup-user err test to use same approach as success test
* add test for when user should not be created
* don't hard-code options in "create" test, remove redundant provider in no-account-requested test
* de-generalise "user already signed up" test
* add test for malformed email
* flesh out & comment successful signup tests
* flesh out "invalid email" tests
* clarify no account requested test comment
* remove phpunit:quick - I don't think it's needed
* add comment explaining this is an integration test
* experiment – disable feature flag, is this why the tests are failing?
* revert test commit - restore feature gate (experimental flag)
* skip all tests if CreateAccount is disabled due to feature flag
* d'oh - expose CreateAccount:is_feature_enabled so can be used in tests
* add jsdoc for checkout-state shouldCreateAccount field
* remove unnecessary comment + fix whitespace/indentation
* simulate logged-out user for createaccount signup tests
* use a single, compound if statement for early return (review nitpick)
* don't hide `checkoutAllowsSignup` store setting behind feature flag:
- the feature flag should be used to enable/disable behaviour
- it's dangerous to adjust store settings/options based on feature flag
* rejig tests so they require woocommerce_blocks_phase==3:
- make feature gate method private to avoid exposing
- remove feature flag check & test skip for other builds
- set blocks phase in travis config
* remove redundant user-logout in test setup - cleaner to just require this
* use WP function bracket style (same line)
Co-authored-by: Darren Ethier <darren@roughsmootheng.in>
Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com>
2020-10-01 02:07:16 +00:00
|
|
|
<PanelBody
|
|
|
|
title={ __(
|
|
|
|
'Account options',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
>
|
|
|
|
<ToggleControl
|
|
|
|
label={ __(
|
2020-10-22 13:49:55 +00:00
|
|
|
'Allow shoppers to sign up for a user account during checkout',
|
Support "create account" option in checkout block (https://github.com/woocommerce/woocommerce-blocks/pull/2851)
* prototype 'create account' checkbox in checkout block
* expose store config for generating password/username to blocks:
+ use FILTER_VALIDATE_BOOLEAN instead of hard-coded `yes`
* stub out signup form in checkout block
* context / provider to store checkout signup form data
* revert signup form - checkout block will always generate username etc
* persist signup checkbox in checkout state & pass to checkout API
* add `create_account` param to order API, fix name in client POST
* handle creating user account as part of order (first cut)
* ensure the order is associated with the new customer
* only show 'create account' checkbox when appropriate (guest checkout)
* remove unnecessary username/password variables
* refactor account-creation logic into functions:
- clarify inputs and outputs
- use RouteException for error handling
- use woo options directly, avoid dependency on WC_Checkout
* update "email exists" error message to use existing error message text
* handle all known errors from wc_create_new_customer + use core message
* only show "create account" checkbox to shopper when necessary:
- if guest checkout is disabled, user must create account - not optional
* only show "create account" if account creation is optional:
- fixes incorrect logic in previous commit
- add some comments to clarify
* fix create account logic in API when checkout requires account:
- use correct woo setting option name
- reverse logic to match option = allow guest false means registration required
* strip html tags from create account error messages
* temporarily force enable autogenerate user/pass in new account API
* fix rebase errors
* add new allowCreateAccount attribute in checkout block
* show/hide `Create account` checkbox dependent on block attribute:
- previously was dependent on store setting
* new create user API, with set initial password email (first cut):
- use core register_new_user for creating the user
- this triggers core "set new password" email
- generate username using logic lifted from WC core
- rough cut, lots to tidy/polish here
* remove alternative/unused create account function
* set `Customer` role for signups during checkout
* eslint fix - switch case break
* remove comments that mirror code & might go stale
* tidy func comment
* remove unused function
* use store setting `allow signup` for default value of new block option
* refactor order signup logic to service class first cut:
- new CreateAccount service
- hook up via custom action (for now at least)
- paste over existing create account logic (temporary - will be replaced)
* adapt wc_create_new_customer logic in CreateAccount service (WIP)
* set default_password_nag on new account + throw instead of WP_Error
* rename `createAccount` => `shouldCreateAccount` to clarify meaning
* fix checkout block - renamed `shouldCreateAccount` (missed in prev commit)
* prototype sending alternative email template for checkout signup
* add magic link to set password to blocks new account html email
* tidy up new account email templates - set password link, subject/heading
* use same id so merchant setting tweaks apply to our new improved email
* remove logging
* code tidies in CreateAccount service:
- remove unnecessary constructor
- type-hint in should_create_customer_account
- streamline logic in should_create_customer_account - remove
unnecessary `empty` check
- add comments to illuminate different use-cases handled by should_create_customer_account
* don't provide password to new account email templates (no longer used)
* declare dependencies in root namespace
* code tidies on new account email class:
- correct namespace and camelcase name
- declare class in file, don't instantiate; instantiate in client code
(CreateAccount service) when used
- no require/file import, use `use`
* move CustomerNewEmail to folder matching namespace
* use Package->get_path for email template paths:
- CreateAccount service now depends on Package
- CreateAccount passes Package to email class so it can use `get_path`
- note: CustomerNewAccount is not registered with DI container as it
needs to be instantiated after Woo init (for `WC_Email`)
- shift email templates to {plugin}/templates, consistent with WP
convention
* call CreateAccount::from_order_request directly, no custom hook:
- custom hook is not appropriate as we may not want to allow
extensibility in this way - TBD
* add appropriate margin above create account checkbox
* remove unnecessary direct-access protection
* generalise name of error-handling method
* simplify CustomerNewAccount - instantiate directly, when needed
* remove unused new_account_email member - now instantiated on demand
* numerous fixes and updates due to rebase changes
* fix typo in name of CustomerNewAccount php file (missing `n`)
* experiment - link to lost-password form in my-account (prototype branded screen)
* Revert "experiment - link to lost-password form in my-account (prototype branded screen)"
This reverts commit e1dc6dd5e9f0218ede81da92188d813c2d0856d9.
* feature gate CreateAccount service init to dev build only +
+ remove stale comment
* feature gate front end "Create account" checkbox to feature plugin only
* feature gate editor "allow signup" option to dev build only
* feature gate checkout api create account - dev build only
* tweak feature gating PHP logic so it's robust:
- all PHP feature gating is in the service class
- all publicly-available methods return early if feature gate off
- Checkout rest API transparently calls service - no explicit feature
gate at API level
* ensure frontend/editor features are feature gated (isExperimentalBuild is a function)
* feature gate value of checkoutAllowsSignup - can only be true in feature plugin
* fix a / an typo in comment
Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com>
* remove commented code
* hello world unit test (doesn't test anything yet)
* add a command for running unit tests when container already up:
- this should probably move to another PR/branch
* basic tests of core logic in CreateAccount service
* import isExperimentalBuild direct:
- import from alias package was causing an issue, likely a dependency cycle
* refactor from_order_request to return new user ID so it's easier to test
* test creating a customer from an order + rest request:
- i.e. a full end-to-end integration test
* delete redundant test and tidy comments
* generalise test to provider format
* refactor create-dup-user err test to use same approach as success test
* add test for when user should not be created
* don't hard-code options in "create" test, remove redundant provider in no-account-requested test
* de-generalise "user already signed up" test
* add test for malformed email
* flesh out & comment successful signup tests
* flesh out "invalid email" tests
* clarify no account requested test comment
* remove phpunit:quick - I don't think it's needed
* add comment explaining this is an integration test
* experiment – disable feature flag, is this why the tests are failing?
* revert test commit - restore feature gate (experimental flag)
* skip all tests if CreateAccount is disabled due to feature flag
* d'oh - expose CreateAccount:is_feature_enabled so can be used in tests
* add jsdoc for checkout-state shouldCreateAccount field
* remove unnecessary comment + fix whitespace/indentation
* simulate logged-out user for createaccount signup tests
* use a single, compound if statement for early return (review nitpick)
* don't hide `checkoutAllowsSignup` store setting behind feature flag:
- the feature flag should be used to enable/disable behaviour
- it's dangerous to adjust store settings/options based on feature flag
* rejig tests so they require woocommerce_blocks_phase==3:
- make feature gate method private to avoid exposing
- remove feature flag check & test skip for other builds
- set blocks phase in travis config
* remove redundant user-logout in test setup - cleaner to just require this
* use WP function bracket style (same line)
Co-authored-by: Darren Ethier <darren@roughsmootheng.in>
Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com>
2020-10-01 02:07:16 +00:00
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
checked={ allowCreateAccount }
|
|
|
|
onChange={ () =>
|
|
|
|
setAttributes( {
|
|
|
|
allowCreateAccount: ! allowCreateAccount,
|
|
|
|
} )
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</PanelBody>
|
|
|
|
) }
|
2020-07-31 15:17:01 +00:00
|
|
|
<PanelBody
|
|
|
|
title={ __( 'Order notes', 'woo-gutenberg-products-block' ) }
|
|
|
|
>
|
|
|
|
<p className="wc-block-checkout__controls-text">
|
|
|
|
{ __(
|
|
|
|
'Reduce the number of fields to checkout.',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
</p>
|
|
|
|
<ToggleControl
|
|
|
|
label={ __(
|
2020-10-22 13:49:55 +00:00
|
|
|
'Allow shoppers to optionally add order notes',
|
2020-07-31 15:17:01 +00:00
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
checked={ showOrderNotes }
|
|
|
|
onChange={ () =>
|
|
|
|
setAttributes( {
|
|
|
|
showOrderNotes: ! showOrderNotes,
|
|
|
|
} )
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</PanelBody>
|
2020-03-16 16:38:24 +00:00
|
|
|
<PanelBody
|
2020-05-05 21:25:41 +00:00
|
|
|
title={ __(
|
|
|
|
'Navigation options',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
2020-03-16 16:38:24 +00:00
|
|
|
>
|
|
|
|
<ToggleControl
|
|
|
|
label={ __(
|
|
|
|
'Show links to policies',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
help={ __(
|
2020-05-05 21:25:41 +00:00
|
|
|
'Shows links to your "terms and conditions" and "privacy policy" pages.',
|
2020-03-16 16:38:24 +00:00
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
checked={ showPolicyLinks }
|
|
|
|
onChange={ () =>
|
|
|
|
setAttributes( {
|
|
|
|
showPolicyLinks: ! showPolicyLinks,
|
|
|
|
} )
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
{ showPolicyLinks && ( ! PRIVACY_URL || ! TERMS_URL ) && (
|
|
|
|
<Notice
|
|
|
|
className="wc-block-base-control-notice"
|
|
|
|
isDismissible={ false }
|
|
|
|
>
|
2020-09-26 13:51:21 +00:00
|
|
|
{ createInterpolateElement(
|
2020-03-16 16:38:24 +00:00
|
|
|
__(
|
|
|
|
'Pages must be first setup in store settings: <a1>Privacy policy</a1>, <a2>Terms and conditions</a2>.',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
),
|
|
|
|
{
|
|
|
|
a1: (
|
|
|
|
// eslint-disable-next-line jsx-a11y/anchor-has-content
|
|
|
|
<a
|
|
|
|
href={ getAdminLink(
|
|
|
|
'admin.php?page=wc-settings&tab=account'
|
|
|
|
) }
|
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
/>
|
|
|
|
),
|
|
|
|
a2: (
|
|
|
|
// eslint-disable-next-line jsx-a11y/anchor-has-content
|
|
|
|
<a
|
|
|
|
href={ getAdminLink(
|
|
|
|
'admin.php?page=wc-settings&tab=advanced'
|
|
|
|
) }
|
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
/>
|
|
|
|
),
|
|
|
|
}
|
|
|
|
) }
|
|
|
|
</Notice>
|
|
|
|
) }
|
|
|
|
<ToggleControl
|
|
|
|
label={ __(
|
2020-05-05 21:25:41 +00:00
|
|
|
'Show a "Return to Cart" link',
|
2020-03-16 16:38:24 +00:00
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
checked={ showReturnToCart }
|
|
|
|
onChange={ () =>
|
|
|
|
setAttributes( {
|
|
|
|
showReturnToCart: ! showReturnToCart,
|
|
|
|
} )
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</PanelBody>
|
2020-04-22 16:44:12 +00:00
|
|
|
{ showReturnToCart &&
|
|
|
|
! (
|
|
|
|
currentPostId === CHECKOUT_PAGE_ID && savedCartPageId === 0
|
|
|
|
) && (
|
|
|
|
<PageSelector
|
|
|
|
pageId={ cartPageId }
|
|
|
|
setPageId={ ( id ) =>
|
|
|
|
setAttributes( { cartPageId: id } )
|
|
|
|
}
|
|
|
|
labels={ {
|
|
|
|
title: __(
|
|
|
|
'Return to Cart button',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
),
|
|
|
|
default: __(
|
|
|
|
'WooCommerce Cart Page',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
),
|
|
|
|
} }
|
|
|
|
/>
|
|
|
|
) }
|
2020-08-14 11:08:16 +00:00
|
|
|
<PanelBody title={ __( 'Style', 'woo-gutenberg-products-block' ) }>
|
|
|
|
<ToggleControl
|
|
|
|
label={ __(
|
|
|
|
'Dark mode inputs',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
help={ __(
|
|
|
|
'Inputs styled specifically for use on dark background colors.',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
checked={ hasDarkControls }
|
|
|
|
onChange={ () =>
|
|
|
|
setAttributes( {
|
|
|
|
hasDarkControls: ! hasDarkControls,
|
|
|
|
} )
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</PanelBody>
|
2020-08-09 20:18:36 +00:00
|
|
|
<CartCheckoutFeedbackPrompt />
|
2020-03-16 16:38:24 +00:00
|
|
|
</InspectorControls>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const CheckoutEditor = ( { attributes, setAttributes } ) => {
|
2020-04-08 15:03:39 +00:00
|
|
|
const { className, isPreview } = attributes;
|
2020-03-16 16:38:24 +00:00
|
|
|
return (
|
2021-03-19 10:05:42 +00:00
|
|
|
<>
|
|
|
|
<EditorProvider
|
|
|
|
previewData={ { previewCart, previewSavedPaymentMethods } }
|
2020-08-13 13:24:51 +00:00
|
|
|
>
|
2021-03-19 10:05:42 +00:00
|
|
|
<div
|
|
|
|
className={ classnames(
|
|
|
|
className,
|
|
|
|
'wp-block-woocommerce-checkout',
|
|
|
|
{
|
|
|
|
'is-editor-preview': isPreview,
|
|
|
|
}
|
2020-03-16 16:38:24 +00:00
|
|
|
) }
|
|
|
|
>
|
2021-03-19 10:05:42 +00:00
|
|
|
<BlockSettings
|
|
|
|
attributes={ attributes }
|
|
|
|
setAttributes={ setAttributes }
|
|
|
|
/>
|
|
|
|
<BlockErrorBoundary
|
|
|
|
header={ __(
|
|
|
|
'Checkout Block Error',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
text={ __(
|
|
|
|
'There was an error whilst rendering the checkout block. If this problem continues, try re-creating the block.',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
showErrorMessage={ true }
|
|
|
|
errorMessagePrefix={ __(
|
|
|
|
'Error message:',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
>
|
|
|
|
<StoreNoticesProvider context="wc/checkout">
|
|
|
|
<Disabled>
|
|
|
|
<Block attributes={ attributes } />
|
|
|
|
</Disabled>
|
|
|
|
</StoreNoticesProvider>
|
|
|
|
</BlockErrorBoundary>
|
|
|
|
</div>
|
|
|
|
</EditorProvider>
|
|
|
|
<CartCheckoutCompatibilityNotice blockName="checkout" />
|
|
|
|
</>
|
2019-12-03 14:12:46 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-03-16 16:38:24 +00:00
|
|
|
export default CheckoutEditor;
|