Skip to content
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

Merged
merged 3 commits into from
Sep 28, 2016

Conversation

tuka217
Copy link
Contributor

@tuka217 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
Copy link
Contributor

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

Copy link
Member

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then

Copy link
Contributor

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
Copy link
Contributor

@michalmarcinkowski michalmarcinkowski Sep 23, 2016

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this variant is unknown :)

@michalmarcinkowski
Copy link
Contributor

We should also add scenarios when we buy more that one item, to verify all items are back in stock.

@tuka217 tuka217 force-pushed the order-cancelation-inventory branch 4 times, most recently from aece5a4 to 8537054 Compare September 23, 2016 15:47
@tuka217 tuka217 force-pushed the order-cancelation-inventory branch 2 times, most recently from 42556a3 to abe7331 Compare September 26, 2016 09:26
@tuka217 tuka217 changed the title [WIP][Inventory] Inventory back to stock after order cancellation [Inventory] Inventory back to stock after order cancellation Sep 26, 2016
@@ -440,7 +441,10 @@ public function thisOrderIsAlreadyPaid(OrderInterface $order)

/**
* @Given /^the customer canceled (this order)$/
Copy link
Contributor

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()) {

Copy link
Contributor

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()),
Copy link
Contributor

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()) {
Copy link
Contributor

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.

@tuka217 tuka217 force-pushed the order-cancelation-inventory branch 2 times, most recently from b957964 to ca4dea3 Compare September 26, 2016 10:47
And I am logged in as an administrator

@ui
Scenario: Verify the reserved inventory is back in stock after order cancellation
Copy link
Contributor

@michalmarcinkowski michalmarcinkowski Sep 27, 2016

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
Copy link
Contributor

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;
}
}
}
Copy link
Contributor

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--.

Copy link
Contributor Author

@tuka217 tuka217 Sep 27, 2016

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(
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In next iteration


return;
}
$this->release($order);
Copy link
Contributor

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()) {

Copy link
Contributor

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(
Copy link
Contributor

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.

Copy link
Contributor Author

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 */
Copy link
Contributor

@pamil pamil Sep 28, 2016

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;
    }

    // ...
}

Copy link
Contributor Author

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]);
}
}
Copy link
Contributor

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);


Copy link
Contributor

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
Copy link
Contributor

@pamil pamil Sep 28, 2016

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.

tuka217 and others added 3 commits September 28, 2016 15:00
[CoreBundle] Add callbacks with OrderInventoryOperator in state_machines and add its declaration in services.xml
@michalmarcinkowski michalmarcinkowski merged commit 4a6e557 into Sylius:master Sep 28, 2016
@michalmarcinkowski
Copy link
Contributor

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"
Copy link
Contributor

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)$/
Copy link
Contributor

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

pamil pushed a commit to pamil/Sylius that referenced this pull request May 7, 2019
[Inventory] Inventory back to stock after order cancellation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants