Skip to content
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
// ------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// ------------------------------------------------------------------------------------------------

namespace Microsoft.Integration.Shopify;

codeunit 30407 "Shpfy Shop Review Mgt."
{
Access = Internal;

procedure OpenReviewLink(Notification: Notification)
var
StoreURL: Text;
begin
Hyperlink(GetReviewLink());

StoreURL := Notification.GetData(GetStoreNameKey());
if StoreURL <> '' then
MarkStoreAsReviewed(StoreURL);
end;

procedure OpenReviewLinkFromShop(StoreURL: Text)
begin
Hyperlink(GetReviewLink());

MarkStoreAsReviewed(StoreURL);
end;

procedure MarkReviewCompleted(Notification: Notification)
var
StoreURL: Text;
begin
StoreURL := Notification.GetData(GetStoreNameKey());
if StoreURL <> '' then
MarkStoreAsReviewed(StoreURL);
end;

local procedure MarkStoreAsReviewed(StoreURL: Text)
var
RegisteredStore: Record "Shpfy Registered Store New";
begin
if not RegisteredStore.Get(StoreURL) then
exit;

RegisteredStore."Review Completed" := true;
RegisteredStore.Modify(true);
end;


local procedure GetReviewLink(): Text
begin
exit('https://aka.ms/bcshopifyvote');
end;

procedure MaybeShowReviewReminder(StoreURL: Text)
var
RegisteredStore: Record "Shpfy Registered Store New";
OrderHeader: Record "Shpfy Order Header";
begin
if not RegisteredStore.Get(StoreURL) then
exit;

if RegisteredStore."Review Completed" then
exit;

if RegisteredStore."Review Prompt Date" <> 0D then
if RegisteredStore."Review Prompt Date" > CalcDate('<-60D>', Today()) then
exit;

OrderHeader.SetRange(Processed, true);
if OrderHeader.Count() < GetReviewReminderMinimumProcessedOrders() then
exit;

ShowReviewReminder(RegisteredStore);
end;

local procedure ShowReviewReminder(var RegisteredStore: Record "Shpfy Registered Store New")
var
ReminderNotification: Notification;
begin
RegisteredStore."Review Prompt Date" := Today();
RegisteredStore.Modify(true);

ReminderNotification.Id := GetReviewReminderNotificationId();
ReminderNotification.Message := ReviewReminderMessageTxt;
ReminderNotification.Scope := NotificationScope::LocalScope;
ReminderNotification.SetData(GetStoreNameKey(), RegisteredStore.Store);
ReminderNotification.AddAction(ReviewReminderReviewActionLbl, Codeunit::"Shpfy Shop Review Mgt.", 'OpenReviewLink');
ReminderNotification.AddAction(ReviewReminderAlreadyDidActionLbl, Codeunit::"Shpfy Shop Review Mgt.", 'MarkReviewCompleted');
ReminderNotification.Send();

LogReviewReminderTelemetry();
end;

local procedure LogReviewReminderTelemetry()
begin
Session.LogMessage('0000SVO', ReviewReminderTelemetryMsg, Verbosity::Normal, DataClassification::SystemMetadata, TelemetryScope::ExtensionPublisher, 'Category', ReviewReminderTelemetryCategoryTok);
end;

local procedure GetReviewReminderNotificationId(): Guid
begin
exit('5aab1677-6f6a-4f86-9eca-3ad3dfd986b2');
end;

local procedure GetReviewReminderMinimumProcessedOrders(): Integer
begin
exit(100);
end;

local procedure GetStoreNameKey(): Text
begin
exit('StoreURL');
end;

var
ReviewReminderMessageTxt: Label 'Relying on the Shopify connector for integration? Leave a review in the Shopify App Store to help others discover it.';
ReviewReminderReviewActionLbl: Label 'Review';
ReviewReminderAlreadyDidActionLbl: Label 'Already did';
ReviewReminderTelemetryMsg: Label 'Shopify review reminder notification displayed.', Locked = true;
ReviewReminderTelemetryCategoryTok: Label 'Shopify Integration', Locked = true;
}
22 changes: 22 additions & 0 deletions src/Apps/W1/Shopify/App/src/Base/Pages/ShpfyShopCard.Page.al
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,21 @@ page 30101 "Shpfy Shop Card"
CommunicationMgt.ClearApiVersionCache();
end;
}
action(LeaveReview)
{
ApplicationArea = All;
Caption = 'Leave a Review';
Image = CustomerRating;
ToolTip = 'Open the Shopify App Store to leave a review for the Shopify connector.';

trigger OnAction()
var
ShopReviewMgt: Codeunit "Shpfy Shop Review Mgt.";
begin
ShopReviewMgt.OpenReviewLinkFromShop(Rec.GetStoreName());
end;
}

}
group(Sync)
{
Expand Down Expand Up @@ -1255,6 +1270,13 @@ page 30101 "Shpfy Shop Card"
end;
end;

trigger OnClosePage()
var
ShopReviewMgt: Codeunit "Shpfy Shop Review Mgt.";
begin
ShopReviewMgt.MaybeShowReviewReminder(Rec.GetStoreName());
end;

trigger OnAfterGetCurrRecord()
begin
CheckReturnRefundsVisible();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ table 30138 "Shpfy Registered Store New"
Caption = 'Actual Scope';
DataClassification = SystemMetadata;
}
field(4; "Review Prompt Date"; Date)
{
Caption = 'Review Prompt Date';
DataClassification = SystemMetadata;
}
field(5; "Review Completed"; Boolean)
{
Caption = 'Review Completed';
DataClassification = SystemMetadata;
}
}
keys
{
Expand Down
Loading