Skip to content

Commit

Permalink
#145 - Use config path in default config values + fix email template …
Browse files Browse the repository at this point in the history
…reference
  • Loading branch information
thomas-kl1 committed Aug 23, 2024
1 parent 3a9750d commit d2eed19
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 131 deletions.
58 changes: 7 additions & 51 deletions Model/Notifier/AbstractMailSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,18 @@

abstract class AbstractMailSender
{
protected TransportBuilder $transportBuilder;

private ScopeConfigInterface $scopeConfig;
private const CONFIG_PATH_ENABLED = 'gdpr/notification/enabled';

/**
* @var string[]
*/
private array $configPaths;

/**
* @param TransportBuilder $transportBuilder
* @param ScopeConfigInterface $scopeConfig
* @param string[] $configPaths
*/
public function __construct(
TransportBuilder $transportBuilder,
ScopeConfigInterface $scopeConfig,
array $configPaths
) {
$this->transportBuilder = $transportBuilder;
$this->scopeConfig = $scopeConfig;
$this->configPaths = $configPaths;
}
protected TransportBuilder $transportBuilder,
private ScopeConfigInterface $scopeConfig,
private array $configPaths = []
) {}

/**
* @param string $sendTo
* @param string|null $name [optional] Specify the to name.
* @param int|null $storeId [optional Current store ID is used by default.
* @param array $vars
* @throws LocalizedException
* @throws MailException
*/
Expand Down Expand Up @@ -77,10 +60,6 @@ protected function sendMail(string $sendTo, ?string $name = null, ?int $storeId
}

/**
* @param string $sendTo
* @param string|null $name [optional] Specify the to name.
* @param int|null $storeId [optional Current store ID is used by default.
* @param array $vars
* @throws MailException
*/
protected function prepareMail(string $sendTo, ?string $name = null, ?int $storeId = null, array $vars = []): void
Expand All @@ -92,23 +71,12 @@ protected function prepareMail(string $sendTo, ?string $name = null, ?int $store
->addTo($sendTo, $name);
}

/**
* @param int|null $storeId [optional] Retrieves the value by scope.
* @return bool
*/
protected function isAvailable(?int $storeId = null): bool
{
return $this->scopeConfig->isSetFlag(
$this->configPaths['is_available'],
ScopeInterface::SCOPE_STORE,
$storeId
);
return $this->scopeConfig->isSetFlag(self::CONFIG_PATH_ENABLED, ScopeInterface::SCOPE_STORE, $storeId)
&& $this->scopeConfig->isSetFlag($this->configPaths['is_available'], ScopeInterface::SCOPE_STORE, $storeId);
}

/**
* @param int|null $storeId [optional] Retrieves the value by scope.
* @return string
*/
protected function getFrom(?int $storeId = null): string
{
return (string)$this->scopeConfig->getValue(
Expand All @@ -118,10 +86,6 @@ protected function getFrom(?int $storeId = null): string
);
}

/**
* @param int|null $storeId [optional] Retrieves the value by scope.
* @return array
*/
protected function getCopyTo(?int $storeId = null): array
{
return explode(
Expand All @@ -134,10 +98,6 @@ protected function getCopyTo(?int $storeId = null): array
);
}

/**
* @param int|null $storeId [optional] Retrieves the value by scope.
* @return string
*/
protected function getCopyMethod(?int $storeId = null): string
{
return (string)$this->scopeConfig->getValue(
Expand All @@ -147,10 +107,6 @@ protected function getCopyMethod(?int $storeId = null): string
);
}

/**
* @param int|null $storeId [optional] Retrieves the value by scope.
* @return string
*/
protected function getTemplateIdentifier(?int $storeId = null): string
{
return (string)$this->scopeConfig->getValue(
Expand Down
2 changes: 1 addition & 1 deletion etc/adminhtml/system/notification.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<label>Enabled</label>
<comment>It will enable the module features in the admin and frontend ui.</comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<config_path>gdpr/notification/erase_enabled</config_path>
<config_path>gdpr/notification/enabled</config_path>
</field>
</group>
<group id="erase" translate="label" showInDefault="1" showInWebsite="1" showInStore="1" sortOrder="20">
Expand Down
105 changes: 26 additions & 79 deletions etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
<enabled>0</enabled>
<page_id>privacy-policy-cookie-restriction-mode</page_id>
</general>
<action>
</action>
<anonymize>
<customer_attributes>
<email>
Expand Down Expand Up @@ -207,83 +205,32 @@
<subscriber_attributes>email</subscriber_attributes>
</export>
<notification>
<general>
<enabled>0</enabled>
</general>
<erasure>
<pending>
<customer>
<enabled>1</enabled>
<template>gdpr_email_erase_pending_template</template>
<identity>general</identity>
<copy_method>bcc</copy_method>
</customer>
<order>
<enabled>1</enabled>
<template>gdpr_email_erase_pending_guest_template</template>
<identity>general</identity>
<copy_method>bcc</copy_method>
</order>
</pending>
<succeeded>
<customer>
<enabled>1</enabled>
<template>gdpr_email_erase_succeeded_template</template>
<identity>general</identity>
<copy_method>bcc</copy_method>
</customer>
<order>
<enabled>1</enabled>
<template>gdpr_email_erase_succeeded_guest_template</template>
<identity>general</identity>
<copy_method>bcc</copy_method>
</order>
</succeeded>
<canceled>
<customer>
<enabled>1</enabled>
<template>gdpr_email_erase_canceled_template</template>
<identity>general</identity>
<copy_method>bcc</copy_method>
</customer>
<order>
<enabled>1</enabled>
<template>gdpr_email_erase_canceled_guest_template</template>
<identity>general</identity>
<copy_method>bcc</copy_method>
</order>
</canceled>
</erasure>
<export>
<pending>
<customer>
<enabled>1</enabled>
<template>gdpr_email_export_pending_template</template>
<identity>general</identity>
<copy_method>bcc</copy_method>
</customer>
<order>
<enabled>1</enabled>
<template>gdpr_email_export_pending_guest_template</template>
<identity>general</identity>
<copy_method>bcc</copy_method>
</order>
</pending>
<ready>
<customer>
<enabled>1</enabled>
<template>gdpr_email_export_ready_template</template>
<identity>general</identity>
<copy_method>bcc</copy_method>
</customer>
<order>
<enabled>1</enabled>
<template>gdpr_email_export_ready_guest_template</template>
<identity>general</identity>
<copy_method>bcc</copy_method>
</order>
</ready>
</export>
<enabled>0</enabled>
<erase_pending_enabled>1</erase_pending_enabled>
<erase_pending_identity>general</erase_pending_identity>
<erase_pending_copy_method>bcc</erase_pending_copy_method>
<erase_pending_template>opengento_gdpr_notification_notification_erase_pending_template</erase_pending_template>
<erase_pending_guest_template>opengento_gdpr_notification_notification_erase_pending_guest_template</erase_pending_guest_template>
<erase_succeeded_enabled>1</erase_succeeded_enabled>
<erase_succeeded_identity>general</erase_succeeded_identity>
<erase_succeeded_copy_method>bcc</erase_succeeded_copy_method>
<erase_succeeded_template>opengento_gdpr_notification_notification_erase_succeeded_template</erase_succeeded_template>
<erase_succeeded_guest_template>opengento_gdpr_notification_notification_erase_succeeded_guest_template</erase_succeeded_guest_template>
<erase_canceled_enabled>1</erase_canceled_enabled>
<erase_canceled_identity>general</erase_canceled_identity>
<erase_canceled_copy_method>bcc</erase_canceled_copy_method>
<erase_canceled_template>opengento_gdpr_notification_notification_erase_canceled_template</erase_canceled_template>
<erase_canceled_guest_template>opengento_gdpr_notification_notification_erase_canceled_guest_template</erase_canceled_guest_template>
<export_pending_enabled>1</export_pending_enabled>
<export_pending_identity>general</export_pending_identity>
<export_pending_copy_method>bcc</export_pending_copy_method>
<export_pending_template>opengento_gdpr_notification_notification_export_pending_template</export_pending_template>
<export_pending_guest_template>opengento_gdpr_notification_notification_export_pending_guest_template</export_pending_guest_template>
<export_ready_enabled>1</export_ready_enabled>
<export_ready_identity>general</export_ready_identity>
<export_ready_copy_method>bcc</export_ready_copy_method>
<export_ready_template>opengento_gdpr_notification_notification_export_ready_template</export_ready_template>
<export_ready_guest_template>opengento_gdpr_notification_notification_export_ready_guest_template</export_ready_guest_template>
</notification>
</gdpr>
</default>
Expand Down

0 comments on commit d2eed19

Please sign in to comment.