VirtueMart Forum

VirtueMart 2 + 3 + 4 => General Questions => Topic started by: webgobe on April 28, 2021, 18:11:08 PM

Title: Adding multiple products to cart with one button
Post by: webgobe on April 28, 2021, 18:11:08 PM
I need to build a module which dynamically lists products (based on multiple criteria - done) which can be added to the cart with a single click. Searched a lot in the forums, but none of solutions found seems to work for me. I am using latest VM on latest Joomla.
TIA
Title: Re: Adding multiple products to cart with one button
Post by: pinochico on April 28, 2021, 21:04:20 PM
https://www.minijoomla.org/extensions/virtuemart-extensions/related-products-extended-for-virtuemart

or send me info
Title: Re: Adding multiple products to cart with one button
Post by: webgobe on April 29, 2021, 09:59:21 AM
Sorry, but your product does not know what I need. I need a relatively simple functionality for an existing module which lists the products giving to a (pretty complex) criteria. I need to add to that module the option to add the products listed to the cart, with one click. Not one by one - that is working already. The key needed trick is the use of a single add-to-cart button. Something like there:
http://vm3.sm-planet.net/catproduct/new-checkbox-example-detail
You see that below the main product the related products are listed with checkboxes. And after selecting the ones you need, you can add them with ONE CLICK to the cart.
Title: Re: Adding multiple products to cart with one button
Post by: Studio 42 on April 29, 2021, 10:10:35 AM
Why not using catproduct ?
I implement a javascript in the category view for a customer so you can select each product.
https://www.willys.be/index.php/fr/component/virtuemart/189/body-smal-stuf-mirror.html?Itemid=333
If you do not need to show the checkbox you can use a javascript list of product ids (or hidden input) and send to the cart using ajax, display the cart popup then update the cart module
Title: Re: Adding multiple products to cart with one button
Post by: webgobe on April 29, 2021, 10:27:38 AM
I was considering it, because is close  in some regards to what the client wants, but it is overkill. He wanted an extremely simple interface to select products related to the main/master products and some extra functionalities CatProduct does not provide, as dynamic discounts, like if the associated products are bought together with the master product, to have a discounted price. And more: if they are put and removed independently from cart, the prices to change accordingly.
Let me give you an example, let's see the main product is a hat, the associated products are a pair of gloves and a bag. First part is simple, the gloves and the bag should be shown in the hat's page, and ALL 3 (or ideally the master product and the selected associated products) to have a single add to cart button. This part is what catproduct can do. (BTW, the interface to set this up is over-complicated in the client's opinion, but let's not take that in consideration). Let's say, if these are bought together the associated products have a discounted price.
The trick here is, that the discount should be applied or not to the products in the cart regardless of how they get there. So, if I am adding only the master to the cart, and later I am adding one of associated products - and not with that infamous single add to cart button, the discount should be applied.
More, if later I remove the master product from the cart, the associated product's price should be re-adjusted to show the non discounted base price. Well, this is the part which catproduct can't handle. And the component I built can do all that (and more). This is why catproduct does not fit the bill there.
BTW, it is a terrific product - just simply can't do what I am required to provide.
Title: Re: Adding multiple products to cart with one button
Post by: pinochico on April 29, 2021, 12:12:00 PM
Quotethe associated product's price should be re-adjusted to show the non discounted base price

Nice custom work :)
Catproduct we use on two shops (yes we know, the development is stoped from 2019), so I'm waiting for your solutions.
Title: Re: Adding multiple products to cart with one button
Post by: ermes on April 29, 2021, 17:08:38 PM
See if you are interested in a solution like the one we created for the https://wwwnumeritermoadesivi.it site with the lower bar "Create your box".
Title: Re: Adding multiple products to cart with one button
Post by: webgobe on April 29, 2021, 17:09:42 PM
Will post it as done. In mean time I found what I did wrong - I have too many VM related ongoing developments, one of those conflicted with the new module and I was thinking that this module is the culprit ;).
Thanks for your time trying to help me!
Title: Re: Adding multiple products to cart with one button
Post by: pinochico on April 29, 2021, 21:06:54 PM
QuoteWill post it as done. In mean time I found what I did wrong - I have too many VM related ongoing developments, one of those conflicted with the new module and I was thinking that this module is the culprit ;).
Thanks for your time trying to help me!

Closed without a description of the solution for others?
It may not be right, but it can be an inspiration for the future.
Title: Re: Adding multiple products to cart with one button
Post by: webgobe on April 30, 2021, 13:14:48 PM
Promised, that when all will be done, will post the solution there. The solution was inspired by this thread: https://forum.virtuemart.net/index.php?topic=136440.0
Title: Re: Adding multiple products to cart with one button
Post by: pinochico on April 30, 2021, 15:42:09 PM
Yep, you are right

the finally solutions will be between catproduct, product builder and awo coupon.

We spend most of our time doing the same steps - purchasing an approximate product for the solution and then reprogramming it to suit the end client's intentions.

But we also have a responsibility and we have to tell the client his ideas.
Not all its requirements and ideas are correct for an ecommerce solution, then we refuse to develop and integrate this solution.
Title: Re: Adding multiple products to cart with one button
Post by: webgobe on April 30, 2021, 18:29:11 PM
BTW, the promised solution I was looking for:
<form method="post" action="index.php">
  <?php foreach($products as $id){
$rel=ModVMCDHelper::getProduct($id); ?>

  <div class="vmcd-module"><?php echo $rel->product_name?><br />
    <input type="hidden" name="virtuemart_product_id[]" value="<?php echo $id?>">
    <label>Quantity</label>
    <input type="checkbox" name="quantity[]" value="1">
  </div>
  <?php ?>
  <br />
  <input type="hidden" name="option" value="com_virtuemart" />
  <input type="hidden" name="view" value="cart" />
  <input type="hidden" name="task" value="add" />
  <input type="submit" name="addtocart" class="addtocart-button" value="Add to Cart" title="Add to Cart" />
</form>

Some explanations:
$products is an array holding the product ID's,
ModVMCDHelper::getProduct($id) is a helper function wich fetches the product details - product name in the example.
If checkboxes shown are checked, the products are added in the cart. You can use standard text input boxes, in which case you can enter the quantities desired, if 0 is added, the respective product isn't added to the cart.
But this is the essence of the trick. Tested and works on VM 2+.
Title: Re: Adding multiple products to cart with one button
Post by: pinochico on May 01, 2021, 09:58:56 AM
QuoteModVMCDHelper::getProduct($id)

I think similiar function exist in core VM, or not?
Title: Re: Adding multiple products to cart with one button
Post by: Studio 42 on May 01, 2021, 18:02:29 PM
The problem is not to render the list, but to apply discounts
Cat product can do it, my plugin extra products too.
But none can calculate discounts.
The only solution i know is to use a virtuemart coupon plugin
Title: Re: Adding multiple products to cart with one button
Post by: balai on May 01, 2021, 23:26:51 PM
Did you check Product Bundles?
https://breakdesigns.net/extensions/joomla/product-bundles
Title: Re: Adding multiple products to cart with one button
Post by: webgobe on May 02, 2021, 08:22:21 AM
LOL, the problem is NOT to add discounts, that can be handled with a little coding. The real problem is to add/remove these dynamically, based on the exact contents of the cart, as I described above (https://forum.virtuemart.net/index.php?topic=146716.msg522740#msg522740). And that's the part what NONE of the above proposed solutions can handle.
Title: Re: Adding multiple products to cart with one button
Post by: pinochico on May 02, 2021, 10:49:31 AM
A little thought off topic:

If I have to analyze the needs or mistakes of our customers, they must provide me with all available information.

If they don't deliver, I'll charge them lost time for additional questions (such as the error URL) for information they don't deliver immediately.

For 15 years, I have trained most customers to send the URL, domain, error preview, description and request straight away.

Also, when I don't provide this information to my developers, they don't start work - they don't write that they need something, but they just don't do the task until I provide the information.

Unfortunately, the negative feature of most forums is the same - respondents will not provide all the information available to others.

This is followed by the usual game - divination with crystal balls.

Sometimes I get involved in the game, but when I'm not in the mood and time, it's not worth dealing with the question at all - I even struggle with the idea that the interviewer does not appreciate any help and does not provide information intentionally :)

For example:
the online domain of the site is already helping
helps the URL where the problem occurs
helps preview the circled problem
helps video in gif

I understand that some do not want to show the domain of the site they are working on so as not to reveal which site it is and not lose a customer (here are the biggest hysterics Japanese),
but no one will repair the car unless it comes to service.
Title: Re: Adding multiple products to cart with one button
Post by: Studio 42 on May 02, 2021, 20:01:43 PM
Quote from: webgobe on May 02, 2021, 08:22:21 AM
LOL, the problem is NOT to add discounts, that can be handled with a little coding. The real problem is to add/remove these dynamically, based on the exact contents of the cart
To do this you have product builder See https://breakdesigns.net/extensions/joomla/product-builder
But this add all the products in the car line by line and not 1 product.
Si to apply discount, you have to find own solution
If you have a easy solution for the discount, please explain how you do this ?
Title: Re: Adding multiple products to cart with one button
Post by: balai on May 03, 2021, 01:14:43 AM
QuoteMore, if later I remove the master product from the cart, the associated product's price should be re-adjusted to show the non discounted base price.
This is a feature of Product Bundles.