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

Add cart data to filters #4164

Merged
merged 2 commits into from
May 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 },
senadir marked this conversation as resolved.
Show resolved Hide resolved
mikejolley marked this conversation as resolved.
Show resolved Hide resolved
// 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 ]
mikejolley marked this conversation as resolved.
Show resolved Hide resolved
);
const priceCurrency = getCurrencyFromPriceResponse( prices );
const name = __experimentalApplyCheckoutFilter( {
Expand Down