diff --git a/CHANGELOG.md b/CHANGELOG.md index cd1f504..668fb9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ ### Added -- Added the ability to link customers in the plugin settings. +- Added the ability to define customer aliases in the plugin settings. ### Changed diff --git a/src/controllers/SlideoutController.php b/src/controllers/SlideoutController.php index caa773c..ab9bb5d 100644 --- a/src/controllers/SlideoutController.php +++ b/src/controllers/SlideoutController.php @@ -19,14 +19,14 @@ class SlideoutController extends Controller public function actionRender(): Response { $customer = $this->request->getRequiredParam('customer'); - $linkedCustomers = PluginSales::$plugin->settings->getLinkedCustomers($customer); + $customerAliases = PluginSales::$plugin->settings->getCustomerAliases($customer); $url = $this->getUrlFromCustomer($customer); $sales = PluginSales::$plugin->reports->getSalesData($customer); return $this->asCpScreen() ->contentTemplate('plugin-sales/_slideout', [ 'customer' => $customer, - 'linkedCustomers' => $linkedCustomers, + 'customerAliases' => $customerAliases, 'url' => $url, 'sales' => $sales, ]); diff --git a/src/models/SettingsModel.php b/src/models/SettingsModel.php index bcd16a1..91c32d9 100644 --- a/src/models/SettingsModel.php +++ b/src/models/SettingsModel.php @@ -44,7 +44,7 @@ class SettingsModel extends Model /** * @var array */ - public array $linkedCustomers = []; + public array $customerAliases = []; /** * @var int @@ -52,19 +52,19 @@ class SettingsModel extends Model public int $refreshSalesJobTtr = 3600; /** - * Returns linked customers for the given customer. + * Returns customer aliases for the given customer. */ - public function getLinkedCustomers(string $customer): array + public function getCustomerAliases(string $customer): array { - $linkedCustomers = []; + $customerAliases = []; - foreach ($this->linkedCustomers as $linkedCustomer) { - if ($linkedCustomer['canonical'] === $customer) { - $linkedCustomers[] = $linkedCustomer['linked']; + foreach ($this->customerAliases as $customerAlias) { + if ($customerAlias['customer'] === $customer) { + $customerAliases[] = $customerAlias['alias']; } } - return $linkedCustomers; + return $customerAliases; } /** diff --git a/src/services/SalesService.php b/src/services/SalesService.php index 45d7d9f..39c455f 100755 --- a/src/services/SalesService.php +++ b/src/services/SalesService.php @@ -211,7 +211,7 @@ public function refresh(callable $setProgressHandler = null): bool|int } } - $this->updateLinkedCustomers(); + $this->updateCustomerAliases(); $this->updateFirstSales(); $refreshRecord = new RefreshRecord(); @@ -327,20 +327,20 @@ private function saveSales(array $sales): int } /** - * Updates all linked customers. + * Updates all customer aliases. */ - private function updateLinkedCustomers(): void + private function updateCustomerAliases(): void { - $linkedCustomers = PluginSales::$plugin->settings->linkedCustomers; + $customerAliases = PluginSales::$plugin->settings->customerAliases; - foreach ($linkedCustomers as $linkedCustomer) { + foreach ($customerAliases as $customerAlias) { Db::update( SaleRecord::tableName(), [ - 'customer' => $linkedCustomer['canonical'], + 'customer' => $customerAlias['customer'], ], [ - 'customer' => $linkedCustomer['linked'], + 'customer' => $customerAlias['alias'], ] ); } diff --git a/src/templates/_slideout.twig b/src/templates/_slideout.twig index 80f7114..e5af6d9 100644 --- a/src/templates/_slideout.twig +++ b/src/templates/_slideout.twig @@ -1,10 +1,10 @@
{{ linkedCustomer }}
+ Customer aliases:
+ {% for customerAlias in customerAliases %}
+ {{ customerAlias }}
{{- not loop.last ? ',' }}
{% endfor %}
diff --git a/src/templates/settings.twig b/src/templates/settings.twig
index 8c39fd5..ba2036a 100644
--- a/src/templates/settings.twig
+++ b/src/templates/settings.twig
@@ -117,22 +117,22 @@
} %}
{{ forms.editableTableField({
- label: 'Linked Customers'|t('plugin-sales'),
- instructions: 'Customers can be linked together, useful to ease the transition from Craft ID to Craft Console, which added support for organisations.'|t('plugin-sales'),
- name: 'linkedCustomers',
- id: 'linkedCustomers',
+ label: 'Customer Aliases'|t('plugin-sales'),
+ instructions: 'Customers can be assigned aliases, useful to ease the transition from Craft ID to Craft Console, which added support for organisations. Customer aliases will be replaced with the customer name on each refresh.'|t('plugin-sales'),
+ name: 'customerAliases',
+ id: 'customerAliases',
cols: {
- canonical: {
+ customer: {
type: 'singleline',
- heading: 'Canonical customer'|t('plugin-sales'),
+ heading: 'Customer'|t('plugin-sales'),
},
- linked: {
+ alias: {
type: 'singleline',
- heading: 'Linked customer'|t('plugin-sales'),
+ heading: 'Alias'|t('plugin-sales'),
},
},
- rows: settings.linkedCustomers,
- addRowLabel: 'Add a linked customer'|t('plugin-sales'),
+ rows: settings.customerAliases,
+ addRowLabel: 'Add customer alias'|t('plugin-sales'),
allowAdd: true,
allowDelete: true,
allowReorder: true,