Skip to content

Commit

Permalink
Removed store view optional request
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalii-bezuhlyi committed Nov 18, 2024
1 parent 1639a97 commit cfd212e
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 11 deletions.
17 changes: 15 additions & 2 deletions Apps.Magento/Actions/PageActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,22 @@ public async Task<PageResponse> UpdatePageByIdAsync([ActionParameter] PageIdenti
page.Active = pageRequest.Active ?? page.Active;

var request = new ApiRequest($"/rest/V1/cmsPage/{identifier.PageId}", Method.Put, Creds)
.AddBody(new { page });
await Client.ExecuteWithErrorHandling<PageResponse>(request);
.AddBody(new { page = new
{
id = page.Id,
identifier = page.Identifier,
title = page.Title,
page_layout = page.PageLayout,
meta_title = page.MetaTitle,
meta_keywords = page.MetaKeywords,
meta_description = page.MetaDescription,
content_heading = page.ContentHeading,
content = page.Content,
sort_order = page.SortOrder,
active = page.Active
} });

await Client.ExecuteWithErrorHandling<PageResponse>(request);
return await GetPageByIdAsync(identifier);
}

Expand Down
12 changes: 11 additions & 1 deletion Apps.Magento/Actions/ProductActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ public async Task<FileReference> GetProductBySkuAsHtmlAsync(
[Action("Create product", Description = "Create product with specified data")]
public async Task<ProductResponse> CreateProductAsync([ActionParameter] CreateProductRequest createProductRequest)
{
var customAttributes = new List<object>();
if (!string.IsNullOrEmpty(createProductRequest.PriceView))
{
customAttributes.Add(new
{
attribute_code = "price_view",
value = createProductRequest.PriceView
});
}

var body = new
{
product = new
Expand All @@ -91,7 +101,7 @@ public async Task<ProductResponse> CreateProductAsync([ActionParameter] CreatePr
{
category_links = new List<object>()
},
custom_attributes = new List<object>()
custom_attributes = customAttributes
}
};

Expand Down
3 changes: 3 additions & 0 deletions Apps.Magento/Models/Requests/Products/CreateProductRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@ public class CreateProductRequest
public string TypeId { get; set; } = string.Empty;

public double Weight { get; set; }

[Display("Price view")]
public string? PriceView { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Blackbird.Applications.Sdk.Common;

namespace Apps.Magento.Polling.Models.Requests;

public class OnProductsUpdatedRequest
{
[Display("Title", Description = "By setting this parameter, the event will only trigger when the product title contains the specified value")]
public string? Title { get; set; }
}
15 changes: 7 additions & 8 deletions Apps.Magento/Polling/ProductPollingList.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using Apps.Magento.Api;
using Apps.Magento.Invocables;
using Apps.Magento.Models.Identifiers;
using Apps.Magento.Models.Requests;
using Apps.Magento.Models.Responses.Products;
using Apps.Magento.Polling.Models;
using Apps.Magento.Polling.Models.Requests;
using Blackbird.Applications.Sdk.Common.Invocation;
using Blackbird.Applications.Sdk.Common.Polling;
using RestSharp;
Expand All @@ -16,7 +16,7 @@ public class ProductPollingList(InvocationContext invocationContext) : AppInvoca
[PollingEvent("On products created", "Triggered when new products are created")]
public async Task<PollingEventResponse<DateMemory, ProductsResponse>> OnProductsCreated(
PollingEventRequest<DateMemory> request,
[PollingEventParameter] StoreViewOptionalIdentifier storeViewIdentifier)
[PollingEventParameter] OnProductsUpdatedRequest filterRequest)
{
if (request.Memory is null)
{
Expand All @@ -30,7 +30,7 @@ public async Task<PollingEventResponse<DateMemory, ProductsResponse>> OnProducts
};
}

var products = await GetProducts(new BaseFilterRequest { CreatedAt = request.Memory.LastInteractionDate }, storeViewIdentifier.ToString());
var products = await GetProducts(new BaseFilterRequest { CreatedAt = request.Memory.LastInteractionDate, Title = filterRequest.Title });
return new()
{
FlyBird = products.Items.Any(),
Expand All @@ -45,7 +45,7 @@ public async Task<PollingEventResponse<DateMemory, ProductsResponse>> OnProducts
[PollingEvent("On products updated", "Triggered when products are updated")]
public async Task<PollingEventResponse<DateMemory, ProductsResponse>> OnProductsUpdated(
PollingEventRequest<DateMemory> request,
[PollingEventParameter] StoreViewOptionalIdentifier storeViewIdentifier)
[PollingEventParameter] OnProductsUpdatedRequest filterRequest)
{
if (request.Memory is null)
{
Expand All @@ -59,8 +59,7 @@ public async Task<PollingEventResponse<DateMemory, ProductsResponse>> OnProducts
};
}

var products = await GetProducts(new BaseFilterRequest { UpdatedAt = request.Memory.LastInteractionDate },
storeViewIdentifier.ToString());
var products = await GetProducts(new BaseFilterRequest { UpdatedAt = request.Memory.LastInteractionDate, Title = filterRequest.Title });
products.Items = products.Items.Where(x => x.CreatedAt != x.UpdatedAt).ToList();

return new()
Expand All @@ -74,10 +73,10 @@ public async Task<PollingEventResponse<DateMemory, ProductsResponse>> OnProducts
};
}

private async Task<ProductsResponse> GetProducts(BaseFilterRequest request, string storeView)
private async Task<ProductsResponse> GetProducts(BaseFilterRequest request)
{
var queryString = BuildQueryString(request);
var requestUrl = $"/rest/{storeView}/V1/products?searchCriteria{queryString}";
var requestUrl = $"/rest/V1/products?searchCriteria{queryString}";
return await Client.ExecuteWithErrorHandling<ProductsResponse>(new ApiRequest(requestUrl, Method.Get, Creds));
}
}

0 comments on commit cfd212e

Please sign in to comment.