-
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 6 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
8.0 | ||
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 | ||
{ | ||
|
@@ -37,8 +38,9 @@ public function __construct( | |
|
||
public function __invoke(string $orderNumber, \DateTimeInterface $dateTime): void | ||
{ | ||
/** @var OrderInterface $order */ | ||
$order = $this->orderRepository->findOneByNumber($orderNumber); | ||
/** @var OrderInterface|null $order */ | ||
$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.
This file should be removed