From 45cd12038d4cd72b258dbce0ee361f8fdaf33108 Mon Sep 17 00:00:00 2001 From: Maciej Kucmus Date: Fri, 13 Dec 2019 08:04:46 +0100 Subject: [PATCH 1/6] feat(product): handle variants change. --- .../composables/__tests__/useProduct.spec.ts | 11 +-- .../composables/src/hooks/useCms/index.ts | 15 +++- .../composables/src/hooks/useProduct/index.ts | 29 ++++++- .../components/SwProductCard.vue | 4 +- .../components/views/ProductView.vue | 78 +++++++++++++++---- .../src/product/getProductMediaGallery.ts | 4 +- .../helpers/src/product/getProductOption.ts | 1 + .../src/product/getProductOptionUrl.ts | 53 +++++++++++++ .../helpers/src/product/getProductOptions.ts | 51 ++++++++++-- packages/helpers/src/product/index.ts | 1 + .../helpers/src/product/isProductSimple.ts | 5 ++ packages/helpers/src/ui-interfaces.ts | 2 + .../models/content/product/Product.ts | 23 ++++++ .../src/services/pageService.ts | 4 +- 14 files changed, 243 insertions(+), 38 deletions(-) create mode 100644 packages/helpers/src/product/getProductOptionUrl.ts diff --git a/packages/composables/__tests__/useProduct.spec.ts b/packages/composables/__tests__/useProduct.spec.ts index 9c4c76b9c..4796cfccb 100644 --- a/packages/composables/__tests__/useProduct.spec.ts +++ b/packages/composables/__tests__/useProduct.spec.ts @@ -58,12 +58,13 @@ describe("Composables - useProduct", () => { id: "3f637f17cd9f4891a2d7625d19fb37c9", parentId: "1c3e927309014a67a07f3bb574f9e804" }; - mockedGetProduct.getProduct.mockResolvedValueOnce( - { } as any - ); + mockedGetProduct.getProduct.mockResolvedValueOnce({} as any); const { loadAssociations } = useProduct(loadedProduct); - loadAssociations({} as any) - expect(mockedGetProduct.getProduct).toBeCalledWith("1c3e927309014a67a07f3bb574f9e804", {}) + loadAssociations({} as any); + expect(mockedGetProduct.getProduct).toBeCalledWith( + "1c3e927309014a67a07f3bb574f9e804", + {} + ); }); it("should have associations if loadAssociations was triggered", async () => { diff --git a/packages/composables/src/hooks/useCms/index.ts b/packages/composables/src/hooks/useCms/index.ts index a540e41f0..e81b36ca1 100644 --- a/packages/composables/src/hooks/useCms/index.ts +++ b/packages/composables/src/hooks/useCms/index.ts @@ -9,7 +9,20 @@ export const useCms = (): any => { const search = async (path: string) => { loading.value = true; try { - const result = await getPage(path); + const result = await getPage(path, { + configuration: { + associations: [ + { + name: "options", + associations: [ + { + name: "group" + } + ] + } + ] + } + }); page.value = result; return result; } catch (e) { diff --git a/packages/composables/src/hooks/useProduct/index.ts b/packages/composables/src/hooks/useProduct/index.ts index f806d30c2..eed812599 100644 --- a/packages/composables/src/hooks/useProduct/index.ts +++ b/packages/composables/src/hooks/useProduct/index.ts @@ -1,4 +1,4 @@ -import { ref, Ref } from "@vue/composition-api"; +import { ref, Ref, watch } from "@vue/composition-api"; import { getProduct, Product } from "@shopware-pwa/shopware-6-client"; const NO_PRODUCT_REFERENCE_ERROR = @@ -25,9 +25,30 @@ export const useProduct = ( if (!product || !product.value || !product.value.id) { throw NO_PRODUCT_REFERENCE_ERROR; } - - const result = await getProduct(product.value.parentId || product.value.id, associations); - product.value = result; + //const productData = await getProduct(product.value.parentId || product.value.id, associations); + const { + id, + name, + description, + media, + cover, + properties, + productReviews, + children + } = await getProduct( + product.value.parentId || product.value.id, + associations + ); + console.warn("ID ", id); + product.value = Object.assign({}, product.value, { + name, + description, + media, + cover, + properties, + productReviews, + children + }); }; const search = async (path: string) => { diff --git a/packages/default-theme/components/SwProductCard.vue b/packages/default-theme/components/SwProductCard.vue index df983b4ba..8271ead30 100644 --- a/packages/default-theme/components/SwProductCard.vue +++ b/packages/default-theme/components/SwProductCard.vue @@ -30,7 +30,7 @@