Edit in GitHubLog an issue

ProductListing

These talons provide logic for components that render products in a shopping cart and forms that update the quantity or configuration for each product.

Functions

useProductListing(props)ProductListingTalonProps

This talon contains logic for a component that renders a list of products for a cart. It performs effects and returns prop data to render the component on a cart page.

This talon performs the following effects:

  • Fetch product listing data associated with the cart
  • Log any GraphQL errors to the console
useProduct(props)ProductTalonProps

This talon contains logic for a product component used in a product listing component. It performs effects and returns prop data for that component.

This talon performs the following effects:

  • Manage the updating state of the cart while a product is being updated or removed
useEditModal()EditModalTalonProps

This talon contains logic for a product edit modal used on a cart page. It returns prop data for rendering an interactive modal component.

deriveOptionSelectionsFromProduct(props)ProductFormTalonProps

This talon contains logic for a product edit form. It performs effects and returns data for rendering the component inside a modal container.

This talon performs the following effects:

  • Manage the updating state of the cart while form data is being saved
  • Set the variant price on a product depending on the product's options

Typedefs

ProductListingQueries : Object

GraphQL queries for getting product listing data. This is a type used in the useProductListing talon.

ProductListingTalonProps : Object

Object type returned by the useProductListing talon. It provides props data for a component that renders a product list.

ProductMutations : Object

GraphQL mutations for a product in a cart. This is a type used by the useProduct talon.

ProductTalonProps : Object

Object type returned by the useProduct talon. It provides prop data for rendering a product component on a cart page.

ProductItem : Object

Data about a product item in the cart. This type is used in the ProductTalonProps type returned by the useProduct talon.

QuantityTalonProps : Object

Object type returned by the useQuantityStepper talon. It provides props data for a quantity UI component.

EditModalTalonProps : Object

Object type returned by the useEditModal talon. It provides props data for rendering an edit modal component.

ProductFormTalonProps : Object

Object type returned by the useProductForm talon. It provides props data for a product form UI component inside a modal.

This talon contains logic for a component that renders a list of products for a cart. It performs effects and returns prop data to render the component on a cart page.

This talon performs the following effects:

  • Fetch product listing data associated with the cart
  • Log any GraphQL errors to the console

Returns: Parameters

NameTypeDescription
props
Object
props.queries
GraphQL queries for getting product listing data.

Example (Importing into your project)

Copied to your clipboard
import { useProductListing } from '@magento/peregrine/lib/talons/CartPage/ProductListing/useProductListing';

This talon contains logic for a product component used in a product listing component. It performs effects and returns prop data for that component.

This talon performs the following effects:

  • Manage the updating state of the cart while a product is being updated or removed

Returns: Parameters

NameTypeDescription
props
Object
props.item
Product item data
props.operations
GraphQL mutations for a product in a cart
props.setActiveEditItem
function
Function for setting the actively editing item
props.setIsCartUpdating
function
Function for setting the updating state of the cart

Example (Importing into your project)

Copied to your clipboard
import { useProduct } from '@magento/peregrine/lib/talons/CartPage/ProductListing/useProduct';

This talon contains logic for a product edit modal used on a cart page. It returns prop data for rendering an interactive modal component.

Returns: Example (Importing into your project)

Copied to your clipboard
import { useEditModal } from '@magento/peregrine/lib/talons/CartPage/ProductListing/EditModal/useEditModal';

This talon contains logic for a product edit form. It performs effects and returns data for rendering the component inside a modal container.

This talon performs the following effects:

  • Manage the updating state of the cart while form data is being saved
  • Set the variant price on a product depending on the product's options

Returns: Parameters

NameTypeDescription
props
Object
props.cartItem
Object
The cart item to configure on the form
props.getConfigurableOptionsQuery
GraphQLDocument
GraphQL query to get the configurable options for a product.
props.setIsCartUpdating
function
Function for setting the updating state for the shopping cart.
props.setVariantPrice
function
Function for setting the variant price on a product.
props.updateConfigurableOptionsMutation
GraphQLDocument
GraphQL mutation for updating the configurable options for a product.
props.updateQuantityMutation
GraphQLDocument
GraphQL mutation for updating the quantity of a product in a cart.
props.setActiveEditItem
function
Function for setting the actively editing item.

Example (Importing into your project)

Copied to your clipboard
import { useProductForm } from '@magento/peregrine/lib/talons/CartPage/ProductListing/EditModal/useProductForm';

GraphQL queries for getting product listing data. This is a type used in the useProductListing talon.

See: productListingFragments.js for the queries used in Venia
Properties

NameTypeDescription
getProductListingQuery
GraphQLDocument
Query to get the product list for a cart

Object type returned by the useProductListing talon. It provides props data for a component that renders a product list.

Properties

NameTypeDescription
activeEditItem
Object
The product item currently being edited
isLoading
boolean
True if the query to get the product listing is still in progress. False otherwise.
error
Error | null
An array of graphql errors
items
Array.<Object>
A list of products in a cart
setActiveEditItem
function
Function for setting the current item to edit

GraphQL mutations for a product in a cart. This is a type used by the useProduct talon.

See: product.js to see the mutations used in Venia
Properties

NameTypeDescription
removeItemMutation
GraphQLDocument
Mutation for removing an item in a cart
updateItemQuantityMutation
GraphQLDocument
Mutation for updating the item quantity in a cart

Object type returned by the useProduct talon. It provides prop data for rendering a product component on a cart page.

Properties

NameTypeDescription
errorMessage
String
Error message from an operation perfored on a cart product.
handleEditItem
function
Function to use for handling when a product is modified.
handleRemoveFromCart
function
Function to use for handling the removal of a cart product.
handleUpdateItemQuantity
function
Function to use for handling updates to the product quantity in a cart.
isEditable
boolean
True if a cart product is editable. False otherwise.
product
Cart product data

Data about a product item in the cart. This type is used in the ProductTalonProps type returned by the useProduct talon.

Properties

NameTypeDescription
currency
String
The currency associated with the cart product
image
String
The url for the cart product image
name
String
The name of the product
options
Array.<Object>
A list of configurable option objects
quantity
number
The quantity associated with the cart product
unitPrice
number
The product's unit price
urlKey
String
The product's url key
urlSuffix
String
The product's url suffix

Object type returned by the useQuantityStepper talon. It provides props data for a quantity UI component.

Properties

NameTypeDescription
isDecrementDisabled
boolean
True if decrementing should be disabled
isIncrementDisabled
boolean
True if incrementing should be disabled
handleBlur
function
Callback function for handling a blur event on a component
handleDecrement
function
Callback function for handling a quantity decrement event
handleIncrement
function
Callback function for handling an increment event
maskInput
function
Function for masking a value when decimal values are allowed

Object type returned by the useEditModal talon. It provides props data for rendering an edit modal component.

Properties

NameTypeDescription
setVariantPrice
function
Function for setting a product's variant price.
variantPrice
Object
The variant price for a product. See Money object.

Object type returned by the useProductForm talon. It provides props data for a product form UI component inside a modal.

Properties

NameTypeDescription
configItem
Object
Cart item to configure
errors
Array.<Error>
An array of form errors resulting from a configuration or quantity value
handleOptionSelection
function
A callback function handling an option selection event
handleSubmit
function
A callback function for handling form submission
isLoading
boolean
True if the form is loading data. False otherwise.
isSaving
boolean
True if the form is saving data. False otherwise.
isDialogOpen
boolean
True if the form is visible. False otherwise.
handleClose
function
A callback function for handling form closing
configurableThumbnailSource
String
A string indicating which thumbnail should be used for configurable products

Source Code: pwa-studio/packages/peregrine/lib/talons/CartPage/ProductListing/useProductListing.js

Examples

useProductListing()

Copied to your clipboard
import React from 'react';
import { useProductListing } from '@magento/peregrine/lib/talons/CartPage/ProductListing/useProductListing';
import { GET_PRODUCT_LISTING } from './myProductListing.gql';
const MyProductListing = props => {
const { setIsCartUpdating } = props;
const talonProps = useProductListing({
queries: {
getProductListing: GET_PRODUCT_LISTING
}
});
const { activeEditItem, isLoading, items, setActiveEditItem } = talonProps;
if (isLoading) {
return <div>Loading...</div>;
}
return (
// JSX that renders the list of products in a cart using the talon props
)
}
export default MyProductListing;
  • Privacy
  • Terms of Use
  • Do not sell or share my personal information
  • AdChoices
Copyright © 2024 Adobe. All rights reserved.