Skip to content

Commit

Permalink
Add configurable products with their selected options
Browse files Browse the repository at this point in the history
  • Loading branch information
royduin committed Nov 29, 2023
1 parent c898886 commit 2bb7984
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions resources/js/components/Product/AddToCart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ export default {
// TODO: Maybe make this generic? See: https://github.com/rapidez/core/pull/376
// TODO: Use await instead of this chain?
// TODO: Maybe migrate to fetch? We don't need axios anymore?
// TODO: Check why configurable products are added as simple product. See: https://github.com/magento/devdocs/issues/9493
// There is also an alternative way: https://developer.adobe.com/commerce/webapi/graphql/schema/cart/mutations/add-products/#specify-the-sku-with-selected-options
// But then we need the encoded values
axios.post(config.magento_url + '/graphql', {
query: `mutation (
$cartId: String!,
Expand All @@ -93,8 +90,7 @@ export default {
entered_options: $entered_options
}]) { cart { ` + config.queries.cart + ` } user_errors { code message } } }`,
variables: {
sku: this.simpleProduct.sku,
parent_sku: this.product.sku,
sku: this.product.sku,
cartId: mask.value,
quantity: this.qty,
selected_options: this.selectedOptions,
Expand Down Expand Up @@ -262,6 +258,10 @@ export default {
selectedOptions: function () {
let selectedOptions = []
Object.entries(this.options).forEach(([optionId, optionValue]) => {
selectedOptions.push(btoa('configurable/'+optionId+'/'+optionValue))
})
Object.entries(this.customSelectedOptions).forEach(([optionId, optionValue]) => {
selectedOptions.push(btoa('custom-option/'+optionId+'/'+optionValue))
})
Expand Down

0 comments on commit 2bb7984

Please sign in to comment.