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

Allow adding multiple products to the cart via the add-to-cart query string #17477

Closed
jtsternberg opened this issue Oct 31, 2017 · 13 comments
Closed

Comments

@jtsternberg
Copy link
Contributor

@jtsternberg jtsternberg commented Oct 31, 2017

I have written a tutorial for doing this (in a bit of hacky way, due to WC_Form_Handler's private methods), but this seems like prime territory for WC core. If this is considered blessed, I can start on a PR for it along the lines of the code in the tutorial.

https://dsgnwrks.pro/snippets/woocommerce-allow-adding-multiple-products-to-the-cart-via-the-add-to-cart-query-string/

@mikejolley
Copy link
Member

@mikejolley mikejolley commented Oct 31, 2017

Related #16742

@jtsternberg
Copy link
Contributor Author

@jtsternberg jtsternberg commented Oct 31, 2017

Well looky there... it's my tutorial. We can close this issue if you want to keep the thread in one place? -- I see that one is closed, so will continue the discussion here.

@jtsternberg
Copy link
Contributor Author

@jtsternberg jtsternberg commented Oct 31, 2017

A summary from #16742:

What I'd rather see is either:

  • handling for multiple products in core
    OR
  • splitting/refactoring the methods for easier reuse.

A new query param is one option.

@claudiulodro
Copy link
Contributor

@claudiulodro claudiulodro commented Oct 31, 2017

Feel free to submit a pull request for this! A new query param is probably the easiest solution, since it's a bonus feature not directly used in core.

@yangkennyk
Copy link

@yangkennyk yangkennyk commented Nov 3, 2017

3.2 seems to have broken ability to add multiple variable products with this snippet as well.

@wloske
Copy link

@wloske wloske commented Nov 10, 2017

Ok, I'll add a use case for this: We have rewritten the looks of a variable product in the store so that two attributes ("Side" with left and right and "Color" with a list of colors as choices) are not displayed as a "Side" pulldown and a "Color" pulldown but as a fixed row "Left" and fixed row "Right" with a color pulldown for each. As it is currently implemented we have to add an order button to both lines and purchase two single items of the same product on one screen but the product is intended as a pair so only a single button would be nice - the basket still could and should have to single products. We call this a "matrix" product.

Perhaps we are thinking too complicated here for this use case. If anyone has a suggestion for this, it would be very welcomed.

@jtsternberg
Copy link
Contributor Author

@jtsternberg jtsternberg commented Nov 21, 2017

@mikejolley How do you feel about the curie notation for defining the product ids/quantities? e.g.

?items-to-cart=<product1-id>:<product1-qty>,<product2-id>:<product2-qty>

Background: https://dsgnwrks.pro/snippets/woocommerce-allow-adding-multiple-products-to-the-cart-via-the-add-to-cart-query-string/#comment-12236

(I'm envisioning doing a simple version of the same thing for varations: <variation1-id>:<variation1-qty>)

I think the alternative would possibly be multiple params, e.g.

?items-to-cart=<product1-id>,<product2-id>&quantities=<product1-qty>,<product2-qty>

@mikejolley
Copy link
Member

@mikejolley mikejolley commented Nov 21, 2017

I guess thats an option :) Did you see how grouped products do it?

@jtsternberg
Copy link
Contributor Author

@jtsternberg jtsternberg commented Nov 21, 2017

Yah, was working through that now actually. Appears to be an array with $item => $quantity, where I presume $item is the product id. Is that preferred then? The main reason I'm not a fan of that is the URL can get quite long as you have to do something like:

?items-to-cart[<product1-id>]=<product1-qty>&items-to-cart[<product2-id>]=<product2-qty>

But if we use a custom query var, I guess I we can make it a smaller query var for the ids/quantities, e.g.

?items-to-cart=1&add[<product1-id>]=<product1-qty>&add[<product2-id>]=<product2-qty>

@jtsternberg
Copy link
Contributor Author

@jtsternberg jtsternberg commented Nov 21, 2017

(oops)

@jtsternberg jtsternberg reopened this Nov 21, 2017
@mikejolley
Copy link
Member

@mikejolley mikejolley commented Nov 21, 2017

Is the main goal to have a short url, or to just support it across product types? And query string only, or support post/forms too?

jtsternberg added a commit to zao-web/woocommerce that referenced this issue Nov 22, 2017
…erce#17477

Adding multiple products:
```
?items-to-cart=1&add[<product1-id>]=<product1-qty>&add[<product2-id>]=<product2-qty>
```

Adding multiple variable products looks the same as the above, except
replace product-id with variation-id.

Adding multiple grouped products looks like:
```
?items-to-cart=1&add[<group-id>][<groupproduct1-id>]=<groupproduct1-qty>&add[<group-id>][<groupproduct2-id>]=<groupproduct2-qty>
```
@jtsternberg
Copy link
Contributor Author

@jtsternberg jtsternberg commented Nov 22, 2017

@mikejolley ideally all of the above, I guess. #17855 ready for review.

@mikejolley
Copy link
Member

@mikejolley mikejolley commented Dec 14, 2017

Let's continue discussion in #17855

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants