Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Add cart data to filters (#4164)
Browse files Browse the repository at this point in the history
* add cart data to filters

* add extensions back to footer filter
  • Loading branch information
senadir authored and grogou committed Aug 20, 2021
1 parent c10fdf2 commit beadbab
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import PropTypes from 'prop-types';
import Dinero from 'dinero.js';
import { getSetting } from '@woocommerce/settings';
import { useCallback, useMemo } from '@wordpress/element';
import { useStoreCart } from '@woocommerce/base-context/hooks';

/**
* Internal dependencies
Expand All @@ -41,6 +42,11 @@ const OrderSummaryItem = ( { cartItem } ) => {
extensions = {},
} = cartItem;

// Prepare props to pass to the __experimentalApplyCheckoutFilter filter.
// We need to pluck out receiveCart.
// eslint-disable-next-line no-unused-vars
const { receiveCart, ...cart } = useStoreCart();

const productPriceValidation = useCallback(
( value ) => mustBeString( value ) && mustContain( value, '<price/>' ),
[]
Expand All @@ -50,8 +56,9 @@ const OrderSummaryItem = ( { cartItem } ) => {
() => ( {
context: 'summary',
cartItem,
cart,
} ),
[ cartItem ]
[ cartItem, cart ]
);

const priceCurrency = getCurrencyFromPriceResponse( prices );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,16 @@ const SHOW_TAXES =

const TotalsFooterItem = ( { currency, values } ) => {
const { total_price: totalPrice, total_tax: totalTax } = values;
const { extensions } = useStoreCart();

// Prepare props to pass to the __experimentalApplyCheckoutFilter filter.
// We need to pluck out receiveCart.
// eslint-disable-next-line no-unused-vars
const { receiveCart, ...cart } = useStoreCart();
const label = __experimentalApplyCheckoutFilter( {
filterName: 'totalLabel',
defaultValue: __( 'Total', 'woo-gutenberg-products-block' ),
extensions,
extensions: cart.extensions,
arg: { cart },
// Only accept strings.
validation: mustBeString,
} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import ProductName from '@woocommerce/base-components/product-name';
import {
useStoreCartItemQuantity,
useStoreEvents,
useStoreCart,
} from '@woocommerce/base-context/hooks';
import {
ProductBackorderBadge,
Expand Down Expand Up @@ -114,12 +115,18 @@ const CartLineItemRow = ( {
( value ) => mustBeString( value ) && mustContain( value, '<price/>' ),
[]
);

// Prepare props to pass to the __experimentalApplyCheckoutFilter filter.
// We need to pluck out receiveCart.
// eslint-disable-next-line no-unused-vars
const { receiveCart, ...cart } = useStoreCart();
const arg = useMemo(
() => ( {
context: 'cart',
cartItem: lineItem,
cart,
} ),
[ lineItem ]
[ lineItem, cart ]
);
const priceCurrency = getCurrencyFromPriceResponse( prices );
const name = __experimentalApplyCheckoutFilter( {
Expand Down

0 comments on commit beadbab

Please sign in to comment.