-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2239 from graphcommerce-org/feature/update-price-…
…with-customizable-options-GCOM-1351 Feature/update price with customizable options gcom 1351
- Loading branch information
Showing
9 changed files
with
358 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@graphcommerce/magento-product-configurable": patch | ||
"@graphcommerce/magento-product": patch | ||
--- | ||
|
||
Prices of products are now updated when customizable options are selected |
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
78 changes: 63 additions & 15 deletions
78
packages/magento-product/components/ProductCustomizable/CustomizableDropDownOption.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,33 +1,81 @@ | ||
import { SelectElement } from '@graphcommerce/ecommerce-ui' | ||
import { SelectElement, useController } from '@graphcommerce/ecommerce-ui' | ||
import { SectionHeader, filterNonNullableKeys } from '@graphcommerce/next-ui' | ||
import { Box } from '@mui/material' | ||
import { Box, ListItemText, MenuItem, TextField, Typography } from '@mui/material' | ||
import { useFormAddProductsToCart } from '../AddProductsToCart' | ||
import { OptionTypeRenderer } from './CustomizableAreaOption' | ||
import { Money } from '@graphcommerce/magento-store' | ||
|
||
type CustomizableDropDownOptionProps = React.ComponentProps< | ||
OptionTypeRenderer['CustomizableDropDownOption'] | ||
> | ||
|
||
export function CustomizableDropDownOption(props: CustomizableDropDownOptionProps) { | ||
const { uid, required, index, title, dropdownValue } = props | ||
const { control } = useFormAddProductsToCart() | ||
const { uid, required, index, title, dropdownValue, productPrice, currency } = props | ||
const { control, getValues } = useFormAddProductsToCart() | ||
|
||
const { | ||
field: { onChange, value, ref, ...field }, | ||
fieldState: { invalid, error }, | ||
} = useController({ | ||
name: `cartItems.${index}.customizable_options.${uid}`, | ||
rules: { | ||
required: Boolean(required), | ||
}, | ||
control, | ||
defaultValue: '', | ||
}) | ||
|
||
return ( | ||
<Box> | ||
<SectionHeader labelLeft={title} sx={{ mt: 0 }} /> | ||
<SelectElement | ||
sx={{ width: '100%' }} | ||
|
||
<TextField | ||
sx={{ | ||
width: '100%', | ||
'& .MuiSelect-select': { | ||
display: 'flex', | ||
justifyContent: 'space-between', | ||
alignItems: 'center', | ||
}, | ||
}} | ||
color='primary' | ||
control={control} | ||
name={`cartItems.${index}.customizable_options.${uid}`} | ||
label={title} | ||
value={value ?? ''} | ||
{...field} | ||
inputRef={ref} | ||
onChange={(event) => onChange(event.target.value)} | ||
select | ||
required={Boolean(required)} | ||
defaultValue='' | ||
options={filterNonNullableKeys(dropdownValue, ['title']).map((option) => ({ | ||
id: option.uid, | ||
label: option.title, | ||
}))} | ||
/> | ||
error={invalid} | ||
helperText={error?.message} | ||
> | ||
{filterNonNullableKeys(dropdownValue, ['title']).map((option) => ( | ||
<MenuItem key={option.uid} value={option.uid}> | ||
<Box>{option.title}</Box> | ||
|
||
{option.price ? ( | ||
<Box | ||
sx={{ | ||
// display: 'flex', | ||
typography: 'body1', | ||
'&.sizeMedium': { typographty: 'subtitle1' }, | ||
'&.sizeLarge': { typography: 'h6' }, | ||
color: option.uid === value ? 'text.primary' : 'text.secondary', | ||
}} | ||
> | ||
<span style={{ fontFamily: 'arial', paddingTop: '1px' }}>+ </span> | ||
<Money | ||
value={ | ||
option.price_type === 'PERCENT' | ||
? productPrice * (option.price / 100) | ||
: option.price | ||
} | ||
currency={currency} | ||
/> | ||
</Box> | ||
) : null} | ||
</MenuItem> | ||
))} | ||
</TextField> | ||
</Box> | ||
) | ||
} |
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
Oops, something went wrong.