diff --git a/resources/js/callbacks.js b/resources/js/callbacks.js index 32cef762f..8543223cb 100644 --- a/resources/js/callbacks.js +++ b/resources/js/callbacks.js @@ -14,40 +14,38 @@ Vue.prototype.updateCart = async function (data, response) { getAttributeValues().then((response) => { if (!response?.data?.customAttributeMetadata?.items) { - return; + return } const mapping = Object.fromEntries( - response.data.customAttributeMetadata.items.map( - (attribute) => [ - attribute.attribute_code, - Object.fromEntries(attribute.attribute_options.map((value) => [value.value, value.label])) - ] - ) - ); + response.data.customAttributeMetadata.items.map((attribute) => [ + attribute.attribute_code, + Object.fromEntries(attribute.attribute_options.map((value) => [value.value, value.label])), + ]), + ) - cart.value.items = cart.value.items.map((cartItem => { - cartItem.product.attribute_values = {}; + cart.value.items = cart.value.items.map((cartItem) => { + cartItem.product.attribute_values = {} for (const key in mapping) { - cartItem.product.attribute_values[key] = cartItem.product[key]; + cartItem.product.attribute_values[key] = cartItem.product[key] if (cartItem.product.attribute_values[key] === null) { - continue; + continue } if (typeof cartItem.product.attribute_values[key] === 'string') { - cartItem.product.attribute_values[key] = cartItem.product.attribute_values[key].split(','); + cartItem.product.attribute_values[key] = cartItem.product.attribute_values[key].split(',') } if (typeof cartItem.product.attribute_values[key] !== 'object') { - cartItem.product.attribute_values[key] = [cartItem.product.attribute_values[key]]; + cartItem.product.attribute_values[key] = [cartItem.product.attribute_values[key]] } cartItem.product.attribute_values[key] = cartItem.product.attribute_values[key].map((value) => mapping[key][value] || value) } return cartItem - })) + }) }) return response.data diff --git a/resources/js/stores/useCart.js b/resources/js/stores/useCart.js index 66eb7d74b..e4cb89609 100644 --- a/resources/js/stores/useCart.js +++ b/resources/js/stores/useCart.js @@ -58,11 +58,11 @@ export const fetchCustomerCart = async function () { export const fetchAttributeValues = async function (attributes = []) { if (!attributes.length) { - return {"data": {"customAttributeMetadata": {"items": null}}}; + return { data: { customAttributeMetadata: { items: null } } } } - return await window - .magentoGraphQL(` + return await window.magentoGraphQL( + ` query attributeValues($attributes: [AttributeInput!]!) { customAttributeMetadata(attributes: $attributes) { items { @@ -74,16 +74,21 @@ export const fetchAttributeValues = async function (attributes = []) { } } } - `, {attributes: attributes.map(attribute_code => {return {attribute_code: attribute_code, entity_type: 'catalog_product'}})}) + `, + { + attributes: attributes.map((attribute_code) => { + return { attribute_code: attribute_code, entity_type: 'catalog_product' } + }), + }, + ) } -const fetchAttributeValuesMemo = useMemoize(fetchAttributeValues); +const fetchAttributeValuesMemo = useMemoize(fetchAttributeValues) export const getAttributeValues = async function () { return await fetchAttributeValuesMemo(window.config.cart_attributes) } - export const cart = computed({ get() { if (!cartStorage.value?.id && mask.value) {