Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/1.14.0 #74

Merged
merged 5 commits into from
Jan 23, 2024
Merged
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
6 changes: 6 additions & 0 deletions Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Config
const XML_PATH_EXTENSION_SHIPPING_METHOD = 'mollie_subscriptions/general/shipping_method';
const XML_PATH_DEBUG = 'mollie_subscriptions/general/debug';
const XML_PATH_PREPAYMENT_REMINDER_DAYS_BEFORE_REMINDER = 'mollie_subscriptions/prepayment_reminder/days_before_reminder';
const XML_PATH_PREPAYMENT_REMINDER_NEXT_PAYMENT_DATE_FORMAT = 'mollie_subscriptions/prepayment_reminder/next_payment_date_format';
const XML_PATH_PREPAYMENT_REMINDER_ENABLED = 'mollie_subscriptions/prepayment_reminder/enabled';
const XML_PATH_PREPAYMENT_REMINDER_TEMPLATE = 'mollie_subscriptions/prepayment_reminder/template';
const XML_PATH_PREPAYMENT_REMINDER_SEND_BCC_TO = 'mollie_subscriptions/prepayment_reminder/send_bcc_to';
Expand Down Expand Up @@ -243,6 +244,11 @@ public function daysBeforePrepaymentReminder($storeId = null, $scope = ScopeInte
return $this->getStoreValue(static::XML_PATH_PREPAYMENT_REMINDER_DAYS_BEFORE_REMINDER, $storeId, $scope);
}

public function nextPaymentDateFormat($storeId = null, $scope = ScopeInterface::SCOPE_STORE): string
{
return $this->getStoreValue(static::XML_PATH_PREPAYMENT_REMINDER_NEXT_PAYMENT_DATE_FORMAT, $storeId, $scope);
}

/**
* @param null|int|string $storeId
* @param string $scope
Expand Down
36 changes: 30 additions & 6 deletions Service/Email/SubscriptionToProductEmailVariables.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,24 @@

use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Framework\Pricing\PriceCurrencyInterface;
use Magento\Framework\Stdlib\DateTime\DateTime;
use Mollie\Api\MollieApiClient;
use Mollie\Api\Resources\Customer;
use Mollie\Subscriptions\Api\Data\SubscriptionToProductInterface;
use Mollie\Subscriptions\Config;
use Mollie\Subscriptions\Service\Mollie\MollieSubscriptionApi;

class SubscriptionToProductEmailVariables
{
/**
* @var MollieSubscriptionApi
* @var Config
*/
private $mollieSubscriptionApi;
private $config;

/**
* @var Customer[]
* @var MollieSubscriptionApi
*/
private $customers = [];
private $mollieSubscriptionApi;

/**
* @var ProductRepositoryInterface
Expand All @@ -35,19 +37,31 @@ class SubscriptionToProductEmailVariables
*/
private $priceCurrency;

/**
* @var DateTime
*/
private $dateTime;
/**
* @var MollieApiClient[]
*/
private $apiToStore = [];
/**
* @var Customer[]
*/
private $customers = [];

public function __construct(
Config $config,
MollieSubscriptionApi $mollieSubscriptionApi,
ProductRepositoryInterface $productRepository,
PriceCurrencyInterface $priceCurrency
PriceCurrencyInterface $priceCurrency,
DateTime $dateTime
) {
$this->config = $config;
$this->mollieSubscriptionApi = $mollieSubscriptionApi;
$this->productRepository = $productRepository;
$this->priceCurrency = $priceCurrency;
$this->dateTime = $dateTime;
}

public function getMollieCustomer(SubscriptionToProductInterface $subscriptionToProduct): Customer
Expand Down Expand Up @@ -82,10 +96,12 @@ public function get(SubscriptionToProductInterface $subscriptionToProduct): arra
$subscriptionToProduct->getStoreId()
);

$date = $this->formatDate($subscription->nextPaymentDate, $subscriptionToProduct->getStoreId());

return [
'subscription_id' => $subscriptionToProduct->getSubscriptionId(),
'subscription_description' => $subscription->description,
'subscription_nextPaymentDate' => $subscription->nextPaymentDate,
'subscription_nextPaymentDate' => $date,
'subscription_amount' => $amount,
'customer_name' => $customer->name,
'customer_email' => $customer->email,
Expand All @@ -102,4 +118,12 @@ private function getApiForStore($storeId): MollieApiClient
$this->apiToStore[$storeId] = $this->mollieSubscriptionApi->loadByStore($storeId);
return $this->apiToStore[$storeId];
}

public function formatDate(string $nextPaymentDate, int $storeId): string
{
return $this->dateTime->date(
$this->config->nextPaymentDateFormat($storeId),
$nextPaymentDate
);
}
}
1 change: 1 addition & 0 deletions Service/Magento/CreateOrderFromSubscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ private function formatAddress($address): AddressInterface
$quoteAddress->setSuffix($address->getSuffix());
$quoteAddress->setPrefix($address->getPrefix());
$quoteAddress->setRegionId($address->getRegionId());
$quoteAddress->setCustomAttributes($address->getCustomAttributes());

return $quoteAddress;
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "mollie/magento2-subscriptions",
"description": "Mollie subscriptions extension for Magento 2",
"type": "magento2-module",
"version": "1.13.0",
"version": "1.14.0",
"license": [
"OSL-3.0",
"AFL-3.0"
Expand Down
12 changes: 11 additions & 1 deletion etc/adminhtml/system/prepayment_reminder.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,17 @@
<field id="enabled">1</field>
</depends>
</field>
<field id="cron_expr" translate="label" type="select" sortOrder="40" showInDefault="1" showInWebsite="0"
<field id="next_payment_date_format" translate="label" type="text" sortOrder="40" showInDefault="1" showInWebsite="1"
showInStore="1">
<label>Next payment date format</label>
<config_path>mollie_subscriptions/prepayment_reminder/next_payment_date_format</config_path>
<comment><![CDATA[How to format the date in the next payment date reminder emails. Must be in a format that is accepted by <a href="https://www.php.net/manual/en/function.date.php" target="_blank">PHP date format</a>]]></comment>
<validate>required-entry</validate>
<depends>
<field id="enabled">1</field>
</depends>
</field>
<field id="cron_expr" translate="label" type="select" sortOrder="50" showInDefault="1" showInWebsite="0"
showInStore="0">
<label>Cron time</label>
<config_path>mollie_subscriptions/prepayment_reminder/cron_expr</config_path>
Expand Down
3 changes: 2 additions & 1 deletion etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<default>
<mollie_subscriptions>
<general>
<version>v1.13.0</version>
<version>v1.14.0</version>
<enable>0</enable>
<debug>1</debug>
</general>
Expand All @@ -24,6 +24,7 @@
<enabled>0</enabled>
<template>mollie_subscriptions_pre_payment_reminder_template</template>
<days_before_reminder>3</days_before_reminder>
<next_payment_date_format>d-m-Y</next_payment_date_format>
<cron_expr>0 1 * * *</cron_expr>
</prepayment_reminder>
<emails>
Expand Down
2 changes: 1 addition & 1 deletion i18n/nl_NL.csv
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Type,Type
"We confirm that you canceled the subscription with ID %subscription_id.","We bevestigen dat u het abonnement met ID %subscription_id heeft geannuleerd."
"New subscription","Nieuw abonnement"
"The customer %customerName has started a new subscription with the description %description and ID %subscription_id.","De klant %customerName heeft een nieuw abonnement gestart met de beschrijving %description en ID %subscription_id."
"Your new subscription","Uw nieuw abonnement"
"Your new subscription","Uw nieuwe abonnement"
"Good news! We confirm your subscription to %product_name. The next order will be sent on its way to you on %nextPaymentDate.","Goed nieuws! We bevestigen uw abonnement op %product_name. De volgende bestelling wordt op %nextPaymentDate naar u verzonden."
"Upcoming subscription renewal from %store_name","Aankomende abonnementsvernieuwing van %store_name"
"We are very excited to get your %product_name subscription ready for %nextPaymentDate!","We zijn erg enthousiast om uw abonnement op %product_name klaar te maken voor %nextPaymentDate!"
Expand Down