-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Link order generation to state machine #283
base: 1.0
Are you sure you want to change the base?
Changes from 4 commits
1b76e14
a817d69
380941a
7e36063
3ec77e8
f77bc23
3c3a1fd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,19 +34,19 @@ function it_requests_invoices_creation_for_multiple_orders( | |
OrderInterface $secondOrder, | ||
OrderInterface $thirdOrder | ||
): void { | ||
$firstOrder->getNumber()->willReturn('0000001'); | ||
$secondOrder->getNumber()->willReturn('0000002'); | ||
$thirdOrder->getNumber()->willReturn('0000003'); | ||
$firstOrder->getNumber()->willReturn('000001'); | ||
$secondOrder->getNumber()->willReturn('000002'); | ||
$thirdOrder->getNumber()->willReturn('000003'); | ||
|
||
$firstInvoiceDateTime = new \DateTimeImmutable('2019-02-25'); | ||
$secondInvoiceDateTime = new \DateTimeImmutable('2019-02-25'); | ||
$thirdInvoiceDateTime = new \DateTimeImmutable('2019-02-25'); | ||
|
||
$dateTimeProvider->__invoke()->willReturn($firstInvoiceDateTime, $secondInvoiceDateTime, $thirdInvoiceDateTime); | ||
|
||
$invoiceCreator->__invoke('0000001', $firstInvoiceDateTime)->shouldBeCalled(); | ||
$invoiceCreator->__invoke('0000002', $secondInvoiceDateTime)->shouldBeCalled(); | ||
$invoiceCreator->__invoke('0000003', $thirdInvoiceDateTime)->shouldBeCalled(); | ||
$invoiceCreator->__invoke('000001', $firstInvoiceDateTime)->shouldBeCalled(); | ||
$invoiceCreator->__invoke('000002', $secondInvoiceDateTime)->shouldBeCalled(); | ||
$invoiceCreator->__invoke('000003', $thirdInvoiceDateTime)->shouldBeCalled(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
|
||
$this->__invoke([$firstOrder->getWrappedObject(), $secondOrder->getWrappedObject(), $thirdOrder->getWrappedObject()]); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,8 +28,8 @@ function it_requests_invoice_creation(InvoiceCreatorInterface $invoiceCreator): | |
{ | ||
$issuedAt = new \DateTimeImmutable(); | ||
|
||
$invoiceCreator->__invoke('0000001', $issuedAt)->shouldBeCalled(); | ||
$invoiceCreator->__invoke('000001', $issuedAt)->shouldBeCalled(); | ||
|
||
$this(new OrderPlaced('0000001', $issuedAt)); | ||
$this(new OrderPlaced('000001', $issuedAt)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here 😉 |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,15 +13,16 @@ | |
|
||
namespace Sylius\InvoicingPlugin\Creator; | ||
|
||
use Webmozart\Assert\Assert; | ||
use Doctrine\ORM\ORMException; | ||
use Sylius\Component\Core\Model\OrderInterface; | ||
use Sylius\Component\Core\Repository\OrderRepositoryInterface; | ||
use Sylius\InvoicingPlugin\Doctrine\ORM\InvoiceRepositoryInterface; | ||
use Sylius\InvoicingPlugin\Entity\InvoiceInterface; | ||
use Sylius\InvoicingPlugin\Exception\InvoiceAlreadyGenerated; | ||
use Sylius\Component\Core\Repository\OrderRepositoryInterface; | ||
use Sylius\InvoicingPlugin\Generator\InvoiceGeneratorInterface; | ||
use Sylius\InvoicingPlugin\Generator\InvoicePdfFileGeneratorInterface; | ||
use Sylius\InvoicingPlugin\Manager\InvoiceFileManagerInterface; | ||
use Sylius\InvoicingPlugin\Doctrine\ORM\InvoiceRepositoryInterface; | ||
use Sylius\InvoicingPlugin\Generator\InvoicePdfFileGeneratorInterface; | ||
|
||
final class InvoiceCreator implements InvoiceCreatorInterface | ||
{ | ||
|
@@ -38,7 +39,8 @@ public function __construct( | |
public function __invoke(string $orderNumber, \DateTimeInterface $dateTime): void | ||
{ | ||
/** @var OrderInterface $order */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This phpdoc is missing the possibility of |
||
$order = $this->orderRepository->findOneByNumber($orderNumber); | ||
$order = $this->orderRepository->findOneBy(['number' => $orderNumber]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you change that in this PR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because public function findOneByNumber(string $number): ?OrderInterface
{
return $this->createQueryBuilder('o')
->andWhere('o.state != :state')
->andWhere('o.number = :number')
->setParameter('state', OrderInterface::STATE_CART)
->setParameter('number', $number)
->getQuery()
->getOneOrNullResult()
;
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So what is the reason the order is in cart state? Because in the moment of creating an invoice the checkout should be completed and the order shouldn't be in the cart state anymore. I guess, but I'm not sure, there is a difference with the moment of dispatching the event between state machine callback and the doctrine events. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At this moment the order |
||
Assert::notNull($order, sprintf('Order with number "%s" does not exist.', $orderNumber)); | ||
|
||
/** @var InvoiceInterface|null $invoice */ | ||
$invoice = $this->invoiceRepository->findOneByOrder($order); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,13 @@ winzou_state_machine: | |
on: ['complete'] | ||
do: ['@sylius_invoicing_plugin.event_producer.order_payment_paid', '__invoke'] | ||
args: ['object'] | ||
sylius_order_checkout: | ||
callbacks: | ||
after: | ||
sylius_invoicing_plugin_order_placed_producer: | ||
on: ['complete'] | ||
do: ['@sylius_invoicing_plugin.event_producer.order_placed', '__invoke'] | ||
args: ['object'] | ||
Comment on lines
+28
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if it wouldn't be better to put this logic on the callback after There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ping @Prometee There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @GSadee yes it will make the same thing, but one issue will happen here if the $order = $this->orderFactory->createNew();
/* add product, address and select payment, shipping etc */
$this->stateMachineFactory
->get($order, OrderCheckoutTransitions::GRAPH)
->apply(OrderCheckoutTransitions::TRANSITION_COMPLETE)
; The result will be an error on the To solve this, the I know it's a big change and it will make useless triggering the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if I correctly understand you, is there a problem with moving the callback to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. During the
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From my point of view the |
||
|
||
sylius_grid: | ||
templates: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To ease the reviewing of your PR by Sylius core team members, can you revert it by adding the missing zero ?