Skip to content

Commit

Permalink
Add invoice filename setting
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Fedurtsya <[email protected]>
  • Loading branch information
Sieg committed Oct 1, 2024
1 parent be5a2c8 commit 623d7d2
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/Settings/ModuleSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class ModuleSettings implements ModuleSettingsInterface
public const SETTING_INVOICE_NUMBER_FORMAT = 'fa_invoice_InvoiceNumberFormat';
public const SETTING_INVOICE_DATE_FORMAT = 'fa_invoice_InvoiceDateFormat';
public const SETTING_SEND_INVOICE_ON_USER_ORDER_EMAIL = 'fa_invoice_SendInvoiceOnUserOrderEmail';
public const SETTING_INVOICE_ON_ORDER_EMAIL_FILENAME = 'fa_invoice_InvoiceOnOrderEmailFilename';

public function __construct(
private ModuleSettingServiceInterface $moduleSettingService
Expand Down Expand Up @@ -48,6 +49,11 @@ public function getInvoiceDateFormat(): string
return $this->getStringSetting(self::SETTING_INVOICE_DATE_FORMAT);
}

public function getInvoiceInOrderEmailFilename(): string
{
return $this->getStringSetting(self::SETTING_INVOICE_ON_ORDER_EMAIL_FILENAME);
}

private function getStringSetting(string $key): string
{
return $this->moduleSettingService
Expand Down
2 changes: 2 additions & 0 deletions src/Settings/ModuleSettingsInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ public function getInvoiceNumberFormat(): string;
public function getInvoiceDateFormat(): string;

public function isSendInvoiceOnUserOrderEmailActive(): bool;

public function getInvoiceInOrderEmailFilename(): string;
}
4 changes: 3 additions & 1 deletion src/Transition/Core/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ public function sendOrderEmailToUser($order, $subject = null)
public function send()
{
if ($this->attachInvoice) {
$moduleSettings = $this->getServiceFromContainer(ModuleSettingsInterface::class);

$this->addAttachment(
path: $this->attachInvoice,
name: 'invoice.pdf',
name: $moduleSettings->getInvoiceInOrderEmailFilename(),
);
$this->attachInvoice = null;
}
Expand Down
5 changes: 3 additions & 2 deletions tests/Integration/Transition/Core/EmailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public function testInvoiceGeneratedAndAttachedWithOptionOn(): void
invoiceDataService: $invoiceDataService = $this->createMock(Invoice::class),
invoiceGenerator: $invoiceGeneratorSpy = $this->createMock(InvoiceGeneratorInterface::class),
moduleSettings: $this->createConfiguredMock(ModuleSettingsInterface::class, [
'isSendInvoiceOnUserOrderEmailActive' => true
'isSendInvoiceOnUserOrderEmailActive' => true,
'getInvoiceInOrderEmailFilename' => $fileName = uniqid()
]),
)
);
Expand All @@ -53,7 +54,7 @@ public function testInvoiceGeneratedAndAttachedWithOptionOn(): void
$this->assertSame($parentOrderEmailSendResult, $sut->sendOrderEmailToUser($order, $emailSubject));

$sut->expects($this->once())->method('addAttachment')
->with($invoicePath, 'invoice.pdf');
->with($invoicePath, $fileName);
$sut->method('faCallParentSend')->willReturn($parentSendResult = uniqid());

$this->assertSame($parentSendResult, $sut->send());
Expand Down
13 changes: 13 additions & 0 deletions tests/Unit/Settings/ModuleSettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ public function testGetInvoiceNumberFormat(): void
$this->assertSame($value, $sut->getInvoiceNumberFormat());
}

public function testGetInvoiceInOrderEmailFilename(): void
{
$value = uniqid();

$mssMock = $this->createMock(ModuleSettingServiceInterface::class);
$mssMock->method('getString')->willReturnMap([
[ModuleSettings::SETTING_INVOICE_ON_ORDER_EMAIL_FILENAME, Module::MODULE_ID, new UnicodeString($value)]
]);

$sut = new ModuleSettings($mssMock);
$this->assertSame($value, $sut->getInvoiceInOrderEmailFilename());
}

public function testGetInvoiceDateFormat(): void
{
$value = uniqid();
Expand Down
1 change: 1 addition & 0 deletions views/admin_twig/de/fainvoice_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@
# Module settings invoice mails
'SHOP_MODULE_GROUP_fa_invoice_emails' => 'E-Mail-Optionen',
'SHOP_MODULE_fa_invoice_SendInvoiceOnUserOrderEmail' => 'Rechnung generieren und an Bestellbestätigungs-E-Mail des Kunden anhängen',
'SHOP_MODULE_fa_invoice_InvoiceOnOrderEmailFilename' => 'Dateiname für an Bestellbestätigungs-E-Mail angehängte Rechnung',
]);
1 change: 1 addition & 0 deletions views/admin_twig/en/fainvoice_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@
# Module settings invoice mails
'SHOP_MODULE_GROUP_fa_invoice_emails' => 'Email options',
'SHOP_MODULE_fa_invoice_SendInvoiceOnUserOrderEmail' => 'Generate and attach invoice to Customer order confirmation email',
'SHOP_MODULE_fa_invoice_InvoiceOnOrderEmailFilename' => 'Filename for invoice attached to order confirmation email',
]);
1 change: 1 addition & 0 deletions views/admin_twig/lt/fainvoice_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@
# Module settings invoice mails
'SHOP_MODULE_GROUP_fa_invoice_emails' => 'Email options',
'SHOP_MODULE_fa_invoice_SendInvoiceOnUserOrderEmail' => 'Generate and attach invoice to Customer order confirmation email',
'SHOP_MODULE_fa_invoice_InvoiceOnOrderEmailFilename' => 'Filename for invoice attached to order confirmation email',
]);

0 comments on commit 623d7d2

Please sign in to comment.