Skip to content

Commit 536461a

Browse files
committed
42083 V14: Integrations (Shopify)
- Add product list when open shopify product picker modal
1 parent a8b7db3 commit 536461a

File tree

4 files changed

+66
-52
lines changed

4 files changed

+66
-52
lines changed

src/Umbraco.Cms.Integrations.Commerce.Shopify/Client/src/config/amount/amount-property-editor.element.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ export class ShopifyAmountElement extends UmbElementMixin(LitElement){
99
#shopifyContext!: typeof SHOPIFY_CONTEXT_TOKEN.TYPE;
1010
@property()
1111
minValue: number = 0;
12+
maxValue: number = 0;
1213

1314
render() {
1415
return html`
1516
<div>
1617
<uui-input .value=${this.minValue}></uui-input>
1718
<span>-</span>
18-
<uui-input placeholder=""></uui-input>
19+
<uui-input placeholder="" .value=${this.maxValue}></uui-input>
1920
</div>
2021
`;
2122
}

src/Umbraco.Cms.Integrations.Commerce.Shopify/Client/src/modal/shopify-products-modal.element.ts

Lines changed: 62 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { html, css, state, customElement } from "@umbraco-cms/backoffice/externa
55
import type { ProductDtoModel } from "../../generated";
66
import type { ShopifyProductPickerModalData, ShopifyProductPickerModalValue } from "./shopify.modal-token.js";
77
import type { ShopifyServiceStatus } from "../models/shopify-service.model.js";
8-
import type { UmbTableColumn, UmbTableConfig, UmbTableItem } from '@umbraco-cms/backoffice/components';
8+
import type { UmbTableColumn, UmbTableConfig, UmbTableItem, UmbTableSelectedEvent, UmbTableElement, UmbTableDeselectedEvent } from '@umbraco-cms/backoffice/components';
99
import type {ShopifyCollectionModel} from "../types/types.js";
1010
import type { UmbDefaultCollectionContext } from '@umbraco-cms/backoffice/collection';
1111
import { UMB_COLLECTION_CONTEXT } from '@umbraco-cms/backoffice/collection';
@@ -17,9 +17,12 @@ export default class ShopifyProductsModalElement extends UmbModalBaseElement<Sho
1717
#shopifyContext!: typeof SHOPIFY_CONTEXT_TOKEN.TYPE;
1818
#collectionContext!: UmbDefaultCollectionContext<ShopifyCollectionModel>;
1919

20+
@state()
21+
private _selection: Array<string> = [];
22+
2023
@state()
2124
private _tableConfig: UmbTableConfig = {
22-
allowSelection: false,
25+
allowSelection: true,
2326
};
2427

2528
@state()
@@ -84,7 +87,6 @@ export default class ShopifyProductsModalElement extends UmbModalBaseElement<Sho
8487

8588
this.consumeContext(UMB_COLLECTION_CONTEXT, (instance) => {
8689
this.#collectionContext = instance;
87-
this.#observeCollectionItems();
8890
});
8991
}
9092

@@ -120,43 +122,66 @@ export default class ShopifyProductsModalElement extends UmbModalBaseElement<Sho
120122
if (!data.isValid || data.isExpired) {
121123
this._showError("Data is invalid or expired."!);
122124
}
123-
}
124125

125-
private _onSelect(products: Array<ProductDtoModel>) {
126-
this.value = { products };
127-
this._submitModal();
126+
this.#createTableItems(this._products);
128127
}
129128

129+
#onSelected(event: UmbTableSelectedEvent) {
130+
event.stopPropagation();
131+
const table = event.target as UmbTableElement;
132+
const selection = table.selection;
133+
this.#collectionContext?.selection.setSelection(selection);
134+
}
135+
136+
#onDeselected(event: UmbTableDeselectedEvent) {
137+
event.stopPropagation();
138+
const table = event.target as UmbTableElement;
139+
const selection = table.selection;
140+
this.#collectionContext?.selection.setSelection(selection);
141+
}
142+
130143
private async _showError(message: string) {
131144
const notificationContext = await this.getContext(UMB_NOTIFICATION_CONTEXT);
132145
notificationContext?.peek("danger", {
133146
data: { message },
134147
});
135148
}
136149

137-
#observeCollectionItems() {
138-
if (!this.#shopifyContext) return;
139-
this.observe(this.#collectionContext.items, (items) => this.#createTableItems(items, this._products), 'umbCollectionItemsObserver');
140-
}
141-
142-
#createTableItems(products: Array<ShopifyCollectionModel>, actual: Array<ProductDtoModel>) {
150+
#createTableItems(products: Array<ProductDtoModel>) {
143151
this._tableItems = products.map((product) => {
144152
return {
145-
id: product.unique,
146-
icon: '',
147-
data: [
148-
{
149-
columnAlias: 'productName',
150-
value: actual[0].title
151-
},
152-
...actual.map(a => {
153-
return {
154-
columnAlias: 'Vendor',
155-
value: a.vendor
156-
};
157-
}),
158-
],
159-
};
153+
id: product.id.toString(),
154+
icon: 'icon-book-alt-2',
155+
data: [{
156+
columnAlias: "productName",
157+
value: product.title,
158+
},
159+
{
160+
columnAlias: "vendor",
161+
value: product.vendor,
162+
},
163+
{
164+
columnAlias: "status",
165+
value: product.status,
166+
},
167+
{
168+
columnAlias: "tags",
169+
value: product.tags,
170+
},
171+
{
172+
columnAlias: "sku",
173+
value: product.variants.map(v => v.sku).join(","),
174+
},
175+
{
176+
columnAlias: "barcode",
177+
value: product.variants.map(v => v.barcode).join(","),
178+
},
179+
{
180+
columnAlias: "price",
181+
value: product.variants[0].price,
182+
},
183+
]
184+
}
160185
});
161186
}
162187

@@ -165,13 +190,19 @@ export default class ShopifyProductsModalElement extends UmbModalBaseElement<Sho
165190
<umb-body-layout>
166191
<uui-box headline="Shopify Products">
167192
${this._loading ? html`<div class="center"><uui-loader></uui-loader></div>` : ""}
168-
<umb-table .config=${this._tableConfig} .columns=${this._tableColumns} .items=${this._tableItems}></umb-table>
193+
<umb-table
194+
.config=${this._tableConfig}
195+
.columns=${this._tableColumns}
196+
.items=${this._tableItems}
197+
.selection=${this._selection}
198+
@selected="${this.#onSelected}"
199+
@deselected="${this.#onDeselected}"></umb-table>
169200
170201
</uui-box>
171202
<span>Add up to x items(s)</span>
172203
173-
<uui-button slot="actions" label="Submit"></uui-button>
174-
<uui-button slot="actions" label="Close"></uui-button>
204+
<uui-button slot="actions" label="Submit" @click=${this._submitModal}></uui-button>
205+
<uui-button slot="actions" label="Close" @click=${this._rejectModal}></uui-button>
175206
</umb-body-layout>
176207
`;
177208
}

src/Umbraco.Cms.Integrations.Commerce.Shopify/Client/src/types/types.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1+
import { ProductDtoModel } from "@umbraco-integrations/shopify/generated";
12
import type { ShopifyCollectionEntityType, ShopifyVariantsCollectionEntityType } from "../entities/entities";
23

34
export interface ShopifyCollectionModel {
45
unique: string;
56
entityType: ShopifyCollectionEntityType;
6-
title: string;
7-
vendor: string;
8-
status: string;
9-
tags: string;
10-
variants: Array<ShopifyVariantsCollectionModel>;
11-
barcode: string;
12-
price: string;
7+
products: Array<ProductDtoModel>;
138
}
149

1510
export interface ShopifyVariantsCollectionModel {

src/Umbraco.Cms.Integrations.Commerce.Shopify/Services/ShopifyService.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.Net;
44
using System.Net.Http;
55
using System.Threading.Tasks;
6-
76
using Newtonsoft.Json;
87
using Umbraco.Cms.Integrations.Commerce.Shopify.Configuration;
98
using Umbraco.Cms.Integrations.Commerce.Shopify.Models;
@@ -15,21 +14,9 @@
1514
using System.Web;
1615
using Umbraco.Cms.Integrations.Commerce.Shopify.Helpers;
1716
using static Umbraco.Cms.Core.Constants.HttpContext;
18-
19-
20-
21-
22-
23-
24-
#if NETCOREAPP
2517
using Microsoft.Extensions.Logging;
2618
using Microsoft.Extensions.Options;
2719
using ShopifyLogLevel = Umbraco.Cms.Core.Logging.LogLevel;
28-
#else
29-
using System.Configuration;
30-
using Umbraco.Core.Logging;
31-
using ShopifyLogLevel = Umbraco.Core.Logging.LogLevel;
32-
#endif
3320

3421
namespace Umbraco.Cms.Integrations.Commerce.Shopify.Services
3522
{

0 commit comments

Comments
 (0)