Skip to content

Commit

Permalink
Merge pull request #170 from EmanuelRamos115/feat/add-to-cart-prop
Browse files Browse the repository at this point in the history
feat: dynamic cart redirect on quickorder
  • Loading branch information
ataideverton authored Sep 26, 2024
2 parents e0b5cb3 + 8a27f9b commit 52cf02c
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- Add a cart url prop so the store can control the redirect via theme

## [3.15.5] - 2024-08-20

Expand Down
13 changes: 9 additions & 4 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ To use these blocks, follow the instructions below.
"props": {
"componentOnly": false,
"text": "Copy/Paste Skus",
"description": "[SKU Reference ID],[Quantity]"
"description": "[SKU Reference ID],[Quantity]",
"checkoutUrl:": "/checkout#/cart"
}
},

Expand All @@ -116,7 +117,8 @@ To use these blocks, follow the instructions below.
"text": "Upload",
"description": "Upload a Spreadsheet with two columns (SKU, Quantity) to bulk order",
"downloadText": "Click here to download a spreadsheet model",
"alwaysShowAddToCart:": true
"alwaysShowAddToCart:": true,
"checkoutUrl:": "/checkout#/cart"
}
},

Expand All @@ -130,7 +132,8 @@ To use these blocks, follow the instructions below.
"props": {
"componentOnly": false,
"text": "One by One",
"description": "Type the product name, select, enter quantity, add to the cart"
"description": "Type the product name, select, enter quantity, add to the cart",
"checkoutUrl:": "/checkout#/cart"
}
},

Expand All @@ -144,7 +147,8 @@ To use these blocks, follow the instructions below.
"props": {
"componentOnly": false,
"text": "Categories",
"description": "Add products directly from their categories"
"description": "Add products directly from their categories",
"checkoutUrl:": "/checkout#/cart"
}
}
}
Expand All @@ -159,6 +163,7 @@ All blocks exported by the `quickorder` app share the same props:
| `text` | `string` | Component title. | `undefined` |
| `description` | `string` | Component description. It should be used to explain users how to properly bulk order using the given component. | `undefined` |
| `componentOnly` | `boolean` | If `true`, only the component will be loaded, removing the `text` and `description` column. | `false` |
| `checkoutUrl` | `string` | Checkout cart URL for redirect | `/checkout#/cart` |

Especially, the `quickorder-upload` block also can use the following prop:

Expand Down
6 changes: 5 additions & 1 deletion react/AutocompleteBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const AutocompleteBlock: FunctionComponent<any & WrappedComponentProps> = ({
description,
componentOnly,
intl,
checkoutUrl,
}) => {
const client = useApolloClient()
const { showToast } = useContext(ToastContext)
Expand Down Expand Up @@ -76,7 +77,10 @@ const AutocompleteBlock: FunctionComponent<any & WrappedComponentProps> = ({
action = success
? {
label: translateMessage(messages.seeCart),
href: '/checkout/#/cart',
href:
typeof checkoutUrl === 'string' && checkoutUrl !== ''
? checkoutUrl
: '/checkout/#/cart',
}
: undefined
}
Expand Down
6 changes: 5 additions & 1 deletion react/CategoryBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const CategoryBlock: FunctionComponent<WrappedComponentProps & any> = ({
componentOnly,
intl,
data: { categories },
checkoutUrl,
}) => {
const [state, setState] = useState<any>({
categoryItems: {},
Expand Down Expand Up @@ -89,7 +90,10 @@ const CategoryBlock: FunctionComponent<WrappedComponentProps & any> = ({
action = success
? {
label: intl.formatMessage(messages.seeCart),
href: '/checkout/#/cart',
href:
typeof checkoutUrl === 'string' && checkoutUrl !== ''
? checkoutUrl
: '/checkout/#/cart',
}
: undefined
}
Expand Down
15 changes: 13 additions & 2 deletions react/TextAreaBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@ interface ItemType {

const TextAreaBlock: FunctionComponent<
TextAreaBlockInterface & WrappedComponentProps
> = ({ intl, value, text, hiddenColumns, description, componentOnly }: any) => {
> = ({
intl,
value,
text,
hiddenColumns,
description,
componentOnly,
checkoutUrl,
}: any) => {
const [state, setState] = useState<any>({
reviewState: false,
showAddToCart: null,
Expand Down Expand Up @@ -72,7 +80,10 @@ const TextAreaBlock: FunctionComponent<
const action = success
? {
label: translateMessage(messages.seeCart),
href: '/checkout/#/cart',
href:
typeof checkoutUrl === 'string' && checkoutUrl !== ''
? checkoutUrl
: '/checkout/#/cart',
}
: undefined

Expand Down
6 changes: 5 additions & 1 deletion react/UploadBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const UploadBlock: FunctionComponent<
componentOnly,
intl,
alwaysShowAddToCart = true,
checkoutUrl,
}: any) => {
let productsArray: any = []
const [state, setState] = useState<any>({
Expand Down Expand Up @@ -84,7 +85,10 @@ const UploadBlock: FunctionComponent<
const action = success
? {
label: translateMessage(messages.seeCart),
href: '/checkout/#/cart',
href:
typeof checkoutUrl === 'string' && checkoutUrl !== ''
? checkoutUrl
: '/checkout/#/cart',
}
: undefined

Expand Down

0 comments on commit 52cf02c

Please sign in to comment.