diff --git a/src/Apps/W1/Shopify/App/src/Products/Codeunits/ShpfyProduct.Codeunit.al b/src/Apps/W1/Shopify/App/src/Products/Codeunits/ShpfyProduct.Codeunit.al index e3cbde5270..183d4ed323 100644 --- a/src/Apps/W1/Shopify/App/src/Products/Codeunits/ShpfyProduct.Codeunit.al +++ b/src/Apps/W1/Shopify/App/src/Products/Codeunits/ShpfyProduct.Codeunit.al @@ -15,6 +15,7 @@ codeunit 30234 "Shpfy Product" var SyncProducts: Codeunit "Shpfy Sync Products"; + ProductExport: Codeunit "Shpfy Product Export"; /// /// Adds the specified item to the specified Shopify shop. @@ -25,6 +26,30 @@ codeunit 30234 "Shpfy Product" begin SyncProducts.AddItemToShopify(Item, ShopifyShop); end; + + /// + /// Confirms whether the specified item should be added to a Shopify shop, prompting for shop selection when more than one mapped shop is available. + /// + /// The item record to be added. + /// Returns the Shopify shop the item will be added to. + /// True if adding the item was confirmed; otherwise, false. + procedure ConfirmAddItemToShopify(Item: Record Item; var ShopifyShop: Record "Shpfy Shop"): Boolean + begin + exit(SyncProducts.ConfirmAddItemToShopify(Item, ShopifyShop)); + end; + + /// + /// Checks whether the item's attributes are compatible with Shopify product options for the specified shop. + /// + /// The item record to be checked. + /// The Shopify shop record the item will be added to. + /// True if the item's attributes are compatible with product options; otherwise, false. + procedure CheckItemAttributesCompatibleForProductOptions(Item: Record Item; ShopifyShop: Record "Shpfy Shop"): Boolean + begin + ProductExport.SetShop(ShopifyShop); + exit(ProductExport.CheckItemAttributesCompatibleForProductOptions(Item)); + end; + /// /// Retrieves the product URL for the specified Shopify Variant. /// @@ -35,6 +60,17 @@ codeunit 30234 "Shpfy Product" exit(SyncProducts.GetProductUrl(ShopifyVariant)); end; + /// + /// Retrieves the product URL for the specified item in the specified Shopify shop. + /// + /// The item record. + /// The Shopify shop code. + /// The product URL for the specified item. + procedure GetProductUrl(Item: Record Item; ShopCode: Code[20]): Text + begin + exit(SyncProducts.GetProductUrl(Item, ShopCode)); + end; + /// /// Retrieves and display the overview of products for the specified Shopify Variant. /// diff --git a/src/Apps/W1/Shopify/Test/Products/ShpfyItemAttrAsOptionTest.Codeunit.al b/src/Apps/W1/Shopify/Test/Products/ShpfyItemAttrAsOptionTest.Codeunit.al index bc6cfcafc4..db863077e1 100644 --- a/src/Apps/W1/Shopify/Test/Products/ShpfyItemAttrAsOptionTest.Codeunit.al +++ b/src/Apps/W1/Shopify/Test/Products/ShpfyItemAttrAsOptionTest.Codeunit.al @@ -366,6 +366,32 @@ codeunit 139596 "Shpfy Item Attr As Option Test" end; #endregion + #region Product facade + [Test] + procedure UnitTestCheckItemAttributesCompatibleForProductOptionsFromFacade() + var + Item: Record Item; + ShopifyProductMgt: Codeunit "Shpfy Product"; + CompatibilityCheckResult: Boolean; + ExpFailureMessageErr: Label 'maximum of 3 product options'; + begin + // [SCENARIO] The "Shpfy Product" facade checks item attribute compatibility and primes the shop itself. + + // [GIVEN] Shopify Shop is created + Initialize(); + + // [GIVEN] Item is created without Item variants but with 4 'As Option' Item Attributes (exceeds Shopify limit of 3) + Item := CreateItemWithAsOptionAttributes(4); + + // [WHEN] Check item attributes compatible for product options through the facade (the facade sets the shop) + CompatibilityCheckResult := ShopifyProductMgt.CheckItemAttributesCompatibleForProductOptions(Item, Shop); + + // [THEN] Returns false and skipped entry is logged about too many attributes + VerifyResultOfCompatibilityCheck(CompatibilityCheckResult); + VerifySkippedEntryExists(Item.RecordId, ExpFailureMessageErr); + end; + #endregion + #region Helper Procedures local procedure Initialize() var diff --git a/src/Apps/W1/Shopify/Test/Products/ShpfyProductMappingTest.Codeunit.al b/src/Apps/W1/Shopify/Test/Products/ShpfyProductMappingTest.Codeunit.al index c97b379184..c477516223 100644 --- a/src/Apps/W1/Shopify/Test/Products/ShpfyProductMappingTest.Codeunit.al +++ b/src/Apps/W1/Shopify/Test/Products/ShpfyProductMappingTest.Codeunit.al @@ -289,4 +289,35 @@ codeunit 139604 "Shpfy Product Mapping Test" // [THEN] ShopifyProduct."Item SystemId" should be empty (no mapping made) LibraryAssert.AreEqual(EmptyGuid, ShopifyProduct."Item SystemId", 'ShopifyProduct."Item SystemId" should be empty when barcode fallback is disabled'); end; + + [Test] + procedure UnitTestGetProductUrlForItemFromFacade() + var + Item: Record Item; + Shop: Record "Shpfy Shop"; + ShopifyProduct: Record "Shpfy Product"; + ShopifyVariant: Record "Shpfy Variant"; + InitializeTest: Codeunit "Shpfy Initialize Test"; + ProductInitTest: Codeunit "Shpfy Product Init Test"; + ShopifyProductMgt: Codeunit "Shpfy Product"; + ActualUrl: Text; + ProductUrlTok: Label 'https://test.myshopify.com/products/test-product', Locked = true; + begin + // [SCENARIO] The "Shpfy Product" facade returns the Shopify product URL for an item in a shop. + + // [GIVEN] A shop with a Shopify product linked to an item and holding a URL + Shop := InitializeTest.CreateShop(); + Item := ProductInitTest.CreateItem(); + ShopifyVariant := ProductInitTest.CreateStandardProduct(Shop); + ShopifyProduct.Get(ShopifyVariant."Product Id"); + ShopifyProduct."Item SystemId" := Item.SystemId; + ShopifyProduct.URL := ProductUrlTok; + ShopifyProduct.Modify(); + + // [WHEN] Get the product URL through the facade + ActualUrl := ShopifyProductMgt.GetProductUrl(Item, Shop.Code); + + // [THEN] The facade returns the product's URL + LibraryAssert.AreEqual(ProductUrlTok, ActualUrl, 'The facade should return the Shopify product URL for the item.'); + end; }