Added core pricing metafield and status check job
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
using Newtonsoft.Json;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json;
|
||||
using PartSource.Automation.Jobs.Interfaces;
|
||||
using PartSource.Automation.Models;
|
||||
using PartSource.Data;
|
||||
using PartSource.Data.Models;
|
||||
using PartSource.Data.Shopify;
|
||||
using PartSource.Services;
|
||||
using PartSource.Services.Integrations;
|
||||
using Ratermania.Shopify.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
@@ -31,7 +32,12 @@ namespace PartSource.Automation.Jobs
|
||||
|
||||
public async Task<AutomationJobResult> Run()
|
||||
{
|
||||
IEnumerable<Product> products = await _shopifyClient.Products.Get();
|
||||
IDictionary<string, object> parameters = new Dictionary<string, object>
|
||||
{
|
||||
{ "limit", 250 }
|
||||
};
|
||||
|
||||
IEnumerable<Product> products = await _shopifyClient.Products.Get(parameters);
|
||||
|
||||
while (products != null && products.Any())
|
||||
{
|
||||
@@ -79,30 +85,37 @@ namespace PartSource.Automation.Jobs
|
||||
}
|
||||
|
||||
await SavePositionMetafield(product, vehicleIds, currentPosition);
|
||||
|
||||
importData.UpdatedAt = DateTime.Now;
|
||||
importData.UpdateType = "Positioning";
|
||||
|
||||
|
||||
}
|
||||
|
||||
catch
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(product.Id);
|
||||
Console.WriteLine($"{product.Id}: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Console.Write('.');
|
||||
|
||||
await _partSourceContext.SaveChangesAsync();
|
||||
products = await _shopifyClient.Products.GetNext();
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
{
|
||||
products = await _shopifyClient.Products.GetNext();
|
||||
Console.WriteLine($"Retrying: {ex.Message}");
|
||||
|
||||
products = await _shopifyClient.Products.GetPrevious();
|
||||
}
|
||||
}
|
||||
|
||||
return new AutomationJobResult
|
||||
{
|
||||
Message = "Fitment updated successfully",
|
||||
Message = "Positioning updated successfully",
|
||||
IsSuccess = true
|
||||
};
|
||||
}
|
||||
@@ -119,6 +132,7 @@ namespace PartSource.Automation.Jobs
|
||||
.Where(f => f.PartNumber == partNumber && whiCodes.Contains(f.LineCode) && !string.IsNullOrEmpty(f.Position))
|
||||
.OrderBy(f => f.Position)
|
||||
.ToList();
|
||||
|
||||
}
|
||||
|
||||
[SuppressMessage("Globalization", "CA1308:Normalize strings to uppercase", Justification = "It's a Shopify metafield key")]
|
||||
@@ -152,6 +166,8 @@ namespace PartSource.Automation.Jobs
|
||||
OwnerId = product.Id
|
||||
};
|
||||
|
||||
System.Diagnostics.Debug.WriteLine(json);
|
||||
|
||||
await _shopifyClient.Metafields.Add(vehicleMetafield);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user