-
Notifications
You must be signed in to change notification settings - Fork 37
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 #1955 from Shopify/js-cart-api-docs
Added examples for all cart functions
- Loading branch information
Showing
51 changed files
with
1,194 additions
and
20 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
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
21 changes: 21 additions & 0 deletions
21
...ages/ui-extensions/docs/surfaces/point-of-sale/reference/examples/cart-api/add-address.ts
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,21 @@ | ||
import {Tile, extension} from '@shopify/ui-extensions/point-of-sale'; | ||
|
||
export default extension('pos.home.tile.render', (root, api) => { | ||
const tile = root.createComponent(Tile, { | ||
title: 'My App', | ||
subtitle: 'Call cart function', | ||
enabled: true, | ||
onPress: () => { | ||
api.cart.addAddress({ | ||
address1: '123456 Main Street', | ||
city: 'Ottawa', | ||
province: 'Ontario', | ||
firstName: 'John', | ||
lastName: 'Doe', | ||
country: 'Canada', | ||
}); | ||
}, | ||
}); | ||
|
||
root.append(tile); | ||
}); |
32 changes: 32 additions & 0 deletions
32
...ges/ui-extensions/docs/surfaces/point-of-sale/reference/examples/cart-api/add-address.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,32 @@ | ||
|
||
import React from 'react'; | ||
import { | ||
reactExtension, | ||
useApi, | ||
Tile | ||
} from '@shopify/ui-extensions-react/point-of-sale'; | ||
|
||
const SmartGridTile = () => { | ||
const api = useApi<'pos.home.tile.render'>(); | ||
|
||
return ( | ||
<Tile | ||
title="My App" | ||
subtitle='Call cart function' | ||
enabled | ||
onPress={() => api.cart.addAddress({ | ||
address1: '123456 Main Street', | ||
city: 'Ottawa', | ||
province: 'Ontario', | ||
firstName: 'John', | ||
lastName: 'Doe', | ||
country: 'Canada' | ||
})} | ||
/> | ||
); | ||
}; | ||
|
||
export default reactExtension( | ||
'pos.home.tile.render', | ||
() => <SmartGridTile /> | ||
); |
14 changes: 14 additions & 0 deletions
14
...extensions/docs/surfaces/point-of-sale/reference/examples/cart-api/add-cart-properties.ts
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,14 @@ | ||
import {Tile, extension} from '@shopify/ui-extensions/point-of-sale'; | ||
|
||
export default extension('pos.home.tile.render', (root, api) => { | ||
const tile = root.createComponent(Tile, { | ||
title: 'My App', | ||
subtitle: 'Call cart action', | ||
enabled: true, | ||
onPress: () => { | ||
api.cart.addCartProperties({Engraving: 'John Doe'}); | ||
}, | ||
}); | ||
|
||
root.append(tile); | ||
}); |
25 changes: 25 additions & 0 deletions
25
...xtensions/docs/surfaces/point-of-sale/reference/examples/cart-api/add-cart-properties.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,25 @@ | ||
|
||
import React from 'react'; | ||
import { | ||
reactExtension, | ||
useApi, | ||
Tile | ||
} from '@shopify/ui-extensions-react/point-of-sale'; | ||
|
||
const SmartGridTile = () => { | ||
const api = useApi<'pos.home.tile.render'>(); | ||
|
||
return ( | ||
<Tile | ||
title="My App" | ||
subtitle='Call cart function' | ||
enabled | ||
onPress={() => api.cart.addCartProperties({Engraving: 'John Doe'})} | ||
/> | ||
); | ||
}; | ||
|
||
export default reactExtension( | ||
'pos.home.tile.render', | ||
() => <SmartGridTile /> | ||
); |
19 changes: 19 additions & 0 deletions
19
.../ui-extensions/docs/surfaces/point-of-sale/reference/examples/cart-api/add-custom-sale.ts
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,19 @@ | ||
import {Tile, extension} from '@shopify/ui-extensions/point-of-sale'; | ||
|
||
export default extension('pos.home.tile.render', (root, api) => { | ||
const tile = root.createComponent(Tile, { | ||
title: 'My App', | ||
subtitle: 'Call cart function', | ||
enabled: true, | ||
onPress: () => { | ||
api.cart.addCustomSale({ | ||
title: 'New product', | ||
quantity: 1, | ||
price: '10.00', | ||
taxable: true, | ||
}); | ||
}, | ||
}); | ||
|
||
root.append(tile); | ||
}); |
30 changes: 30 additions & 0 deletions
30
...ui-extensions/docs/surfaces/point-of-sale/reference/examples/cart-api/add-custom-sale.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,30 @@ | ||
|
||
import React from 'react'; | ||
import { | ||
reactExtension, | ||
useApi, | ||
Tile | ||
} from '@shopify/ui-extensions-react/point-of-sale'; | ||
|
||
const SmartGridTile = () => { | ||
const api = useApi<'pos.home.tile.render'>(); | ||
|
||
return ( | ||
<Tile | ||
title="My App" | ||
subtitle='Call cart function' | ||
enabled | ||
onPress={() => api.cart.addCustomSale({ | ||
title: 'New product', | ||
quantity: 1, | ||
price: '10.00', | ||
taxable: true, | ||
})} | ||
/> | ||
); | ||
}; | ||
|
||
export default reactExtension( | ||
'pos.home.tile.render', | ||
() => <SmartGridTile /> | ||
); |
14 changes: 14 additions & 0 deletions
14
...sions/docs/surfaces/point-of-sale/reference/examples/cart-api/add-line-item-properties.ts
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,14 @@ | ||
import {Tile, extension} from '@shopify/ui-extensions/point-of-sale'; | ||
|
||
export default extension('pos.home.tile.render', (root, api) => { | ||
const tile = root.createComponent(Tile, { | ||
title: 'My App', | ||
subtitle: 'Call cart function', | ||
enabled: true, | ||
onPress: () => { | ||
api.cart.addLineItemProperties('aa-1234567', {Engraving: 'John Doe'}); | ||
}, | ||
}); | ||
|
||
root.append(tile); | ||
}); |
25 changes: 25 additions & 0 deletions
25
...ions/docs/surfaces/point-of-sale/reference/examples/cart-api/add-line-item-properties.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,25 @@ | ||
|
||
import React from 'react'; | ||
import { | ||
reactExtension, | ||
useApi, | ||
Tile | ||
} from '@shopify/ui-extensions-react/point-of-sale'; | ||
|
||
const SmartGridTile = () => { | ||
const api = useApi<'pos.home.tile.render'>(); | ||
|
||
return ( | ||
<Tile | ||
title="My App" | ||
subtitle='Call cart function' | ||
enabled | ||
onPress={() => api.cart.addLineItemProperties('aa-1234567', {Engraving: 'John Doe'})} | ||
/> | ||
); | ||
}; | ||
|
||
export default reactExtension( | ||
'pos.home.tile.render', | ||
() => <SmartGridTile /> | ||
); |
Oops, something went wrong.