Fitment update
This commit is contained in:
@@ -35,14 +35,13 @@ namespace PartSource.Automation.Jobs
|
||||
|
||||
public async Task Run(CancellationToken token, params string[] arguments)
|
||||
{
|
||||
List<UpdatePricingResult> pricingReport = new List<UpdatePricingResult>();
|
||||
IEnumerable<Product> products = null;
|
||||
IEnumerable<PartPrice> prices = null;
|
||||
|
||||
try
|
||||
{
|
||||
products = await _shopifyClient.Products.Get(new Dictionary<string, object> { { "limit", 250 } });
|
||||
prices = await _partSourceContext.PartPrices.AsNoTracking().ToListAsync(token);
|
||||
prices = await _partSourceContext.PartPrices.AsNoTracking().ToListAsync();
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
@@ -52,6 +51,7 @@ namespace PartSource.Automation.Jobs
|
||||
throw;
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
while (products != null && products.Any())
|
||||
{
|
||||
foreach (Product product in products)
|
||||
@@ -76,12 +76,12 @@ namespace PartSource.Automation.Jobs
|
||||
|
||||
try
|
||||
{
|
||||
await _shopifyClient.Metafields.Add(new Metafield
|
||||
_shopifyClient.BulkActions.Add(new Metafield
|
||||
{
|
||||
Namespace = "Pricing",
|
||||
Key = "CorePrice",
|
||||
Value = partPrice.Core_Price.HasValue ? partPrice.Core_Price.Value.ToString() : "0.00",
|
||||
Type = "single_line_text_field",
|
||||
Type = "string",
|
||||
OwnerResource = "product",
|
||||
OwnerId = product.Id
|
||||
});
|
||||
@@ -89,13 +89,15 @@ namespace PartSource.Automation.Jobs
|
||||
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning(ex, $"Failed to update core price metafield for product ID {product.Id}");
|
||||
_logger.LogWarning(ex, $"Failed to update pricing for product ID {product.Id}");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await _shopifyClient.Products.Update(product);
|
||||
_shopifyClient.BulkActions.Update(product);
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
@@ -105,12 +107,11 @@ namespace PartSource.Automation.Jobs
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
count += products.Count();
|
||||
products = await _shopifyClient.Products.GetNext();
|
||||
|
||||
_logger.LogInformation($"Total updated: {pricingReport.Count}");
|
||||
_logger.LogInformation($"Total updated: {count}");
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
@@ -119,8 +120,13 @@ namespace PartSource.Automation.Jobs
|
||||
products = await _shopifyClient.Products.GetPrevious();
|
||||
}
|
||||
}
|
||||
|
||||
_emailService.Send("Pricing Update Completed", $"The pricing update has completed.");
|
||||
|
||||
while (_shopifyClient.BulkActions.PendingCount() > 0)
|
||||
{
|
||||
await Task.Delay(15 * 1000, token);
|
||||
_logger.LogInformation(_shopifyClient.BulkActions.PendingCount().ToString());
|
||||
}
|
||||
// _emailService.Send("Pricing Update Completed", $"The pricing update has completed.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user