Current state, whatever that means
This commit is contained in:
@@ -14,6 +14,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -38,14 +39,21 @@ namespace PartSource.Automation.Jobs
|
||||
|
||||
public async Task Run()
|
||||
{
|
||||
IEnumerable<Product> products = null;
|
||||
|
||||
try
|
||||
IList<string> productTypes = new List<string>
|
||||
{
|
||||
products = await _shopifyClient.Products.Get(new Dictionary<string, object> { { "limit", 250 } });//, {"product_type", "CA142-SC130-FL13029_Certified Brake Pads" } });
|
||||
"CA108-SC349-FL34907_CV Shafts, New"
|
||||
};
|
||||
|
||||
foreach (string type in productTypes)
|
||||
{
|
||||
IEnumerable<Product> products = null;
|
||||
|
||||
try
|
||||
{
|
||||
products = await _shopifyClient.Products.Get(new Dictionary<string, object> { { "limit", 250 }, { "product_type", "CA108-SC349-FL34907_CV Shafts, New" } });
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError("Failed to get products from Shopify", ex);
|
||||
throw;
|
||||
@@ -61,14 +69,25 @@ namespace PartSource.Automation.Jobs
|
||||
|
||||
try
|
||||
{
|
||||
importData = await _partSourceContext.ImportData.FirstOrDefaultAsync(parts => parts.ShopifyId == product.Id);
|
||||
IEnumerable<Metafield> metafields = await _shopifyClient.Metafields.Get(new Dictionary<string, object> { { "metafield[owner_id]", product.Id }, { "metafield[owner_resource]", "product" } });
|
||||
|
||||
if (importData == null)
|
||||
//importData = await _partSourceContext.ImportData.FirstOrDefaultAsync(parts => parts.ShopifyId == product.Id);
|
||||
|
||||
//if (importData == null)
|
||||
//{
|
||||
// continue;
|
||||
importData = new ImportData
|
||||
{
|
||||
continue;
|
||||
}
|
||||
LineCode = metafields.FirstOrDefault(m => m.Key == "custom_label_0").Value ?? string.Empty,
|
||||
PartNumber = product.Title.Split(' ')[0],
|
||||
VariantSku = product.Variants[0].Sku // They know we can't do fitment for variants
|
||||
};
|
||||
// }
|
||||
|
||||
//importData.PartNumber = product.Title.Split(' ')[0];
|
||||
|
||||
bool isFitment = false;
|
||||
string bodyHtml = product.BodyHtml.Substring(0, product.BodyHtml.IndexOf("</ul>") + "</ul>".Length);
|
||||
|
||||
IList<Vehicle> vehicles = _vehicleService.GetVehiclesForPart(importData.PartNumber, importData.LineCode);
|
||||
|
||||
@@ -84,6 +103,10 @@ namespace PartSource.Automation.Jobs
|
||||
|
||||
if (vehicleIdFitment.Count > 0)
|
||||
{
|
||||
string vehicleIdString = string.Join('-', vehicleIdFitment.Select(j => $"v{j}"));
|
||||
|
||||
bodyHtml += $"<div id=\"vehicleIDs\" style=\"display:none;\">{vehicleIdString}</div>";
|
||||
|
||||
isFitment = true;
|
||||
|
||||
string json = JsonConvert.SerializeObject(vehicleIdFitment);
|
||||
@@ -114,6 +137,28 @@ namespace PartSource.Automation.Jobs
|
||||
{
|
||||
isFitment = true;
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.AppendLine("<table><tr><th colspan=\"2\">This Part Fits</th></tr>");
|
||||
|
||||
foreach (string fitment in ymmFitment)
|
||||
{
|
||||
try
|
||||
{
|
||||
string[] parts = fitment.Split(' ', 2);
|
||||
|
||||
stringBuilder.AppendLine($"<tr><td>{parts[1]}</td><td>{parts[0].Replace("-", ", ")}</td></tr>");
|
||||
}
|
||||
|
||||
catch
|
||||
{
|
||||
// This is still a POC at this point. Oh well...
|
||||
}
|
||||
}
|
||||
|
||||
stringBuilder.AppendLine("</table>");
|
||||
|
||||
bodyHtml += $"<div id=\"seoData\">{stringBuilder.ToString()}</div>";
|
||||
|
||||
string json = JsonConvert.SerializeObject(ymmFitment);
|
||||
if (json.Length < 100000)
|
||||
{
|
||||
@@ -149,12 +194,32 @@ namespace PartSource.Automation.Jobs
|
||||
|
||||
await _shopifyClient.Metafields.Add(isFitmentMetafield);
|
||||
|
||||
List<string> tags = new List<string>
|
||||
Metafield lineCodeMetafield = new Metafield
|
||||
{
|
||||
importData.LineCode,
|
||||
importData.PartNumber
|
||||
Namespace = "google",
|
||||
Key = "custom_label_0",
|
||||
Value = importData.LineCode,
|
||||
ValueType = "string",
|
||||
OwnerResource = "product",
|
||||
OwnerId = product.Id
|
||||
};
|
||||
|
||||
//await _shopifyClient.Metafields.Add(lineCodeMetafield);
|
||||
|
||||
Metafield partNumberMetafield = new Metafield
|
||||
{
|
||||
Namespace = "google",
|
||||
Key = "custom_label_1",
|
||||
Value = importData.PartNumber,
|
||||
ValueType = "string",
|
||||
OwnerResource = "product",
|
||||
OwnerId = product.Id
|
||||
};
|
||||
|
||||
// await _shopifyClient.Metafields.Add(partNumberMetafield);
|
||||
|
||||
List<string> tags = new List<string>();
|
||||
|
||||
for (int j = 0; j < vehicleIdFitment.Count; j += 25)
|
||||
{
|
||||
tags.Add(string.Join('-', vehicleIdFitment.Skip(j).Take(25).Select(j => $"v{j}")));
|
||||
@@ -173,8 +238,8 @@ namespace PartSource.Automation.Jobs
|
||||
|
||||
tags.Add(zzzIsFitment);
|
||||
|
||||
product.Tags = string.Join(',', tags);
|
||||
|
||||
//product.Tags = string.Join(',', tags);
|
||||
product.BodyHtml = bodyHtml;
|
||||
await _shopifyClient.Products.Update(product);
|
||||
|
||||
importData.IsFitment = isFitment;
|
||||
@@ -205,5 +270,7 @@ namespace PartSource.Automation.Jobs
|
||||
}
|
||||
}
|
||||
}
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user