2020-03-05 19:54:05 +00:00
|
|
|
// @ts-nocheck
|
Cart block: line-items front end initial work (https://github.com/woocommerce/woocommerce-blocks/pull/1333)
* render block on front end, add `Shopping cart` heading (baby steps)
* fake data for editing full cart + show line count in header
* add note about core/html using `is-active` class for toggle state
* reinstate work-in-progress full cart component (lost in rebase)
* reinstate full cart from master
* component for full cart title & item count + margin tweaks:
- add margin between main cart & sidebar
- add margin after cart block
* add cart items sample data + factor sample product image to module
* use sample cart data for item count
* basic table of cart line items (no styling)
* prettification
* show images for cart line items + initial table styling
* cart quantity selector component (work in progress)
* use state for cart product quantity, allow incr/decr from UI (WIP)
* replace WIP custom quantity control with number edit (temporary)
* correctly format cart line item total price
* align cart item columns with headings + indent image on desktop
* tweak css for cart line item padding on mobile so it's more explicit
* show cart line item full price if discounted
* add placeholder for cart remove item link
* switch cart table to flex layout (was table)…
This will allow us to move things around for mobile/responsive layout.
* only show cart items table header on desktop
* more cart items styling - row borders, appropriate padding +
+ move image width to variable
+ fix class name plurality for row (item not items)
* use standard $gap instead of 1em for padding/margins
* responsive (mobile) layout for cart line items:
- shift line $ total to bottom right
- stack quantity selector in product info column
* remove extraneous cart table padding on mobile
* comment about unused styles for quantity selector component
* add follow up issue for todo
* remove inappropriate href
* render srcset & sizes for cart line item product image
* remove todo comment
* switch back to table markup for cart items (in progress):
- table is more semantic, associates headers with columns
* cart line items column widths - product column is larger (60%)
* reinstate table row borders
* bottom-align line item price on mobile
* cart contents heading should be H2 + prettify
* remove unused QuantitySelector code/styles, rename main class in line with BEM
* defaults for QuantitySelector props
* variable/property name tidies - match conventions/API
* fix bug: line total price is only bottom-align on small screen
* move QuantitySelector to root of components, intended to be generally useful
* use lineItem directly for cart, specify shape in PropTypes
* rename cart components to align with "line item" rather than "product"
* rejig class names to better align with new component names & BEM style
* show cart item image correct size:
- use single column for product image and info, with flex container
- specify image width (rem instead of px)
* fix safari issue - cart product images displaying vertically stretched
* shift product name left margin from image, to account for no-image case
* experiment: bump bundlewatch size limit for cart temporarily:
- our fake data inline image is heavy
- when we switch to real API we will no longer need it
* fix issue introduced when moving margin from image to details div:
- product details needs margin on left (not right)
* fix react props issues:
- explicitly destructure image props for srcSet (vs srcset)
- use API key field for line item key instead of id, fix duplicate test id
- CartLineItemsTable takes an array of lineItems (incorrect PropTypes)
* remove redundant divs + use conventional `null` (when no full price)
* override editor styles to ensure cart product image is correct size
* move cart items editor style override to editor.css
* add an explicit readable heading for cart heading to match visual layout
2020-01-09 22:50:14 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2020-02-18 23:06:37 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2020-03-06 12:27:54 +00:00
|
|
|
import { __ } from '@wordpress/i18n';
|
2020-01-10 14:37:27 +00:00
|
|
|
import {
|
2020-12-09 07:29:34 +00:00
|
|
|
TotalsCoupon,
|
|
|
|
TotalsDiscount,
|
2020-03-06 12:27:54 +00:00
|
|
|
TotalsFooterItem,
|
2021-02-03 11:35:17 +00:00
|
|
|
TotalsShipping,
|
2020-03-30 13:04:27 +00:00
|
|
|
} from '@woocommerce/base-components/cart-checkout';
|
2021-01-20 20:35:53 +00:00
|
|
|
import {
|
|
|
|
Subtotal,
|
|
|
|
TotalsFees,
|
|
|
|
TotalsTaxes,
|
|
|
|
ExperimentalOrderMeta,
|
|
|
|
} from '@woocommerce/blocks-checkout';
|
2021-02-04 15:30:28 +00:00
|
|
|
|
|
|
|
import { getCurrencyFromPriceResponse } from '@woocommerce/price-format';
|
2020-01-10 14:37:27 +00:00
|
|
|
import {
|
|
|
|
COUPONS_ENABLED,
|
2020-03-03 10:12:18 +00:00
|
|
|
DISPLAY_CART_PRICES_INCLUDING_TAX,
|
2020-01-10 14:37:27 +00:00
|
|
|
} from '@woocommerce/block-settings';
|
2020-04-02 14:04:43 +00:00
|
|
|
import {
|
|
|
|
useStoreCartCoupons,
|
|
|
|
useStoreCart,
|
|
|
|
useStoreNotices,
|
|
|
|
} from '@woocommerce/base-hooks';
|
2020-02-26 15:49:07 +00:00
|
|
|
import classnames from 'classnames';
|
2020-03-12 09:41:35 +00:00
|
|
|
import {
|
|
|
|
Sidebar,
|
|
|
|
SidebarLayout,
|
|
|
|
Main,
|
|
|
|
} from '@woocommerce/base-components/sidebar-layout';
|
2020-05-25 16:45:38 +00:00
|
|
|
import Title from '@woocommerce/base-components/title';
|
2020-03-17 10:30:52 +00:00
|
|
|
import { getSetting } from '@woocommerce/settings';
|
2020-04-02 14:04:43 +00:00
|
|
|
import { useEffect } from '@wordpress/element';
|
|
|
|
import { decodeEntities } from '@wordpress/html-entities';
|
2020-11-16 13:12:56 +00:00
|
|
|
import { CartProvider } from '@woocommerce/base-context';
|
Cart block: line-items front end initial work (https://github.com/woocommerce/woocommerce-blocks/pull/1333)
* render block on front end, add `Shopping cart` heading (baby steps)
* fake data for editing full cart + show line count in header
* add note about core/html using `is-active` class for toggle state
* reinstate work-in-progress full cart component (lost in rebase)
* reinstate full cart from master
* component for full cart title & item count + margin tweaks:
- add margin between main cart & sidebar
- add margin after cart block
* add cart items sample data + factor sample product image to module
* use sample cart data for item count
* basic table of cart line items (no styling)
* prettification
* show images for cart line items + initial table styling
* cart quantity selector component (work in progress)
* use state for cart product quantity, allow incr/decr from UI (WIP)
* replace WIP custom quantity control with number edit (temporary)
* correctly format cart line item total price
* align cart item columns with headings + indent image on desktop
* tweak css for cart line item padding on mobile so it's more explicit
* show cart line item full price if discounted
* add placeholder for cart remove item link
* switch cart table to flex layout (was table)…
This will allow us to move things around for mobile/responsive layout.
* only show cart items table header on desktop
* more cart items styling - row borders, appropriate padding +
+ move image width to variable
+ fix class name plurality for row (item not items)
* use standard $gap instead of 1em for padding/margins
* responsive (mobile) layout for cart line items:
- shift line $ total to bottom right
- stack quantity selector in product info column
* remove extraneous cart table padding on mobile
* comment about unused styles for quantity selector component
* add follow up issue for todo
* remove inappropriate href
* render srcset & sizes for cart line item product image
* remove todo comment
* switch back to table markup for cart items (in progress):
- table is more semantic, associates headers with columns
* cart line items column widths - product column is larger (60%)
* reinstate table row borders
* bottom-align line item price on mobile
* cart contents heading should be H2 + prettify
* remove unused QuantitySelector code/styles, rename main class in line with BEM
* defaults for QuantitySelector props
* variable/property name tidies - match conventions/API
* fix bug: line total price is only bottom-align on small screen
* move QuantitySelector to root of components, intended to be generally useful
* use lineItem directly for cart, specify shape in PropTypes
* rename cart components to align with "line item" rather than "product"
* rejig class names to better align with new component names & BEM style
* show cart item image correct size:
- use single column for product image and info, with flex container
- specify image width (rem instead of px)
* fix safari issue - cart product images displaying vertically stretched
* shift product name left margin from image, to account for no-image case
* experiment: bump bundlewatch size limit for cart temporarily:
- our fake data inline image is heavy
- when we switch to real API we will no longer need it
* fix issue introduced when moving margin from image to details div:
- product details needs margin on left (not right)
* fix react props issues:
- explicitly destructure image props for srcSet (vs srcset)
- use API key field for line item key instead of id, fix duplicate test id
- CartLineItemsTable takes an array of lineItems (incorrect PropTypes)
* remove redundant divs + use conventional `null` (when no full price)
* override editor styles to ensure cart product image is correct size
* move cart items editor style override to editor.css
* add an explicit readable heading for cart heading to match visual layout
2020-01-09 22:50:14 +00:00
|
|
|
|
2019-12-05 21:08:48 +00:00
|
|
|
/**
|
2019-12-12 19:46:56 +00:00
|
|
|
* Internal dependencies
|
2019-12-05 21:08:48 +00:00
|
|
|
*/
|
2020-04-29 10:57:58 +00:00
|
|
|
import CheckoutButton from '../checkout-button';
|
Cart block: line-items front end initial work (https://github.com/woocommerce/woocommerce-blocks/pull/1333)
* render block on front end, add `Shopping cart` heading (baby steps)
* fake data for editing full cart + show line count in header
* add note about core/html using `is-active` class for toggle state
* reinstate work-in-progress full cart component (lost in rebase)
* reinstate full cart from master
* component for full cart title & item count + margin tweaks:
- add margin between main cart & sidebar
- add margin after cart block
* add cart items sample data + factor sample product image to module
* use sample cart data for item count
* basic table of cart line items (no styling)
* prettification
* show images for cart line items + initial table styling
* cart quantity selector component (work in progress)
* use state for cart product quantity, allow incr/decr from UI (WIP)
* replace WIP custom quantity control with number edit (temporary)
* correctly format cart line item total price
* align cart item columns with headings + indent image on desktop
* tweak css for cart line item padding on mobile so it's more explicit
* show cart line item full price if discounted
* add placeholder for cart remove item link
* switch cart table to flex layout (was table)…
This will allow us to move things around for mobile/responsive layout.
* only show cart items table header on desktop
* more cart items styling - row borders, appropriate padding +
+ move image width to variable
+ fix class name plurality for row (item not items)
* use standard $gap instead of 1em for padding/margins
* responsive (mobile) layout for cart line items:
- shift line $ total to bottom right
- stack quantity selector in product info column
* remove extraneous cart table padding on mobile
* comment about unused styles for quantity selector component
* add follow up issue for todo
* remove inappropriate href
* render srcset & sizes for cart line item product image
* remove todo comment
* switch back to table markup for cart items (in progress):
- table is more semantic, associates headers with columns
* cart line items column widths - product column is larger (60%)
* reinstate table row borders
* bottom-align line item price on mobile
* cart contents heading should be H2 + prettify
* remove unused QuantitySelector code/styles, rename main class in line with BEM
* defaults for QuantitySelector props
* variable/property name tidies - match conventions/API
* fix bug: line total price is only bottom-align on small screen
* move QuantitySelector to root of components, intended to be generally useful
* use lineItem directly for cart, specify shape in PropTypes
* rename cart components to align with "line item" rather than "product"
* rejig class names to better align with new component names & BEM style
* show cart item image correct size:
- use single column for product image and info, with flex container
- specify image width (rem instead of px)
* fix safari issue - cart product images displaying vertically stretched
* shift product name left margin from image, to account for no-image case
* experiment: bump bundlewatch size limit for cart temporarily:
- our fake data inline image is heavy
- when we switch to real API we will no longer need it
* fix issue introduced when moving margin from image to details div:
- product details needs margin on left (not right)
* fix react props issues:
- explicitly destructure image props for srcSet (vs srcset)
- use API key field for line item key instead of id, fix duplicate test id
- CartLineItemsTable takes an array of lineItems (incorrect PropTypes)
* remove redundant divs + use conventional `null` (when no full price)
* override editor styles to ensure cart product image is correct size
* move cart items editor style override to editor.css
* add an explicit readable heading for cart heading to match visual layout
2020-01-09 22:50:14 +00:00
|
|
|
import CartLineItemsTitle from './cart-line-items-title';
|
|
|
|
import CartLineItemsTable from './cart-line-items-table';
|
2021-02-19 15:16:39 +00:00
|
|
|
import { CartExpressPayment } from '../../payment-methods';
|
Cart block: line-items front end initial work (https://github.com/woocommerce/woocommerce-blocks/pull/1333)
* render block on front end, add `Shopping cart` heading (baby steps)
* fake data for editing full cart + show line count in header
* add note about core/html using `is-active` class for toggle state
* reinstate work-in-progress full cart component (lost in rebase)
* reinstate full cart from master
* component for full cart title & item count + margin tweaks:
- add margin between main cart & sidebar
- add margin after cart block
* add cart items sample data + factor sample product image to module
* use sample cart data for item count
* basic table of cart line items (no styling)
* prettification
* show images for cart line items + initial table styling
* cart quantity selector component (work in progress)
* use state for cart product quantity, allow incr/decr from UI (WIP)
* replace WIP custom quantity control with number edit (temporary)
* correctly format cart line item total price
* align cart item columns with headings + indent image on desktop
* tweak css for cart line item padding on mobile so it's more explicit
* show cart line item full price if discounted
* add placeholder for cart remove item link
* switch cart table to flex layout (was table)…
This will allow us to move things around for mobile/responsive layout.
* only show cart items table header on desktop
* more cart items styling - row borders, appropriate padding +
+ move image width to variable
+ fix class name plurality for row (item not items)
* use standard $gap instead of 1em for padding/margins
* responsive (mobile) layout for cart line items:
- shift line $ total to bottom right
- stack quantity selector in product info column
* remove extraneous cart table padding on mobile
* comment about unused styles for quantity selector component
* add follow up issue for todo
* remove inappropriate href
* render srcset & sizes for cart line item product image
* remove todo comment
* switch back to table markup for cart items (in progress):
- table is more semantic, associates headers with columns
* cart line items column widths - product column is larger (60%)
* reinstate table row borders
* bottom-align line item price on mobile
* cart contents heading should be H2 + prettify
* remove unused QuantitySelector code/styles, rename main class in line with BEM
* defaults for QuantitySelector props
* variable/property name tidies - match conventions/API
* fix bug: line total price is only bottom-align on small screen
* move QuantitySelector to root of components, intended to be generally useful
* use lineItem directly for cart, specify shape in PropTypes
* rename cart components to align with "line item" rather than "product"
* rejig class names to better align with new component names & BEM style
* show cart item image correct size:
- use single column for product image and info, with flex container
- specify image width (rem instead of px)
* fix safari issue - cart product images displaying vertically stretched
* shift product name left margin from image, to account for no-image case
* experiment: bump bundlewatch size limit for cart temporarily:
- our fake data inline image is heavy
- when we switch to real API we will no longer need it
* fix issue introduced when moving margin from image to details div:
- product details needs margin on left (not right)
* fix react props issues:
- explicitly destructure image props for srcSet (vs srcset)
- use API key field for line item key instead of id, fix duplicate test id
- CartLineItemsTable takes an array of lineItems (incorrect PropTypes)
* remove redundant divs + use conventional `null` (when no full price)
* override editor styles to ensure cart product image is correct size
* move cart items editor style override to editor.css
* add an explicit readable heading for cart heading to match visual layout
2020-01-09 22:50:14 +00:00
|
|
|
|
2019-12-12 19:46:56 +00:00
|
|
|
import './style.scss';
|
2019-12-05 21:08:48 +00:00
|
|
|
|
2020-11-16 13:12:56 +00:00
|
|
|
const Block = ( props ) => {
|
|
|
|
return (
|
|
|
|
<CartProvider>
|
|
|
|
<Cart { ...props } />
|
|
|
|
</CartProvider>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2019-12-05 21:08:48 +00:00
|
|
|
/**
|
2019-12-12 19:46:56 +00:00
|
|
|
* Component that renders the Cart block when user has something in cart aka "full".
|
2020-09-20 23:54:08 +00:00
|
|
|
*
|
|
|
|
* @param {Object} props Incoming props for the component.
|
|
|
|
* @param {Object} props.attributes Incoming attributes for block.
|
2019-12-05 21:08:48 +00:00
|
|
|
*/
|
2020-03-17 10:30:52 +00:00
|
|
|
const Cart = ( { attributes } ) => {
|
2020-11-17 11:58:38 +00:00
|
|
|
const { isShippingCalculatorEnabled, hasDarkControls } = attributes;
|
2020-03-13 13:41:59 +00:00
|
|
|
|
2020-03-17 12:11:30 +00:00
|
|
|
const {
|
|
|
|
cartItems,
|
2021-01-13 16:57:42 +00:00
|
|
|
cartFees,
|
2020-03-17 12:11:30 +00:00
|
|
|
cartTotals,
|
|
|
|
cartIsLoading,
|
|
|
|
cartItemsCount,
|
2020-04-02 14:04:43 +00:00
|
|
|
cartItemErrors,
|
2020-08-20 14:14:12 +00:00
|
|
|
cartNeedsPayment,
|
2020-04-02 17:10:36 +00:00
|
|
|
cartNeedsShipping,
|
2020-03-17 12:11:30 +00:00
|
|
|
} = useStoreCart();
|
|
|
|
|
2020-02-25 11:36:53 +00:00
|
|
|
const {
|
|
|
|
applyCoupon,
|
|
|
|
removeCoupon,
|
|
|
|
isApplyingCoupon,
|
|
|
|
isRemovingCoupon,
|
2020-03-13 20:05:45 +00:00
|
|
|
appliedCoupons,
|
2020-02-25 11:36:53 +00:00
|
|
|
} = useStoreCartCoupons();
|
|
|
|
|
2020-04-17 20:18:54 +00:00
|
|
|
const { addErrorNotice } = useStoreNotices();
|
2020-04-02 14:04:43 +00:00
|
|
|
|
|
|
|
// Ensures any cart errors listed in the API response get shown.
|
|
|
|
useEffect( () => {
|
|
|
|
cartItemErrors.forEach( ( error ) => {
|
|
|
|
addErrorNotice( decodeEntities( error.message ), {
|
2020-04-17 20:18:54 +00:00
|
|
|
isDismissible: true,
|
|
|
|
id: error.code,
|
2020-04-02 14:04:43 +00:00
|
|
|
} );
|
|
|
|
} );
|
2020-10-27 14:37:18 +00:00
|
|
|
}, [ addErrorNotice, cartItemErrors ] );
|
2020-04-02 14:04:43 +00:00
|
|
|
|
2020-02-14 03:43:13 +00:00
|
|
|
const totalsCurrency = getCurrencyFromPriceResponse( cartTotals );
|
2020-01-10 14:37:27 +00:00
|
|
|
|
2020-02-26 15:49:07 +00:00
|
|
|
const cartClassName = classnames( 'wc-block-cart', {
|
2020-03-13 13:41:59 +00:00
|
|
|
'wc-block-cart--is-loading': cartIsLoading,
|
2020-08-14 11:08:16 +00:00
|
|
|
'has-dark-controls': hasDarkControls,
|
2020-02-26 15:49:07 +00:00
|
|
|
} );
|
|
|
|
|
2019-12-05 21:08:48 +00:00
|
|
|
return (
|
2021-02-09 08:10:45 +00:00
|
|
|
<>
|
|
|
|
<CartLineItemsTitle itemCount={ cartItemsCount } />
|
|
|
|
<SidebarLayout className={ cartClassName }>
|
|
|
|
<Main className="wc-block-cart__main">
|
|
|
|
<CartLineItemsTable
|
|
|
|
lineItems={ cartItems }
|
|
|
|
isLoading={ cartIsLoading }
|
|
|
|
/>
|
|
|
|
</Main>
|
|
|
|
<Sidebar className="wc-block-cart__sidebar">
|
|
|
|
<Title
|
|
|
|
headingLevel="2"
|
|
|
|
className="wc-block-cart__totals-title"
|
|
|
|
>
|
|
|
|
{ __( 'Cart totals', 'woo-gutenberg-products-block' ) }
|
|
|
|
</Title>
|
|
|
|
<Subtotal
|
|
|
|
currency={ totalsCurrency }
|
2020-06-05 10:00:19 +00:00
|
|
|
values={ cartTotals }
|
2021-02-09 08:10:45 +00:00
|
|
|
/>
|
|
|
|
<TotalsFees
|
2020-06-05 10:00:19 +00:00
|
|
|
currency={ totalsCurrency }
|
2021-02-09 08:10:45 +00:00
|
|
|
cartFees={ cartFees }
|
2020-06-05 10:00:19 +00:00
|
|
|
/>
|
2021-02-09 08:10:45 +00:00
|
|
|
<TotalsDiscount
|
|
|
|
cartCoupons={ appliedCoupons }
|
2020-06-05 10:00:19 +00:00
|
|
|
currency={ totalsCurrency }
|
2021-02-09 08:10:45 +00:00
|
|
|
isRemovingCoupon={ isRemovingCoupon }
|
|
|
|
removeCoupon={ removeCoupon }
|
2020-06-05 10:00:19 +00:00
|
|
|
values={ cartTotals }
|
|
|
|
/>
|
2021-02-09 08:10:45 +00:00
|
|
|
{ cartNeedsShipping && (
|
|
|
|
<TotalsShipping
|
|
|
|
showCalculator={ isShippingCalculatorEnabled }
|
|
|
|
showRateSelector={ true }
|
|
|
|
values={ cartTotals }
|
|
|
|
currency={ totalsCurrency }
|
|
|
|
/>
|
|
|
|
) }
|
|
|
|
{ ! DISPLAY_CART_PRICES_INCLUDING_TAX && (
|
|
|
|
<TotalsTaxes
|
|
|
|
currency={ totalsCurrency }
|
|
|
|
values={ cartTotals }
|
|
|
|
/>
|
|
|
|
) }
|
|
|
|
{ COUPONS_ENABLED && (
|
|
|
|
<TotalsCoupon
|
|
|
|
onSubmit={ applyCoupon }
|
|
|
|
isLoading={ isApplyingCoupon }
|
|
|
|
/>
|
|
|
|
) }
|
|
|
|
<TotalsFooterItem
|
|
|
|
currency={ totalsCurrency }
|
|
|
|
values={ cartTotals }
|
2020-08-20 14:14:12 +00:00
|
|
|
/>
|
2021-02-09 08:10:45 +00:00
|
|
|
<ExperimentalOrderMeta.Slot />
|
|
|
|
<div className="wc-block-cart__payment-options">
|
|
|
|
{ cartNeedsPayment && <CartExpressPayment /> }
|
|
|
|
<CheckoutButton
|
|
|
|
link={ getSetting(
|
|
|
|
'page-' + attributes?.checkoutPageId,
|
|
|
|
false
|
|
|
|
) }
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</Sidebar>
|
|
|
|
</SidebarLayout>
|
|
|
|
</>
|
2019-12-05 21:08:48 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-02-18 23:06:37 +00:00
|
|
|
Cart.propTypes = {
|
2020-03-17 10:30:52 +00:00
|
|
|
attributes: PropTypes.object.isRequired,
|
2020-02-18 23:06:37 +00:00
|
|
|
};
|
2019-12-05 21:08:48 +00:00
|
|
|
|
2020-11-16 13:12:56 +00:00
|
|
|
export default Block;
|