Skip to content

Instantly share code, notes, and snippets.

@cornobils
Created April 25, 2019 12:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cornobils/7de201968c17574e1a6b6d187d8a6d7b to your computer and use it in GitHub Desktop.
Save cornobils/7de201968c17574e1a6b6d187d8a6d7b to your computer and use it in GitHub Desktop.
Adding link to invoice in Order completed email and making invoice available in public #Sylius #sylius/invoicing-plugin@0.8.3 #Symfony
<?php
declare(strict_types=1);
namespace App\Voter;
use Sylius\Component\Core\Repository\OrderRepositoryInterface;
use Sylius\InvoicingPlugin\Entity\InvoiceInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
use Webmozart\Assert\Assert;
final class InvoiceVoter extends Voter
{
public const ACCESS = 'access';
private const ATTRIBUTES = [self::ACCESS];
/** @var OrderRepositoryInterface */
private $orderRepository;
public function __construct(OrderRepositoryInterface $orderRepository)
{
$this->orderRepository = $orderRepository;
}
protected function supports($attribute, $subject): bool
{
if (!in_array($attribute, self::ATTRIBUTES, true)) {
return false;
}
if (!$subject instanceof InvoiceInterface) {
return false;
}
return true;
}
protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
{
/** @var InvoiceInterface $subject */
Assert::isInstanceOf($subject, InvoiceInterface::class);
return true;
}
}
{# templates/bundles/SyliusShopBundle/Email/orderConfirmation.html.twig #}
{% block subject %}
Order confirmation
{% endblock %}
{% block body %}
{% set url = order.channel.hostname is not null ? 'http://' ~ order.channel.hostname ~ path('sylius_shop_order_show', {'tokenValue': order.tokenValue, '_locale': order.localeCode}) : url('sylius_shop_order_show', {'tokenValue': order.tokenValue, '_locale': order.localeCode}) %}
{% set invoiceUrl = order.channel.hostname is not null ? 'http://' ~ order.channel.hostname ~ url('sylius_invoicing_plugin_shop_invoice_download', {'id': invoice.id}) : url('sylius_invoicing_plugin_shop_invoice_download', {'id': invoice.id}) %}
{% autoescape %}
Your order no. {{ order.number }} has been successfully placed.
<br/>
Your order invoice is available at <a href="{{ invoiceUrl }}">{{ invoiceUrl }}</a><br/>
To view order or change payment method - please visit <a href="{{ url|raw }}">{{ url|raw }}</a>
<br/><br/>
Thank you for shopping at our store!
{% endautoescape %}
{% endblock %}
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Sylius\Bundle\ShopBundle\EmailManager;
use Sylius\Bundle\CoreBundle\Mailer\Emails;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Mailer\Sender\SenderInterface;
final class OrderEmailManager implements OrderEmailManagerInterface
{
/** @var SenderInterface */
private $emailSender;
public function __construct(SenderInterface $emailSender)
{
$this->emailSender = $emailSender;
}
/**
* {@inheritdoc}
*/
public function sendConfirmationEmail(OrderInterface $order): void
{
$this->emailSender->send(Emails::ORDER_CONFIRMATION, [$order->getCustomer()->getEmail()], ['order' => $order]);
}
}
sylius.email_manager.order:
class: App\EmailManager\OrderEmailManager
Sylius\InvoicingPlugin\Security\Voter\InvoiceVoter:
class: App\Voter\InvoiceVoter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment