Skip to content

Add support to "bundles" #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
fcc3ee3
feat: manage bundle prices
marcomontalbano Dec 6, 2022
5f600b8
fix: unit tests
marcomontalbano Feb 6, 2024
bb89612
chore: debounce updatePrice to manage the update of kind and code at …
marcomontalbano Apr 9, 2024
402c51d
feat: manage bundle add-to-cart
marcomontalbano Apr 9, 2024
b1a1245
fix: unit tests
marcomontalbano Apr 9, 2024
d228734
chore: introduce kind to cl-add-to-cart and cl-availability
marcomontalbano Apr 10, 2024
23f32b3
chore: better folder structure for skus and bundles
marcomontalbano Apr 10, 2024
a713428
wip
marcomontalbano Apr 15, 2024
ac4a4bc
deps: update dependencies to latest minor
marcomontalbano May 27, 2024
5d7eab2
chore: cleanup apis for bundles and skus
marcomontalbano May 27, 2024
6cb7954
fix: blank slot when changing props
marcomontalbano May 27, 2024
bc07738
feat: disable add-to-cart when bundle out-of-stock
marcomontalbano May 27, 2024
e05ca27
chore: update docs
marcomontalbano May 27, 2024
d193cb2
deps: update gh workflow scripts
marcomontalbano May 28, 2024
785b7e1
chore: update docs
marcomontalbano May 28, 2024
2a780b6
deps: update pnpm to v9
marcomontalbano May 30, 2024
24c1fe1
docs: update demo
marcomontalbano May 30, 2024
8a9d9ad
chore: update docs with bundle cases
sfiorucci May 30, 2024
20a4838
deps: update dependencies to the latest minor
marcomontalbano May 30, 2024
d333bea
fix: cl-cart-count is showing the line items in the cart
marcomontalbano May 30, 2024
45ee0ae
chore: update e2e
marcomontalbano May 30, 2024
9800da2
chore: freeze pnpm version to v9.1.3
marcomontalbano May 30, 2024
95ffa09
chore: update favicon
marcomontalbano May 30, 2024
ea39f9a
docs: update editorial banner
marcomontalbano May 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/gh-pages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ jobs:
uses: actions/checkout@v4

- name: pnpm 🧰
uses: pnpm/action-setup@v3
uses: pnpm/action-setup@v4
with:
version: 8
version: 9.1.3

- name: Node 🧰
uses: actions/setup-node@v4
Expand All @@ -46,7 +46,7 @@ jobs:
run: pnpm build

- name: Setup Pages 🧰
uses: actions/configure-pages@v4
uses: actions/configure-pages@v5

- name: Upload artifact 🚀
uses: actions/upload-pages-artifact@v3
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ jobs:
uses: actions/checkout@v4

- name: pnpm 🧰
uses: pnpm/action-setup@v3
uses: pnpm/action-setup@v4
with:
version: 8
version: 9.1.3

- name: Node 🧰
uses: actions/setup-node@v4
Expand Down Expand Up @@ -47,7 +47,7 @@ jobs:

- name: Post to a Slack channel
id: slack
uses: slackapi/slack-github-action@v1.25.0
uses: slackapi/slack-github-action@v1.26
with:
# Slack channel id, channel name, or user id to post message.
# See also: https://api.slack.com/methods/chat.postMessage#channels
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
name: Release

permissions:
contents: write
discussions: write

on:
push:
tags: ["v*"]
Expand All @@ -13,7 +17,7 @@ jobs:
uses: actions/checkout@v4

- name: Create a draft GitHub release 🎁
uses: softprops/action-gh-release@v1
uses: softprops/action-gh-release@v2
with:
token: ${{ secrets.COMMERCELAYER_CI_TOKEN }}
draft: true
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ jobs:
uses: actions/checkout@v4

- name: pnpm 🧰
uses: pnpm/action-setup@v3
uses: pnpm/action-setup@v4
with:
version: 8
version: 9.1.3

- name: Node 🧰
uses: actions/setup-node@v4
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,17 @@
"license": "MIT",
"engines": {
"node": ">=18.18.0",
"pnpm": ">=8"
"pnpm": "9.1.3"
},
"packageManager": "pnpm@9.1.3",
"devDependencies": {
"@commercelayer/eslint-config-ts": "^1.4.5",
"concurrently": "^8.2.2",
"eslint": "^8.57.0",
"husky": "^9.0.11",
"lerna": "^8.1.3",
"lint-staged": "^15.2.4",
"replace-in-file": "^7.1.0",
"lint-staged": "^15.2.5",
"replace-in-file": "^7.2.0",
"typescript": "^5.4.5"
}
}
2 changes: 1 addition & 1 deletion packages/docs/.lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"*.{js,jsx,ts,tsx}": [
"eslint ./ --ext ts,tsx"
"eslint ./ --ext ts,tsx --fix"
]
}
1 change: 0 additions & 1 deletion packages/docs/.storybook/manager-head.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
<meta name="description" content="Commerce Layer drop-in.js lets you transform any plain HTML page into an enterprise-grade static commerce website, with almost no coding required, thanks to a set of micro frontends that handle the main ecommerce functionalities." key="desc" />
<link rel="shortcut icon" href="favicon.ico" />
<link rel="stylesheet" href="https://data.commercelayer.app/assets/css/storybook-manager-v8.css" />
42 changes: 21 additions & 21 deletions packages/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,41 @@
"build:sass": "sass ./stories/assets/styles/:./public/",
"build:sass:watch": "nodemon --watch ./node_modules/@commercelayer/drop-in.js -e scss --exec 'pnpm build:sass'",
"build": "pnpm build:sass && pnpm build:copy && storybook build --docs && pnpm replace:title",
"replace:title": "sed -i -e 's/Webpack App/Commerce Layer drop-in library/g' ./storybook-static/index.html",
"replace:title": "sed -i -e 's#@storybook/cli - Storybook#Commerce Layer drop-in library#g' ./storybook-static/index.html",
"serve": "http-server storybook-static -o"
},
"author": {
"name": "Marco Montalbano",
"email": "marco.montalbano@commercelayer.io"
},
"devDependencies": {
"@babel/core": "^7.24.5",
"@babel/preset-env": "^7.24.5",
"@babel/preset-react": "^7.24.1",
"@babel/preset-typescript": "^7.24.1",
"@storybook/addon-essentials": "^8.1.2",
"@storybook/addon-interactions": "^8.1.2",
"@storybook/addon-links": "^8.1.2",
"@storybook/addon-webpack5-compiler-swc": "^1.0.2",
"@storybook/blocks": "^8.1.2",
"@storybook/components": "^8.1.2",
"@storybook/core-common": "^8.1.2",
"@storybook/html": "^8.1.2",
"@storybook/html-webpack5": "^8.1.2",
"@babel/core": "^7.24.6",
"@babel/preset-env": "^7.24.6",
"@babel/preset-react": "^7.24.6",
"@babel/preset-typescript": "^7.24.6",
"@storybook/addon-essentials": "^8.1.5",
"@storybook/addon-interactions": "^8.1.5",
"@storybook/addon-links": "^8.1.5",
"@storybook/addon-webpack5-compiler-swc": "^1.0.3",
"@storybook/blocks": "^8.1.5",
"@storybook/components": "^8.1.5",
"@storybook/core-common": "^8.1.5",
"@storybook/html": "^8.1.5",
"@storybook/html-webpack5": "^8.1.5",
"@storybook/icons": "^1.2.9",
"@storybook/manager-api": "^8.1.2",
"@storybook/test": "^8.1.2",
"@storybook/theming": "^8.1.2",
"@storybook/types": "^8.1.2",
"@storybook/manager-api": "^8.1.5",
"@storybook/test": "^8.1.5",
"@storybook/theming": "^8.1.5",
"@storybook/types": "^8.1.5",
"@types/common-tags": "^1.8.4",
"@types/react": "^18",
"babel-loader": "^9.1.3",
"common-tags": "^1.8.2",
"http-server": "^14.1.1",
"nodemon": "^3.1.0",
"nodemon": "^3.1.2",
"remark-gfm": "^4.0.0",
"sass": "^1.77.2",
"storybook": "^8.1.2",
"sass": "^1.77.3",
"storybook": "^8.1.5",
"typescript": "^5.4.5",
"webpack": "^5.91.0"
},
Expand Down
Binary file removed packages/docs/public/favicon.ico
Binary file not shown.
20 changes: 20 additions & 0 deletions packages/docs/public/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/docs/public/register-h.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/docs/public/welcomeback-h.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 15 additions & 2 deletions packages/docs/stories/add-to-cart/cl-add-to-cart.mdx
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import { Canvas, Meta, Story, Controls } from '@storybook/blocks'
import * as Stories from './cl-add-to-cart.stories.ts';
import * as Stories from './cl-add-to-cart.stories.ts'
import { codes } from '../assets/constants.ts'
import { Alert } from '../assets/components'

<Meta of={Stories} />

# Add to cart

Once you have correctly set up your organization in Commerce Layer and imported the drop-in library as described [here](?path=/docs/getting-started--docs), you can use the `cl-add-to-cart` component to display a buy button on any page with embedded validation rules. By clicking the button, you will be able to add to the shopping cart a specified quantity of a specific product, as shown in the code snippets below.
Once you have correctly set up your organization in Commerce Layer and imported the drop-in library as described [here](?path=/docs/getting-started--docs), you can use the `cl-add-to-cart` component to display a buy button on any page with embedded validation rules. By clicking the button, you will be able to add to the shopping cart a specified quantity of a specific product or bundle, as shown in the code snippets below.

To enable the buy button, the `quantity` value must be greater than `0`. If the quantity isn't specified the default value will be used and just one unit of the selected product will be added to the shopping cart.

<Canvas of={Stories.Basic} />

<Controls of={Stories.Basic} />

<Alert title="Bundles" type="info">
The pre-filled code in the *Control* field refers to an SKU. If you select <code>bundle</code> as the kind of item, make sure to change it with a bundle code (e.g. <code>{codes.bundleAvailable}</code>) so that the button in the example above is enabled.
</Alert>

## Validation rules

As mentioned, the buy button provided by the `cl-add-to-cart` component comes with a set of embedded validation rules, meaning that the button is enabled or disabled based on whether those rules are met or not. Please find here below some common use cases.
Expand All @@ -30,6 +35,10 @@ The <code>cl-add-to-cart</code> component checks the inventory for the product i

<Canvas of={Stories.OutOfStock} />

The same happens when the item you want to add to the shopping cart is a bundle that contains one or more products that are out of stock (e.g. <code>{codes.bundleOutOfStock}</code>), like in the example below:

<Canvas of={Stories.BundleOutOfStock} />

### Non-existing code

The provided code must exist among the products of your organization. If you set as the <code>code</code> attribute a non-existing one (e.g. <code>{codes.nonexisting}</code>) the button will be rendered as disabled, as shown in the example below:
Expand All @@ -42,6 +51,10 @@ In order to prevent overselling errors, the <code>cl-add-to-cart</code> componen

<Canvas of={Stories.OversellingPrevention} />

The same happens if the available quantity of a product is exceeded across bundles, as shown in the example below where the bundle with code <code>{codes.bundleAvailable}</code> contains <code>10</code> units of the product with code <code>{codes.noOverselling}</code> that has a stock quantity less than <code>100</code>. If you try to add to the shopping cart <code>10</code> of those bundles (<code>10*10=100</code>), the button will be rendered as disabled:

<Canvas of={Stories.BundleOversellingPrevention} />

### Virtually infinite stock

Some products (e.g.<code>{codes.doNotTrack}</code>) can be assigned a virtually infinite stock (to do that, you just need to set the <code>do_not_track</code> attribute of the SKU to <code>true</code>). In this case, the component will let you add as many units as you want and the button will be rendered as enabled for any value of the <code>quantity</code> attribute (as long as it's greater than <code>0</code>), as shown in the example below:
Expand Down
26 changes: 20 additions & 6 deletions packages/docs/stories/add-to-cart/cl-add-to-cart.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default meta
const Template: StoryFn<Args> = (args) => {
return create(html`
<cl-add-to-cart
kind=${args.kind ?? nothing}
code=${args.code ?? nothing}
quantity=${args.quantity ?? nothing}
frequency=${args.frequency ?? nothing}
Expand All @@ -30,19 +31,19 @@ Basic.args = {
code: codes.available
}

export const Subscription = Template.bind({})
Subscription.args = {
code: codes.subscription,
frequency: 'three-month'
}

export const WithoutAttributes = Template.bind({})

export const OutOfStock = Template.bind({})
OutOfStock.args = {
code: codes.outOfStock
}

export const BundleOutOfStock = Template.bind({})
BundleOutOfStock.args = {
kind: 'bundle',
code: codes.bundleOutOfStock
}

export const Nonexisting = Template.bind({})
Nonexisting.args = {
code: codes.nonexisting
Expand All @@ -54,8 +55,21 @@ OversellingPrevention.args = {
quantity: 100
}

export const BundleOversellingPrevention = Template.bind({})
BundleOversellingPrevention.args = {
kind: 'bundle',
code: codes.bundleAvailable,
quantity: 10
}

export const DoNotTrack = Template.bind({})
DoNotTrack.args = {
code: codes.doNotTrack,
quantity: 9999
}

export const Subscription = Template.bind({})
Subscription.args = {
code: codes.subscription,
frequency: 'three-month'
}
4 changes: 3 additions & 1 deletion packages/docs/stories/assets/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ export const codes = {
noDiscount: 'BACKPACKFFFFFF000000XXXX',
outOfStock: '5PANECAP9D9CA1FFFFFFXXXX',
doNotTrack: 'BOTT17OZFFFFFF000000XXXX',
subscription: 'POLOMXXX000000FFFFFFMXXX'
subscription: 'POLOMXXX000000FFFFFFMXXX',
bundleAvailable: 'CLGETTINGSTARTED',
bundleOutOfStock: 'CLOUTOFSTOCK'
}

// // stg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default meta
const Template: StoryFn<Args> = (args) => {
return create(
html`
<cl-availability code=${args.code ?? nothing} rule=${args.rule ?? nothing}>
<cl-availability kind=${args.kind ?? nothing} code=${args.code ?? nothing} rule=${args.rule ?? nothing}>
<cl-availability-status type="available">
<span style="color: green;">• available</span>
ready to be shipped in
Expand Down
Loading