WIP
This commit is contained in:
@@ -15,6 +15,7 @@ using Ratermania.Automation.Interfaces;
|
||||
using Ratermania.Shopify;
|
||||
using Ratermania.Shopify.Resources;
|
||||
using System.Web;
|
||||
using System.IO;
|
||||
|
||||
namespace PartSource.Automation.Jobs
|
||||
{
|
||||
@@ -37,20 +38,24 @@ namespace PartSource.Automation.Jobs
|
||||
|
||||
public async Task Run(CancellationToken token, params string[] arguments)
|
||||
{
|
||||
string logfile = Path.Combine(Path.GetTempPath(), $"missing_fitment_{DateTime.Now:yyyy-MM-dd}.csv");
|
||||
using StreamWriter noFitmentWriter = File.AppendText(logfile);
|
||||
noFitmentWriter.WriteLine("SKU,LineCode,PartNumber");
|
||||
|
||||
IList<string> productTypes = await _fitmentContext.ProductTypes
|
||||
_logger.LogInformation($"Logging products without fitment to {logfile}");
|
||||
|
||||
IList<ProductType> productTypes = await _fitmentContext.ProductTypes
|
||||
.Where(p => p.Active)
|
||||
.Select(p => HttpUtility.UrlEncode(p.Name))
|
||||
.ToListAsync();
|
||||
|
||||
foreach (string productType in productTypes)
|
||||
foreach (ProductType productType in productTypes)
|
||||
{
|
||||
_logger.LogInformation("Processing {productType}", HttpUtility.UrlDecode(productType));
|
||||
_logger.LogInformation("Processing {productType}", productType.Name);
|
||||
|
||||
IEnumerable<Product> products = null;
|
||||
try
|
||||
{
|
||||
products = await _shopifyClient.Products.Get(new Dictionary<string, object> { { "limit", 250 }, { "product_type", productType } });
|
||||
products = await _shopifyClient.Products.Get(new Dictionary<string, object> { { "limit", 250 }, { "product_type", HttpUtility.UrlEncode(productType.Name) } });
|
||||
//products = new List<Product>
|
||||
//{
|
||||
// await _shopifyClient.Products.GetById(7458071052335)
|
||||
@@ -88,6 +93,12 @@ namespace PartSource.Automation.Jobs
|
||||
continue;
|
||||
}
|
||||
|
||||
// Temporarily skip castrol oils
|
||||
if (importData.LineCode == "CST")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Extract Partsource bullet points if present.
|
||||
string bodyHtml = string.IsNullOrEmpty(product.BodyHtml)
|
||||
? string.Empty
|
||||
@@ -99,6 +110,8 @@ namespace PartSource.Automation.Jobs
|
||||
if (!vehicleIdFitment.Any())
|
||||
{
|
||||
Console.WriteLine($"No fitment data for {importData.LineCode} {importData.PartNumber}");
|
||||
noFitmentWriter.WriteLine($"\"{importData.VariantSku}\",\"{importData.LineCode}\",\"{importData.PartNumber}\"");
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -181,6 +194,9 @@ namespace PartSource.Automation.Jobs
|
||||
products = await _shopifyClient.Products.GetPrevious();
|
||||
}
|
||||
}
|
||||
|
||||
productType.Active = false;
|
||||
await _fitmentContext.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user