Merge branch 'trunk' into e2e/e2e-shopper-cart-redirection
This commit is contained in:
commit
5cb034fdc7
|
@ -1218,15 +1218,30 @@ class WC_Cart extends WC_Legacy_Cart {
|
|||
$products_qty_in_cart = $this->get_cart_item_quantities();
|
||||
|
||||
if ( isset( $products_qty_in_cart[ $product_data->get_stock_managed_by_id() ] ) && ! $product_data->has_enough_stock( $products_qty_in_cart[ $product_data->get_stock_managed_by_id() ] + $quantity ) ) {
|
||||
throw new Exception(
|
||||
sprintf(
|
||||
'<a href="%s" class="button wc-forward">%s</a> %s',
|
||||
wc_get_cart_url(),
|
||||
__( 'View cart', 'woocommerce' ),
|
||||
/* translators: 1: quantity in stock 2: current quantity */
|
||||
sprintf( __( 'You cannot add that amount to the cart — we have %1$s in stock and you already have %2$s in your cart.', 'woocommerce' ), wc_format_stock_quantity_for_display( $product_data->get_stock_quantity(), $product_data ), wc_format_stock_quantity_for_display( $products_qty_in_cart[ $product_data->get_stock_managed_by_id() ], $product_data ) )
|
||||
)
|
||||
$stock_quantity = $product_data->get_stock_quantity();
|
||||
$stock_quantity_in_cart = $products_qty_in_cart[ $product_data->get_stock_managed_by_id() ];
|
||||
|
||||
$message = sprintf(
|
||||
'<a href="%s" class="button wc-forward">%s</a> %s',
|
||||
wc_get_cart_url(),
|
||||
__( 'View cart', 'woocommerce' ),
|
||||
/* translators: 1: quantity in stock 2: current quantity */
|
||||
sprintf( __( 'You cannot add that amount to the cart — we have %1$s in stock and you already have %2$s in your cart.', 'woocommerce' ), wc_format_stock_quantity_for_display( $stock_quantity, $product_data ), wc_format_stock_quantity_for_display( $stock_quantity_in_cart, $product_data ) )
|
||||
);
|
||||
|
||||
/**
|
||||
* Filters message about product not having enough stock accounting for what's already in the cart.
|
||||
*
|
||||
* @param string $message Message.
|
||||
* @param WC_Product $product_data Product data.
|
||||
* @param int $stock_quantity Quantity remaining.
|
||||
* @param int $stock_quantity_in_cart
|
||||
*
|
||||
* @since 5.3.0
|
||||
*/
|
||||
$message = apply_filters( 'woocommerce_cart_product_not_enough_stock_already_in_cart_message', $message, $product_data, $stock_quantity, $stock_quantity_in_cart );
|
||||
|
||||
throw new Exception( $message );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
## Added
|
||||
|
||||
- Shopper Checkout Login Account
|
||||
- Shopper My Account Create Account
|
||||
- Shopper Cart Redirection
|
||||
|
||||
|
|
|
@ -77,6 +77,7 @@ The functions to access the core tests are:
|
|||
- `runSingleProductPageTest` - Shopper can view single product page in many variations (simple, variable, grouped)
|
||||
- `runVariableProductUpdateTest` - Shopper can view and update variations on a variable product
|
||||
- `runCheckoutCreateAccountTest` - Shopper can create an account during checkout
|
||||
- `runCheckoutLoginAccountTest` - Shopper can login to an account during checkout
|
||||
- `runMyAccountCreateAccountTest` - Shopper can create an account via my account page
|
||||
- `runCartRedirectionTest` - Shopper is redirected to the cart page after adding to cart
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ const runMyAccountCreateAccountTest = require( './shopper/front-end-my-account-c
|
|||
const runSingleProductPageTest = require( './shopper/front-end-single-product.test' );
|
||||
const runVariableProductUpdateTest = require( './shopper/front-end-variable-product-updates.test' );
|
||||
const runCheckoutCreateAccountTest = require( './shopper/front-end-checkout-create-account.test' );
|
||||
const runCheckoutLoginAccountTest = require( './shopper/front-end-checkout-login-account.test' );
|
||||
const runCartRedirectionTest = require( './shopper/front-end-cart-redirection.test' );
|
||||
|
||||
// Merchant tests
|
||||
|
@ -66,7 +67,8 @@ const runShopperTests = () => {
|
|||
runSingleProductPageTest();
|
||||
runVariableProductUpdateTest();
|
||||
runCheckoutCreateAccountTest();
|
||||
runCartRedirectionTest();
|
||||
runCheckoutLoginAccountTest();
|
||||
runCartRedirectionTest();
|
||||
};
|
||||
|
||||
const runMerchantTests = () => {
|
||||
|
@ -137,6 +139,7 @@ module.exports = {
|
|||
runApiTests,
|
||||
runAnalyticsPageLoadsTest,
|
||||
runCheckoutCreateAccountTest,
|
||||
runCheckoutLoginAccountTest,
|
||||
runMyAccountCreateAccountTest,
|
||||
runCartRedirectionTest,
|
||||
};
|
||||
|
|
|
@ -28,10 +28,14 @@ const runCheckoutCreateAccountTest = () => {
|
|||
beforeAll(async () => {
|
||||
await merchant.login();
|
||||
await createSimpleProduct();
|
||||
|
||||
// Set checkbox for creating an account during checkout
|
||||
await merchant.openSettings('account');
|
||||
await setCheckbox('#woocommerce_enable_signup_and_login_from_checkout');
|
||||
await settingsPageSaveChanges();
|
||||
await merchant.logout();
|
||||
|
||||
// Add simple product to cart and proceed to checkout
|
||||
await shopper.goToShop();
|
||||
await shopper.addToCartFromShopPage(simpleProductName);
|
||||
await uiUnblocked();
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
/* eslint-disable jest/no-export, jest/no-disabled-tests, jest/expect-expect */
|
||||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
const {
|
||||
shopper,
|
||||
merchant,
|
||||
createSimpleProduct,
|
||||
uiUnblocked,
|
||||
setCheckbox,
|
||||
settingsPageSaveChanges,
|
||||
} = require( '@woocommerce/e2e-utils' );
|
||||
|
||||
/**
|
||||
* External dependencies
|
||||
*/
|
||||
const {
|
||||
it,
|
||||
describe,
|
||||
beforeAll,
|
||||
} = require( '@jest/globals' );
|
||||
|
||||
const config = require('config');
|
||||
const simpleProductName = config.get('products.simple.name');
|
||||
|
||||
const runCheckoutLoginAccountTest = () => {
|
||||
describe('Shopper Checkout Login Account', () => {
|
||||
beforeAll(async () => {
|
||||
await merchant.login();
|
||||
await createSimpleProduct();
|
||||
|
||||
// Set checkbox for logging to account during checkout
|
||||
await merchant.openSettings('account');
|
||||
await setCheckbox('#woocommerce_enable_checkout_login_reminder');
|
||||
await settingsPageSaveChanges();
|
||||
await merchant.logout();
|
||||
|
||||
// Add simple product to cart and proceed to checkout
|
||||
await shopper.goToShop();
|
||||
await shopper.addToCartFromShopPage(simpleProductName);
|
||||
await uiUnblocked();
|
||||
await shopper.goToCheckout();
|
||||
});
|
||||
|
||||
it('can login to an existing account during checkout', async () => {
|
||||
// Click to login during checkout
|
||||
await page.waitForSelector('.woocommerce-form-login-toggle');
|
||||
await expect(page).toClick('.woocommerce-info > a.showlogin');
|
||||
|
||||
// Fill shopper's login credentials and proceed further
|
||||
await page.type( '#username', config.get('users.customer.username') );
|
||||
await page.type( '#password', config.get('users.customer.password') );
|
||||
|
||||
await Promise.all([
|
||||
page.waitForNavigation({waitUntil: 'networkidle0'}),
|
||||
page.click('button[name="login"]'),
|
||||
]);
|
||||
|
||||
// Place an order
|
||||
await shopper.placeOrder();
|
||||
await expect(page).toMatchElement('h1.entry-title', {text: 'Order received'});
|
||||
|
||||
// Verify the email of a logged in user
|
||||
await expect(page).toMatchElement('ul > li.email', {text: 'Email: john.doe@example.com'});
|
||||
|
||||
// Verify the user is logged in on my account page
|
||||
await shopper.gotoMyAccount();
|
||||
await expect(page.url()).toMatch('my-account/');
|
||||
await expect(page).toMatchElement('h1', {text: 'My account'});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = runCheckoutLoginAccountTest;
|
|
@ -0,0 +1,6 @@
|
|||
/*
|
||||
* Internal dependencies
|
||||
*/
|
||||
const { runCheckoutLoginAccountTest } = require( '@woocommerce/e2e-core-tests' );
|
||||
|
||||
runCheckoutLoginAccountTest();
|
Loading…
Reference in New Issue