-
-
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
[Inventory] Inventory back to stock after order cancellation #6192
[Inventory] Inventory back to stock after order cancellation #6192
Conversation
tuka217
commented
Sep 23, 2016
Q | A |
---|---|
Bug fix? | no |
New feature? | yes |
BC breaks? | no |
Related tickets | - |
License | MIT |
|
||
@todo | ||
Scenario: Verify the reserved inventory is back in stock after order cancellation by customer | ||
Given the customer canceled this order |
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.
Given the order "#22" was canceled
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.
And if we still prefer british english - cancelled
:)
Scenario: Verify the reserved inventory is back in stock after order cancellation by customer | ||
Given the customer canceled this order | ||
When I view all variants of the product "T-shirt banana" | ||
And this variant should have 0 items on hold |
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.
Then
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 would also add a check for onHand
here.
|
||
@todo | ||
Scenario: Verify the reserved inventory is back in stock after order cancellation | ||
When I cancel this order |
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.
When I cancel order XXX
Scenario: Verify the reserved inventory is back in stock after order cancellation | ||
When I cancel this order | ||
And I view all variants of the product "T-shirt banana" | ||
And this variant should have 0 items on hold |
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 variant
is unknown :)
We should also add scenarios when we buy more that one item, to verify all items are back in stock. |
aece5a4
to
8537054
Compare
42556a3
to
abe7331
Compare
abe7331
to
25400f0
Compare
@@ -440,7 +441,10 @@ public function thisOrderIsAlreadyPaid(OrderInterface $order) | |||
|
|||
/** | |||
* @Given /^the customer canceled (this order)$/ |
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.
Since you're double elling stuff, might as well do it here and in the method's name.
} | ||
|
||
if ('paid' === $order->getPaymentState()) { | ||
|
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.
Unnecessary empty line.
} | ||
|
||
Assert::greaterThanEq( | ||
($variant->getOnHold() - $orderItem->getQuantity()), |
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.
You're using ::getOnHold/Hand
a lot. How 'bout putting those in variables?
continue; | ||
} | ||
|
||
if ('cancelled' === $order->getState() && 'paid' !== $order->getPaymentState()) { |
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.
It seems that the 2nd check will always be fulfilled as you check for the opposite a couple of lines up.
b957964
to
ca4dea3
Compare
And I am logged in as an administrator | ||
|
||
@ui | ||
Scenario: Verify the reserved inventory is back in stock after order cancellation |
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.
after cancellation of a new order
And this variant should have 0 items on hold | ||
|
||
@ui | ||
Scenario: Verify the reserved inventory and quantity of product's items is back in stock after order cancellation |
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.
after cancellation of a paid order
continue; | ||
} | ||
} | ||
} |
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 method should be splitted into 2: hold
and release
.
hold
method will have the same logic as previous decrease
in OnHoldQuantityUpdater
(see this) and should be called on checkout complete transition (no need to check the order state in the method).
release
method should be called on before cancel transition and have the following logic: If order payment state is paid
then onHand++
otherwise onHold--
.
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.
Ok, but when we decrease onHold and onHand when order go from new to paid? Now it is done by OrderInventoryHandler which should be removed.
continue; | ||
} | ||
|
||
Assert::greaterThanEq( |
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.
How about creating a custom exception something like InventoryOperationException
?
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.
In next iteration
ca4dea3
to
0e76d71
Compare
|
||
return; | ||
} | ||
$this->release($order); |
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.
Missing a blank line above.
$variant = $orderItem->getVariant(); | ||
|
||
if ($variant->isTracked()) { | ||
|
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.
Not needed blank line.
|
||
if ($variant->isTracked()) { | ||
|
||
Assert::greaterThanEq( |
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.
The more specific exception than \InvalidArgumentException
would be nicer to work with.
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.
As I wrote above in next iteration
*/ | ||
public function hold(OrderInterface $order) | ||
{ | ||
/** @var OrderItemInterface $orderItem */ |
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.
foreach ($order->getItems() as $orderItem) {
$variant = $orderItem->getVariant();
if ($variant->isTracked()) {
// ...
}
}
is used quite often in this class, we might extract it to method returning an array of all tracked order item or a method executing a callback on every tracked order item.
Something like this:
foreach ($this->getTrackedOrderItems($order) as $orderItem) {
// ...
}
Or just use the early continue
to lower the nesting level:
foreach ($order->getItems() as $orderItem) {
$variant = $orderItem->getVariant();
if (!$variant->isTracked()) {
continue;
}
// ...
}
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.
Early continue is fine, but only for hold
and giveBack
|
||
$this->shouldThrow(\InvalidArgumentException::class)->during('sell', [$order]); | ||
} | ||
} |
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.
Missing blank line at the end.
$variant->getOnHold()->willReturn(10); | ||
$variant->getOnHand()->willReturn(10); | ||
|
||
|
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.
Doubled blank line.
* | ||
* @author Anna Walasek <anna.walasek@lakion.com> | ||
*/ | ||
final class OrderInventoryOperatorSpec extends ObjectBehavior |
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.
It misses specs for ignoring variants that aren't tracked.
…their implementation
[CoreBundle] Add callbacks with OrderInventoryOperator in state_machines and add its declaration in services.xml
0e76d71
to
5fc3919
Compare
Great work Ania! 👍 |
Given there is a customer "john.doe@gmail.com" that placed an order "#00000022" | ||
And the customer bought 3 items of "Green" variant of product "T-shirt banana" | ||
And the customer chose "Free" shipping method to "United States" with "Cash on Delivery" payment | ||
And I cancelled the order "#00000022" |
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.
And the order "#00000022" was cancelled
- is more apropriate
* @Given /^(this order) was cancelled$/ | ||
* @Given the order :order was cancelled | ||
* @Given I cancelled the order :order | ||
* @Given /^I cancelled (this order)$/ |
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.
"Given I did something" steps should be removed
[Inventory] Inventory back to stock after order cancellation