Added core pricing metafield and status check job
This commit is contained in:
@@ -1,13 +1,10 @@
|
||||
using PartSource.Automation.Jobs.Interfaces;
|
||||
using PartSource.Automation.Models;
|
||||
using PartSource.Automation.Services;
|
||||
using PartSource.Data;
|
||||
using PartSource.Data.Models;
|
||||
using PartSource.Data.Shopify;
|
||||
using PartSource.Services;
|
||||
using PartSource.Services.Integrations;
|
||||
using Ratermania.Shopify.Entities;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
@@ -38,33 +35,30 @@ namespace PartSource.Automation.Jobs
|
||||
|
||||
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
|
||||
List<ProductImage> productImages = new List<ProductImage>();
|
||||
string[] imageUrls = importData.ImageSrc?.Split(',');
|
||||
IList<ProductImage> productImages = items.SelectMany(v => {
|
||||
IList<ProductImage> images = new List<ProductImage>();
|
||||
|
||||
if (imageUrls?.Length > 0)
|
||||
{
|
||||
foreach (string url in imageUrls)
|
||||
foreach (string src in v.ImageSrc?.Split(','))
|
||||
{
|
||||
productImages.Add(new ProductImage
|
||||
images.Add(new ProductImage
|
||||
{
|
||||
Src = url,
|
||||
Alt = importData.ImageAltText
|
||||
Src = src,
|
||||
Alt = v.ImageAltText
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
return images;
|
||||
}).ToList();
|
||||
|
||||
if (productImages.Count > 0)
|
||||
{
|
||||
productImages.Add(new ProductImage
|
||||
{
|
||||
Src = "https://cdn.shopify.com/s/files/1/2239/4255/files/No_Image_Found.jpg",
|
||||
@@ -75,27 +69,32 @@ namespace PartSource.Automation.Jobs
|
||||
// Product Tags
|
||||
List<string> productTags = new List<string>
|
||||
{
|
||||
importData.LineCode,
|
||||
importData.PartNumber,
|
||||
items[0].LineCode,
|
||||
items[0].PartNumber,
|
||||
};
|
||||
|
||||
List<ProductVariant> productVariants = new List<ProductVariant>();
|
||||
productVariants.Add(new ProductVariant
|
||||
|
||||
foreach (ImportData itemVariant in items)
|
||||
{
|
||||
InventoryPolicy = "Deny",
|
||||
CompareAtPrice = importData.CompareAt,
|
||||
Price = importData.Price,
|
||||
Sku = importData.VariantSku,
|
||||
Title = importData.VariantTitle,
|
||||
Option1 = importData.IsVariant.ToString(),
|
||||
RequiresShipping = false
|
||||
});
|
||||
productVariants.Add(new ProductVariant
|
||||
{
|
||||
InventoryPolicy = "Deny",
|
||||
CompareAtPrice = itemVariant.CompareAt,
|
||||
Price = itemVariant.Price,
|
||||
Sku = itemVariant.VariantSku,
|
||||
Title = itemVariant.VariantTitle,
|
||||
Option1 = itemVariant.VariantTitle,
|
||||
RequiresShipping = false,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Product requestData = new Product
|
||||
{
|
||||
BodyHtml = importData.BodyHtml,
|
||||
Title = importData.Title,
|
||||
Vendor = importData.Vendor,
|
||||
BodyHtml = items[0].BodyHtml,
|
||||
Title = items[0].Title,
|
||||
Vendor = items[0].Vendor,
|
||||
Tags = string.Join(",", productTags),
|
||||
Published = true,
|
||||
//ProductType = importData.FINELINE_NM,
|
||||
@@ -109,19 +108,24 @@ namespace PartSource.Automation.Jobs
|
||||
|
||||
if (requestData.Id > 0)
|
||||
{
|
||||
importData.ShopifyId = requestData.Id;
|
||||
foreach (ImportData variant in items)
|
||||
{
|
||||
variant.ShopifyId = requestData.Id;
|
||||
}
|
||||
|
||||
_partSourceContext.SaveChanges();
|
||||
|
||||
Console.WriteLine($"{importData.VariantSku}");
|
||||
Console.WriteLine($"{items[0].VariantSku}");
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user