Skip to content

Commit 25584c0

Browse files
committed
Save product ids only
1 parent bb0d1df commit 25584c0

File tree

12 files changed

+51
-36
lines changed

12 files changed

+51
-36
lines changed

src/Umbraco.Cms.Integrations.Commerce.Shopify/Api/Management/Controllers/GetListByIdsController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ public GetListByIdsController(IOptions<ShopifySettings> shopifySettings, IShopif
1616
{
1717
}
1818

19-
[HttpGet("list-by-ids")]
19+
[HttpPost("list-by-ids")]
2020
[ProducesResponseType(typeof(ResponseDto<ProductsListDto>), StatusCodes.Status200OK)]
2121
public async Task<IActionResult> GetListByIds([FromBody] RequestDto dto)
2222
{
23-
var result = await ShopifyService.GetProductsByIds(dto.Ids.Select(p => (long.Parse(p))).ToArray());
23+
var result = await ShopifyService.GetProductsByIds(dto.Ids.Select(p => p).ToArray());
2424
return Ok(result);
2525
}
2626
}

src/Umbraco.Cms.Integrations.Commerce.Shopify/Client/generated/services.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export class ShopifyService {
7979
*/
8080
public static getListByIds(data: GetListByIdsData = {}): CancelablePromise<GetListByIdsResponse> {
8181
return __request(OpenAPI, {
82-
method: 'GET',
82+
method: 'POST',
8383
url: '/umbraco/shopify/management/api/v1/list-by-ids',
8484
body: data.requestBody,
8585
mediaType: 'application/json',

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ export type $OpenApiTs = {
160160
};
161161
};
162162
'/umbraco/shopify/management/api/v1/list-by-ids': {
163-
get: {
163+
post: {
164164
req: GetListByIdsData;
165165
res: {
166166
/**

src/Umbraco.Cms.Integrations.Commerce.Shopify/Client/src/context/shopify.context.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { UmbControllerBase } from "@umbraco-cms/backoffice/class-api";
22
import { UmbContextToken } from "@umbraco-cms/backoffice/context-api";
33
import type { UmbControllerHost } from "@umbraco-cms/backoffice/controller-api";
44
import { ShopifyRepository } from "../repository/shopify.repository";
5-
import { EditorSettingsModel, type OAuthRequestDtoModel } from "@umbraco-integrations/shopify/generated";
5+
import { EditorSettingsModel, RequestDtoModel, type OAuthRequestDtoModel } from "@umbraco-integrations/shopify/generated";
66
import { UmbObjectState } from "@umbraco-cms/backoffice/observable-api";
77

88
export class ShopifyContext extends UmbControllerBase{
@@ -44,8 +44,8 @@ export class ShopifyContext extends UmbControllerBase{
4444
return await this.#repository.getList(pageInfo);
4545
}
4646

47-
async getListByIds(){
48-
return await this.#repository.getListByIds();
47+
async getListByIds(model: RequestDtoModel){
48+
return await this.#repository.getListByIds(model);
4949
}
5050

5151
async getTotalPages(){

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,9 @@ export default class ShopifyProductsModalElement extends UmbModalBaseElement<Sho
214214
});
215215
}
216216

217-
async #loadSelectionItems(){
217+
async #loadSelectionItems() {
218218
this._selection = this.data!.selectedItemIdList;
219-
this._addUpToItems = this.data?.config?.maxItems! - this.data?.config?.minItems!;
219+
this._addUpToItems = (this.data?.config?.maxItems ? this.data?.config?.maxItems : 0) - (this.data?.config?.minItems ? this.data?.config?.minItems : 0);
220220
}
221221

222222
#onSelected(event: UmbTableSelectedEvent) {
@@ -273,9 +273,9 @@ export default class ShopifyProductsModalElement extends UmbModalBaseElement<Sho
273273
}
274274

275275
_onSubmit() {
276-
if(this._numberOfSelection > this.data?.config?.maxItems! || this._numberOfSelection < this.data?.config?.minItems!){
276+
if (this._addUpToItems != 0 && this._numberOfSelection > this._addUpToItems) {
277277
this._showError("Please select the amount of items that has been configured in the setting.");
278-
}else{
278+
} else {
279279
if(this._numberOfSelection == 0){
280280
this._rejectModal();
281281
}
@@ -319,12 +319,16 @@ export default class ShopifyProductsModalElement extends UmbModalBaseElement<Sho
319319
${this.#renderPagination()}
320320
</uui-box>
321321
322-
<div class="maximum-selection">
323-
<span>
324-
Add up to ${this._addUpToItems} items(s)
325-
</span>
326-
</div>
327-
322+
${this._addUpToItems > 0
323+
? html`
324+
<div class="maximum-selection">
325+
<span>
326+
Add up to ${this._addUpToItems} items(s)
327+
</span>
328+
</div>
329+
`
330+
: nothing
331+
}
328332
<uui-button look="primary" slot="actions" label="Submit" @click=${this._onSubmit}></uui-button>
329333
<uui-button slot="actions" label="Close" @click=${this._rejectModal}></uui-button>
330334
</umb-body-layout>

src/Umbraco.Cms.Integrations.Commerce.Shopify/Client/src/property-editor/shopify-product-picker-property-editor.element.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
import { SHOPIFY_MODAL_TOKEN } from "../modal/shopify.modal-token";
77
import { ConfigDescription, type ShopifyServiceStatus } from "../models/shopify-service.model";
88
import { SHOPIFY_CONTEXT_TOKEN } from "../context/shopify.context";
9-
import type { EditorSettingsModel, ProductDtoModel } from "@umbraco-integrations/shopify/generated";
9+
import type { EditorSettingsModel, ProductDtoModel, RequestDtoModel } from "@umbraco-integrations/shopify/generated";
1010
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
1111
import { UmbPropertyEditorUiElement } from '@umbraco-cms/backoffice/extension-registry';
1212
import type { UmbPropertyEditorConfigCollection } from "@umbraco-cms/backoffice/property-editor";
@@ -16,6 +16,7 @@ const elementName = "shopify-product-picker";
1616

1717
@customElement(elementName)
1818
export class ShopifyProductPickerPropertyEditor extends UmbLitElement implements UmbPropertyEditorUiElement {
19+
#shopifyContext!: typeof SHOPIFY_CONTEXT_TOKEN.TYPE;
1920
#modalManagerContext?: typeof UMB_MODAL_MANAGER_CONTEXT.TYPE;
2021
#settingsModel?: EditorSettingsModel;
2122

@@ -57,6 +58,7 @@ export class ShopifyProductPickerPropertyEditor extends UmbLitElement implements
5758
});
5859
this.consumeContext(SHOPIFY_CONTEXT_TOKEN, (context) => {
5960
if (!context) return;
61+
this.#shopifyContext = context;
6062
this.observe(context.settingsModel, (settingsModel) => {
6163
this.#settingsModel = settingsModel;
6264
});
@@ -81,8 +83,18 @@ export class ShopifyProductPickerPropertyEditor extends UmbLitElement implements
8183

8284
if (this.value == null || this.value.length == 0) return;
8385

84-
const dto: Array<ProductDtoModel> = JSON.parse(JSON.stringify(this.value));
85-
this.products = dto;
86+
await this.#getProducts();
87+
}
88+
89+
async #getProducts() {
90+
const model: RequestDtoModel = {
91+
ids: JSON.parse(JSON.stringify(this.value))
92+
};
93+
94+
const { data } = await this.#shopifyContext.getListByIds(model);
95+
if (!data) return;
96+
97+
this.products = data.result.products;
8698
}
8799

88100
private async _openModal() {
@@ -97,8 +109,8 @@ export class ShopifyProductPickerPropertyEditor extends UmbLitElement implements
97109
const data = await pickerContext?.onSubmit();
98110
if (!data) return;
99111

100-
this.value = JSON.stringify(data.productList);
101-
this.products = JSON.parse(this.value);
112+
this.value = JSON.stringify(data.productList.map(product => product.id));
113+
this.products = data.productList;
102114
this.dispatchEvent(new CustomEvent('property-value-change'));
103115
}
104116

@@ -112,7 +124,7 @@ export class ShopifyProductPickerPropertyEditor extends UmbLitElement implements
112124
deleteForm(id: number){
113125
var index = this.products.map(p => p.id).indexOf(id);
114126
this.products.splice(index, 1);
115-
this.value = JSON.stringify(this.products);
127+
this.value = JSON.stringify(this.products.map(product => product.id));
116128
this.dispatchEvent(new CustomEvent('property-value-change'));
117129
}
118130

src/Umbraco.Cms.Integrations.Commerce.Shopify/Client/src/repository/shopify.repository.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { UmbControllerBase } from "@umbraco-cms/backoffice/class-api";
22
import type { UmbControllerHost } from "@umbraco-cms/backoffice/controller-api";
33
import { tryExecuteAndNotify } from "@umbraco-cms/backoffice/resources";
4-
import { ShopifyService, type OAuthRequestDtoModel } from "@umbraco-integrations/shopify/generated";
4+
import { ShopifyService, type OAuthRequestDtoModel, RequestDtoModel } from "@umbraco-integrations/shopify/generated";
55

66
export class ShopifyRepository extends UmbControllerBase {
77
constructor(host: UmbControllerHost) {
@@ -58,8 +58,10 @@ export class ShopifyRepository extends UmbControllerBase {
5858
return { data };
5959
}
6060

61-
async getListByIds(){
62-
const { data, error } = await tryExecuteAndNotify(this, ShopifyService.getListByIds());
61+
async getListByIds(model: RequestDtoModel) {
62+
const { data, error } = await tryExecuteAndNotify(this, ShopifyService.getListByIds({
63+
requestBody: model
64+
}));
6365

6466
if (error || !data) {
6567
return { error };

src/Umbraco.Cms.Integrations.Commerce.Shopify/Constants.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ public static class Constants
1818

1919
public static class RenderingComponent
2020
{
21-
public const string DefaultV8ViewPath = ViewFolderPath + "/Render/Products.cshtml";
22-
23-
public const string DefaultV9ViewPath = ViewFolderPath + "/Render/ProductsV9.cshtml";
21+
public const string DefaultViewPath = ViewFolderPath + "/Render/Products.cshtml";
2422
}
2523

2624
public static class ManagementApi

src/Umbraco.Cms.Integrations.Commerce.Shopify/Editors/ShopifyProductPickerValueConverter.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Umbraco.Cms.Core.Models.PublishedContent;
1+
using Newtonsoft.Json;
2+
using Umbraco.Cms.Core.Models.PublishedContent;
23
using Umbraco.Cms.Core.PropertyEditors;
34
using Umbraco.Cms.Integrations.Commerce.Shopify.Models.ViewModels;
45
using Umbraco.Cms.Integrations.Commerce.Shopify.Services;
@@ -27,10 +28,7 @@ public override object ConvertSourceToIntermediate(IPublishedElement owner, IPub
2728
{
2829
if (source == null) return null;
2930

30-
return source.ToString()
31-
.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries)
32-
.Select(long.Parse)
33-
.ToArray();
31+
return JsonConvert.DeserializeObject<long[]>(source.ToString());
3432
}
3533

3634
public override object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType,

src/Umbraco.Cms.Integrations.Commerce.Shopify/Helpers/HtmlHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public static class ShopifyHtmlExtensions
99
{
1010
public static IHtmlContent RenderShopifyProductsList(this IHtmlHelper<dynamic> htmlHelper, List<ProductViewModel> vm, string renderingViewPath = "")
1111
{
12-
return htmlHelper.Partial(string.IsNullOrEmpty(renderingViewPath) ? Constants.RenderingComponent.DefaultV9ViewPath : renderingViewPath, vm);
12+
return htmlHelper.Partial(string.IsNullOrEmpty(renderingViewPath) ? Constants.RenderingComponent.DefaultViewPath : renderingViewPath, vm);
1313
}
1414
}
1515
}

0 commit comments

Comments
 (0)