Skip to content

Commit

Permalink
fix(minicart): fix resolving configurable variants data (#456)
Browse files Browse the repository at this point in the history
Co-authored-by: Bartosz Herba <[email protected]>
  • Loading branch information
bartoszherba and bartoszherba authored Jan 20, 2022
1 parent 6b29737 commit 7705477
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
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

0 comments on commit 7705477

Please sign in to comment.