mirror of
https://github.com/vercel/commerce.git
synced 2025-06-19 13:41:22 +00:00
Updates
This commit is contained in:
parent
f16cb7206b
commit
af10abe3ba
@ -148,8 +148,11 @@ const ProductView: FC<Props> = ({ product }) => {
|
|||||||
className={s.button}
|
className={s.button}
|
||||||
onClick={addToCart}
|
onClick={addToCart}
|
||||||
loading={loading}
|
loading={loading}
|
||||||
|
disabled={variant?.availableForSale === false}
|
||||||
>
|
>
|
||||||
Add to Cart
|
{variant?.availableForSale === false
|
||||||
|
? 'Not Available'
|
||||||
|
: 'Add To Cart'}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
.root {
|
.root {
|
||||||
composes: root from 'components/ui/Button/Button.module.css';
|
composes: root from 'components/ui/Button/Button.module.css';
|
||||||
@apply h-12 py-0 px-3 bg-primary text-primary rounded-full mr-3 inline-flex
|
@apply h-12 p-0 bg-primary text-primary rounded-full mr-3 inline-flex
|
||||||
items-center justify-center cursor-pointer transition duration-150 ease-in-out
|
items-center justify-center cursor-pointer transition duration-150 ease-in-out
|
||||||
shadow-none border-gray-200 border box-border;
|
shadow-none border-gray-200 border box-border;
|
||||||
|
|
||||||
@ -15,6 +15,10 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.size {
|
||||||
|
@apply px-3 leading-none;
|
||||||
|
}
|
||||||
|
|
||||||
.color {
|
.color {
|
||||||
@apply text-black transition duration-150 ease-in-out;
|
@apply text-black transition duration-150 ease-in-out;
|
||||||
|
|
||||||
|
@ -21,14 +21,14 @@ const Swatch: FC<Omit<ButtonProps, 'variant'> & Props> = ({
|
|||||||
active,
|
active,
|
||||||
...props
|
...props
|
||||||
}) => {
|
}) => {
|
||||||
variant = variant?.toLowerCase()
|
|
||||||
label = label?.toLowerCase()
|
label = label?.toLowerCase()
|
||||||
|
const isColor = color !== ''
|
||||||
|
|
||||||
const rootClassName = cn(
|
const rootClassName = cn(
|
||||||
s.root,
|
s.root,
|
||||||
{
|
{
|
||||||
[s.active]: active,
|
[s.active]: active,
|
||||||
[s.size]: variant !== 'color',
|
[s.size]: !isColor,
|
||||||
[s.color]: color,
|
[s.color]: color,
|
||||||
[s.dark]: color ? isDark(color) : false,
|
[s.dark]: color ? isDark(color) : false,
|
||||||
},
|
},
|
||||||
@ -38,17 +38,18 @@ const Swatch: FC<Omit<ButtonProps, 'variant'> & Props> = ({
|
|||||||
return (
|
return (
|
||||||
<Button
|
<Button
|
||||||
className={rootClassName}
|
className={rootClassName}
|
||||||
style={color ? { backgroundColor: color } : {}}
|
style={isColor ? { backgroundColor: color } : {}}
|
||||||
aria-label="Variant Swatch"
|
aria-label="Variant Swatch"
|
||||||
{...(variant === 'color' && { title: label })}
|
{...(isColor && { title: label })}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
{variant === 'color' && active && (
|
{isColor ? (
|
||||||
<span>
|
<span>
|
||||||
<Check />
|
<Check />
|
||||||
</span>
|
</span>
|
||||||
|
) : (
|
||||||
|
label
|
||||||
)}
|
)}
|
||||||
{variant !== 'color' ? label : null}
|
|
||||||
</Button>
|
</Button>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@ export type ProductOptionValues = {
|
|||||||
export type ProductVariant = {
|
export type ProductVariant = {
|
||||||
id: string | number
|
id: string | number
|
||||||
options: ProductOption[]
|
options: ProductOption[]
|
||||||
|
availableForSale?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Product = {
|
export type Product = {
|
||||||
|
@ -11,11 +11,11 @@ export const getSearchVariables = ({
|
|||||||
let query = ''
|
let query = ''
|
||||||
|
|
||||||
if (search) {
|
if (search) {
|
||||||
query += `product_type:${search} OR title:${search} OR tag:${search}`
|
query += `product_type:${search} OR title:${search} OR tag:${search} `
|
||||||
}
|
}
|
||||||
|
|
||||||
if (brandId) {
|
if (brandId) {
|
||||||
query += `${search ? ' AND ' : ''}vendor:${brandId}`
|
query += `${search ? 'AND ' : ''}vendor:${brandId}`
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -37,9 +37,12 @@ const normalizeProductOption = ({
|
|||||||
label: value,
|
label: value,
|
||||||
}
|
}
|
||||||
if (displayName.match(/colou?r/gi)) {
|
if (displayName.match(/colou?r/gi)) {
|
||||||
|
const mapedColor = colorMap[value]
|
||||||
|
if (mapedColor) {
|
||||||
output = {
|
output = {
|
||||||
...output,
|
...output,
|
||||||
hexColors: [colorMap[value] || value],
|
hexColors: [mapedColor],
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return output
|
return output
|
||||||
@ -56,7 +59,16 @@ const normalizeProductImages = ({ edges }: ImageConnection) =>
|
|||||||
const normalizeProductVariants = ({ edges }: ProductVariantConnection) => {
|
const normalizeProductVariants = ({ edges }: ProductVariantConnection) => {
|
||||||
return edges?.map(
|
return edges?.map(
|
||||||
({
|
({
|
||||||
node: { id, selectedOptions, sku, title, priceV2, compareAtPriceV2 },
|
node: {
|
||||||
|
id,
|
||||||
|
selectedOptions,
|
||||||
|
sku,
|
||||||
|
title,
|
||||||
|
priceV2,
|
||||||
|
compareAtPriceV2,
|
||||||
|
requiresShipping,
|
||||||
|
availableForSale,
|
||||||
|
},
|
||||||
}) => {
|
}) => {
|
||||||
return {
|
return {
|
||||||
id,
|
id,
|
||||||
@ -64,7 +76,8 @@ const normalizeProductVariants = ({ edges }: ProductVariantConnection) => {
|
|||||||
sku: sku ?? id,
|
sku: sku ?? id,
|
||||||
price: +priceV2.amount,
|
price: +priceV2.amount,
|
||||||
listPrice: +compareAtPriceV2?.amount,
|
listPrice: +compareAtPriceV2?.amount,
|
||||||
requiresShipping: true,
|
requiresShipping,
|
||||||
|
availableForSale,
|
||||||
options: selectedOptions.map(({ name, value }: SelectedOption) => {
|
options: selectedOptions.map(({ name, value }: SelectedOption) => {
|
||||||
const options = normalizeProductOption({
|
const options = normalizeProductOption({
|
||||||
id,
|
id,
|
||||||
|
@ -3,6 +3,7 @@ const getProductQuery = /* GraphQL */ `
|
|||||||
productByHandle(handle: $slug) {
|
productByHandle(handle: $slug) {
|
||||||
id
|
id
|
||||||
handle
|
handle
|
||||||
|
availableForSale
|
||||||
title
|
title
|
||||||
productType
|
productType
|
||||||
vendor
|
vendor
|
||||||
@ -33,6 +34,8 @@ const getProductQuery = /* GraphQL */ `
|
|||||||
id
|
id
|
||||||
title
|
title
|
||||||
sku
|
sku
|
||||||
|
availableForSale
|
||||||
|
requiresShipping
|
||||||
selectedOptions {
|
selectedOptions {
|
||||||
name
|
name
|
||||||
value
|
value
|
||||||
|
Loading…
x
Reference in New Issue
Block a user