-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Fix unexpected error about not enough stocks while completing the payment in the Admin Panel #15688
Conversation
jakubtobiasz
commented
Dec 30, 2023
•
edited by GSadee
Loading
edited by GSadee
Q | A |
---|---|
Branch? | 1.12 |
Bug fix? | yes |
New feature? | no |
BC breaks? | no |
Deprecations? | no |
Related tickets | #16160 |
License | MIT |
…ment in the Admin Panel
Bunnyshell Preview Environment deployedIt will be automatically stopped in 4 hours. Use the command
Available commands:
|
return false; | ||
} | ||
|
||
if ($variant->getOnHand() - $quantity < 0) { |
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.
I'm not sure, but I feel that we should only check onHold
. However, what happens if someone orders a product variant and, before completing this order, the administrator activates tracking for this variant?
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 logic comes from the \Sylius\Component\Core\Inventory\Operator\OrderInventoryOperator::sell
method.
<?php
// ...
Assert::greaterThanEq(
($variant->getOnHold() - $orderItem->getQuantity()),
0,
sprintf(
'Not enough units to decrease on hold quantity from the inventory of a variant "%s".',
$variant->getName(),
),
);
Assert::greaterThanEq(
($variant->getOnHand() - $orderItem->getQuantity()),
0,
sprintf(
'Not enough units to decrease on hand quantity from the inventory of a variant "%s".',
$variant->getName(),
),
);
// ...
So both values are checked, same as in the example above. If you hold
a variant, the onHand
value is not decreased.
1. There're 4 socks in stock (onHand: 4, onHold: 0)
2. You buy 2 socks with using the offline payment method (onHand: 4, onHold 2)
3. As an admin you complete the payment (onHand: 2, onHold: 0)
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.
However, what happens if someone orders a product variant and, before completing this order, the administrator activates tracking for this variant?
I guess we have to think about it, as currently it'll throw an exception. We'll discuss it on the daily meeting, and create a task if needed.
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 onHand/onHold pre-sell check logic feels important enough to varant it's own checker.
For example, why not add new method canBeSold
to
public function sell(OrderInterface $order): void |
OrderInventoryChecker
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.
I think it needs a bit of work.
Because the
Assert::greaterThanEq( |
Assert::greaterThanEq( |
Let me explain:
- On a Variant, stock management is activated
- A customer places an order with this variant
- An administrator deactivates stock management on this variant
- On actions, such as payment, order cancellation, etc., we get a 500 error because the assertion is not correct.
@@ -99,7 +99,6 @@ | |||
</service> | |||
|
|||
<service id="Sylius\Bundle\CoreBundle\EventListener\PaymentPreCompleteListener"> | |||
<argument type="service" id="Sylius\Component\Inventory\Checker\AvailabilityCheckerInterface" /> |
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.
Just in case, can service's argument be removed BC wise?
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.
That's debatable. In theory, it can "break" something in terms of the system might start behaving differently. On the other hand,
- we never bothered about it, as our hands could be tied too much and make Sylius development harder
- our documentation doesn't mention it
- Symfony documentation also doesn't mention anything about it
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.
Something happened with this file,
- file name is not right
- feature/background parts are identical to
finalizing_order_payment.feature
aside from inventory line.
And the "Angel T-Shirt" product's inventory has become tracked with 1 items
Can this line be moved from background to scenario, so original Finalizing order payment
and this feature file could be merged?
Otherwise, please rename file and feature accordingly.
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.
Right, I wanted to just reproduce the bug, I forgot to merge/rename that file.
return false; | ||
} | ||
|
||
if ($variant->getOnHand() - $quantity < 0) { |
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 onHand/onHold pre-sell check logic feels important enough to varant it's own checker.
For example, why not add new method canBeSold
to
public function sell(OrderInterface $order): void |
OrderInventoryChecker
…ing a payment (GSadee) This PR was merged into the 1.12 branch. Discussion ---------- | Q | A |-----------------|----- | Branch? | 1.12 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Related tickets | caused by #15280, fixes #16160, replaces #15688, closes #16258 | License | MIT <!-- - Bug fixes must be submitted against the 1.12 or 1.13 branches - Features and deprecations must be submitted against the 1.14 branch - Features, removing deprecations and BC breaks must be submitted against the 2.0 branch - Make sure that the correct base branch is set To be sure you are not breaking any Backward Compatibilities, check the documentation: https://docs.sylius.com/en/latest/book/organization/backward-compatibility-promise.html --> Commits ------- Fix unexpected error about not enough stocks while completing the payment in the Admin Panel [Behat] Refactor scenarios for finalizing order's payment Add spec for PaymentPreCompleteListener with minor improvements [Behat] Cover scenarios for finalizing order's payment in API [Inventory] Introduce custom exceptions for inventory operations [Behat] Adjust scenario and feature names for finalizing payment with item that has become tracked
I'm closing this ticket as the problem was resolved here: #16307 |