Changed a lot LOL
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
using PartSource.Automation.Jobs.Interfaces;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using PartSource.Automation.Jobs.Interfaces;
|
||||
using PartSource.Automation.Models;
|
||||
using PartSource.Data;
|
||||
using PartSource.Data.Models;
|
||||
@@ -27,11 +29,13 @@ namespace PartSource.Automation.Jobs
|
||||
public async Task<AutomationJobResult> Run()
|
||||
{
|
||||
IEnumerable<Product> products = null;
|
||||
IEnumerable<PartPrice> prices = null;
|
||||
int updateCount = 0;
|
||||
|
||||
try
|
||||
{
|
||||
products = await _shopifyClient.Products.Get();
|
||||
products = await _shopifyClient.Products.Get(new Dictionary<string, object> { { "limit", 250 } });
|
||||
prices = await _partSourceContext.PartPrices.ToListAsync();
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
@@ -50,8 +54,9 @@ namespace PartSource.Automation.Jobs
|
||||
{
|
||||
if (product.Variants.Length > 0)
|
||||
{
|
||||
|
||||
Variant variant = product.Variants[0];
|
||||
PartPrice partPrice = _partSourceContext.PartPrices.Where(p => p.SKU == variant.Sku).FirstOrDefault();
|
||||
PartPrice partPrice = prices.Where(p => p.SKU == variant.Sku).FirstOrDefault();
|
||||
|
||||
if (partPrice == null || !partPrice.Your_Price.HasValue || !partPrice.Compare_Price.HasValue)
|
||||
{
|
||||
@@ -65,7 +70,8 @@ namespace PartSource.Automation.Jobs
|
||||
product.Variants[0].Price = partPrice.Your_Price.Value;
|
||||
product.Variants[0].CompareAtPrice = partPrice.Compare_Price.Value;
|
||||
|
||||
product.PublishedAt = partPrice.Active.ToUpperInvariant() == "Y" ? DateTime.Now : default;
|
||||
product.PublishedAt = partPrice.Active.Trim().ToUpperInvariant() == "Y" ? (DateTime?)DateTime.Now : null;
|
||||
product.PublishedScope = PublishedScope.Global;
|
||||
|
||||
Metafield metafield = new Metafield
|
||||
{
|
||||
@@ -81,29 +87,37 @@ namespace PartSource.Automation.Jobs
|
||||
{
|
||||
await _shopifyClient.Metafields.Add(metafield);
|
||||
await _shopifyClient.Products.Update(product);
|
||||
|
||||
|
||||
updateCount++;
|
||||
|
||||
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Console.WriteLine("bad update");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
{
|
||||
;
|
||||
Console.WriteLine("failed getting parts");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_partSourceContext.SaveChanges();
|
||||
// _partSourceContext.SaveChanges();
|
||||
|
||||
try
|
||||
{
|
||||
//await _shopifyClient.Products.SaveChanges();
|
||||
|
||||
products = await _shopifyClient.Products.GetNext();
|
||||
|
||||
Console.SetCursorPosition(0, 2);
|
||||
Console.Clear();
|
||||
Console.Write($"Updated: {updateCount} ");
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
|
||||
Reference in New Issue
Block a user