Below the wishlist page we should also include an 'add all products to cart' button. I could not find a really neat implementation so I kept on looping through the submit function. Based on previous patch in this comment thread.

It works somewhat.

Comments

aramboyajyan’s picture

Good call, I agree.

chadsten’s picture

Assigned: neograph734 » chadsten
neograph734’s picture

Issue summary: View changes
StatusFileSize
new5.14 KB

Feel free to give this a spin. Attached is where I left off.

chadsten’s picture

@neograph734 - Awesome, thanks for posting that. I'll begin work on this with your code as a baseline.

neograph734’s picture

I believe it did work, but I disliked the double code therefor it has not yet been committed. It shouldn't be that much work to get it implemented properly.

chadsten’s picture

Issue summary: View changes
StatusFileSize
new5.93 KB

I have moved the duplicate code to a helper function, and done a little cleanup. I believe there is still more that needs done, like removing items from the wishlist once they are added to the cart.

Thoughts on other tasks related to this one?

neograph734’s picture

Thanks for the help!

If I am not mistaken the items should be automatically removed from the wishlist as soon as the user checks out. (At least that was the intended behavior.) Until bought, the items are still wished for ;).

I'll give the patch a spin this weekend and will get back to you.

chadsten’s picture

@neograph734 - Gotcha, I haven't dug around that much yet. I think that functionality is superior, didn't realize it was there.

Just keep me posted - I'm somewhat new to Drupal Commerce, so I'm more than open to suggestions/guidance if I have done something in a less than optimal way. Thanks!

chadsten’s picture

Status: Active » Needs review
neograph734’s picture

Status: Needs review » Needs work

Cool, seems to be working pretty nice. I ain't no hero in Drupal Commerce either, but I guess this is quite a neat way to handle this.

I am not sure what you meant with @TODO - remove the item from the wishlist . Is that related to the WSOD I get when I set the desired amount of one item to 0, and the add to cart amount to a positive integer? So we should update amounts first and then add items to the cart?

chadsten’s picture

No, that was before I realized we clear the contents upon successful checkout. I'll remove that comment when I commit my changes to the repo.

neograph734’s picture

Understood.

Do you think you could take a look at the WSOD descibed above?

chadsten’s picture

Sure, I'll take a look today or tomorrow at this.

chadsten’s picture

Sorry for the delay. I'm on this today.

chadsten’s picture

StatusFileSize
new3.44 KB

Okay, I've isolated the issue, and we have a few options for a solution.

Firstly, I'll attempt to describe the issue. Adding a single item to the cart uses the second quantity field (which makes sense), but adding ALL to cart uses the wishlist quantity, not the 'add to cart quantity'. This being the case, an item set to 0 in the wishlist quantity field, but a non-zero number in the add to cart will still attempt to add 0 to the cart.

To remedy this specifically, I've created a patch that simply checks if ($line_item['#value'] > 0), and it will skip attempting to add the product if the quantity is set to 0.

Now, is this desired behavior? Why do we look at one field for adding a single, but the other for adding multiple? Let me know your thoughts on this, and I'll adjust my solution accordingly.

chadsten’s picture

Another option would be to have both add single and add multiple look at the 2nd (add to cart) quantity values, and only use the wishlist quantity for maintaining the wishlist, and setting the default amount in the add to cart quantity. This seems a little more intuitive in my mind, but obviously a single opinion isn't of much merit.

chadsten’s picture

Status: Needs work » Needs review
neograph734’s picture

I agree that the last option (#16) sounds the most intuitive. That would be my preferred solution as well.

neograph734’s picture

Oh, one small thing (it took me a while to realise this was an incremental patch). Please make sure that a submitted patch contains all code required to solve the issue as a whole.

This means the patch of #15 should also include the changes in #6. This way we can commit one patch instead of several incremental ones (and testbots on more advanced projects will fail to apply the patch otherwise). The inbetween changes can be uploaded as an interdiff.txt file.

Thanks a lot for your time and effort though!

chadsten’s picture

Great, I'll move forward with #16, and I'll create a full patch of both. I'm still pretty green with the patch process, so thanks for the heads up on that!

aramboyajyan’s picture

Status: Needs review » Needs work

Updating the status.

neograph734’s picture

@chadsten, how is the patch coming along? Could you give us an update?

Also could you remove the // @TODO get rid of this dpm() ? line from the patch in #6? It is blocking #2571617: Remove form validation from commerce_wishlist_handler_field_add_to_cart_from_wishlist. I didn't want to commit the other issue because it would break this patch.

Thanks in advance.

chadsten’s picture

@neograph734 - I'm going to work on the patch today/tomorrow, and will update this issue when I'm ready for review.

neograph734’s picture

@chadsten, did you have had a chance to look at this? Otherwise I'll start digging into it.

neograph734’s picture

Assigned: chadsten » neograph734

I'll continue with this.

  • Neograph734 committed 585380e on 7.x-3.x
    Issue #2504757 by chadsten, Neograph734: 'Add all to cart' button
    
neograph734’s picture

Status: Needs work » Fixed

Introduced a secondary submit handler so both buttons actually trigger different actions. This prevents the 'Add all to cart' button from triggering the update quantities actions.

Added a check to see if the add to cart section (quantity + button) is in the view, and do not display the button if it is not.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.