Skip to content

Commit

Permalink
Release 2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
vttn committed Jan 21, 2021
1 parent fa5eaa0 commit 25f1ece
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 56 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 2.1.0
- Fix email issues

# 2.0.0
- Fix cart recreation on promotions
- Remove availability rules
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG_de-DE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 2.1.0
- E-Mail-Probleme behoben

# 2.0.0
- Warenkorb-Wiederherstellung bei Werbeaktionen korrigiert
- Verfügbarkeitsregeln entfernt
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ tail -f var/log/postfinancecheckout_payment*.log

## Documentation

[Documentation](https://plugin-documentation.postfinance-checkout.ch/pfpayments/shopware-6/2.0.0/docs/en/documentation.html)
[Documentation](https://plugin-documentation.postfinance-checkout.ch/pfpayments/shopware-6/2.1.0/docs/en/documentation.html)

## License

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@
"postfinancecheckout/sdk": "2.1.6"
},
"type": "shopware-platform-plugin",
"version": "2.0.0"
"version": "2.1.0"
}
2 changes: 1 addition & 1 deletion docs/en/documentation.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ <h2>Documentation</h2> </div>
</a>
</li>
<li>
<a href="https://github.com/pfpayments/shopware-6/releases/tag/2.0.0/">
<a href="https://github.com/pfpayments/shopware-6/releases/tag/2.1.0/">
Source
</a>
</li>
Expand Down
120 changes: 67 additions & 53 deletions src/Core/Api/Transaction/Service/OrderMailService.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
use Shopware\Core\{
Checkout\Cart\Event\CheckoutOrderPlacedEvent,
Checkout\Cart\Exception\OrderNotFoundException,
Checkout\Order\OrderEntity,
Content\MailTemplate\MailTemplateEntity,
Expand All @@ -13,7 +14,9 @@
Framework\Context,
Framework\DataAbstractionLayer\Search\Criteria,
Framework\DataAbstractionLayer\Search\Filter\EqualsFilter,
Framework\Validation\DataBag\DataBag,
Framework\DataAbstractionLayer\Search\Filter\NotFilter,
Framework\DataAbstractionLayer\Search\Filter\OrFilter,
Framework\Event\EventAction\EventActionCollection,
System\SalesChannel\SalesChannelEntity};
use PostFinanceCheckoutPayment\Core\{
Api\Transaction\Entity\TransactionEntity,
Expand Down Expand Up @@ -74,9 +77,8 @@ public function setLogger(LoggerInterface $logger): void
/**
* @param string $orderId
* @param \Shopware\Core\Framework\Context $context
* @param string $technicalName
*/
public function send(string $orderId, Context $context, string $technicalName = MailTemplateTypes::MAILTYPE_ORDER_CONFIRM): void
public function send(string $orderId, Context $context): void
{
try {

Expand Down Expand Up @@ -104,9 +106,11 @@ public function send(string $orderId, Context $context, string $technicalName =
self::EMAIL_ORIGIN_IS_POSTFINANCECHECKOUT => true,
];

$data = $this->getData($order, $context, $technicalName);
$data = $this->getData($order, $context);

$this->mailService->send($data->all(), $context, $templateData);
foreach ($data as $datum){
$this->mailService->send($datum, $context, $templateData);
}
$this->markTransactionEntityConfirmationEmailAsSent($orderId, $context);


Expand Down Expand Up @@ -168,73 +172,83 @@ protected function getOrder(string $orderId, Context $context): OrderEntity
return $order;
}


/**
* @param \Shopware\Core\Checkout\Order\OrderEntity $order
* @param \Shopware\Core\Framework\Context $context
*
* @return mixed
* @return array
*/
protected function getSalesChannel(OrderEntity $order, Context $context): SalesChannelEntity
protected function getData(OrderEntity $order, Context $context): array
{
$languageId = $order->getLanguageId();
$salesChannelCriteria = new Criteria([$order->getSalesChannel()->getId()]);
$salesChannelCriteria->getAssociation('domains')
->addFilter(
new EqualsFilter('languageId', $languageId)
);
return $this->container->get('sales_channel.repository')->search($salesChannelCriteria, $context)->first();
}
$data = [];

/**
* @var
*/
/** @var \Shopware\Core\Framework\Event\EventAction\EventActionCollection $eventActionEntities */
$eventActionEntities = $this->getBusinessEvents($order, $context);
$customerRecipient = [
$order->getOrderCustomer()->getEmail() => $order->getOrderCustomer()->getFirstName() . ' ' . $order->getOrderCustomer()->getLastName(),
];

/**
* @param \Shopware\Core\Checkout\Order\OrderEntity $order
* @param \Shopware\Core\Framework\Context $context
* @param string $technicalName
*
* @return \Shopware\Core\Framework\Validation\DataBag\DataBag
*/
protected function getData(OrderEntity $order, Context $context, string $technicalName): DataBag
{
$mailTemplate = $this->getMailTemplate($order, $context, $technicalName, true);
$data = new DataBag();
$data->add([
'recipients' => [$order->getOrderCustomer()->getEmail() => $order->getOrderCustomer()->getFirstName() . ' ' . $order->getOrderCustomer()->getLastName(),],
'senderName' => $mailTemplate->getTranslation('senderName'),
'salesChannelId' => $order->getSalesChannelId(),
'templateId' => $mailTemplate->getId(),
'customFields' => $mailTemplate->getCustomFields(),
'contentHtml' => $mailTemplate->getTranslation('contentHtml'),
'contentPlain' => $mailTemplate->getTranslation('contentPlain'),
'subject' => $mailTemplate->getTranslation('subject'),
]);
foreach ($eventActionEntities as $eventActionEntity) {

$eventConfig = $eventActionEntity->getConfig();
$mailTemplateId = $eventConfig['mail_template_id'];
$recipients = !empty($eventConfig['recipients']) ? $eventConfig['recipients'] : $customerRecipient;
$mailTemplate = $this->getMailTemplateById($context, $mailTemplateId);

$data[] = [
'recipients' => $recipients,
'senderName' => $mailTemplate->getTranslation('senderName'),
'salesChannelId' => $order->getSalesChannelId(),
'templateId' => $mailTemplateId,
'customFields' => $mailTemplate->getCustomFields(),
'contentHtml' => $mailTemplate->getTranslation('contentHtml'),
'contentPlain' => $mailTemplate->getTranslation('contentPlain'),
'subject' => $mailTemplate->getTranslation('subject'),
];
}

return $data;
}

protected function getBusinessEvents(OrderEntity $order, Context $context): EventActionCollection
{
$criteria = (new Criteria())
->addAssociations([
'rules',
'salesChannels',
])
->addFilter(new EqualsFilter('eventName', CheckoutOrderPlacedEvent::EVENT_NAME))
->addFilter(new EqualsFilter('active', true))
->addFilter(new NotFilter(NotFilter::CONNECTION_AND, [new EqualsFilter('config.mail_template_id', null)]))
->addFilter(new OrFilter([
new EqualsFilter('salesChannels.id', $order->getSalesChannelId()),
new EqualsFilter('salesChannels.id', null),
]));


/** @var EventActionCollection $events */
$events = $this->container->get('event_action.repository')
->search($criteria, $context)
->getEntities();
return $events;
}

/**
* @param \Shopware\Core\Checkout\Order\OrderEntity $order
* @param \Shopware\Core\Framework\Context $context
* @param string $technicalName
* @param bool $filterBySalesChannelId
* @param \Shopware\Core\Framework\Context $context
* @param string $id
*
* @return \Shopware\Core\Content\MailTemplate\MailTemplateEntity
*/
protected function getMailTemplate(OrderEntity $order, Context $context, string $technicalName, bool $filterBySalesChannelId = true): MailTemplateEntity
protected function getMailTemplateById(Context $context, string $id): MailTemplateEntity
{
$criteria = (new Criteria())->addFilter(new EqualsFilter('mailTemplateType.technicalName', $technicalName))
->addAssociation('media.media')
->setLimit(1);

if ($filterBySalesChannelId && !empty($order->getSalesChannelId())) {
$criteria->addFilter(
new EqualsFilter('mail_template.salesChannels.salesChannel.id', $order->getSalesChannelId())
);
}
$criteria = (new Criteria([$id]))->addAssociations(['media', 'media.media', 'salesChannels', 'mailTemplateType']);

$mailTemplateEntity = $this->container->get('mail_template.repository')->search($criteria, $context)->first();
if (empty($mailTemplateEntity) && $filterBySalesChannelId) {
return $this->getMailTemplate($order, $context, $technicalName, false);
}

return $mailTemplateEntity;
}

Expand Down

0 comments on commit 25f1ece

Please sign in to comment.