Stuff and things.
This commit is contained in:
@@ -31,10 +31,6 @@ namespace PartSource.Automation.Jobs
|
||||
|
||||
public async Task<AutomationJobResult> Run()
|
||||
{
|
||||
IList<ImportData> importDataz = _partSourceContext.ImportData.ToList();
|
||||
|
||||
return new AutomationJobResult();
|
||||
|
||||
IDictionary<string, object> parameters = new Dictionary<string, object>
|
||||
{
|
||||
{ "limit", 250 }
|
||||
@@ -50,7 +46,7 @@ namespace PartSource.Automation.Jobs
|
||||
{
|
||||
ImportData importData = _partSourceContext.ImportData.FirstOrDefault(i => i.VariantSku == product.Variants[0].Sku);
|
||||
|
||||
if (importData?.LineCode == "SVG") // Headlights go in front, DUH
|
||||
if (importData == null || importData?.LineCode == "SVG") // Headlights go in front, DUH
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -65,35 +61,70 @@ namespace PartSource.Automation.Jobs
|
||||
|
||||
//await DeletePositionMetafields(product.Id);
|
||||
|
||||
string currentPosition = fitments[0].Position;
|
||||
List<int> vehicleIds = new List<int>();
|
||||
//string currentPosition = fitments[0].Position;
|
||||
//List<int> vehicleIds = new List<int>();
|
||||
|
||||
foreach (Fitment fitment in fitments)
|
||||
{
|
||||
if (fitment.Position != currentPosition)
|
||||
{
|
||||
await SavePositionMetafield(product, vehicleIds, currentPosition);
|
||||
//foreach (Fitment fitment in fitments)
|
||||
//{
|
||||
// if (fitment.Position != currentPosition)
|
||||
// {
|
||||
// await SavePositionMetafield(product, vehicleIds, currentPosition);
|
||||
|
||||
currentPosition = fitment.Position;
|
||||
vehicleIds = new List<int>();
|
||||
}
|
||||
// currentPosition = fitment.Position;
|
||||
// vehicleIds = new List<int>();
|
||||
// }
|
||||
|
||||
// We don't need to DCF map because these are both sourced from WHI
|
||||
IList<int> fitmentVehicleIds = vehicles.Where(v => v.BaseVehicleId == fitment.BaseVehicleId && v.EngineConfigId == fitment.EngineConfigId)
|
||||
.Select(v => v.VehicleToEngineConfigId)
|
||||
// // We don't need to DCF map because these are both sourced from WHI
|
||||
// IList<int> fitmentVehicleIds = vehicles.Where(v => v.BaseVehicleId == fitment.BaseVehicleId && v.EngineConfigId == fitment.EngineConfigId)
|
||||
// .Select(v => v.VehicleToEngineConfigId)
|
||||
// .Distinct()
|
||||
// .ToList();
|
||||
|
||||
// vehicleIds.AddRange(fitmentVehicleIds);
|
||||
//}
|
||||
|
||||
//await SavePositionMetafield(product, vehicleIds, currentPosition);
|
||||
|
||||
|
||||
IList<string> notes = fitments.Select(f => f.NoteText)
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
vehicleIds.AddRange(fitmentVehicleIds);
|
||||
IList<object> vehicleNotes = new List<object>();
|
||||
|
||||
foreach (string noteText in notes)
|
||||
{
|
||||
IList<int> vehicleIds = fitments.Where(f => f.NoteText == noteText)
|
||||
.Select(f => new { f.EngineConfigId, f.BaseVehicleId })
|
||||
.SelectMany(f => vehicles.Where(v => v.BaseVehicleId == f.BaseVehicleId && v.EngineConfigId == f.EngineConfigId))
|
||||
.Select(v => v.VehicleToEngineConfigId)
|
||||
.ToList();
|
||||
|
||||
|
||||
vehicleNotes.Add(new { noteText, vehicleIds });
|
||||
}
|
||||
|
||||
await SavePositionMetafield(product, vehicleIds, currentPosition);
|
||||
string json = JsonConvert.SerializeObject(vehicleNotes);
|
||||
if (json.Length >= 100000)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Metafield vehicleMetafield = new Metafield
|
||||
{
|
||||
Namespace = "fitment",
|
||||
Key = "note_text",
|
||||
Value = json,
|
||||
ValueType = "json_string",
|
||||
OwnerResource = "product",
|
||||
OwnerId = product.Id
|
||||
};
|
||||
|
||||
await _shopifyClient.Metafields.Add(vehicleMetafield);
|
||||
|
||||
importData.UpdatedAt = DateTime.Now;
|
||||
importData.UpdateType = "Positioning";
|
||||
|
||||
//importData.UpdatedAt = DateTime.Now;
|
||||
//importData.UpdateType = "Positioning";
|
||||
;
|
||||
|
||||
}
|
||||
|
||||
@@ -106,7 +137,7 @@ namespace PartSource.Automation.Jobs
|
||||
try
|
||||
{
|
||||
Console.Write('.');
|
||||
await _partSourceContext.SaveChangesAsync();
|
||||
// await _partSourceContext.SaveChangesAsync();
|
||||
products = await _shopifyClient.Products.GetNext();
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"profiles": {
|
||||
"PartSource.Automation": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "UpdatePositioning",
|
||||
"commandLineArgs": "UpdatePricing",
|
||||
"environmentVariables": {
|
||||
"PS_AUTOMATION_ENVIRONMENT": "development"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user