For context: what I'm trying to do is have a job that runs and builds an XML file for a Google Shopping Feed based on all the published products on our site.
I have a job that loops through a JSON file list of products, looks up the product in the db based on the PartNumber, and then updates the product in the db with the fields from the JSON file.
The first thing I'm looking to do, but am unfamiliar with, is return all products on the site to a list in code. I want any product that is purchasable on the site to be return to a list, and from there I can figure the rest out. Can't seem to find any code to work for this in the mean time.
This code isn't my attempt at it, just how I was getting the products by individual lookup - am looking for a way similar to this but in bulk. Ultimately, getting our purchaseable products into an XML for the purposes of a Google Shopping Feed file is the ultimate goal, so if there is a better solution for that please let me know! Thank you!
private void ProcessInventoryUpdate(ProductInventory inventoryUpdate, InventoryStats stats)
{
var productLink = ProductHelper.GetCatalogEntryByMetaField("PartNumber", inventoryUpdate?.ItemId);
if (productLink == null)
{
stats.ProductsNotFound++;
return;
}
// Get the product as CatalongBase from the content loader so I can modify the SiteProductVariation settings
var product = _contentLoader?.Get<CatalogContentBase>(productLink?.ContentLink) as SiteProductVariation;
if (product?.CreateWritableClone() is SiteProductVariation writableProduct)
{
UpdateProduct(writableProduct, inventoryUpdate, productLink.Code, stats);
}
UpdateInventoryRecord(productLink.Code, inventoryUpdate, stats);
stats.TotalProcessed++;
}