Stuff and things
This commit is contained in:
38
PartSource.Api/Controllers/WebhooksController.cs
Normal file
38
PartSource.Api/Controllers/WebhooksController.cs
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata.Internal;
|
||||||
|
using PartSource.Data.Dtos;
|
||||||
|
using PartSource.Data.Models;
|
||||||
|
using PartSource.Services;
|
||||||
|
using Ratermania.Shopify.Resources;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace PartSource.Api.Controllers
|
||||||
|
{
|
||||||
|
/// <remarks>
|
||||||
|
/// This endpoint handles Shopify webhooks
|
||||||
|
/// </remarks>
|
||||||
|
[Route("v2/[controller]")]
|
||||||
|
[ApiController]
|
||||||
|
[ApiExplorerSettings(GroupName = "v2")]
|
||||||
|
public class WebhooksController : BaseApiController
|
||||||
|
{
|
||||||
|
private readonly ShopifyChangelogService _shopifyChangelogService;
|
||||||
|
|
||||||
|
public WebhooksController(ShopifyChangelogService shopifyChangelogService)
|
||||||
|
{
|
||||||
|
_shopifyChangelogService = shopifyChangelogService;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
[Route("products/update")]
|
||||||
|
public async Task<ActionResult> OnProductUpdate([FromBody]Product product)
|
||||||
|
{
|
||||||
|
await _shopifyChangelogService.AddEntry(product);
|
||||||
|
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -28,8 +28,11 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.0.1" />
|
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.0.1" />
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.15" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
|
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
|
||||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.3" />
|
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.3" />
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||||
|
<PackageReference Include="Ratermania.Shopify" Version="1.3.1" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.5.1" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.5.1" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore.ReDoc" Version="5.5.1" />
|
<PackageReference Include="Swashbuckle.AspNetCore.ReDoc" Version="5.5.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -106,5 +106,10 @@
|
|||||||
<response code="200"><strong>OK:</strong> The engine with the provided EngineConfigId.</response>
|
<response code="200"><strong>OK:</strong> The engine with the provided EngineConfigId.</response>
|
||||||
<response code="404"><strong>Not Found:</strong> No engine was found matching the provided EngineConfigId.</response>
|
<response code="404"><strong>Not Found:</strong> No engine was found matching the provided EngineConfigId.</response>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="T:PartSource.Api.Controllers.WebhooksController">
|
||||||
|
<remarks>
|
||||||
|
This endpoint handles Shopify webhooks
|
||||||
|
</remarks>
|
||||||
|
</member>
|
||||||
</members>
|
</members>
|
||||||
</doc>
|
</doc>
|
||||||
|
|||||||
@@ -6,9 +6,10 @@ using Microsoft.EntityFrameworkCore;
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.OpenApi.Models;
|
using Microsoft.OpenApi.Models;
|
||||||
using PartSource.Api.Formatters;
|
using Newtonsoft.Json;
|
||||||
using PartSource.Data;
|
using Newtonsoft.Json.Serialization;
|
||||||
using PartSource.Data.AutoMapper;
|
using PartSource.Data.AutoMapper;
|
||||||
|
using PartSource.Data.Contexts;
|
||||||
using PartSource.Services;
|
using PartSource.Services;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
@@ -30,6 +31,14 @@ namespace PartSource.Api
|
|||||||
{
|
{
|
||||||
options.OutputFormatters.RemoveType(typeof(StringOutputFormatter));
|
options.OutputFormatters.RemoveType(typeof(StringOutputFormatter));
|
||||||
options.EnableEndpointRouting = false;
|
options.EnableEndpointRouting = false;
|
||||||
|
})
|
||||||
|
.AddNewtonsoftJson(options =>
|
||||||
|
{
|
||||||
|
options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
|
||||||
|
options.SerializerSettings.ContractResolver = new DefaultContractResolver()
|
||||||
|
{
|
||||||
|
NamingStrategy = new SnakeCaseNamingStrategy()
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
services.AddSwaggerGen(c =>
|
services.AddSwaggerGen(c =>
|
||||||
@@ -46,6 +55,7 @@ namespace PartSource.Api
|
|||||||
services.AddTransient<NexpartService>();
|
services.AddTransient<NexpartService>();
|
||||||
services.AddTransient<SecurityService>();
|
services.AddTransient<SecurityService>();
|
||||||
services.AddTransient<VehicleService>();
|
services.AddTransient<VehicleService>();
|
||||||
|
services.AddTransient<ShopifyChangelogService>();
|
||||||
|
|
||||||
services.AddCors(o => o.AddPolicy("Default", builder =>
|
services.AddCors(o => o.AddPolicy("Default", builder =>
|
||||||
{
|
{
|
||||||
@@ -57,6 +67,9 @@ namespace PartSource.Api
|
|||||||
services.AddDbContext<PartSourceContext>(options =>
|
services.AddDbContext<PartSourceContext>(options =>
|
||||||
options.UseSqlServer(Configuration.GetConnectionString("PartSourceDatabase"))
|
options.UseSqlServer(Configuration.GetConnectionString("PartSourceDatabase"))
|
||||||
);
|
);
|
||||||
|
services.AddDbContext<FitmentContext>(options =>
|
||||||
|
options.UseSqlServer(Configuration.GetConnectionString("FitmentDatabase"))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
{
|
{
|
||||||
"ConnectionStrings": {
|
"ConnectionStrings": {
|
||||||
"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=False;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=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;",
|
||||||
},
|
"FitmentDatabase": "Data Source=localhost;Initial Catalog=WhiFitment;Integrated Security=true"
|
||||||
|
},
|
||||||
"Logging": {
|
"Logging": {
|
||||||
"LogLevel": {
|
"LogLevel": {
|
||||||
"Default": "Warning"
|
"Default": "Warning"
|
||||||
|
|||||||
@@ -42,94 +42,36 @@ namespace PartSource.Automation.Jobs
|
|||||||
string directory = Path.Combine(_ftpConfiguration.Destination, _seoDataType.ToString().ToLowerInvariant());
|
string directory = Path.Combine(_ftpConfiguration.Destination, _seoDataType.ToString().ToLowerInvariant());
|
||||||
DirectoryInfo directoryInfo = new DirectoryInfo(directory);
|
DirectoryInfo directoryInfo = new DirectoryInfo(directory);
|
||||||
|
|
||||||
ConcurrentQueue<FileInfo> files = new ConcurrentQueue<FileInfo>(directoryInfo.GetFiles().Where(f => f.Name.EndsWith("csv.gz")).OrderBy(f => f.Length));
|
IEnumerable<IGrouping<string, FileInfo>> fileGroups = directoryInfo.GetFiles().Where(f => f.Name.EndsWith("csv.gz")).GroupBy(x => x.Name.Split('_').Last());
|
||||||
|
|
||||||
while (files.Count > 0)
|
foreach (IGrouping<string, FileInfo> fileGroup in fileGroups)
|
||||||
{
|
{
|
||||||
Parallel.For(0, 4, index =>
|
foreach (FileInfo fileInfo in fileGroup)
|
||||||
{
|
{
|
||||||
if (!files.TryDequeue(out FileInfo fileInfo))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
string filename = Decompress(fileInfo);
|
|
||||||
|
|
||||||
using DataTable dataTable = new DataTable();
|
|
||||||
dataTable.Columns.Add("LineCode", typeof(string));
|
|
||||||
dataTable.Columns.Add("PartNumber", typeof(string));
|
|
||||||
dataTable.Columns.Add("BaseVehicleId", typeof(int));
|
|
||||||
dataTable.Columns.Add("EngineConfigId", typeof(int));
|
|
||||||
dataTable.Columns.Add("Position", typeof(string));
|
|
||||||
dataTable.Columns.Add("NoteText", typeof(string));
|
|
||||||
|
|
||||||
using StreamReader reader = new StreamReader(filename);
|
|
||||||
string line = reader.ReadLine(); // Burn the header row
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
int skippedLines = 0;
|
string filename = Decompress(fileInfo);
|
||||||
while (reader.Peek() > 0)
|
DataTable dataTable = GetDataTable(filename);
|
||||||
{
|
|
||||||
line = reader.ReadLine();
|
|
||||||
|
|
||||||
string[] columns = line.Split("\",\"");
|
|
||||||
|
|
||||||
if (columns.Length != 8)
|
|
||||||
{
|
|
||||||
skippedLines++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < columns.Length; i++)
|
|
||||||
{
|
|
||||||
columns[i] = columns[i].Replace("\"", string.Empty);
|
|
||||||
}
|
|
||||||
|
|
||||||
string lineCode = Regex.Replace(columns[0], "[^a-zA-Z0-9]", string.Empty).Trim();
|
|
||||||
string partNumber = Regex.Replace(columns[1], "[^a-zA-Z0-9]", string.Empty).Trim();
|
|
||||||
string position = columns[7].Trim();
|
|
||||||
string noteText = columns[4].Trim();
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(lineCode)
|
|
||||||
&& !string.IsNullOrEmpty(partNumber)
|
|
||||||
&& int.TryParse(columns[5], out int baseVehicleId)
|
|
||||||
&& int.TryParse(columns[6], out int engineConfigId))
|
|
||||||
{
|
|
||||||
dataTable.Rows.Add(new object[] { lineCode, partNumber, baseVehicleId, engineConfigId, position, noteText });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
string tableName = fileInfo.Name.Substring(0, fileInfo.Name.IndexOf('.'));
|
string tableName = fileInfo.Name.Substring(0, fileInfo.Name.IndexOf('.'));
|
||||||
|
|
||||||
_whiSeoService.BulkCopy(_seoDataType, dataTable, tableName);
|
_whiSeoService.BulkCopy(_seoDataType, dataTable, tableName);
|
||||||
|
|
||||||
if (skippedLines == 0)
|
_logger.LogInformation($"Copied {fileInfo.Name} to the database.");
|
||||||
{
|
|
||||||
_logger.LogInformation($"Copied {filename} to the database.");
|
|
||||||
}
|
|
||||||
|
|
||||||
else
|
File.Delete(filename);
|
||||||
{
|
|
||||||
_logger.LogWarning($"Copied {filename} to the database with warnings. {skippedLines} lines contained errors and could not be processed.");
|
|
||||||
}
|
|
||||||
|
|
||||||
File.Delete(fileInfo.FullName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError($"Failed to copy {filename} to the database.", ex);
|
_logger.LogError($"Failed to write {fileInfo.Name} to the database - {ex.Message}", ex);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try
|
string fitmentTable = fileGroup.Key.Substring(0, fileGroup.Key.IndexOf('.'));
|
||||||
{
|
_whiSeoService.CreateFitmentTable(fitmentTable);
|
||||||
reader.Close();
|
|
||||||
File.Delete(filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
catch (Exception ex) { }
|
_logger.LogInformation($"Created fitment table for part group {fitmentTable}.");
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_whiSeoService.CreateFitmentView();
|
_whiSeoService.CreateFitmentView();
|
||||||
@@ -146,5 +88,45 @@ namespace PartSource.Automation.Jobs
|
|||||||
|
|
||||||
return decompressedFile;
|
return decompressedFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private DataTable GetDataTable(string filename)
|
||||||
|
{
|
||||||
|
using DataTable dataTable = new DataTable();
|
||||||
|
dataTable.Columns.Add("LineCode", typeof(string));
|
||||||
|
dataTable.Columns.Add("PartNumber", typeof(string));
|
||||||
|
dataTable.Columns.Add("BaseVehicleId", typeof(int));
|
||||||
|
dataTable.Columns.Add("EngineConfigId", typeof(int));
|
||||||
|
//dataTable.Columns.Add("Position", typeof(string));
|
||||||
|
//dataTable.Columns.Add("NoteText", typeof(string));
|
||||||
|
|
||||||
|
using StreamReader reader = new StreamReader(filename);
|
||||||
|
string line = reader.ReadLine(); // Burn the header row
|
||||||
|
|
||||||
|
while (reader.Peek() > 0)
|
||||||
|
{
|
||||||
|
line = reader.ReadLine();
|
||||||
|
|
||||||
|
string[] columns = line.Split("\",\"");
|
||||||
|
for (int i = 0; i < columns.Length; i++)
|
||||||
|
{
|
||||||
|
columns[i] = columns[i].Replace("\"", string.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
string lineCode = Regex.Replace(columns[0], "[^a-zA-Z0-9]", string.Empty).Trim();
|
||||||
|
string partNumber = Regex.Replace(columns[1], "[^a-zA-Z0-9]", string.Empty).Trim();
|
||||||
|
string position = columns[7].Trim();
|
||||||
|
string noteText = columns[4].Trim();
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(lineCode)
|
||||||
|
&& !string.IsNullOrEmpty(partNumber)
|
||||||
|
&& int.TryParse(columns[5], out int baseVehicleId)
|
||||||
|
&& int.TryParse(columns[6], out int engineConfigId))
|
||||||
|
{
|
||||||
|
dataTable.Rows.Add(new object[] { lineCode, partNumber, baseVehicleId, engineConfigId }); //, position, noteText });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return dataTable;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,17 +1,14 @@
|
|||||||
using Ratermania.Automation.Interfaces;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using PartSource.Automation.Models;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using PartSource.Data;
|
using PartSource.Data.Contexts;
|
||||||
using PartSource.Services;
|
using PartSource.Data.Models;
|
||||||
|
using Ratermania.Automation.Interfaces;
|
||||||
using Ratermania.Shopify;
|
using Ratermania.Shopify;
|
||||||
using Ratermania.Shopify.Resources;
|
using Ratermania.Shopify.Resources;
|
||||||
using PartSource.Data.Models;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace PartSource.Automation.Jobs
|
namespace PartSource.Automation.Jobs
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ namespace PartSource.Automation.Jobs
|
|||||||
|
|
||||||
bool isFitment = false;
|
bool isFitment = false;
|
||||||
|
|
||||||
IList<Vehicle> vehicles = _vehicleService.GetVehiclesForPart(importData.PartNumber, importData.LineCode, 255);
|
IList<Vehicle> vehicles = _vehicleService.GetVehiclesForPart(importData.PartNumber, importData.LineCode);
|
||||||
|
|
||||||
//if (vehicles.Count > 250)
|
//if (vehicles.Count > 250)
|
||||||
//{
|
//{
|
||||||
@@ -166,9 +166,9 @@ namespace PartSource.Automation.Jobs
|
|||||||
|
|
||||||
tags.AddRange(ymmFitment);
|
tags.AddRange(ymmFitment);
|
||||||
|
|
||||||
if (tags.Count > 250)
|
if (tags.Count > 249)
|
||||||
{
|
{
|
||||||
tags = tags.Take(250).ToList();
|
tags = tags.Take(249).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
string zzzIsFitment = isFitment
|
string zzzIsFitment = isFitment
|
||||||
@@ -188,7 +188,7 @@ namespace PartSource.Automation.Jobs
|
|||||||
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError($"Failed to updated fitment data for SKU {importData?.VariantSku}", ex);
|
_logger.LogError($"Failed to updated fitment data for SKU {importData?.VariantSku} - {ex.Message}", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Logging.Abstractions;
|
using Microsoft.Extensions.Logging;
|
||||||
using Ratermania.Automation.Interfaces;
|
using PartSource.Automation.Services;
|
||||||
using PartSource.Automation.Models;
|
using PartSource.Data.Contexts;
|
||||||
using PartSource.Data;
|
|
||||||
using PartSource.Data.Models;
|
using PartSource.Data.Models;
|
||||||
|
using Ratermania.Automation.Interfaces;
|
||||||
using Ratermania.Shopify;
|
using Ratermania.Shopify;
|
||||||
using Ratermania.Shopify.Resources;
|
using Ratermania.Shopify.Resources;
|
||||||
using Ratermania.Shopify.Resources.Enums;
|
using Ratermania.Shopify.Resources.Enums;
|
||||||
@@ -11,8 +11,6 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using PartSource.Automation.Services;
|
|
||||||
|
|
||||||
namespace PartSource.Automation.Jobs
|
namespace PartSource.Automation.Jobs
|
||||||
{
|
{
|
||||||
@@ -56,35 +54,45 @@ namespace PartSource.Automation.Jobs
|
|||||||
{
|
{
|
||||||
if (product.Variants.Length > 0)
|
if (product.Variants.Length > 0)
|
||||||
{
|
{
|
||||||
Variant variant = product.Variants[0];
|
bool hasUpdate = false;
|
||||||
PartPrice partPrice = prices.Where(p => p.SKU == variant.Sku).FirstOrDefault();
|
|
||||||
|
|
||||||
if (partPrice == null || !partPrice.Your_Price.HasValue || !partPrice.Compare_Price.HasValue)
|
for (int i = 0; i < product.Variants.Length; i++)
|
||||||
{
|
{
|
||||||
continue;
|
Variant variant = product.Variants[i];
|
||||||
|
PartPrice partPrice = prices.Where(p => p.SKU == variant.Sku).FirstOrDefault();
|
||||||
|
|
||||||
|
if (partPrice == null || !partPrice.Your_Price.HasValue || !partPrice.Compare_Price.HasValue)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (product.Variants[i].Price.ToString("G29") != partPrice.Your_Price.Value.ToString("G29") || product.Variants[i].CompareAtPrice.ToString("G29") != partPrice.Compare_Price.Value.ToString("G29"))
|
||||||
|
{
|
||||||
|
product.Variants[i].Price = partPrice.Your_Price.Value;
|
||||||
|
product.Variants[i].CompareAtPrice = partPrice.Compare_Price.Value;
|
||||||
|
|
||||||
|
product.PublishedAt = partPrice.Active.Trim().ToUpperInvariant() == "Y" ? (DateTime?)DateTime.Now : null;
|
||||||
|
product.PublishedScope = PublishedScope.Global;
|
||||||
|
|
||||||
|
//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
|
||||||
|
//};
|
||||||
|
|
||||||
|
hasUpdate = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (product.Variants[0].Price != partPrice.Your_Price.Value || product.Variants[0].CompareAtPrice != partPrice.Compare_Price.Value)
|
if (hasUpdate)
|
||||||
{
|
{
|
||||||
product.Variants[0].Price = partPrice.Your_Price.Value;
|
|
||||||
product.Variants[0].CompareAtPrice = partPrice.Compare_Price.Value;
|
|
||||||
|
|
||||||
product.PublishedAt = partPrice.Active.Trim().ToUpperInvariant() == "Y" ? (DateTime?)DateTime.Now : null;
|
|
||||||
product.PublishedScope = PublishedScope.Global;
|
|
||||||
|
|
||||||
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.Metafields.Add(metafield);
|
//await _shopifyClient.Metafields.Add(metafield);
|
||||||
await _shopifyClient.Products.Update(product);
|
await _shopifyClient.Products.Update(product);
|
||||||
|
|
||||||
updateCount++;
|
updateCount++;
|
||||||
@@ -92,7 +100,7 @@ namespace PartSource.Automation.Jobs
|
|||||||
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogWarning(ex, $"Failed to update pricing for SKU {variant.Sku}");
|
_logger.LogWarning(ex, $"Failed to update pricing for product ID {product.Id}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -100,7 +108,7 @@ namespace PartSource.Automation.Jobs
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
products = await _shopifyClient.Products.GetNext();
|
products = await _shopifyClient.Products.GetNext();
|
||||||
|
|
||||||
_logger.LogInformation($"Total updated: {updateCount}");
|
_logger.LogInformation($"Total updated: {updateCount}");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,23 +70,23 @@ namespace PartSource.Automation
|
|||||||
{
|
{
|
||||||
options.HasBaseInterval(new TimeSpan(0, 15, 0))
|
options.HasBaseInterval(new TimeSpan(0, 15, 0))
|
||||||
.HasMaxFailures(5)
|
.HasMaxFailures(5)
|
||||||
//
|
//
|
||||||
//.HasJob<SyncronizeProducts>(options => options.HasInterval(new TimeSpan(24, 0, 0))
|
//.HasJob<SyncronizeProducts>(options => options.HasInterval(new TimeSpan(24, 0, 0))
|
||||||
// .HasJob<ProcessWhiFitment>(options => options.HasInterval(new TimeSpan(24, 0, 0))
|
// .HasJob<ProcessWhiFitment>(options => options.HasInterval(new TimeSpan(24, 0, 0))
|
||||||
//.HasJob<UpdateFitment>(options => options.HasInterval(new TimeSpan(24, 0, 0))
|
//.HasJob<UpdateFitment>(options => options.HasInterval(new TimeSpan(24, 0, 0))
|
||||||
// .HasDependency<ProcessWhiFitment>()
|
// .HasDependency<ProcessWhiFitment>()
|
||||||
// .StartsAt(DateTime.Today.AddHours(8))
|
// .StartsAt(DateTime.Today.AddHours(8))
|
||||||
//)
|
//)
|
||||||
.HasJob<StatusCheck>(options => options.HasInterval(new TimeSpan(24, 0, 0))
|
//.HasJob<StatusCheck>(options => options.HasInterval(new TimeSpan(24, 0, 0))
|
||||||
.StartsAt(DateTime.Parse("2021-04-01 08:00:00"))
|
// .StartsAt(DateTime.Parse("2021-04-01 08:00:00"))
|
||||||
)
|
//)
|
||||||
.HasJob<ExecuteSsisPackages>(options => options.HasInterval(new TimeSpan(24, 0, 0))
|
.HasJob<ExecuteSsisPackages>(options => options.HasInterval(new TimeSpan(24, 0, 0))
|
||||||
.StartsAt(DateTime.Today.AddHours(26))
|
.StartsAt(DateTime.Today.AddHours(26))
|
||||||
)
|
)
|
||||||
.HasJob<UpdatePricing>(options => options.HasInterval(new TimeSpan(24, 0, 0))
|
.HasJob<UpdatePricing>(options => options.HasInterval(new TimeSpan(24, 0, 0))
|
||||||
.HasDependency<ExecuteSsisPackages>()
|
.HasDependency<ExecuteSsisPackages>()
|
||||||
.StartsAt(DateTime.Today.AddHours(27)
|
.StartsAt(DateTime.Today.AddHours(27)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
//.AddApiServer();
|
//.AddApiServer();
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
#pragma warning disable CA2100 // Review SQL queries for security vulnerabilities
|
||||||
|
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using PartSource.Automation.Models.Configuration;
|
using PartSource.Automation.Models.Configuration;
|
||||||
using PartSource.Automation.Models.Enums;
|
using PartSource.Automation.Models.Enums;
|
||||||
@@ -65,20 +67,28 @@ namespace PartSource.Automation.Services
|
|||||||
using SqlConnection connection = new SqlConnection(_connectionString);
|
using SqlConnection connection = new SqlConnection(_connectionString);
|
||||||
connection.Open();
|
connection.Open();
|
||||||
|
|
||||||
#pragma warning disable CA2100 // Review SQL queries for security vulnerabilities
|
|
||||||
using SqlCommand command = new SqlCommand($"EXEC AddFitmentTable @tableName = '{tableName}'", connection);
|
using SqlCommand command = new SqlCommand($"EXEC CreateFitmentTempTable @tableName = '{tableName}'", connection);
|
||||||
command.ExecuteNonQuery();
|
command.ExecuteNonQuery();
|
||||||
#pragma warning restore CA2100 // Review SQL queries for security vulnerabilities
|
|
||||||
|
|
||||||
using SqlBulkCopy bulk = new SqlBulkCopy(connection)
|
using SqlBulkCopy bulk = new SqlBulkCopy(connection)
|
||||||
{
|
{
|
||||||
DestinationTableName = $"{seoDataType}.{tableName}",
|
DestinationTableName = $"FitmentTemp.{tableName}",
|
||||||
BulkCopyTimeout = 14400
|
BulkCopyTimeout = 14400
|
||||||
};
|
};
|
||||||
|
|
||||||
bulk.WriteToServer(dataTable);
|
bulk.WriteToServer(dataTable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void CreateFitmentTable(string tableName)
|
||||||
|
{
|
||||||
|
using SqlConnection connection = new SqlConnection(_connectionString);
|
||||||
|
connection.Open();
|
||||||
|
|
||||||
|
using SqlCommand command = new SqlCommand($"exec CreateFitmentTable @tableName = '{tableName}'", connection);
|
||||||
|
command.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
|
||||||
public void CreateFitmentView()
|
public void CreateFitmentView()
|
||||||
{
|
{
|
||||||
using SqlConnection connection = new SqlConnection(_connectionString);
|
using SqlConnection connection = new SqlConnection(_connectionString);
|
||||||
@@ -89,3 +99,4 @@ namespace PartSource.Automation.Services
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#pragma warning restore CA2100 // Review SQL queries for security vulnerabilities
|
||||||
@@ -2,9 +2,10 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.Metadata;
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
using Microsoft.EntityFrameworkCore.Metadata.Internal;
|
using Microsoft.EntityFrameworkCore.Metadata.Internal;
|
||||||
|
using PartSource.Data.Converters;
|
||||||
using PartSource.Data.Models;
|
using PartSource.Data.Models;
|
||||||
|
|
||||||
namespace PartSource.Data
|
namespace PartSource.Data.Contexts
|
||||||
{
|
{
|
||||||
public class PartSourceContext : DbContext
|
public class PartSourceContext : DbContext
|
||||||
{
|
{
|
||||||
@@ -29,6 +30,8 @@ namespace PartSource.Data
|
|||||||
|
|
||||||
public DbSet<Part> Parts { get; set; }
|
public DbSet<Part> Parts { get; set; }
|
||||||
|
|
||||||
|
public DbSet<ShopifyChangelog> ShopifyChangelogs { get; set; }
|
||||||
|
|
||||||
public DbSet<Vehicle> Vehicles { get; set; }
|
public DbSet<Vehicle> Vehicles { get; set; }
|
||||||
|
|
||||||
public DbSet<PartsAvailability> PartAvailabilities { get; set; }
|
public DbSet<PartsAvailability> PartAvailabilities { get; set; }
|
||||||
@@ -55,11 +58,18 @@ namespace PartSource.Data
|
|||||||
|
|
||||||
modelBuilder.Entity<PartsAvailability>().HasKey(p => new { p.Store, p.SKU });
|
modelBuilder.Entity<PartsAvailability>().HasKey(p => new { p.Store, p.SKU });
|
||||||
|
|
||||||
|
modelBuilder.Entity<ShopifyChangelog>()
|
||||||
|
.Property(s => s.ResourceType)
|
||||||
|
.HasConversion(new TypeToStringConverter());
|
||||||
|
|
||||||
|
modelBuilder.Entity<ShopifyChangelog>()
|
||||||
|
.Property(s => s.Data)
|
||||||
|
.HasConversion(new ObjectToJsonConverter());
|
||||||
|
|
||||||
foreach (IMutableEntityType entityType in modelBuilder.Model.GetEntityTypes())
|
foreach (IMutableEntityType entityType in modelBuilder.Model.GetEntityTypes())
|
||||||
{
|
{
|
||||||
entityType.Relational().TableName = entityType.ClrType.Name;
|
entityType.Relational().TableName = entityType.ClrType.Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
27
PartSource.Data/Converters/ObjectToJsonConverter.cs
Normal file
27
PartSource.Data/Converters/ObjectToJsonConverter.cs
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Serialization;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace PartSource.Data.Converters
|
||||||
|
{
|
||||||
|
public class ObjectToJsonConverter : ValueConverter<object, string>
|
||||||
|
{
|
||||||
|
private static readonly JsonSerializerSettings _serializerSettings = new JsonSerializerSettings()
|
||||||
|
{
|
||||||
|
NullValueHandling = NullValueHandling.Ignore,
|
||||||
|
ContractResolver = new DefaultContractResolver()
|
||||||
|
{
|
||||||
|
NamingStrategy = new SnakeCaseNamingStrategy()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public ObjectToJsonConverter() : base(ObjectToJson, JsonToObject) { }
|
||||||
|
|
||||||
|
public static Expression<Func<string, object>> JsonToObject = value => JsonConvert.DeserializeObject(value, _serializerSettings);
|
||||||
|
public static Expression<Func<object, string>> ObjectToJson = value => JsonConvert.SerializeObject(value, _serializerSettings);
|
||||||
|
}
|
||||||
|
}
|
||||||
16
PartSource.Data/Converters/TypeToStringConverter.cs
Normal file
16
PartSource.Data/Converters/TypeToStringConverter.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace PartSource.Data.Converters
|
||||||
|
{
|
||||||
|
public class TypeToStringConverter : ValueConverter<Type, string>
|
||||||
|
{
|
||||||
|
public TypeToStringConverter() : base(TypeToString, StringToType) { }
|
||||||
|
|
||||||
|
public static Expression<Func<string, Type>> StringToType = value => Type.GetType(value);
|
||||||
|
public static Expression<Func<Type, string>> TypeToString = value => value.AssemblyQualifiedName;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,15 +1,14 @@
|
|||||||
// <auto-generated />
|
// <auto-generated />
|
||||||
using System;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
using Microsoft.EntityFrameworkCore.Metadata;
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
using PartSource.Data.Contexts;
|
||||||
using PartSource.Data;
|
using System;
|
||||||
|
|
||||||
namespace PartSource.Data.Migrations
|
namespace PartSource.Data.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(PartSourceContext))]
|
[DbContext(typeof(PartSourceContext))]
|
||||||
[Migration("20190811020941_ImportDateDcfMapping")]
|
[Migration("20190811020941_ImportDateDcfMapping")]
|
||||||
partial class ImportDateDcfMapping
|
partial class ImportDateDcfMapping
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using Microsoft.EntityFrameworkCore.Infrastructure;
|
|||||||
using Microsoft.EntityFrameworkCore.Metadata;
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
using PartSource.Data;
|
using PartSource.Data;
|
||||||
|
using PartSource.Data.Contexts;
|
||||||
|
|
||||||
namespace PartSource.Data.Migrations
|
namespace PartSource.Data.Migrations
|
||||||
{
|
{
|
||||||
|
|||||||
19
PartSource.Data/Models/ShopifyChangelog.cs
Normal file
19
PartSource.Data/Models/ShopifyChangelog.cs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace PartSource.Data.Models
|
||||||
|
{
|
||||||
|
public class ShopifyChangelog
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public Type ResourceType { get; set; }
|
||||||
|
|
||||||
|
public long ShopifyId { get; set; }
|
||||||
|
|
||||||
|
public DateTime Timestamp { get; set; }
|
||||||
|
|
||||||
|
public object Data { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,73 +0,0 @@
|
|||||||
//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);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using PartSource.Data;
|
using PartSource.Data;
|
||||||
|
using PartSource.Data.Contexts;
|
||||||
using PartSource.Data.Dtos;
|
using PartSource.Data.Dtos;
|
||||||
using PartSource.Data.Models;
|
using PartSource.Data.Models;
|
||||||
using System;
|
using System;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="AutoMapper" Version="10.0.0" />
|
<PackageReference Include="AutoMapper" Version="10.0.0" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||||
|
<PackageReference Include="Ratermania.Shopify" Version="1.3.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using PartSource.Data;
|
using PartSource.Data;
|
||||||
|
using PartSource.Data.Contexts;
|
||||||
using PartSource.Data.Models;
|
using PartSource.Data.Models;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
|||||||
34
PartSource.Services/ShopifyChangelogService.cs
Normal file
34
PartSource.Services/ShopifyChangelogService.cs
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
using PartSource.Data.Contexts;
|
||||||
|
using PartSource.Data.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Ratermania.Shopify.Resources;
|
||||||
|
|
||||||
|
namespace PartSource.Services
|
||||||
|
{
|
||||||
|
public class ShopifyChangelogService
|
||||||
|
{
|
||||||
|
private readonly PartSourceContext _partsourceContext;
|
||||||
|
|
||||||
|
public ShopifyChangelogService(PartSourceContext partsourceContext)
|
||||||
|
{
|
||||||
|
_partsourceContext = partsourceContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task AddEntry<T>(T data) where T : BaseShopifyResource
|
||||||
|
{
|
||||||
|
ShopifyChangelog shopifyChangelog = new ShopifyChangelog
|
||||||
|
{
|
||||||
|
ResourceType = typeof(T),
|
||||||
|
ShopifyId = data.Id,
|
||||||
|
Data = data,
|
||||||
|
Timestamp = DateTime.Now
|
||||||
|
};
|
||||||
|
|
||||||
|
await _partsourceContext.AddAsync(shopifyChangelog);
|
||||||
|
await _partsourceContext.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user