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 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
POV: Create Cross-Sells product list
- Loading branch information
1 parent
4562973
commit 855d828
Showing
10 changed files
with
145 additions
and
7 deletions.
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
47 changes: 47 additions & 0 deletions
47
assets/js/blocks/cart/cart-cross-sells-product-list/cart-cross-sells-item.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,47 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { ProductImage } from '@woocommerce/base-components/cart-checkout'; | ||
import ProductName from '@woocommerce/base-components/product-name'; | ||
import ProductPrice from '@woocommerce/base-components/product-price'; | ||
import { getCurrencyFromPriceResponse } from '@woocommerce/price-format'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { AddToCartButton } from '../../../atomic/blocks/product-elements/add-to-cart/shared'; | ||
|
||
const CartCrossSellsItem = ( { crossSellsItem } ): JSX.Element => { | ||
const { images, name, prices, permalink } = crossSellsItem; | ||
const priceCurrency = getCurrencyFromPriceResponse( prices ); | ||
|
||
return ( | ||
<div> | ||
<ProductDataContextProvider | ||
product={ product } | ||
isLoading={ isLoading } | ||
> | ||
<a href={ permalink }> | ||
<ProductImage | ||
image={ images.length ? images[ 0 ] : {} } | ||
fallbackAlt={ name } | ||
/> | ||
<ProductName disabled={ true } name={ name } /> | ||
<div>[ Product rating ]</div> | ||
<ProductPrice | ||
currency={ priceCurrency } | ||
price={ prices.price } | ||
regularPrice={ prices.regular_price } | ||
className="wc-block-components-cross-sells-item__individual-prices" | ||
priceClassName="wc-block-components-cross-sells-item__individual-price" | ||
regularPriceClassName="wc-block-components-cross-sells-item__regular-individual-price" | ||
format={ '<price/>' } | ||
/> | ||
</a> | ||
<AddToCartButton /> | ||
</ProductDataContextProvider> | ||
</div> | ||
); | ||
}; | ||
|
||
export default CartCrossSellsItem; |
39 changes: 39 additions & 0 deletions
39
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,39 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { CartResponseItem } from '@woocommerce/type-defs/cart-response'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import CartCrossSellsItem from './cart-cross-sells-item'; | ||
|
||
const placeholderRows = [ ...Array( 3 ) ].map( ( _x, i ) => ( | ||
<CartCrossSellsItem crossSellsItem={ {} } key={ i } /> | ||
) ); | ||
|
||
interface CrossSellsProducListProps { | ||
crossSellsItems: CartResponseItem[]; | ||
isLoading: boolean; | ||
className?: string; | ||
} | ||
|
||
const CartCrossSellsProductList = ( { | ||
crossSellsItems = [], | ||
isLoading = false, | ||
}: CrossSellsProducListProps ): JSX.Element => { | ||
const products = isLoading | ||
? placeholderRows | ||
: crossSellsItems.map( ( crossSellsItem ) => { | ||
return ( | ||
<CartCrossSellsItem | ||
key={ crossSellsItem.key } | ||
crossSellsItem={ crossSellsItem } | ||
/> | ||
); | ||
} ); | ||
|
||
return <>{ products }</>; | ||
}; | ||
|
||
export default CartCrossSellsProductList; |
26 changes: 19 additions & 7 deletions
26
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 |
---|---|---|
@@ -1,10 +1,22 @@ | ||
const Block = (): JSX.Element => { | ||
const divStyle = { | ||
border: '1px solid', | ||
padding: '5px 10px', | ||
textAlign: 'center', | ||
}; | ||
return <div style={ divStyle }>CROSS SELLS PRODUCTS</div>; | ||
/** | ||
* External dependencies | ||
*/ | ||
import { useStoreCart } from '@woocommerce/base-context/hooks'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import CartCrossSellsProductList from '../../cart-cross-sells-product-list'; | ||
|
||
const Block = ( { className }: { className: string } ): JSX.Element => { | ||
const { crossSellsItems, cartIsLoading } = useStoreCart(); | ||
return ( | ||
<CartCrossSellsProductList | ||
className={ className } | ||
crossSellsItems={ crossSellsItems } | ||
isLoading={ cartIsLoading } | ||
/> | ||
); | ||
}; | ||
|
||
export default Block; |
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
36 changes: 36 additions & 0 deletions
36
assets/js/blocks/cart/inner-blocks/cart-cross-sells-products/editor.scss
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,36 @@ | ||
.wp-block-woocommerce-cart-cross-sells-products-block { | ||
display: flex; | ||
flex-wrap: wrap; | ||
|
||
div { | ||
flex: 0 0 30%; | ||
list-style: none; | ||
padding-right: 5%; | ||
text-align: center; | ||
|
||
&:nth-child(3n + 3) { | ||
padding-right: 0%; | ||
} | ||
|
||
a { | ||
display: block; | ||
color: unset; | ||
|
||
.wc-block-components-product-name { | ||
font-weight: 600; | ||
} | ||
} | ||
|
||
.wc-block-components-product-add-to-cart-button:not(.is-link) { | ||
background-color: #eeeeee; | ||
color: #333333; | ||
margin-top: 1em; | ||
|
||
&:focus, &:hover { | ||
background-color: #d5d5d5; | ||
border-color: #d5d5d5; | ||
color: #333333; | ||
} | ||
} | ||
} | ||
} |
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
File renamed without changes
File renamed without changes
File renamed without changes