Skip to content
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

fix(minicart): fix resolving configurable variants data #456

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 8 additions & 1 deletion packages/api-client/src/api/cart/cart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ export default gql`
configurable_product_option_value_uid
value_label
}
configured_variant {
sku
thumbnail {
url
}
}
}
... on BundleCartItem {
bundle_options {
Expand Down Expand Up @@ -177,4 +183,5 @@ export default gql`
}
}
}
}`;
}
`;
5 changes: 4 additions & 1 deletion packages/composables/src/getters/cartGetters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
Cart,
CartItem,
Product,
SelectedShippingMethod,
SelectedShippingMethod, ConfigurableCartItem, ProductInterface,
} from '@vue-storefront/magento-api';
import productGetters from './productGetters';
import { AgnosticPaymentMethod } from '../types';
Expand Down Expand Up @@ -133,6 +133,8 @@ export const getTotalItems = (cart: Cart): number => {
return cart.total_quantity;
};

export const getConfiguredVariant = (product: ConfigurableCartItem): ProductInterface | {} => product?.configured_variant || {};

// eslint-disable-next-line import/no-named-as-default-member
export const getFormattedPrice = (price: number) => productGetters.getFormattedPrice(price);

Expand Down Expand Up @@ -196,6 +198,7 @@ const cartGetters: CartGetters = {
getTotals,
productHasSpecialPrice,
getStockStatus,
getConfiguredVariant,
};

export default cartGetters;
5 changes: 4 additions & 1 deletion packages/theme/components/CartSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,10 @@ export default defineComponent({
const { isAuthenticated } = useUser();
const { send: sendNotification, notifications } = useUiNotification();

const products = computed(() => cartGetters.getItems(cart.value).filter(Boolean));
const products = computed(() => cartGetters
.getItems(cart.value)
.filter(Boolean)
.map((item) => ({ ...item, product: { ...item.product, ...item.configured_variant } })));
const totals = computed(() => cartGetters.getTotals(cart.value));
const totalItems = computed(() => cartGetters.getTotalItems(cart.value));
const getAttributes = (product) => product.configurable_options || [];
Expand Down