Skip to content

Commit 1d1b101

Browse files
author
Marcin Kwiatkowski
committed
fix: m2-668. fixed pricing calculation on pdp
1 parent 45b12e0 commit 1d1b101

File tree

10 files changed

+187
-150
lines changed

10 files changed

+187
-150
lines changed

packages/api-client/src/api/productDetail/productDetailsQuery.ts

Lines changed: 21 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -90,51 +90,29 @@ export default gql`
9090
}
9191
options_container
9292
special_to_date
93-
... on BundleProduct {
94-
items {
95-
position
96-
required
97-
sku
98-
title
99-
type
100-
uid
101-
options {
102-
can_change_quantity
103-
is_default
104-
position
105-
uid
106-
quantity
107-
product {
108-
uid
109-
sku
110-
name
111-
price_range {
112-
maximum_price {
113-
final_price {
114-
currency
115-
value
116-
}
117-
regular_price {
118-
currency
119-
value
120-
}
121-
}
122-
minimum_price {
123-
final_price {
124-
currency
125-
value
126-
}
127-
regular_price {
128-
currency
129-
value
130-
}
131-
}
132-
}
93+
... on ConfigurableProduct {
94+
price_range {
95+
maximum_price {
96+
final_price {
97+
currency
98+
value
99+
}
100+
regular_price {
101+
currency
102+
value
103+
}
104+
}
105+
minimum_price {
106+
final_price {
107+
currency
108+
value
109+
}
110+
regular_price {
111+
currency
112+
value
133113
}
134114
}
135115
}
136-
}
137-
... on ConfigurableProduct {
138116
configurable_options {
139117
attribute_code
140118
attribute_uid
@@ -190,47 +168,7 @@ export default gql`
190168
}
191169
}
192170
}
193-
... on GroupedProduct {
194-
items {
195-
position
196-
qty
197-
product {
198-
uid
199-
sku
200-
name
201-
stock_status
202-
only_x_left_in_stock
203-
price_range {
204-
maximum_price {
205-
final_price {
206-
currency
207-
value
208-
}
209-
regular_price {
210-
currency
211-
value
212-
}
213-
}
214-
minimum_price {
215-
final_price {
216-
currency
217-
value
218-
}
219-
regular_price {
220-
currency
221-
value
222-
}
223-
}
224-
}
225-
thumbnail {
226-
url
227-
position
228-
disabled
229-
label
230-
}
231-
}
232-
}
233-
}
171+
234172
... on DownloadableProduct {
235173
downloadable_product_samples {
236174
sample_url

packages/theme/modules/catalog/pages/product.vue

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import {
3838
useFetch,
3939
onMounted,
4040
} from '@nuxtjs/composition-api';
41+
import { merge } from 'lodash-es';
4142
import { useCache, CacheTagPrefix } from '@vue-storefront/cache';
4243
import { SfBreadcrumbs, SfLoader } from '@storefront-ui/vue';
4344
import { getBreadcrumbs } from '~/modules/catalog/product/getters/productGetters';
@@ -131,14 +132,15 @@ export default defineComponent({
131132
});
132133
133134
onMounted(async () => {
134-
if (product.value) {
135-
const { data } = await query<ProductDetailsQuery>(getProductPriceBySkuGql, { sku: product.value.sku });
136-
137-
product.value = {
138-
...product.value,
139-
price_range: data.products?.items?.[0].price_range,
140-
};
135+
if (!product.value) {
136+
await fetchProduct();
141137
}
138+
139+
const { data } = await query<ProductDetailsQuery>(getProductPriceBySkuGql, { sku: product.value.sku });
140+
141+
product.value = {
142+
...merge(product.value, data.products?.items?.[0] as Product),
143+
};
142144
});
143145
144146
return {

packages/theme/modules/catalog/pricing/getGroupedProductPriceCommand.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ export function getGroupedProductPriceCommand(product: GroupedProduct): number {
88
return regular > special && special !== null ? special : regular;
99
};
1010

11-
return product.items.reduce(
11+
return product.items ? product.items.reduce(
1212
(acc, curr) => curr.qty * evalProductPrice(curr.product) + acc,
1313
0,
14-
);
14+
) : 0;
1515
}

packages/theme/modules/catalog/product/components/product-types/bundle/BundleProduct.vue

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,23 @@
3737
/>
3838
</div>
3939
<div class="product__price-and-rating">
40-
<client-only>
41-
<div class="product__price">
42-
<span class="product__price-label">{{ $t('From') }}</span>
43-
<SfPrice
44-
:regular="$fc(productPrice)"
45-
:special="productSpecialPrice && $fc(productSpecialPrice)"
46-
/>
47-
<span class="product__price-label">{{ $t('To') }}</span>
48-
<SfPrice
49-
:regular="$fc(productMaximumPrice)"
50-
/>
40+
<div class="product__price">
41+
<span class="product__price-label">{{ $t('From') }}</span>
42+
<SfPrice
43+
:regular="$fc(productPrices.regular)"
44+
:special="productPrices.special && $fc(productPrices.special)"
45+
/>
46+
<span class="product__price-label">{{ $t('To') }}</span>
47+
<SfPrice
48+
:regular="$fc(productPrices.maximum)"
49+
/>
50+
<div v-if="customizationPrice">
5151
<span class="product__price-label">{{ $t('Your customization') }}</span>
5252
<SfPrice
5353
:regular="$fc(customizationPrice)"
5454
/>
5555
</div>
56-
</client-only>
56+
</div>
5757
<div>
5858
<div class="product__rating">
5959
<SfRating
@@ -90,13 +90,17 @@
9090
tag="p"
9191
class="product__description desktop-only"
9292
/>
93-
<client-only>
94-
<BundleProductSelector
95-
:can-add-to-cart="canAddToCart(product, qty)"
96-
:product="product"
97-
@update-price="customizationPrice = $event"
98-
/>
99-
</client-only>
93+
<BundleProductSelector
94+
v-if="productPrices.regular"
95+
:can-add-to-cart="canAddToCart(product, qty)"
96+
:product="product"
97+
@update-price="customizationPrice = $event"
98+
/>
99+
<div v-else>
100+
<BundleProductOptionSkeleton />
101+
<BundleProductOptionSkeleton />
102+
<BundleProductOptionSkeleton />
103+
</div>
100104
<div class="product__additional-actions">
101105
<AddToWishlist
102106
:is-in-wishlist="isInWishlist"
@@ -155,10 +159,13 @@ import ProductTabs from '~/modules/catalog/product/components/tabs/ProductTabs.v
155159
import { useProductGallery } from '~/modules/catalog/product/composables/useProductGallery';
156160
import { Product } from '~/modules/catalog/product/types';
157161
import { TabsConfig, useProductTabs } from '~/modules/catalog/product/composables/useProductTabs';
162+
import BundleProductOptionSkeleton
163+
from '~/modules/catalog/product/components/product-types/bundle/BundleProductOptionSkeleton.vue';
158164
159165
export default defineComponent({
160166
name: 'BundleProduct',
161167
components: {
168+
BundleProductOptionSkeleton,
162169
BundleProductSelector,
163170
HTMLContent,
164171
LazyHydrate,
@@ -199,10 +206,11 @@ export default defineComponent({
199206
() => props.product?.description?.html || '',
200207
);
201208
202-
const productPrice = ref(getProductPrice(props.product).regular);
203-
const productSpecialPrice = ref(getProductPrice(props.product).special);
204-
const productMaximumPrice = ref(getProductPrice(props.product).maximum);
205-
const customizationPrice = ref(productSpecialPrice.value ?? productPrice.value);
209+
// const productPrice = computed(() => getProductPrice(props.product).regular);
210+
// const productSpecialPrice = computed(() => getProductPrice(props.product).special);
211+
// const productMaximumPrice = computed(() => getProductPrice(props.product).maximum);
212+
const productPrices = computed(() => getProductPrice(props.product));
213+
const customizationPrice = ref(productPrices.value.special ?? productPrices.value.regular);
206214
207215
const totalReviews = computed(() => getTotalReviews(props.product));
208216
const averageRating = computed(() => getAverageRating(props.product));
@@ -218,9 +226,7 @@ export default defineComponent({
218226
productGallery,
219227
getProductName,
220228
getProductSwatchData,
221-
productPrice,
222-
productSpecialPrice,
223-
productMaximumPrice,
229+
productPrices,
224230
customizationPrice,
225231
productShortDescription,
226232
qty,
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<template>
2+
<div>
3+
<SkeletonLoader
4+
width="100%"
5+
height="23px"
6+
/>
7+
<SkeletonLoader
8+
width="100%"
9+
height="240px"
10+
/>
11+
<div>
12+
<SkeletonLoader
13+
width="80px"
14+
height="23px"
15+
/>
16+
</div>
17+
<SkeletonLoader
18+
width="108px"
19+
height="52px"
20+
/>
21+
</div>
22+
</template>
23+
<script lang="ts">
24+
import {
25+
defineComponent,
26+
} from '@nuxtjs/composition-api';
27+
import SkeletonLoader from '~/components/SkeletonLoader/index.vue';
28+
29+
export default defineComponent({
30+
name: 'BundleProductOptionSkeleton',
31+
components: {
32+
SkeletonLoader,
33+
},
34+
});
35+
</script>

packages/theme/modules/catalog/product/components/product-types/configurable/ConfigurableProduct.vue

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,10 @@
3737
/>
3838
</div>
3939
<div class="product__price-and-rating">
40-
<client-only>
41-
<SfPrice
42-
:regular="$fc(productPrice)"
43-
:special="productSpecialPrice && $fc(productSpecialPrice)"
44-
/>
45-
</client-only>
40+
<SfPrice
41+
:regular="$fc(productPrice)"
42+
:special="productSpecialPrice && $fc(productSpecialPrice)"
43+
/>
4644
<div>
4745
<div class="product__rating">
4846
<SfRating
@@ -293,6 +291,7 @@ export default defineComponent({
293291
294292
emit('fetchProduct', { query: getBaseSearchQuery() });
295293
};
294+
296295
return {
297296
addItem,
298297
addItemToWishlist: addOrRemoveItem,

packages/theme/modules/catalog/product/components/product-types/grouped/GroupedProduct.vue

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,10 @@
3737
/>
3838
</div>
3939
<div class="product__price-and-rating">
40-
<client-only>
41-
<SfPrice
42-
:regular="$fc(productPrice)"
43-
:special="productSpecialPrice && $fc(productSpecialPrice)"
44-
/>
45-
</client-only>
40+
<SfPrice
41+
:regular="$fc(productPrice)"
42+
:special="productSpecialPrice && $fc(productSpecialPrice)"
43+
/>
4644
<div>
4745
<div class="product__rating">
4846
<SfRating
@@ -79,13 +77,11 @@
7977
tag="p"
8078
class="product__description desktop-only"
8179
/>
82-
<client-only>
83-
<grouped-product-selector
84-
:can-add-to-cart="canAddToCart(product, qty)"
85-
:product="product"
86-
@update-price="basePrice = $event"
87-
/>
88-
</client-only>
80+
<grouped-product-selector
81+
:can-add-to-cart="canAddToCart(product, qty)"
82+
:product="product"
83+
@update-price="basePrice = $event"
84+
/>
8985
<div class="product__additional-actions">
9086
<AddToWishlist
9187
:is-in-wishlist="isInWishlist"

packages/theme/modules/catalog/product/components/product-types/grouped/GroupedProductSelector.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ export default defineComponent({
126126
127127
watch(
128128
() => props.product,
129-
(product) => {
130-
const price = getGroupedProductPriceCommand(product);
129+
(productNewValue) => {
130+
const price = getGroupedProductPriceCommand(productNewValue);
131131
emit('update-price', price);
132132
},
133133
{

packages/theme/modules/catalog/product/components/product-types/simple/SimpleProduct.vue

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,10 @@
3737
/>
3838
</div>
3939
<div class="product__price-and-rating">
40-
<client-only>
41-
<SfPrice
42-
:regular="$fc(productPrice)"
43-
:special="productSpecialPrice && $fc(productSpecialPrice)"
44-
/>
45-
</client-only>
40+
<SfPrice
41+
:regular="$fc(productPrice)"
42+
:special="productSpecialPrice && $fc(productSpecialPrice)"
43+
/>
4644
<div>
4745
<div class="product__rating">
4846
<SfRating

0 commit comments

Comments
 (0)