Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ codeunit 30234 "Shpfy Product"

var
SyncProducts: Codeunit "Shpfy Sync Products";
ProductExport: Codeunit "Shpfy Product Export";

/// <summary>
/// Adds the specified item to the specified Shopify shop.
Expand All @@ -25,6 +26,30 @@ codeunit 30234 "Shpfy Product"
begin
SyncProducts.AddItemToShopify(Item, ShopifyShop);
end;

/// <summary>
/// Confirms whether the specified item should be added to a Shopify shop, prompting for shop selection when more than one mapped shop is available.
/// </summary>
/// <param name="Item">The item record to be added.</param>
/// <param name="ShopifyShop">Returns the Shopify shop the item will be added to.</param>
/// <returns>True if adding the item was confirmed; otherwise, false.</returns>
procedure ConfirmAddItemToShopify(Item: Record Item; var ShopifyShop: Record "Shpfy Shop"): Boolean
begin
exit(SyncProducts.ConfirmAddItemToShopify(Item, ShopifyShop));
end;

/// <summary>
/// Checks whether the item's attributes are compatible with Shopify product options for the specified shop.
/// </summary>
/// <param name="Item">The item record to be checked.</param>
/// <param name="ShopifyShop">The Shopify shop record the item will be added to.</param>
/// <returns>True if the item's attributes are compatible with product options; otherwise, false.</returns>
procedure CheckItemAttributesCompatibleForProductOptions(Item: Record Item; ShopifyShop: Record "Shpfy Shop"): Boolean
begin
ProductExport.SetShop(ShopifyShop);
exit(ProductExport.CheckItemAttributesCompatibleForProductOptions(Item));
end;

/// <summary>
/// Retrieves the product URL for the specified Shopify Variant.
/// </summary>
Expand All @@ -35,6 +60,17 @@ codeunit 30234 "Shpfy Product"
exit(SyncProducts.GetProductUrl(ShopifyVariant));
end;

/// <summary>
/// Retrieves the product URL for the specified item in the specified Shopify shop.
/// </summary>
/// <param name="Item">The item record.</param>
/// <param name="ShopCode">The Shopify shop code.</param>
/// <returns>The product URL for the specified item.</returns>
procedure GetProductUrl(Item: Record Item; ShopCode: Code[20]): Text
begin
exit(SyncProducts.GetProductUrl(Item, ShopCode));
end;

/// <summary>
/// Retrieves and display the overview of products for the specified Shopify Variant.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Loading