Fix Mini Cart doesn't update data (https://github.com/woocommerce/woocommerce-blocks/pull/5741)
* Remove api hydration for the Mini Cart Block woocommerce/woocommerce-blocks#5729 Remove api hydration for the Mini Cart Block * fix PHP error * send event when the button is clicked * fix import order
This commit is contained in:
parent
d53551d4a7
commit
a594ea5ef5
|
@ -5,6 +5,7 @@ import { __ } from '@wordpress/i18n';
|
|||
import triggerFetch from '@wordpress/api-fetch';
|
||||
import { useEffect, useCallback, useState } from '@wordpress/element';
|
||||
import { decodeEntities } from '@wordpress/html-entities';
|
||||
import { triggerAddedToCartEvent } from '@woocommerce/base-utils';
|
||||
|
||||
/**
|
||||
* Internal dependencies
|
||||
|
@ -107,6 +108,7 @@ const FormSubmit = () => {
|
|||
} else {
|
||||
receiveCart( response );
|
||||
}
|
||||
triggerAddedToCartEvent( { preserveCartData: true } );
|
||||
dispatchActions.setAfterProcessing( response );
|
||||
setIsSubmitting( false );
|
||||
} );
|
||||
|
|
|
@ -27,6 +27,14 @@ class AllProducts extends AbstractBlock {
|
|||
$this->asset_data_registry->add( 'min_rows', wc_get_theme_support( 'product_blocks::min_rows', 1 ), true );
|
||||
$this->asset_data_registry->add( 'max_rows', wc_get_theme_support( 'product_blocks::max_rows', 6 ), true );
|
||||
$this->asset_data_registry->add( 'default_rows', wc_get_theme_support( 'product_blocks::default_rows', 3 ), true );
|
||||
$this->hydrate_from_api();
|
||||
}
|
||||
|
||||
/**
|
||||
* Hydrate the All Product block with data from the API.
|
||||
*/
|
||||
protected function hydrate_from_api() {
|
||||
$this->asset_data_registry->hydrate_api_request( '/wc/store/cart' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -107,8 +107,6 @@ class MiniCart extends AbstractBlock {
|
|||
|
||||
// Hydrate the following data depending on admin or frontend context.
|
||||
if ( ! is_admin() && ! WC()->is_rest_api_request() ) {
|
||||
$this->hydrate_from_api();
|
||||
|
||||
$label_info = $this->get_tax_label();
|
||||
|
||||
$this->tax_label = $label_info['tax_label'];
|
||||
|
@ -209,13 +207,6 @@ class MiniCart extends AbstractBlock {
|
|||
do_action( 'woocommerce_blocks_cart_enqueue_data' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Hydrate the cart block with data from the API.
|
||||
*/
|
||||
protected function hydrate_from_api() {
|
||||
$this->asset_data_registry->hydrate_api_request( '/wc/store/cart' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the script data given its handle.
|
||||
*
|
||||
|
|
|
@ -39,11 +39,12 @@ class SingleProduct extends AbstractBlock {
|
|||
}
|
||||
|
||||
/**
|
||||
* Hydrate the cart block with data from the API.
|
||||
* Hydrate the Single Product block with data from the API.
|
||||
*
|
||||
* @param int $product_id ID of the product.
|
||||
*/
|
||||
protected function hydrate_from_api( int $product_id ) {
|
||||
$this->asset_data_registry->hydrate_api_request( "/wc/store/products/$product_id" );
|
||||
$this->asset_data_registry->hydrate_api_request( '/wc/store/cart' );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue