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