You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Resolvesshop/issues-retail#8521
### Background
The changes made in #2986 need their documentation to be updated.
### Solution
Adds release notes for:
- Added `editable` property
- Added `useCartEditable` hook
- Added `CartNotEditableError` error class
This PR also changes the API method docs to use `Throws` instead of `@throws` as our internal documentation engine doesn't support those tags yet. Ideally, we'd be able to make use of such tags, but for now I think it makes sense to just do without them.
#### Question
Now `editable` affects all cart methods, throwing an error when the cart is not editable. Should we update all examples to include the `editable` check or is that simply noise?
For example, the react examples would probably look like:
```tsx
const editable = useCartEditable();
// ...
return (
<Tile
// ...
onPress={() => editable && api.cart.setCustomer({
id: 1,
})}
/>
);
```
And TypeScript examples would look like:
```ts
const tile = root.createComponent(Tile, {
// ...
onPress: () => api.cart.subscribable.initial.editable && api.cart.setCustomer({
id: 1,
}),
});
// ...
api.cart.subscribable.subscribe((newCart: Cart) => {
tile.updateProps({
onPress: () => editable && api.cart.setCustomer({
id: 1,
}),
});
});
```
Note that the other way of handling cart editability is to disable the tile when `editable` is false. So we could also update the examples in a similar way but just modifying `enabled` instead of doing `editable && ...`.
How do we feel about including these in the examples? Does it detract from the actual example too much?
### 🎩
https://pos.docs.shopify.io/extensions/contributing/documentation#how-to-update-docs-for-stable-api-versions
Here is the result:
| API Docs | Release Notes | Example |
| -------- | ------------- | ------- |
|  |  |  |
### Checklist
- [x] I have 🎩'd these changes
- [x] I have updated relevant documentation
* Set line item discounts to multiple line items at the same time.
190
-
* @param lineItemDiscounts a map of discounts to add. They key is the uuid of the line item you want to add the discount to. The value is the discount input.
191
170
*
192
-
* @throws CartNotEditableError if the cart is not currently editable.
171
+
* @param lineItemDiscounts a map of discounts to add. They key is the uuid of the line item you want to add the discount to. The value is the discount input.
193
172
*/
194
173
bulkSetLineItemDiscounts(
195
174
lineItemDiscounts: SetLineItemDiscountInput[],
196
175
): Promise<void>;
197
176
198
177
/**
199
178
* Sets an attributed staff to all line items in the cart.
200
-
* @param staffId the ID of the staff. Providing undefined will clear the attributed staff from all line items.
201
179
*
202
-
* @throws CartNotEditableError if the cart is not currently editable.
180
+
* @param staffId the ID of the staff. Providing undefined will clear the attributed staff from all line items.
0 commit comments