@wix/headless-restaurants-olo 0.0.44 → 0.0.45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -152,6 +152,7 @@ export interface AddToCartButtonProps {
152
152
  /** Text label for the button */
153
153
  label: React.ReactNode;
154
154
  formattedPrice: string;
155
+ price: number;
155
156
  }>;
156
157
  }
157
158
  /**
@@ -132,7 +132,7 @@ Variants.displayName = 'ItemDetails.Variants';
132
132
  * ```
133
133
  */
134
134
  export const AddToCartButton = React.forwardRef(({ asChild, children, className, addToCartLabelMap, ...props }, ref) => {
135
- return (_jsx(CoreItemDetails.LineItemComponent, { addToCartLabelMap: addToCartLabelMap, children: ({ onHandleAddToCart, buttonState, addToCartButtonDisabled, loadingState, labelText, formattedPrice, lineItem, }) => {
135
+ return (_jsx(CoreItemDetails.LineItemComponent, { addToCartLabelMap: addToCartLabelMap, children: ({ onHandleAddToCart, buttonState, addToCartButtonDisabled, loadingState, labelText, price, formattedPrice, lineItem, }) => {
136
136
  const label = (_jsxs(_Fragment, { children: [_jsx("span", { children: labelText }), " ", _jsx("span", { children: " | " }), _jsx("span", { children: formattedPrice })] }));
137
137
  return (_jsx(AsChildSlot, { asChild: asChild, className: className, customElement: children, customElementProps: {
138
138
  buttonState,
@@ -141,6 +141,7 @@ export const AddToCartButton = React.forwardRef(({ asChild, children, className,
141
141
  onHandleAddToCart,
142
142
  label,
143
143
  formattedPrice,
144
+ price,
144
145
  }, ref: ref, ...props, children: _jsx(Commerce.Actions.AddToCart, { asChild: false, label: label, className: className, lineItems: [lineItem], ...props }) }));
145
146
  } }));
146
147
  });
@@ -28,6 +28,7 @@ interface ItemDetailsLineItemProps {
28
28
  addToCartButtonDisabled: boolean;
29
29
  labelText: string;
30
30
  formattedPrice: string;
31
+ price: number;
31
32
  }) => React.ReactNode;
32
33
  }
33
34
  export declare const LineItemComponent: React.FC<ItemDetailsLineItemProps>;
@@ -48,6 +48,7 @@ export const LineItemComponent = ({ addToCartLabelMap, children, }) => {
48
48
  labelText,
49
49
  formattedPrice,
50
50
  lineItem,
51
+ price,
51
52
  });
52
53
  };
53
54
  export const QuantityComponent = ({ children, }) => {
@@ -63,17 +63,17 @@ export const ItemService = implementService.withConfig()(ItemServiceDefinition,
63
63
  : '');
64
64
  const priceVariants = config.item?.priceVariants || [];
65
65
  let initialVariant;
66
- if (!config.editItemMode) {
67
- initialVariant = priceVariants.length > 0 ? priceVariants[0] : undefined;
66
+ if (config.editItemMode && config.editingItemValues?.selectedVariantId) {
67
+ initialVariant = priceVariants.find((variant) => variant._id === config.editingItemValues?.selectedVariantId);
68
68
  }
69
69
  else {
70
- if (config.editingItemValues?.selectedVariantId) {
71
- initialVariant = priceVariants.find((variant) => variant._id === config.editingItemValues?.selectedVariantId);
72
- }
73
- else {
74
- initialVariant =
75
- priceVariants.length > 0 ? priceVariants[0] : undefined;
76
- }
70
+ initialVariant =
71
+ priceVariants.length > 0
72
+ ? priceVariants.reduce((cheapest, current) => Number(current.priceInfo?.price) <
73
+ Number(cheapest.priceInfo?.price)
74
+ ? current
75
+ : cheapest)
76
+ : undefined;
77
77
  }
78
78
  const selectedVariant = signalsService.signal(initialVariant);
79
79
  const modifierGroups = config.item?.modifierGroups || [];
@@ -152,6 +152,7 @@ export interface AddToCartButtonProps {
152
152
  /** Text label for the button */
153
153
  label: React.ReactNode;
154
154
  formattedPrice: string;
155
+ price: number;
155
156
  }>;
156
157
  }
157
158
  /**
@@ -132,7 +132,7 @@ Variants.displayName = 'ItemDetails.Variants';
132
132
  * ```
133
133
  */
134
134
  export const AddToCartButton = React.forwardRef(({ asChild, children, className, addToCartLabelMap, ...props }, ref) => {
135
- return (_jsx(CoreItemDetails.LineItemComponent, { addToCartLabelMap: addToCartLabelMap, children: ({ onHandleAddToCart, buttonState, addToCartButtonDisabled, loadingState, labelText, formattedPrice, lineItem, }) => {
135
+ return (_jsx(CoreItemDetails.LineItemComponent, { addToCartLabelMap: addToCartLabelMap, children: ({ onHandleAddToCart, buttonState, addToCartButtonDisabled, loadingState, labelText, price, formattedPrice, lineItem, }) => {
136
136
  const label = (_jsxs(_Fragment, { children: [_jsx("span", { children: labelText }), " ", _jsx("span", { children: " | " }), _jsx("span", { children: formattedPrice })] }));
137
137
  return (_jsx(AsChildSlot, { asChild: asChild, className: className, customElement: children, customElementProps: {
138
138
  buttonState,
@@ -141,6 +141,7 @@ export const AddToCartButton = React.forwardRef(({ asChild, children, className,
141
141
  onHandleAddToCart,
142
142
  label,
143
143
  formattedPrice,
144
+ price,
144
145
  }, ref: ref, ...props, children: _jsx(Commerce.Actions.AddToCart, { asChild: false, label: label, className: className, lineItems: [lineItem], ...props }) }));
145
146
  } }));
146
147
  });
@@ -28,6 +28,7 @@ interface ItemDetailsLineItemProps {
28
28
  addToCartButtonDisabled: boolean;
29
29
  labelText: string;
30
30
  formattedPrice: string;
31
+ price: number;
31
32
  }) => React.ReactNode;
32
33
  }
33
34
  export declare const LineItemComponent: React.FC<ItemDetailsLineItemProps>;
@@ -48,6 +48,7 @@ export const LineItemComponent = ({ addToCartLabelMap, children, }) => {
48
48
  labelText,
49
49
  formattedPrice,
50
50
  lineItem,
51
+ price,
51
52
  });
52
53
  };
53
54
  export const QuantityComponent = ({ children, }) => {
@@ -63,17 +63,17 @@ export const ItemService = implementService.withConfig()(ItemServiceDefinition,
63
63
  : '');
64
64
  const priceVariants = config.item?.priceVariants || [];
65
65
  let initialVariant;
66
- if (!config.editItemMode) {
67
- initialVariant = priceVariants.length > 0 ? priceVariants[0] : undefined;
66
+ if (config.editItemMode && config.editingItemValues?.selectedVariantId) {
67
+ initialVariant = priceVariants.find((variant) => variant._id === config.editingItemValues?.selectedVariantId);
68
68
  }
69
69
  else {
70
- if (config.editingItemValues?.selectedVariantId) {
71
- initialVariant = priceVariants.find((variant) => variant._id === config.editingItemValues?.selectedVariantId);
72
- }
73
- else {
74
- initialVariant =
75
- priceVariants.length > 0 ? priceVariants[0] : undefined;
76
- }
70
+ initialVariant =
71
+ priceVariants.length > 0
72
+ ? priceVariants.reduce((cheapest, current) => Number(current.priceInfo?.price) <
73
+ Number(cheapest.priceInfo?.price)
74
+ ? current
75
+ : cheapest)
76
+ : undefined;
77
77
  }
78
78
  const selectedVariant = signalsService.signal(initialVariant);
79
79
  const modifierGroups = config.item?.modifierGroups || [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/headless-restaurants-olo",
3
- "version": "0.0.44",
3
+ "version": "0.0.45",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -78,5 +78,5 @@
78
78
  "groupId": "com.wixpress.headless-components"
79
79
  }
80
80
  },
81
- "falconPackageHash": "8b0e8f84677d9e75b1242a120c014e61d8e0279095afd8bf291e54aa"
81
+ "falconPackageHash": "fc2b5a7894052822fdee845ca019b9b8bb662c3414177a0262d70454"
82
82
  }