codeunit 50500 "Vendor No Shopify Metafield"
{
SingleInstance = true;
// ---------------------------------------------------------
// Phase 1: Prepare metafield value during export
// ---------------------------------------------------------
[EventSubscriber(
ObjectType::Codeunit,
Codeunit::"Shpfy Product Events",
'OnAfterCreateTempShopifyProduct',
'',
false,
false)]
local procedure AddVendorNoMetafield(
Item: Record Item;
var ShopifyProduct: Record "Shpfy Product";
var ShopifyVariant: Record "Shpfy Variant";
var ShopifyTag: Record "Shpfy Tag")
var
Metafield: Record "Shpfy Metafield";
begin
Message(
'Temp Shopify product created for Item %1, ShopifyProduct.Id=%2',
Item."No.",
ShopifyProduct.Id
);
if Item."Vendor No." = '' then
exit;
Metafield.Init();
Metafield."Owner Type" := Metafield."Owner Type"::Product;
Metafield."Owner Id" := ShopifyProduct.Id; // 0 is OK for new products
Metafield.Namespace := 'custom';
Metafield.Name := 'brand';
Metafield."Value Type" := Metafield."Value Type"::String;
Metafield.Value := Item."Vendor No.";
if not Metafield.Insert() then
Metafield.Modify();
end;
}