This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 219
Create Cross-Sells product list #6645
Merged
Merged
Changes from 20 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
aed95be
Create Cross-Sells product list
nielslange 0539936
Show “Read more” button for out-of-stock cross-sells products
nielslange 8085e62
Merge branch 'trunk' into add/6558-create-cross-sells-product-list
nielslange 886d794
Update assets/js/blocks/cart/inner-blocks/cart-cross-sells-products/b…
nielslange 370ecfb
Update assets/js/blocks/cart/cart-cross-sells-product-list/index.tsx
nielslange 6b1ad66
Merge branch 'trunk' into add/6558-create-cross-sells-product-list
nielslange 51a9bac
Remove obsolete isLoading and placeholderRows
nielslange a1af6a1
Merge branch 'add/6558-create-cross-sells-product-list' of github.com…
nielslange a34b8ba
Merge branch 'trunk' into add/6558-create-cross-sells-product-list
nielslange d4ae746
Fix TS errors
nielslange bdfb9d2
Merge branch 'trunk' into add/6558-create-cross-sells-product-list
nielslange 8f1c545
Rename crossSellsProduct to product
nielslange 39733e5
Merge branch 'add/6558-create-cross-sells-product-list' of github.com…
nielslange eaf16c4
Merge branch 'trunk' into add/6558-create-cross-sells-product-list
nielslange 80ed1d8
Merge branch 'trunk' into add/6558-create-cross-sells-product-list
nielslange a0afc30
Merge branch 'trunk' into add/6558-create-cross-sells-product-list
nielslange 9d1e746
Merge branch 'trunk' into add/6558-create-cross-sells-product-list
nielslange f216982
Fix critical error
nielslange 3634e78
Merge branch 'trunk' into add/6558-create-cross-sells-product-list
nielslange fb32b5f
Merge branch 'trunk' into add/6558-create-cross-sells-product-list
nielslange 44efafe
Merge branch 'trunk' into add/6558-create-cross-sells-product-list
nielslange c3c635f
Lock “Cart Cross-Sells products” inner block
nielslange 8bae307
Merge branch 'add/6558-create-cross-sells-product-list' of github.com…
nielslange 2490c9e
Merge branch 'trunk' into add/6558-create-cross-sells-product-list
nielslange 15a3814
Update assets/js/blocks/cart/inner-blocks/cart-cross-sells-products/b…
nielslange a1f4d5a
Prevent moving of the Cross-Sells block
nielslange File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
assets/js/blocks/cart/cart-cross-sells-product-list/cart-cross-sells-product.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { | ||
InnerBlockLayoutContextProvider, | ||
ProductDataContextProvider, | ||
} from '@woocommerce/shared-context'; | ||
import { ProductResponseItem } from '@woocommerce/type-defs/product-response'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { Block as ProductImage } from '../../../atomic/blocks/product-elements/image/block'; | ||
import { Block as ProductName } from '../../../atomic/blocks/product-elements/title/block'; | ||
import { Block as ProductRating } from '../../../atomic/blocks/product-elements/rating/block'; | ||
import { Block as ProductSaleBadge } from '../../../atomic/blocks/product-elements/sale-badge/block'; | ||
import { Block as ProductPrice } from '../../../atomic/blocks/product-elements/price/block'; | ||
import { Block as ProductButton } from '../../../atomic/blocks/product-elements/button/block'; | ||
import AddToCartButton from '../../../atomic/blocks/product-elements/add-to-cart/block'; | ||
|
||
interface CrossSellsProductProps { | ||
product: ProductResponseItem; | ||
isLoading: boolean; | ||
} | ||
|
||
const CartCrossSellsProduct = ( { | ||
product, | ||
}: CrossSellsProductProps ): JSX.Element => { | ||
return ( | ||
<div className="cross-sells-product"> | ||
<InnerBlockLayoutContextProvider | ||
parentName={ 'woocommerce/cart-cross-sells-block' } | ||
parentClassName={ 'wp-block-cart-cross-sells-product' } | ||
> | ||
<ProductDataContextProvider | ||
// Setting isLoading to false, given this parameter is required. | ||
isLoading={ false } | ||
product={ product } | ||
> | ||
<div> | ||
<ProductImage | ||
className={ '' } | ||
showSaleBadge={ false } | ||
/> | ||
<ProductName | ||
align={ '' } | ||
headingLevel={ 2 } | ||
showProductLink={ true } | ||
/> | ||
<ProductRating /> | ||
<ProductSaleBadge /> | ||
<ProductPrice /> | ||
</div> | ||
{ product.is_in_stock ? ( | ||
<AddToCartButton /> | ||
) : ( | ||
<ProductButton /> | ||
) } | ||
</ProductDataContextProvider> | ||
</InnerBlockLayoutContextProvider> | ||
</div> | ||
); | ||
}; | ||
|
||
export default CartCrossSellsProduct; |
37 changes: 37 additions & 0 deletions
37
assets/js/blocks/cart/cart-cross-sells-product-list/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { ProductResponseItem } from '@woocommerce/type-defs/product-response'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import CartCrossSellsProduct from './cart-cross-sells-product'; | ||
|
||
interface CrossSellsProductListProps { | ||
products: ProductResponseItem[]; | ||
className?: string | undefined; | ||
columns: number; | ||
} | ||
|
||
const CartCrossSellsProductList = ( { | ||
products, | ||
columns, | ||
}: CrossSellsProductListProps ): JSX.Element => { | ||
const crossSellsProducts = products.map( ( product, i ) => { | ||
if ( i >= columns ) return null; | ||
|
||
return ( | ||
<CartCrossSellsProduct | ||
// Setting isLoading to false, given this parameter is required. | ||
isLoading={ false } | ||
product={ product } | ||
key={ product.id } | ||
/> | ||
); | ||
} ); | ||
|
||
return <div>{ crossSellsProducts }</div>; | ||
}; | ||
|
||
export default CartCrossSellsProductList; |
17 changes: 17 additions & 0 deletions
17
assets/js/blocks/cart/inner-blocks/cart-cross-sells-block/block.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "woocommerce/cart-cross-sells-block", | ||
"version": "1.0.0", | ||
"title": "Cart Cross-Sells block", | ||
"description": "Shows the Cross-Sells block.", | ||
"category": "woocommerce", | ||
"supports": { | ||
"align": false, | ||
"html": false, | ||
"multiple": false, | ||
"reusable": false, | ||
"inserter": true | ||
}, | ||
"parent": [ "woocommerce/cart-items-block" ], | ||
"textdomain": "woo-gutenberg-products-block", | ||
"apiVersion": 2 | ||
} |
41 changes: 41 additions & 0 deletions
41
assets/js/blocks/cart/inner-blocks/cart-cross-sells-block/edit.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import type { TemplateArray } from '@wordpress/blocks'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { useBlockProps, InnerBlocks } from '@wordpress/block-editor'; | ||
|
||
export const Edit = (): JSX.Element => { | ||
const blockProps = useBlockProps( { | ||
className: 'wc-block-cart__cross-sells', | ||
} ); | ||
const defaultTemplate = [ | ||
[ | ||
'core/heading', | ||
{ | ||
content: __( | ||
'You may be interested in…', | ||
'woo-gutenberg-products-block' | ||
), | ||
level: 3, | ||
}, | ||
, | ||
[], | ||
], | ||
[ 'woocommerce/cart-cross-sells-products-block', {}, [] ], | ||
] as TemplateArray; | ||
|
||
return ( | ||
<div { ...blockProps }> | ||
<InnerBlocks template={ defaultTemplate } templateLock={ false } /> | ||
</div> | ||
); | ||
}; | ||
|
||
export const Save = (): JSX.Element => { | ||
return ( | ||
<div { ...useBlockProps.save() }> | ||
<InnerBlocks.Content /> | ||
</div> | ||
); | ||
}; |
24 changes: 24 additions & 0 deletions
24
assets/js/blocks/cart/inner-blocks/cart-cross-sells-block/frontend.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { useStoreCart } from '@woocommerce/base-context/hooks'; | ||
|
||
interface Props { | ||
children?: JSX.Element | JSX.Element[]; | ||
className?: string; | ||
} | ||
|
||
const FrontendBlock = ( { | ||
children, | ||
className = '', | ||
}: Props ): JSX.Element | null => { | ||
const { crossSellsProducts, cartIsLoading } = useStoreCart(); | ||
|
||
if ( cartIsLoading || crossSellsProducts.length < 1 ) { | ||
return null; | ||
} | ||
|
||
return <div className={ className }>{ children }</div>; | ||
}; | ||
|
||
export default FrontendBlock; |
24 changes: 24 additions & 0 deletions
24
assets/js/blocks/cart/inner-blocks/cart-cross-sells-block/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { Icon, column } from '@wordpress/icons'; | ||
import { registerExperimentalBlockType } from '@woocommerce/block-settings'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { Edit, Save } from './edit'; | ||
import metadata from './block.json'; | ||
|
||
registerExperimentalBlockType( metadata, { | ||
icon: { | ||
src: ( | ||
<Icon | ||
icon={ column } | ||
className="wc-block-editor-components-block-icon" | ||
/> | ||
), | ||
}, | ||
edit: Edit, | ||
save: Save, | ||
} ); |
23 changes: 23 additions & 0 deletions
23
assets/js/blocks/cart/inner-blocks/cart-cross-sells-products/block.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "woocommerce/cart-cross-sells-products-block", | ||
"version": "1.0.0", | ||
"title": "Cart Cross-Sells products", | ||
"description": "Shows the Cross-Sells products.", | ||
"category": "woocommerce", | ||
"supports": { | ||
"align": false, | ||
"html": false, | ||
"multiple": false, | ||
"reusable": false, | ||
"inserter": false | ||
nielslange marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
"attributes": { | ||
"columns": { | ||
"type": "number", | ||
"default": 3 | ||
} | ||
}, | ||
"parent": [ "woocommerce/cart-cross-sells-block" ], | ||
"textdomain": "woo-gutenberg-products-block", | ||
"apiVersion": 2 | ||
} |
33 changes: 33 additions & 0 deletions
33
assets/js/blocks/cart/inner-blocks/cart-cross-sells-products/block.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { useStoreCart } from '@woocommerce/base-context/hooks'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import CartCrossSellsProductList from '../../cart-cross-sells-product-list'; | ||
import metadata from './block.json'; | ||
|
||
interface BlockProps { | ||
className?: string | undefined; | ||
columns: number; | ||
} | ||
|
||
const Block = ( { className, columns }: BlockProps ): JSX.Element => { | ||
const { crossSellsProducts } = useStoreCart(); | ||
|
||
if ( typeof columns === 'undefined' ) { | ||
columns = metadata.attributes.columns.default; | ||
opr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
return ( | ||
<CartCrossSellsProductList | ||
className={ className } | ||
columns={ columns } | ||
products={ crossSellsProducts } | ||
/> | ||
); | ||
}; | ||
|
||
export default Block; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's investigate why
cartIsLoading
is always false for our block, it could be because it's an inner block and it's only rendered when this is finished, if so we could remove this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be great, if you could assist me troubleshooting this one.