PriceSummary
Functions
- usePriceSummary(props) ⇒
PriceSummaryTalonProps
This talon contains logic for a price summary component. It performs effects and returns prop data for rendering the component.
This talon performs the following effects:
- Log a GraphQL error if it occurs when getting the price summary
Typedefs
- FlattenedData :
Object
Query data flattened into a simple object.
- PriceSummaryQueries :
Object
GraphQL queries for price summary component.
- PriceSummaryTalonProps :
Object
Props used for rendering a price summary component.
This talon contains logic for a price summary component. It performs effects and returns prop data for rendering the component.
This talon performs the following effects:
- Log a GraphQL error if it occurs when getting the price summary
Returns: Parameters
Name | Type | Description |
---|---|---|
props | Object | |
props.queries | PriceSummaryQueries | GraphQL queries for a price summary component. |
Example (Importing into your project)
Copied to your clipboardimport { usePriceSummary } from '@magento/peregrine/lib/talons/CartPage/PriceSummary/usePriceSummary';
Query data flattened into a simple object.
Properties
Name | Type | Description |
---|---|---|
subtotal | String | Cart subtotal (excluding tax) |
total | String | Cart grand total |
discounts | Array.<Object> | Applied discounts to the cart |
giftCards | Array.<Object> | Gift cards applied to the cart |
giftOptions | Array.<Object> | Gift Options applied to the cart |
taxes | Array.<Object> | Taxes applied to the cart |
shipping | Array.<Object> | Shipping addresses associated with this cart |
GraphQL queries for price summary component.
See: priceSummary.js
for the queries used in Venia.
Properties
Name | Type | Description |
---|---|---|
getPriceSummary | GraphQLAST | Query to get the price summary for a cart |
Props used for rendering a price summary component.
Properties
Name | Type | Description |
---|---|---|
handleProceedToCheckout | function | Callback function which navigates the browser to the checkout |
hasError | boolean | True if a GraphQL query returns an error. False otherwise. |
hasItems | boolean | True if the cart has any items. False otherwise. |
isLoading | boolean | True while the GraphQL query is still in flight. False otherwise. |
flatData | FlattenedData | Query data that has been flattened into a simple object |
Source Code: pwa-studio/packages/peregrine/lib/talons/CartPage/PriceSummary/usePriceSummary.js
Examples#
usePriceSummary()#
Copied to your clipboard1import React from 'react'2import { usePriceSummary } from '@magento/peregrine/lib/talons/CartPage/PriceSummary/usePriceSummary';34import { GET_PRICE_SUMMARY } from './myPriceSummary.gql';567const MyPriceSummary = props => {8 const { isUpdating } = props;910 const talonProps = usePriceSummary({11 queries: {12 getPriceSummary: GET_PRICE_SUMMARY13 }14 });1516 const {17 handleProceedToCheckout,18 hasError,19 hasItems,20 isCheckout,21 isLoading,22 flatData23 } = talonProps;2425 if (hasError) {26 return (27 <div>28 Something went wrong. Please refresh and try again.29 </div>30 );31 } else if (!hasItems || isLoading) {32 return null;33 }3435 const { subtotal, total, discounts, giftCards, taxes, shipping } = flatData;3637 return (38 // JSX that renders a price summary component using data from the talon39 )40}4142export default MyPriceSummary