Skip to content

Commit

Permalink
Merge branch '1.0' into 2.0
Browse files Browse the repository at this point in the history
* 1.0:
  Add a note about moving configuration files
  Reorganize directory structure
  [Admin] Replace custom invoice_channel filter with entity filter from GridBundle
  [Admin] Remove unneeded route + grid improvements
  Fix and make consistent the translation keys
  Minor clean ups
  Minor refactor SendInvoiceEmailHandler
  Minor refactor GenerateInvoicesCommand
  [CI] Update builds' matrix
  • Loading branch information
GSadee committed Nov 20, 2024
2 parents d724aaf + 2fde725 commit b8deb58
Show file tree
Hide file tree
Showing 144 changed files with 145 additions and 274 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ sylius_invoicing_plugin_invoice:
permission: true
vars:
all:
subheader: sylius_invoicing_plugin.ui.manage_invoices
subheader: sylius_invoicing.ui.manage_invoices
index:
icon: inbox
type: sylius.resource
Expand Down
File renamed without changes
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ sylius_invoicing_plugin_invoice:
permission: true
vars:
all:
subheader: sylius_invoicing_plugin.ui.manage_invoices
subheader: sylius_invoicing.ui.manage_invoices
index:
icon: inbox
type: sylius.resource
Expand All @@ -34,13 +34,3 @@ sylius_invoicing_plugin_admin_invoice_resend:
methods: [GET]
defaults:
_controller: sylius_invoicing_plugin.ui.action.resend_invoice

sylius_invoicing_admin_order_show_by_number:
path: /orders/by-number/{number}
methods: [GET]
defaults:
_controller: Sylius\InvoicingPlugin\Ui\RedirectToOrderShowAction
_sylius:
section: admin
permission: true
alias: invoicing_plugin
24 changes: 12 additions & 12 deletions src/Resources/config/config.yml → config/config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
imports:
- { resource: "@SyliusInvoicingPlugin/Resources/config/app/winzou_state_machine.php" }
- { resource: 'app/twig_hooks/**/*.yaml' }
- { resource: '@SyliusInvoicingPlugin/config/twig_hooks/**/*.yaml' }
- { resource: '@SyliusInvoicingPlugin/config/winzou_state_machine.php' }

parameters:
sylius_invoicing.invoice_save_path: "%kernel.project_dir%/private/invoices/"
Expand All @@ -23,8 +23,6 @@ knp_snappy:

sylius_grid:
templates:
filter:
invoice_channel: '@SyliusInvoicingPlugin/admin/invoice/index/grid/filter/channel.html.twig'
action:
download: '@SyliusInvoicingPlugin/admin/shared/action/download.html.twig'
grids:
Expand All @@ -38,14 +36,14 @@ sylius_grid:
fields:
number:
type: string
label: sylius_invoicing_plugin.ui.invoice_number
label: sylius_invoicing.ui.invoice_number
sortable: true
orderNumber:
type: twig
label: sylius.ui.order
path: order.number
path: order
options:
template: '@SyliusInvoicingPlugin/admin/invoice/index/grid/field/order_number.html.twig'
template: "@SyliusAdmin/shared/grid/field/order_number.html.twig"
sortable: order.number
channel:
type: twig
Expand All @@ -61,25 +59,27 @@ sylius_grid:
template: "@SyliusAdmin/order/grid/field/order_total.html.twig"
issuedAt:
type: datetime
label: sylius_invoicing_plugin.ui.issued_at
label: sylius_invoicing.ui.issued_at
options:
format: 'Y-m-d H:i:s'
sortable: true
filters:
orderNumber:
type: string
label: sylius_invoicing_plugin.ui.order_number
label: sylius_invoicing.ui.order_number
options:
fields: [order.number]
number:
type: string
label: sylius_invoicing_plugin.ui.invoice_number
label: sylius_invoicing.ui.invoice_number
issuedAt:
type: date
label: sylius_invoicing_plugin.ui.issued_at
label: sylius_invoicing.ui.issued_at
channel:
type: invoice_channel
type: entity
label: sylius.ui.channel
form_options:
class: "%sylius.model.channel.class%"
actions:
item:
show:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/Resources/config/services.xml → config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</imports>

<parameters>
<parameter key="default_logo_file">@SyliusInvoicingPlugin/Resources/assets/sylius-logo.png</parameter>
<parameter key="default_logo_file">@SyliusInvoicingPlugin/assets/sylius-logo.png</parameter>
<parameter key="sylius.invoicing.template.logo_file">%env(default:default_logo_file:resolve:SYLIUS_INVOICING_LOGO_FILE)%</parameter>
</parameters>

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions config/services/ui.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>

<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<defaults public="true" />

<service id="sylius_invoicing_plugin.ui.menu.admin_menu_listener" class="Sylius\InvoicingPlugin\Ui\Menu\AdminMenuListener">
<tag name="kernel.event_listener" event="sylius.menu.admin.main" method="__invoke" />
</service>
</services>
</container>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions src/Resources/config/validation.xml → config/validation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,39 @@
<class name="Sylius\InvoicingPlugin\Entity\ShopBillingData">
<property name="company">
<constraint name="NotBlank">
<option name="message">sylius_admin_order_creation.channel.company.not_blank</option>
<option name="message">sylius_invoicing.channel.company.not_blank</option>
<option name="groups">
<value>sylius</value>
</option>
</constraint>
</property>
<property name="taxId">
<constraint name="NotBlank">
<option name="message">sylius_admin_order_creation.channel.taxId.not_blank</option>
<option name="message">sylius_invoicing.channel.taxId.not_blank</option>
<option name="groups">sylius</option>
</constraint>
</property>
<property name="street">
<constraint name="NotBlank">
<option name="message">sylius_admin_order_creation.channel.street.not_blank</option>
<option name="message">sylius_invoicing.channel.street.not_blank</option>
<option name="groups">sylius</option>
</constraint>
</property>
<property name="city">
<constraint name="NotBlank">
<option name="message">sylius_admin_order_creation.channel.city.not_blank</option>
<option name="message">sylius_invoicing.channel.city.not_blank</option>
<option name="groups">sylius</option>
</constraint>
</property>
<property name="postcode">
<constraint name="NotBlank">
<option name="message">sylius_admin_order_creation.channel.postcode.not_blank</option>
<option name="message">sylius_invoicing.channel.postcode.not_blank</option>
<option name="groups">sylius</option>
</constraint>
</property>
<property name="countryCode">
<constraint name="NotBlank">
<option name="message">sylius_admin_order_creation.channel.countryCode.not_blank</option>
<option name="message">sylius_invoicing.channel.countryCode.not_blank</option>
<option name="groups">sylius</option>
</constraint>
</property>
Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions docs/legacy_installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@

```yaml
imports:
- { resource: "@SyliusInvoicingPlugin/Resources/config/config.yml" }
- { resource: '@SyliusInvoicingPlugin/config/config.yaml' }
```
1. Import routing:
```yaml
sylius_invoicing_plugin_admin:
resource: "@SyliusInvoicingPlugin/Resources/config/app/routing/admin_invoicing.yml"
prefix: /admin
resource: '@SyliusInvoicingPlugin/config/admin_routes.yaml'
prefix: '/%sylius_admin.path_name%'
sylius_invoicing_plugin_shop:
resource: "@SyliusInvoicingPlugin/Resources/config/app/routing/shop_invoicing.yml"
resource: '@SyliusInvoicingPlugin/config/shop_routes.yaml'
prefix: /{_locale}
requirements:
_locale: ^[a-z]{2}(?:_[A-Z]{2})?$
Expand All @@ -46,7 +46,7 @@
enabled: true
binary: /usr/local/bin/wkhtmltopdf # Change this! :)
options: []
```
```
1. Apply migrations to your database:
Expand Down
45 changes: 38 additions & 7 deletions spec/CommandHandler/SendInvoiceEmailHandlerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace spec\Sylius\InvoicingPlugin\CommandHandler;

use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Sylius\Component\Core\Model\CustomerInterface;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Repository\OrderRepositoryInterface;
Expand Down Expand Up @@ -41,16 +42,45 @@ function it_requests_an_email_with_an_invoice_to_be_sent(
CustomerInterface $customer,
): void {
$orderRepository->findOneByNumber('0000001')->willReturn($order);

$invoiceRepository->findOneByOrder($order)->willReturn($invoice);

$order->getCustomer()->willReturn($customer);

$customer->getEmail()->willReturn('[email protected]');
$invoiceRepository->findOneByOrder($order)->willReturn($invoice);

$emailSender->sendInvoiceEmail($invoice, '[email protected]')->shouldBeCalled();

$this->__invoke(new SendInvoiceEmail('0000001', new \DateTime('now')));
$this(new SendInvoiceEmail('0000001'));
}

function it_does_not_request_an_email_to_be_sent_if_order_was_not_found(
InvoiceRepositoryInterface $invoiceRepository,
OrderRepositoryInterface $orderRepository,
InvoiceEmailSenderInterface $emailSender,
CustomerInterface $customer,
): void {
$orderRepository->findOneByNumber('0000001')->willReturn(null);

$invoiceRepository->findOneByOrder(Argument::any())->shouldNotBeCalled();
$customer->getEmail()->shouldNotBeCalled();
$emailSender->sendInvoiceEmail(Argument::any(), Argument::any())->shouldNotBeCalled();

$this(new SendInvoiceEmail('0000001'));
}

function it_does_not_request_an_email_to_be_sent_if_customer_was_not_found(
InvoiceRepositoryInterface $invoiceRepository,
OrderRepositoryInterface $orderRepository,
InvoiceEmailSenderInterface $emailSender,
OrderInterface $order,
CustomerInterface $customer,
): void {
$orderRepository->findOneByNumber('0000001')->willReturn($order);
$order->getCustomer()->willReturn(null);

$invoiceRepository->findOneByOrder($order)->shouldNotBeCalled();
$customer->getEmail()->shouldNotBeCalled();
$emailSender->sendInvoiceEmail(Argument::any(), Argument::any())->shouldNotBeCalled();

$this(new SendInvoiceEmail('0000001'));
}

function it_does_not_request_an_email_to_be_sent_if_invoice_was_not_found(
Expand All @@ -61,11 +91,12 @@ function it_does_not_request_an_email_to_be_sent_if_invoice_was_not_found(
CustomerInterface $customer,
): void {
$orderRepository->findOneByNumber('0000001')->willReturn($order);
$order->getCustomer()->willReturn($customer);
$invoiceRepository->findOneByOrder($order)->willReturn(null);

$order->getCustomer()->shouldNotBeCalled();
$customer->getEmail()->shouldNotBeCalled();
$emailSender->sendInvoiceEmail(Argument::any(), Argument::any())->shouldNotBeCalled();

$this->__invoke(new SendInvoiceEmail('0000001', new \DateTime('now')));
$this(new SendInvoiceEmail('0000001'));
}
}
2 changes: 1 addition & 1 deletion spec/EventProducer/OrderPlacedProducerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
namespace spec\Sylius\InvoicingPlugin\EventProducer;

use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\UnitOfWork;
use Doctrine\Persistence\Event\LifecycleEventArgs;
use Mockery;
use Mockery\MockInterface;
use PhpSpec\ObjectBehavior;
Expand Down
4 changes: 2 additions & 2 deletions spec/Generator/InvoicePdfFileGeneratorSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function let(
$fileLocator,
$invoiceFileNameGenerator,
'invoiceTemplate.html.twig',
'@SyliusInvoicingPlugin/Resources/assets/sylius-logo.png',
'@SyliusInvoicingPlugin/assets/sylius-logo.png',
);
}

Expand All @@ -53,7 +53,7 @@ function it_creates_invoice_pdf_with_generated_content_and_filename_basing_on_in
$invoiceFileNameGenerator->generateForPdf($invoice)->willReturn('2015_05_00004444.pdf');
$invoice->channel()->willReturn($channel);

$fileLocator->locate('@SyliusInvoicingPlugin/Resources/assets/sylius-logo.png')->willReturn('located-path/sylius-logo.png');
$fileLocator->locate('@SyliusInvoicingPlugin/assets/sylius-logo.png')->willReturn('located-path/sylius-logo.png');

$twigToPdfGenerator
->generate('invoiceTemplate.html.twig', ['invoice' => $invoice, 'channel' => $channel, 'invoiceLogoPath' => 'located-path/sylius-logo.png'])
Expand Down
18 changes: 8 additions & 10 deletions src/Cli/GenerateInvoicesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@

use Sylius\Component\Core\Repository\OrderRepositoryInterface;
use Sylius\InvoicingPlugin\Creator\MassInvoicesCreatorInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(
name: 'sylius-invoicing:generate-invoices',
description: 'Generates invoices for orders placed before InvoicingPlugin installation',
)]
final class GenerateInvoicesCommand extends Command
{
protected static $defaultName = 'sylius-invoicing:generate-invoices';

public function __construct(
private readonly MassInvoicesCreatorInterface $massInvoicesCreator,
private readonly OrderRepositoryInterface $orderRepository,
Expand All @@ -37,18 +40,13 @@ public function execute(InputInterface $input, OutputInterface $output): int
->createListQueryBuilder()
->andWhere('o.number IS NOT NULL')
->getQuery()
->getResult();
->getResult()
;

$this->massInvoicesCreator->__invoke($orders);

$output->writeln('Invoices generated successfully');

return 0;
}

protected function configure(): void
{
$this->setName(self::$defaultName);
$this->setDescription('Generates invoices for orders placed before InvoicingPlugin installation');
return Command::SUCCESS;
}
}
17 changes: 10 additions & 7 deletions src/CommandHandler/SendInvoiceEmailHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,23 @@ public function __construct(

public function __invoke(SendInvoiceEmail $command): void
{
/** @var OrderInterface $order */
/** @var OrderInterface|null $order */
$order = $this->orderRepository->findOneByNumber($command->orderNumber());
if (null === $order) {
return;
}

/** @var InvoiceInterface|null $invoice */
$invoice = $this->invoiceRepository->findOneByOrder($order);

if (null === $invoice) {
$customer = $order->getCustomer();
if (null === $customer) {
return;
}

if (null === $order->getCustomer()) {
/** @var InvoiceInterface|null $invoice */
$invoice = $this->invoiceRepository->findOneByOrder($order);
if (null === $invoice) {
return;
}

$this->emailSender->sendInvoiceEmail($invoice, $order->getCustomer()->getEmail());
$this->emailSender->sendInvoiceEmail($invoice, $customer->getEmail());
}
}
4 changes: 2 additions & 2 deletions src/DependencyInjection/SyliusInvoicingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final class SyliusInvoicingExtension extends AbstractResourceExtension implement

public function load(array $configs, ContainerBuilder $container): void
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../../config'));
$loader->load('services.xml');

/** @var ConfigurationInterface $configuration */
Expand Down Expand Up @@ -55,7 +55,7 @@ protected function getMigrationsNamespace(): string

protected function getMigrationsDirectory(): string
{
return '@SyliusInvoicingPlugin/Migrations';
return '@SyliusInvoicingPlugin/src/Migrations';
}

protected function getNamespacesOfMigrationsExecutedBefore(): array
Expand Down
Loading

0 comments on commit b8deb58

Please sign in to comment.