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

Incorreclty splits packages #1417

Conversation

DanielePalombo
Copy link
Contributor

rel #1366

On sandbox store:

  1. In the admin, create a new order
  2. Add 1 unit of any item
  3. Update the quantity of item(bug 1) or re-add the same item(bug 2)
  4. Enter customer details and click update button
  5. Two shipments are created, the first with the first quantity added and the second with the remained quantity item

After investigation i see that the order_stock_location isn't update when update_cart is call (https://github.com/solidusio/solidus/blob/master/core/app/models/spree/order_contents.rb#L37-L67), and the order_stock_location creation is skipped if line_item isn't a new record(https://github.com/solidusio/solidus/blob/master/core/app/models/spree/order_contents.rb#L146).

solution to bug 1:
Update the quantity of order_stock_location when the update_cart method is called.
solution to bug 2:
Update the quantity of order_stock_location when an item is add to cart if already present an other variant and stock_location in the cart

@@ -205,14 +219,29 @@
end

context "update cart" do
let!(:shirt) { subject.add variant, 1 }
let!(:shirt) { subject.add variant, 1 , stock_location_quantities: { stock_location.id => 1} }

Choose a reason for hiding this comment

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

Space found before comma.
Space inside } missing.

end
end

def correct_order_stock_location_quantity(line_item, stock_location_quantities, &block)

Choose a reason for hiding this comment

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

Unused method argument - block. If it's necessary, use _ or _block as an argument name to indicate that it won't be used.

options = {
variant_stock_location_quantities: {
@line_item.variant_id => {
@line_item.variant.stock_locations.first.id => 3
Copy link
Contributor

Choose a reason for hiding this comment

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

is this right? should it be first.id: 3?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, i push the changes

Add an options param to update_cart method to update
order_stock_location.
The options param require the follow format:

```
{
    variant_stock_location_quantities: {
          shirt.variant_id => { stock_location.id => 3 }
            }
}
```

Now when method `add` is call with same variant and stock_location, the
`order_stock_location` quantity is updated.

Pass the formatted params to `update_cart` for update
order_stock_location.
@jhawthorn
Copy link
Contributor

This is tricky

Traditionally stock locations aren't associated until the packaging step. This allows for some "intelligent" packaging and allows stock to be drawn from whichever stock location has inventory available. This is the most common path that any frontend store will do, and is probably what out backend should do most of the time.

This changed with the introduction of the OrderStockLocation (which was not a particularly complete implementation IMNSHO). An OrderStockLocation ties some amount of a variant to a particular stock location. When packaging, it builds these as separate shipments.

We run into issues because under different circumstances our banckend behaves differently w/r/t adding an OrderStockLocation. The cart page usually does, and the shipments page doesn't.

I'm don't think adding an OrderStockLocation for the first stock location is the correct fix here, as it's possible that that location runs out of stock or could have other issues. I think we need to clarify to admin users when these records are being created, when they exist, and possibly stop creating them.

@DanielePalombo
Copy link
Contributor Author

Hi @jhawthorn ,

i understand what do you mean, i agree with you probably it's better clarify to the admin user the stock status and how the stock items in the order are splitted.

I propose to change the update quantity logic and give the possibility to change the quantity for each stock item. I drew a mockup to show you how i want implement this.

In order cart page with one item added in order, the user click on edit for change the quantity.
screenshot from 2016-10-07 14-37-36

The admin show the order_stock_locations details.
screenshot from 2016-10-07 16-04-06

The admin can change specific quantity for each order_stock_locations . When done click apply button to update the quantities.
screenshot from 2016-10-07 15-42-13

What do you think about it?

@peterberkenbosch
Copy link
Contributor

@DanielePalombo this needs a rebase with master.

@DanielePalombo
Copy link
Contributor Author

Before rebase or other changes, I'm waiting to know if my proposed solution can be alright.

@peterberkenbosch
Copy link
Contributor

Was about to mention that Daniele after I read the rest of this thread! 👍

@jhawthorn
Copy link
Contributor

@DanielePalombo sorry for the delay.

In addition to being assigned to a specific stock location, the default is that the variant can come from any stock location. IMO whatever UI we come up with should favour this default, since most of the that's probably what an admin would want.

@DanielePalombo
Copy link
Contributor Author

DanielePalombo commented Nov 29, 2016

Sorry I don't understand what do you mean.
Could you explain the problem some more?

@jhawthorn
Copy link
Contributor

jhawthorn commented Feb 17, 2017

This should be fixed by #1709, which bypasses the "location configured package" feature, which is what caused the separate shipments

@jhawthorn jhawthorn closed this Feb 17, 2017
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.

6 participants