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

Add on-hold inventory quantity #938

Merged
merged 6 commits into from
Jan 31, 2014

Conversation

umpirsky
Copy link
Contributor

/**
* Set stock on hold.
*
* @return integer
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be @param integer $onHold not @return =)

);
}

if ($payment::STATE_COMPLETED !== $payment->getState()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Send event only if the payment was completed?

@ghost ghost assigned umpirsky Jan 30, 2014
@winzou
Copy link
Contributor

winzou commented Jan 30, 2014

Looks great so far!

@umpirsky
Copy link
Contributor Author

Thanks for following this PR @winzou! Really appreciate it.

@@ -19,8 +19,9 @@
<mapped-superclass name="Sylius\Bundle\CoreBundle\Model\Variant" table="sylius_variant">
<field name="sku" column="sku" type="string" nullable="true" />
<field name="price" column="price" type="integer" />
<field name="onHold" column="on_hold" type="integer" nullable="true" />
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove this, and put simple 0 in model class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nullable?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I think we should have this defined as in other columns, so instead of nullable give 0 in model definition (actual line 45).

@umpirsky
Copy link
Contributor Author

@winzou @stloyd Fixed reported comments, thanks.

Now I think on my todo list is:

  • Fix travis build.
  • Add specs for holding inventory.
  • Implement service that can release inventory for given order (we can then use it from cron to release order after 15 minutes and have button for each order to release it manually).

Sounds good? Did I miss something?

/cc @kayue @pjedrzejewski

@winzou
Copy link
Contributor

winzou commented Jan 30, 2014

I think the process of releasing inventory units can stay in the service inventoryHandler: it's just a matter of decreasing onhold + changing state.

Then the cron itself + the conditions to trigger it should be done in another PR.

@umpirsky
Copy link
Contributor Author

@winzou Yes, I was thinking about implementing InventoryHandlerInterface::releaseInventory(), not a separate service, I expressed myself wrong.

$units = $order->getInventoryUnitsByVariant($item->getVariant());

foreach ($units as $unit) {
$unit->setInventoryState(InventoryUnitInterface::STATE_ONHOLD);
Copy link
Contributor

Choose a reason for hiding this comment

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

Uhm, it may actually be interesting to check state before setting it to on-hold.
I would add a condition STATE_CHECKOUT === $unit->getInventoryState() before changing the state + for counting the quantity for the inventoryOperator::hold just after.
What do you think?

The aim is to make it possible to trigger more than once this method without any risk (I'm thinking of viewing more than once the finalize step for example).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. I think this can fix it https://gist.github.com/umpirsky/7bce762a0e8858a22aa4

It is just quantity that need to take care of, all items are going to on-hold anyway.

@umpirsky
Copy link
Contributor Author

@winzou Not changing state, but removing inventory units.

* @return Symfony\Component\HttpFoundation\Response
* @throws Symfony\Component\HttpKernel\Exception\NotFoundHttpException
*/
public function releaseInventory()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@winzou I added this action for manual inventory release for order. But it removes onhold items, now I think according to https://github.com/Sylius/Sylius/wiki/Status it is not right. Should it update status from onhold to checkout? But it looks odd to have order in backend with inventory units in checkout status.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pjedrzejewski Except last question everything is pretty finished. Please review.

Copy link
Contributor

Choose a reason for hiding this comment

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

Inventory units can be releases only if order is not paid yet, so so issue to set it back to check out

$quantity--;
}

$unit->setInventoryState(InventoryUnitInterface::STATE_ONHOLD);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not good I think, this setter must be in the if. Imagine there are item already shipped (unit sold), then this would set it back to on hold...
Behavior is: we set to on hold every units that was checkout before.

pjedrzejewski pushed a commit that referenced this pull request Jan 31, 2014
@pjedrzejewski pjedrzejewski merged commit c240be7 into Sylius:master Jan 31, 2014
@pjedrzejewski
Copy link
Member

Thanks Sasha and company! 👍

@umpirsky
Copy link
Contributor Author

@winzou @pjedrzejewski Last comments fixed in #952

@umpirsky umpirsky deleted the feature/on-hold-inventory branch January 31, 2014 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Minor issues and PRs improving the current solutions (optimizations, typo fixes, etc.).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants