-
-
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
Bugfix InventoryHandler to remove units of items that were removed from cart #842
Bugfix InventoryHandler to remove units of items that were removed from cart #842
Conversation
…ed from the cart. Currently the inventory handler only adjusts the units of items that are still in the cart, but when an item is removed from the cart, the inventory unit remains. This PR fixes this.
Partially solves #567 |
@winzou Sorry, I forgot all about your ticket.. see if the new implementation solves things better. |
@@ -113,9 +124,15 @@ protected function addInventoryUnits(OrderInterface $order, VariantInterface $va | |||
protected function removeInventoryUnits(OrderInterface $order, VariantInterface $variant, $quantity) | |||
{ | |||
$units = $order->getInventoryUnitsByVariant($variant); | |||
$counter = 0; | |||
|
|||
foreach ($units as $unit) { |
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 should use $units->slice(0, $quantity)
to stay elegant here.
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 was wondering that too.. can I always count on collections though? The interface only hints at an array..
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.
@Richtermeister I guess you can, the Collection
implements \Countable
interface, so it's supported.
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.
@stloyd \Countable
is not what's needed. The slice()
method is on the ArrayCollection
class.. but I guess we should use collections properly when we have them.. I'll make that change.
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.
@Richtermeister Your question was:
can I always count on collections though?
So my answer was correct =) But additionally, all Collections must implement Collection
interface, which requires: slice()
to be implemented.
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.
@stloyd Ah, sorry, what that is meant to say is "Can I always rely on Collections being returned".. as in "I'm counting on you!" :)
When you look at the specs, for example, they work with arrays, so we'll have to switch those to Collections, if we want to go that route..
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.
@Richtermeister Why still not using slice? Any real reason, or you just forgot =)
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.
@stloyd Did not forget, but it requires updating all the specs to use ArrayCollection instead of array, and currently it's making the specs fail for me when I do that.. and, I'd love @pjedrzejewski to chime in, because he wrote the original specs with arrays..
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, let's skip it, I will create PR about this & fix specs 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'm trying to recall why I have used the arrays instead of the ArrayCollection. I'd prefer to use the Collection interface of course, but I think there was a reason why I did not in the first place...
Just ran into the "hidden feature" where all the units passed to |
@stloyd How about them apples? :) |
@pjedrzejewski Just for my better understanding, what is the purpose of creating inventory units before an order is completed? |
*/ | ||
private function updateVariantUnits(OrderInterface $order, VariantInterface $variant, $quantity) | ||
{ | ||
$units = $order->getInventoryUnitsByVariant($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.
As you get always Collection
object, you can just call:
$quantityDifference = $quantity - $order->getInventoryUnitsByVariant($variant)->count();
Big 👍 on this PR, thanks @Richtermeister Regarding our interfaces, I think yes it will be much easier if we can rely on a |
@pjedrzejewski If there are no technical issues here, could we get this merged? The bug is otherwise affecting shipping calculations.. By the way, that is the reason for the early creation of inventory units, right? Being able to calculate shipping? Also, can you please kick off the subtree split update again (ideally after merging this :).. I'm trying to deploy an app that has some dependencies.. Thanks! |
Bugfix InventoryHandler to remove units of items that were removed from cart
I'm fine with this solution, but we should somehow resolve the @Richtermeister Thanks for the patch and I just started the sync. My script is crashing for some reason and I did not have time to figure it out. (I run it manually on my local) |
Thanks man! 😘 |
Currently the inventory handler only adjusts the units of items that are still in the cart,
but when an item is removed from the cart, the inventory unit remains. This PR fixes this.