Added core pricing metafield and status check job

This commit is contained in:
2020-05-07 21:33:16 -04:00
parent ef5e4422c0
commit 9d3eac20dc
19 changed files with 341 additions and 119 deletions

View File

@@ -1,13 +1,10 @@
using PartSource.Automation.Jobs.Interfaces; using PartSource.Automation.Jobs.Interfaces;
using PartSource.Automation.Models; using PartSource.Automation.Models;
using PartSource.Automation.Services;
using PartSource.Data; using PartSource.Data;
using PartSource.Data.Models; using PartSource.Data.Models;
using PartSource.Data.Shopify;
using PartSource.Services;
using PartSource.Services.Integrations; using PartSource.Services.Integrations;
using Ratermania.Shopify.Entities;
using System; using System;
using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
@@ -38,32 +35,29 @@ namespace PartSource.Automation.Jobs
public async Task AddSkus() public async Task AddSkus()
{ {
ImportData importData = _partSourceContext.ImportData.FirstOrDefault(p => !p.ShopifyId.HasValue); IList<ImportData> items = _partSourceContext.ImportData
.Where(i => i.Title == _partSourceContext.ImportData.First().Title)
.ToList();
while (importData != null) while (items != null && items.Count > 0)
{ {
if (importData == null)
{
continue;
}
// Images // Images
List<ProductImage> productImages = new List<ProductImage>(); IList<ProductImage> productImages = items.SelectMany(v => {
string[] imageUrls = importData.ImageSrc?.Split(','); IList<ProductImage> images = new List<ProductImage>();
if (imageUrls?.Length > 0) foreach (string src in v.ImageSrc?.Split(','))
{ {
foreach (string url in imageUrls) images.Add(new ProductImage
{ {
productImages.Add(new ProductImage Src = src,
{ Alt = v.ImageAltText
Src = url,
Alt = importData.ImageAltText
}); });
} }
}
else return images;
}).ToList();
if (productImages.Count > 0)
{ {
productImages.Add(new ProductImage productImages.Add(new ProductImage
{ {
@@ -75,27 +69,32 @@ namespace PartSource.Automation.Jobs
// Product Tags // Product Tags
List<string> productTags = new List<string> List<string> productTags = new List<string>
{ {
importData.LineCode, items[0].LineCode,
importData.PartNumber, items[0].PartNumber,
}; };
List<ProductVariant> productVariants = new List<ProductVariant>(); List<ProductVariant> productVariants = new List<ProductVariant>();
foreach (ImportData itemVariant in items)
{
productVariants.Add(new ProductVariant productVariants.Add(new ProductVariant
{ {
InventoryPolicy = "Deny", InventoryPolicy = "Deny",
CompareAtPrice = importData.CompareAt, CompareAtPrice = itemVariant.CompareAt,
Price = importData.Price, Price = itemVariant.Price,
Sku = importData.VariantSku, Sku = itemVariant.VariantSku,
Title = importData.VariantTitle, Title = itemVariant.VariantTitle,
Option1 = importData.IsVariant.ToString(), Option1 = itemVariant.VariantTitle,
RequiresShipping = false RequiresShipping = false,
}); });
}
Product requestData = new Product Product requestData = new Product
{ {
BodyHtml = importData.BodyHtml, BodyHtml = items[0].BodyHtml,
Title = importData.Title, Title = items[0].Title,
Vendor = importData.Vendor, Vendor = items[0].Vendor,
Tags = string.Join(",", productTags), Tags = string.Join(",", productTags),
Published = true, Published = true,
//ProductType = importData.FINELINE_NM, //ProductType = importData.FINELINE_NM,
@@ -109,19 +108,24 @@ namespace PartSource.Automation.Jobs
if (requestData.Id > 0) if (requestData.Id > 0)
{ {
importData.ShopifyId = requestData.Id; foreach (ImportData variant in items)
{
variant.ShopifyId = requestData.Id;
}
_partSourceContext.SaveChanges(); _partSourceContext.SaveChanges();
Console.WriteLine($"{importData.VariantSku}"); Console.WriteLine($"{items[0].VariantSku}");
} }
else else
{ {
Console.WriteLine($"SHOPIFY ID WAS 0 - {importData.VariantSku}"); Console.WriteLine($"SHOPIFY ID WAS 0 - {items[0].VariantSku}");
} }
importData = _partSourceContext.ImportData.FirstOrDefault(p => !p.ShopifyId.HasValue); items = _partSourceContext.ImportData
.Where(i => i.Title == _partSourceContext.ImportData.First(d => d.ShopifyId == null).Title)
.ToList();
} }
} }
} }

View File

@@ -1,27 +1,24 @@
using PartSource.Data.Shopify; using PartSource.Automation.Jobs.Interfaces;
using PartSource.Services; using PartSource.Automation.Models;
using PartSource.Automation.Jobs.Interfaces; using PartSource.Data;
using PartSource.Automation.Services; using PartSource.Services.Integrations;
using Ratermania.Shopify.Entities;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Configuration;
using System.Linq; using System.Linq;
using PartSource.Data;
using PartSource.Data.Models;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using PartSource.Services.Integrations;
using PartSource.Automation.Models;
namespace PartSource.Automation.Jobs namespace PartSource.Automation.Jobs
{ {
public class DeleteProducts : IAutomationJob public class DeleteProducts : IAutomationJob
{ {
private readonly ShopifyClient _shopifyClient; private readonly ShopifyClient _shopifyClient;
private readonly PartSourceContext _partSourceContext;
public DeleteProducts(ShopifyClient shopifyClient) public DeleteProducts(ShopifyClient shopifyClient, PartSourceContext partSourceContext)
{ {
_shopifyClient = shopifyClient; _shopifyClient = shopifyClient;
_partSourceContext = partSourceContext;
} }
// If this job fails, oh well. Run it again and again until it works, or use the Shopify UI (LOL) // If this job fails, oh well. Run it again and again until it works, or use the Shopify UI (LOL)
@@ -38,19 +35,33 @@ namespace PartSource.Automation.Jobs
}; };
} }
IEnumerable<Product> products = await _shopifyClient.Products.Get(); IList<long?> shopifyIds = _partSourceContext.ImportData
.Select(i => i.ShopifyId)
.Distinct()
.ToList();
while (products != null) foreach (long? id in shopifyIds)
{ {
foreach (Product product in products) Product product = await _shopifyClient.Products.GetById((long)id);
{
bool result = await _shopifyClient.Products.Delete(product); await _shopifyClient.Products.Delete(product);
Console.WriteLine(id);
} }
products = await _shopifyClient.Products.GetNext(); //IEnumerable<Product> products = await _shopifyClient.Products.Get();
Console.Write('.'); //while (products != null)
} //{
// foreach (Product product in products)
// {
// bool result = await _shopifyClient.Products.Delete(product);
// }
// products = await _shopifyClient.Products.GetNext();
// Console.Write('.');
//}
return new AutomationJobResult return new AutomationJobResult
{ {

View File

@@ -0,0 +1,37 @@
using PartSource.Automation.Jobs.Interfaces;
using PartSource.Automation.Models;
using PartSource.Automation.Services;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace PartSource.Automation.Jobs
{
public class StatusCheck : IAutomationJob
{
private readonly string[] phoneNumbers = { "8593609107", "5134008303" };
private readonly EmailService _emailService;
public StatusCheck(EmailService emailService)
{
_emailService = emailService;
}
public async Task<AutomationJobResult> Run()
{
foreach (string phoneNumber in phoneNumbers)
{
// TODO: One day it won't just be AT&T numbers
string to = $"{phoneNumber}@txt.att.net";
_emailService.Send(to, string.Empty, "Partsource.Automation Running");
}
return new AutomationJobResult
{
IsSuccess = true
};
}
}
}

View File

@@ -6,7 +6,6 @@ using PartSource.Automation.Services;
using PartSource.Data; using PartSource.Data;
using PartSource.Data.Models; using PartSource.Data.Models;
using PartSource.Data.Nexpart; using PartSource.Data.Nexpart;
using PartSource.Data.Shopify;
using PartSource.Services; using PartSource.Services;
using PartSource.Services.Integrations; using PartSource.Services.Integrations;
using System; using System;
@@ -19,6 +18,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using Ratermania.Shopify.Entities;
namespace PartSource.Automation.Jobs namespace PartSource.Automation.Jobs
{ {
@@ -42,22 +42,24 @@ namespace PartSource.Automation.Jobs
{ {
IEnumerable<Product> products = await _shopifyClient.Products.Get(); IEnumerable<Product> products = await _shopifyClient.Products.Get();
int i = 0;
while (products != null && products.Any()) while (products != null && products.Any())
{ {
foreach (Product product in products) foreach (Product product in products)
{ {
try try
{ {
await DeleteFitmentMetafields(product.Id); ImportData importData = _partSourceContext.ImportData.FirstOrDefault(i => i.VariantSku == product.Variants[0].Sku && i.UpdatedAt == null);
ImportData importData = _partSourceContext.ImportData.FirstOrDefault(i => i.VariantSku == product.Variants[0].Sku);
IList<VehicleData> vehicles = _vehicleService.GetVehiclesForPart(importData?.PartNumber, importData?.LineCode); IList<VehicleData> vehicles = _vehicleService.GetVehiclesForPart(importData?.PartNumber, importData?.LineCode);
if (vehicles.Count == 0) if (vehicles == null || vehicles.Count == 0)
{ {
continue; continue;
} }
await DeleteFitmentMetafields(product.Id);
bool isFitment = false; bool isFitment = false;
IList<int> vehicleIdFitment = _vehicleService.GetVehicleIdFitment(vehicles); IList<int> vehicleIdFitment = _vehicleService.GetVehicleIdFitment(vehicles);
@@ -119,23 +121,36 @@ namespace PartSource.Automation.Jobs
}; };
await _shopifyClient.Metafields.Add(isFitmentMetafield); await _shopifyClient.Metafields.Add(isFitmentMetafield);
importData.UpdatedAt = DateTime.Now;
importData.UpdateType = "Fitment";
} }
catch catch (Exception ex)
{ {
Console.WriteLine(product.Id); Console.WriteLine($"{product.Id}: {ex.Message}");
} }
} }
try try
{ {
Console.Write('.'); i++;
Console.WriteLine(i);
await _partSourceContext.SaveChangesAsync();
products = await _shopifyClient.Products.GetNext(); products = await _shopifyClient.Products.GetNext();
} }
catch (Exception ex) catch (Exception ex)
{ {
i++;
Console.WriteLine(i);
Console.WriteLine($"Retrying request: {ex.Message}");
await _partSourceContext.SaveChangesAsync();
products = await _shopifyClient.Products.GetNext(); products = await _shopifyClient.Products.GetNext();
} }
} }

View File

@@ -1,11 +1,12 @@
using Newtonsoft.Json; using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using PartSource.Automation.Jobs.Interfaces; using PartSource.Automation.Jobs.Interfaces;
using PartSource.Automation.Models; using PartSource.Automation.Models;
using PartSource.Data; using PartSource.Data;
using PartSource.Data.Models; using PartSource.Data.Models;
using PartSource.Data.Shopify;
using PartSource.Services; using PartSource.Services;
using PartSource.Services.Integrations; using PartSource.Services.Integrations;
using Ratermania.Shopify.Entities;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
@@ -31,7 +32,12 @@ namespace PartSource.Automation.Jobs
public async Task<AutomationJobResult> Run() public async Task<AutomationJobResult> Run()
{ {
IEnumerable<Product> products = await _shopifyClient.Products.Get(); IDictionary<string, object> parameters = new Dictionary<string, object>
{
{ "limit", 250 }
};
IEnumerable<Product> products = await _shopifyClient.Products.Get(parameters);
while (products != null && products.Any()) while (products != null && products.Any())
{ {
@@ -79,30 +85,37 @@ namespace PartSource.Automation.Jobs
} }
await SavePositionMetafield(product, vehicleIds, currentPosition); await SavePositionMetafield(product, vehicleIds, currentPosition);
importData.UpdatedAt = DateTime.Now;
importData.UpdateType = "Positioning";
} }
catch catch (Exception ex)
{ {
Console.WriteLine(product.Id); Console.WriteLine($"{product.Id}: {ex.Message}");
} }
} }
try try
{ {
Console.Write('.'); Console.Write('.');
await _partSourceContext.SaveChangesAsync();
products = await _shopifyClient.Products.GetNext(); products = await _shopifyClient.Products.GetNext();
} }
catch (Exception ex) catch (Exception ex)
{ {
products = await _shopifyClient.Products.GetNext(); Console.WriteLine($"Retrying: {ex.Message}");
products = await _shopifyClient.Products.GetPrevious();
} }
} }
return new AutomationJobResult return new AutomationJobResult
{ {
Message = "Fitment updated successfully", Message = "Positioning updated successfully",
IsSuccess = true IsSuccess = true
}; };
} }
@@ -119,6 +132,7 @@ namespace PartSource.Automation.Jobs
.Where(f => f.PartNumber == partNumber && whiCodes.Contains(f.LineCode) && !string.IsNullOrEmpty(f.Position)) .Where(f => f.PartNumber == partNumber && whiCodes.Contains(f.LineCode) && !string.IsNullOrEmpty(f.Position))
.OrderBy(f => f.Position) .OrderBy(f => f.Position)
.ToList(); .ToList();
} }
[SuppressMessage("Globalization", "CA1308:Normalize strings to uppercase", Justification = "It's a Shopify metafield key")] [SuppressMessage("Globalization", "CA1308:Normalize strings to uppercase", Justification = "It's a Shopify metafield key")]
@@ -152,6 +166,8 @@ namespace PartSource.Automation.Jobs
OwnerId = product.Id OwnerId = product.Id
}; };
System.Diagnostics.Debug.WriteLine(json);
await _shopifyClient.Metafields.Add(vehicleMetafield); await _shopifyClient.Metafields.Add(vehicleMetafield);
} }

View File

@@ -2,8 +2,8 @@
using PartSource.Automation.Models; using PartSource.Automation.Models;
using PartSource.Data; using PartSource.Data;
using PartSource.Data.Models; using PartSource.Data.Models;
using PartSource.Data.Shopify;
using PartSource.Services.Integrations; using PartSource.Services.Integrations;
using Ratermania.Shopify.Entities;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@@ -53,16 +53,28 @@ namespace PartSource.Automation.Jobs
ProductVariant variant = product.Variants[0]; ProductVariant variant = product.Variants[0];
PartPrice partPrice = _partSourceContext.PartPrices.Where(p => p.SKU == variant.Sku).FirstOrDefault(); 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; continue;
} }
try
{
if (product.Variants[0].Price != partPrice.Your_Price.Value || product.Variants[0].CompareAtPrice != partPrice.Compare_Price.Value) if (product.Variants[0].Price != partPrice.Your_Price.Value || product.Variants[0].CompareAtPrice != partPrice.Compare_Price.Value)
{ {
product.Variants[0].Price = partPrice.Your_Price.Value; product.Variants[0].Price = partPrice.Your_Price.Value;
product.Variants[0].CompareAtPrice = partPrice.Compare_Price.Value; product.Variants[0].CompareAtPrice = partPrice.Compare_Price.Value;
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
};
try try
{ {
await _shopifyClient.Products.Update(product); await _shopifyClient.Products.Update(product);
@@ -72,11 +84,19 @@ namespace PartSource.Automation.Jobs
catch (Exception ex) catch (Exception ex)
{ {
// TODO: Logged failed pricing update here
} }
} }
} }
catch (Exception ex)
{
;
} }
}
}
_partSourceContext.SaveChanges();
try try
{ {
@@ -85,13 +105,7 @@ namespace PartSource.Automation.Jobs
catch (Exception ex) catch (Exception ex)
{ {
// TODO: Logging products = await _shopifyClient.Products.GetPrevious();
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
};
} }
} }

View File

@@ -15,10 +15,10 @@
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.2.0" /> <PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" /> <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.2.0" /> <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.2.0" />
<PackageReference Include="Ratermania.Shopify" Version="1.0.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\shopify\Shopify\Shopify.csproj" />
<ProjectReference Include="..\PartSource.Data\PartSource.Data.csproj" /> <ProjectReference Include="..\PartSource.Data\PartSource.Data.csproj" />
<ProjectReference Include="..\PartSource.Services\PartSource.Services.csproj" /> <ProjectReference Include="..\PartSource.Services\PartSource.Services.csproj" />
</ItemGroup> </ItemGroup>

View File

@@ -1,5 +1,4 @@
using PartSource.Data.Shopify; using PartSource.Services;
using PartSource.Services;
using PartSource.Automation.Factories; using PartSource.Automation.Factories;
using PartSource.Automation.Jobs.Interfaces; using PartSource.Automation.Jobs.Interfaces;
using System; using System;

View File

@@ -2,7 +2,7 @@
"profiles": { "profiles": {
"PartSource.Automation": { "PartSource.Automation": {
"commandName": "Project", "commandName": "Project",
"commandLineArgs": "UpdatePositioning", "commandLineArgs": "AddProducts",
"environmentVariables": { "environmentVariables": {
"PS_AUTOMATION_ENVIRONMENT": "development" "PS_AUTOMATION_ENVIRONMENT": "development"
} }

View File

@@ -20,9 +20,12 @@ namespace PartSource.Automation.Services
public void Send(string subject, string body) public void Send(string subject, string body)
{ {
using (SmtpClient smtpClient = new SmtpClient { Host = _emailConfiguration.SmtpHost }) using SmtpClient smtpClient = new SmtpClient
{ {
MailMessage mailMessage = new MailMessage Host = _emailConfiguration.SmtpHost
};
using MailMessage mailMessage = new MailMessage
{ {
From = new MailAddress(_emailConfiguration.From), From = new MailAddress(_emailConfiguration.From),
Subject = subject, Subject = subject,
@@ -37,6 +40,28 @@ namespace PartSource.Automation.Services
smtpClient.Send(mailMessage); smtpClient.Send(mailMessage);
} }
public void Send(string to, string subject, string body)
{
using SmtpClient smtpClient = new SmtpClient
{
Host = _emailConfiguration.SmtpHost
};
using MailMessage mailMessage = new MailMessage
{
From = new MailAddress(_emailConfiguration.From),
Subject = subject,
Body = body,
IsBodyHtml = false
};
foreach (string address in _emailConfiguration.To.Split(','))
{
mailMessage.To.Add(to);
}
smtpClient.Send(mailMessage);
} }
} }
} }

View File

@@ -1,6 +1,6 @@
{ {
"ConnectionStrings": { "ConnectionStrings": {
//"PartSourceDatabase": "Server=(localdb)\\mssqllocaldb;Database=PartSource;Trusted_Connection=True;" //"PartSourceDatabase": "Server=localhost;Database=ps-whi-stage;Integrated Security=True;"
"PartSourceDatabase": "Server=tcp:ps-whi.database.windows.net,1433;Initial Catalog=ps-whi-stage;Persist Security Info=False;User ID=ps-whi;Password=9-^*N5dw!6:|.5Q;MultipleActiveResultSets=True;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;" "PartSourceDatabase": "Server=tcp:ps-whi.database.windows.net,1433;Initial Catalog=ps-whi-stage;Persist Security Info=False;User ID=ps-whi;Password=9-^*N5dw!6:|.5Q;MultipleActiveResultSets=True;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
}, },
"emailConfiguration": { "emailConfiguration": {

View File

@@ -37,5 +37,9 @@ namespace PartSource.Data.Models
public string LineCode { get; set; } public string LineCode { get; set; }
public string PartNumber { get; set; } public string PartNumber { get; set; }
public DateTime? UpdatedAt { get; set; }
public string UpdateType { get; set; }
} }
} }

View File

@@ -10,6 +10,7 @@ namespace PartSource.Data.Models
public string SKU { get; set; } public string SKU { get; set; }
public Nullable<decimal> Compare_Price { get; set; } public Nullable<decimal> Compare_Price { get; set; }
public Nullable<decimal> Your_Price { get; set; } public Nullable<decimal> Your_Price { get; set; }
public decimal? Core_Price { get; set; }
public string Active { get; set; } public string Active { get; set; }
// public virtual PartData PartData { get; set; } // public virtual PartData PartData { get; set; }

View File

@@ -5,11 +5,20 @@
<Configurations>Debug;Release;Also Debug</Configurations> <Configurations>Debug;Release;Also Debug</Configurations>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<Compile Remove="Shopify\**" />
<EmbeddedResource Remove="Shopify\**" />
<None Remove="Shopify\**" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.2.0" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.2.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.0" /> <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Ratermania.Shopify" Version="1.0.0" /> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\shopify\Shopify\Shopify.csproj" />
</ItemGroup> </ItemGroup>

View File

@@ -1,5 +1,6 @@
using PartSource.Data.Shopify; //using PartSource.Data.Shopify;
using Ratermania.Shopify; using Ratermania.Shopify;
using Ratermania.Shopify.Entities;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;

View File

@@ -0,0 +1,73 @@
//using Newtonsoft.Json;
//using PartSource.Data.Shopify;
//using PartSource.Services.Integrations;
//using Ratermania.Shopify;
//using System;
//using System.Collections.Generic;
//using System.Diagnostics.CodeAnalysis;
//using System.Text;
//using System.Threading.Tasks;
//namespace PartSource.Services
//{
// public class MetafieldService
// {
// private readonly ShopifyClient _shopifyClient;
// public MetafieldService(ShopifyClient shopifyClient)
// {
// _shopifyClient = shopifyClient;
// }
// [SuppressMessage("Globalization", "CA1308:Normalize strings to uppercase", Justification = "Lowercase is expected by Shopify")]
// public async Task SaveMetafield<T>(T shopifyEntity, IList<int> vehicleIds, string @namespace) where T : ShopifyEntity
// {
// if (vehicleIds.Count == 0)
// {
// return;
// }
// string json = JsonConvert.SerializeObject(vehicleIds);
// if (json.Length >= 100000)
// {
// // TODO: Logging
// return;
// }
// string key = @namespace.ToLowerInvariant().Replace(" ", "_");
// if (key.Length > 20)
// {
// key = key.Substring(0, 20);
// }
// Metafield metafield = new Metafield
// {
// Namespace = "position",
// Key = key,
// Value = json,
// ValueType = "json_string",
// OwnerResource = "product",
// OwnerId = shopifyEntity.Id
// };
// await _shopifyClient.Metafields.Add(metafield);
// }
// public async Task DeleteMetafields<T>(long shopifyId) where T : ShopifyEntity
// {
// IDictionary<string, object> parameters = new Dictionary<string, object>
// {
// { "metafield[owner_id]", shopifyId},
// { "metafield[owner_resource]", "product" },
// { "namespace", "position" },
// };
// IEnumerable<Metafield> metafields = await _shopifyClient.Metafields.Get(parameters);
// foreach (Metafield metafield in metafields)
// {
// await _shopifyClient.Metafields.Delete(metafield);
// }
// }
// }
//}

View File

@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework> <TargetFramework>netcoreapp3.1</TargetFramework>
@@ -7,10 +7,10 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Ratermania.Shopify" Version="1.0.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\shopify\Shopify\Shopify.csproj" />
<ProjectReference Include="..\PartSource.Data\PartSource.Data.csproj" /> <ProjectReference Include="..\PartSource.Data\PartSource.Data.csproj" />
</ItemGroup> </ItemGroup>

View File

@@ -101,7 +101,7 @@ namespace PartSource.Services
string tag = $"{string.Join('-', years)} {make.Trim()} {model.Trim()}"; string tag = $"{string.Join('-', years)} {make.Trim()} {model.Trim()}";
Console.WriteLine(tag); System.Diagnostics.Debug.WriteLine(tag);
fitmentTags.Add(tag); fitmentTags.Add(tag);
} }
@@ -116,6 +116,11 @@ namespace PartSource.Services
public IList<VehicleData> GetVehiclesForPart(string partNumber, string lineCode) public IList<VehicleData> GetVehiclesForPart(string partNumber, string lineCode)
{ {
if (string.IsNullOrEmpty(partNumber) || string.IsNullOrEmpty(lineCode))
{
return null;
}
partNumber = Regex.Replace(partNumber, "[^a-zA-Z0-9]", string.Empty); partNumber = Regex.Replace(partNumber, "[^a-zA-Z0-9]", string.Empty);
IQueryable<string> whiCodes = _partSourceContext.DcfMappings IQueryable<string> whiCodes = _partSourceContext.DcfMappings

View File

@@ -11,6 +11,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PartSource.Services", "Part
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PartSource.Automation", "PartSource.Automation\PartSource.Automation.csproj", "{C85D675B-A76C-4F9C-9C57-1E063211C946}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PartSource.Automation", "PartSource.Automation\PartSource.Automation.csproj", "{C85D675B-A76C-4F9C-9C57-1E063211C946}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Shopify", "..\shopify\Shopify\Shopify.csproj", "{E3917C1F-2BBD-482F-90DE-DD693F28C105}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Also Debug|Any CPU = Also Debug|Any CPU Also Debug|Any CPU = Also Debug|Any CPU
@@ -42,6 +44,12 @@ Global
{C85D675B-A76C-4F9C-9C57-1E063211C946}.Debug|Any CPU.Build.0 = Debug|Any CPU {C85D675B-A76C-4F9C-9C57-1E063211C946}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C85D675B-A76C-4F9C-9C57-1E063211C946}.Release|Any CPU.ActiveCfg = Release|Any CPU {C85D675B-A76C-4F9C-9C57-1E063211C946}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C85D675B-A76C-4F9C-9C57-1E063211C946}.Release|Any CPU.Build.0 = Release|Any CPU {C85D675B-A76C-4F9C-9C57-1E063211C946}.Release|Any CPU.Build.0 = Release|Any CPU
{E3917C1F-2BBD-482F-90DE-DD693F28C105}.Also Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E3917C1F-2BBD-482F-90DE-DD693F28C105}.Also Debug|Any CPU.Build.0 = Debug|Any CPU
{E3917C1F-2BBD-482F-90DE-DD693F28C105}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E3917C1F-2BBD-482F-90DE-DD693F28C105}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E3917C1F-2BBD-482F-90DE-DD693F28C105}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E3917C1F-2BBD-482F-90DE-DD693F28C105}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE