Skip to content

Commit

Permalink
Merge branch 'pt-10536/5.6/prerender-invoice-template' into 'master'
Browse files Browse the repository at this point in the history
PT-10536 - Corrects an error in the order confirmation mail.

See merge request shopware/5/services/swagpaymentpaypalunified!28
  • Loading branch information
seggewiss committed Apr 24, 2020
2 parents f394057 + e1ef0c7 commit 3ca5ce4
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 35 deletions.
1 change: 1 addition & 0 deletions Resources/services/subscribers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<argument type="service" id="dbal_connection"/>
<argument type="service" id="snippets"/>
<argument type="service" id="translation" on-invalid="null"/>
<argument type="service" id="template"/>
<tag name="shopware.event_subscriber"/>
</service>

Expand Down
26 changes: 25 additions & 1 deletion Subscriber/Documents/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use Doctrine\DBAL\Connection;
use Enlight\Event\SubscriberInterface;
use Enlight_Template_Manager as Template;
use Shopware_Components_Snippet_Manager as SnippetManager;
use Shopware_Components_Translation;
use SwagPaymentPayPalUnified\Components\Document\InvoiceDocumentHandler;
Expand Down Expand Up @@ -39,16 +40,23 @@ class Invoice implements SubscriberInterface
*/
private $translation;

/**
* @var Enlight_Template_ManagerTemplate
*/
private $templateManager;

public function __construct(
PaymentInstructionService $paymentInstructionService,
Connection $dbalConnection,
SnippetManager $snippetManager,
Shopware_Components_Translation $translation = null
Shopware_Components_Translation $translation = null,
Template $templateManager
) {
$this->paymentInstructionsService = $paymentInstructionService;
$this->dbalConnection = $dbalConnection;
$this->snippetManager = $snippetManager;
$this->translation = $translation;
$this->templateManager = $templateManager;

if ($this->translation === null) {
$this->translation = new Shopware_Components_Translation();
Expand All @@ -62,6 +70,7 @@ public static function getSubscribedEvents()
{
return [
'Shopware_Components_Document::assignValues::after' => 'onBeforeRenderDocument',
'Shopware_Modules_Order_SendMail_FilterVariables' => 'onFilterMailVariables',
];
}

Expand Down Expand Up @@ -99,4 +108,19 @@ public function onBeforeRenderDocument(\Enlight_Hook_HookArgs $args)
);
$documentHandler->handleDocument($orderNumber, $document);
}

public function onFilterMailVariables(\Enlight_Event_EventArgs $eventArgs)
{
$vars = $eventArgs->getReturn();

if ($vars['additional']['payment']['name'] !== 'SwagPaymentPayPalUnified') {
return $vars;
}

$vars['additional']['payment']['additionaldescription'] = $this->templateManager->fetch(
sprintf('string:%s', $vars['additional']['payment']['additionaldescription'])
);

return $vars;
}
}
98 changes: 66 additions & 32 deletions Tests/Functional/Subscriber/Documents/InvoiceSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,7 @@ class InvoiceSubscriberTest extends TestCase

public function test_construct()
{
$subscriber = new Invoice(
Shopware()->Container()->get('paypal_unified.payment_instruction_service'),
Shopware()->Container()->get('dbal_connection'),
Shopware()->Container()->get('snippets'),
$this->getTranslationService()
);
$subscriber = $this->getSubscriber();
static::assertNotNull($subscriber);
}

Expand All @@ -55,7 +50,8 @@ public function test_construct_without_translator()
Shopware()->Container()->get('paypal_unified.payment_instruction_service'),
Shopware()->Container()->get('dbal_connection'),
Shopware()->Container()->get('snippets'),
null
null,
Shopware()->Container()->get('template')
);
static::assertNotNull($subscriber);
}
Expand All @@ -64,31 +60,22 @@ public function test_getSubscribedEvents()
{
$events = Invoice::getSubscribedEvents();

static::assertCount(1, $events);
static::assertCount(2, $events);
static::assertSame('onBeforeRenderDocument', $events['Shopware_Components_Document::assignValues::after']);
static::assertSame('onFilterMailVariables', $events['Shopware_Modules_Order_SendMail_FilterVariables']);
}

public function test_onBeforeRenderDocument_returns_when_no_document_was_given()
{
$subscriber = new Invoice(
Shopware()->Container()->get('paypal_unified.payment_instruction_service'),
Shopware()->Container()->get('dbal_connection'),
Shopware()->Container()->get('snippets'),
$this->getTranslationService()
);
$subscriber = $this->getSubscriber();
$hookArgs = new HookArgsWithoutSubject();

static::assertNull($subscriber->onBeforeRenderDocument($hookArgs));
}

public function test_onBeforeRenderDocument_returns_when_wrong_payment_id_was_given()
{
$subscriber = new Invoice(
Shopware()->Container()->get('paypal_unified.payment_instruction_service'),
Shopware()->Container()->get('dbal_connection'),
Shopware()->Container()->get('snippets'),
$this->getTranslationService()
);
$subscriber = $this->getSubscriber();

$hookArgs = new HookArgsWithWrongPaymentId();

Expand All @@ -97,12 +84,7 @@ public function test_onBeforeRenderDocument_returns_when_wrong_payment_id_was_gi

public function test_onBeforeRenderDocument_returns_when_wrong_payment_type()
{
$subscriber = new Invoice(
Shopware()->Container()->get('paypal_unified.payment_instruction_service'),
Shopware()->Container()->get('dbal_connection'),
Shopware()->Container()->get('snippets'),
$this->getTranslationService()
);
$subscriber = $this->getSubscriber();

$this->updateOrderPaymentId(15, $this->getUnifiedPaymentId());
$hookArgs = new HookArgsWithCorrectPaymentId(Shopware()->Container()->has('shopware.benchmark_bundle.collector'));
Expand All @@ -112,12 +94,7 @@ public function test_onBeforeRenderDocument_returns_when_wrong_payment_type()

public function test_onBeforeRenderDocument_handleDocument()
{
$subscriber = new Invoice(
Shopware()->Container()->get('paypal_unified.payment_instruction_service'),
Shopware()->Container()->get('dbal_connection'),
Shopware()->Container()->get('snippets'),
$this->getTranslationService()
);
$subscriber = $this->getSubscriber();

$this->updateOrderPaymentId(15, $this->getUnifiedPaymentId());
$this->insertTestData();
Expand All @@ -132,6 +109,63 @@ public function test_onBeforeRenderDocument_handleDocument()
static::assertNotNull($view->getVariable('PayPalUnifiedInvoiceInstruction'));
}

public function test_onFilterMailVariables(): void
{
$subscriber = $this->getSubscriber();
$args = new \Enlight_Event_EventArgs();

$template = [
'additional' => [
'payment' => [
'name' => 'SwagPaymentPayPalUnified',
'additionaldescription' => '{link file="frontend/_public/src/img/sidebar-paypal-generic.png" fullPath}',
],
],
];

$args->setReturn($template);
$result = $subscriber->onFilterMailVariables($args);

static::assertStringEndsWith(
'custom/plugins/SwagPaymentPayPalUnified/Resources/views/frontend/_public/src/img/sidebar-paypal-generic.png',
$result['additional']['payment']['additionaldescription']
);
}

public function test_onFilterMailVariables_shouldNotBeRendered(): void
{
$subscriber = $this->getSubscriber();
$args = new \Enlight_Event_EventArgs();

$template = [
'additional' => [
'payment' => [
'name' => 'SomeOtherPaymentMethod',
'additionaldescription' => '{link file="frontend/_public/src/img/sidebar-paypal-generic.png" fullPath}',
],
],
];

$args->setReturn($template);
$result = $subscriber->onFilterMailVariables($args);

static::assertStringEndsWith(
'{link file="frontend/_public/src/img/sidebar-paypal-generic.png" fullPath}',
$result['additional']['payment']['additionaldescription']
);
}

private function getSubscriber(): Invoice
{
return new Invoice(
Shopware()->Container()->get('paypal_unified.payment_instruction_service'),
Shopware()->Container()->get('dbal_connection'),
Shopware()->Container()->get('snippets'),
$this->getTranslationService(),
Shopware()->Container()->get('template')
);
}

private function insertTestData()
{
$instructions = new PaymentInstruction();
Expand Down
10 changes: 8 additions & 2 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@
<compatibility minVersion="5.2.0" maxVersion="5.99.99"/>

<changelog version="REPLACE-GLOBAL-WITH-NEXT-VERSION">
<changes lang="de">PT-11575 - Javascript auf der Bestellbestätigungsseite verbessert, wenn der In-Context Modus benutzt wird;</changes>
<changes lang="en">PT-11575 - Improve Javascript on confirm page, if in-context mode is used;</changes>
<changes lang="de">
PT-10536 - Beseitigt einen Fehler in der Bestellbestätigungsmail.
PT-11575 - Javascript auf der Bestellbestätigungsseite verbessert, wenn der In-Context Modus benutzt wird;
</changes>
<changes lang="en">
PT-10536 - Corrects an error in the order confirmation mail.
PT-11575 - Improve Javascript on confirm page, if in-context mode is used;
</changes>
</changelog>

<changelog version="2.6.5">
Expand Down

0 comments on commit 3ca5ce4

Please sign in to comment.