Fix nonce issues when adding product to cart from All Products (https://github.com/woocommerce/woocommerce-blocks/pull/3598)

* Products extend cart route

* load cart in products
This commit is contained in:
Seghir Nadir 2020-12-24 12:00:51 +01:00 committed by GitHub
parent 84f83f840c
commit 3d92a61102
5 changed files with 6 additions and 3 deletions

View File

@ -55,6 +55,7 @@ export const controls = {
} );
} )
.catch( ( errorResponse ) => {
triggerFetch.setNonce( errorResponse.headers );
if ( typeof errorResponse.json === 'function' ) {
// Parse error response before rejecting it.
errorResponse

View File

@ -8,7 +8,7 @@ use Automattic\WooCommerce\Blocks\StoreApi\Utilities\CartController;
*
* @internal This API is used internally by Blocks--it is still in flux and may be subject to revisions.
*/
class CartCoupons extends AbstractRoute {
class CartCoupons extends AbstractCartRoute {
/**
* Get the path of this REST route.
*

View File

@ -8,7 +8,7 @@ use Automattic\WooCommerce\Blocks\StoreApi\Utilities\CartController;
*
* @internal This API is used internally by Blocks--it is still in flux and may be subject to revisions.
*/
class CartCouponsByCode extends AbstractRoute {
class CartCouponsByCode extends AbstractCartRoute {
/**
* Get the path of this REST route.
*

View File

@ -8,7 +8,7 @@ use Automattic\WooCommerce\Blocks\StoreApi\Utilities\CartController;
*
* @internal This API is used internally by Blocks--it is still in flux and may be subject to revisions.
*/
class CartItemsByKey extends AbstractRoute {
class CartItemsByKey extends AbstractCartRoute {
/**
* Get the path of this REST route.
*

View File

@ -44,6 +44,8 @@ class Products extends AbstractRoute {
* @return \WP_REST_Response
*/
protected function get_route_response( \WP_REST_Request $request ) {
// we load so that we have the same session, this is done so that Add to Cart can function.
$this->maybe_load_cart();
$response = new \WP_REST_Response();
$product_query = new ProductQuery();