Added core pricing metafield and status check job
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
using PartSource.Automation.Models;
|
||||
using PartSource.Data;
|
||||
using PartSource.Data.Models;
|
||||
using PartSource.Data.Shopify;
|
||||
using PartSource.Services.Integrations;
|
||||
using Ratermania.Shopify.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -53,31 +53,51 @@ namespace PartSource.Automation.Jobs
|
||||
ProductVariant variant = product.Variants[0];
|
||||
PartPrice partPrice = _partSourceContext.PartPrices.Where(p => p.SKU == variant.Sku).FirstOrDefault();
|
||||
|
||||
if (partPrice == null)
|
||||
if (partPrice == null || !partPrice.Your_Price.HasValue || !partPrice.Compare_Price.HasValue)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (product.Variants[0].Price != partPrice.Your_Price.Value || product.Variants[0].CompareAtPrice != partPrice.Compare_Price.Value)
|
||||
try
|
||||
{
|
||||
product.Variants[0].Price = partPrice.Your_Price.Value;
|
||||
product.Variants[0].CompareAtPrice = partPrice.Compare_Price.Value;
|
||||
|
||||
try
|
||||
if (product.Variants[0].Price != partPrice.Your_Price.Value || product.Variants[0].CompareAtPrice != partPrice.Compare_Price.Value)
|
||||
{
|
||||
await _shopifyClient.Products.Update(product);
|
||||
product.Variants[0].Price = partPrice.Your_Price.Value;
|
||||
product.Variants[0].CompareAtPrice = partPrice.Compare_Price.Value;
|
||||
|
||||
updateCount++;
|
||||
}
|
||||
Metafield metafield = new Metafield
|
||||
{
|
||||
Namespace = "Pricing",
|
||||
Key = "CorePrice",
|
||||
Value = partPrice.Core_Price.HasValue ? partPrice.Core_Price.Value.ToString() : "0.00",
|
||||
ValueType = "string",
|
||||
OwnerResource = "product",
|
||||
OwnerId = product.Id
|
||||
};
|
||||
|
||||
catch (Exception ex)
|
||||
{
|
||||
// TODO: Logged failed pricing update here
|
||||
try
|
||||
{
|
||||
await _shopifyClient.Products.Update(product);
|
||||
|
||||
updateCount++;
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
{
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_partSourceContext.SaveChanges();
|
||||
|
||||
try
|
||||
{
|
||||
products = await _shopifyClient.Products.GetNext();
|
||||
@@ -85,13 +105,7 @@ namespace PartSource.Automation.Jobs
|
||||
|
||||
catch (Exception ex)
|
||||
{
|
||||
// TODO: Logging
|
||||
|
||||
return new AutomationJobResult
|
||||
{
|
||||
Message = $"Failed to get the next set of products from Shopify.\n\n {ex}\n\n {updateCount} products were able to be updated.",
|
||||
IsSuccess = false
|
||||
};
|
||||
products = await _shopifyClient.Products.GetPrevious();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user