Author Topic: Adding multiple products to cart with one button  (Read 699 times)

webgobe

  • Advanced
  • Full Member
  • *****
  • Posts: 542
  • Follow me on Twitter! http://twitter.com/webgobe
    • Internet craftsman carrying on the heritage of European manufacturing traditions through original Web designs.
Adding multiple products to cart with one button
« 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
Like a fine wine... Good from the start and getting better over time.
Donations are welcome!

pinochico

  • 3rd party VirtueMart Developer
  • Full Member
  • *
  • Posts: 1129
    • MiniJoomla
  • Skype Name: support-easysoftware
  • VirtueMart Version: 3
www.minijoomla.org  - new portal for Joomla!, Virtuemart and other extensions
XML Easy Feeder - feeds from products, orders and database table
Virtuemart Email Manager - customs email templates

webgobe

  • Advanced
  • Full Member
  • *****
  • Posts: 542
  • Follow me on Twitter! http://twitter.com/webgobe
    • Internet craftsman carrying on the heritage of European manufacturing traditions through original Web designs.
Re: Adding multiple products to cart with one button
« Reply #2 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.
Like a fine wine... Good from the start and getting better over time.
Donations are welcome!

Studio 42

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 4448
  • Joomla & Virtuemart developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3
Re: Adding multiple products to cart with one button
« Reply #3 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

webgobe

  • Advanced
  • Full Member
  • *****
  • Posts: 542
  • Follow me on Twitter! http://twitter.com/webgobe
    • Internet craftsman carrying on the heritage of European manufacturing traditions through original Web designs.
Re: Adding multiple products to cart with one button
« Reply #4 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.
Like a fine wine... Good from the start and getting better over time.
Donations are welcome!

pinochico

  • 3rd party VirtueMart Developer
  • Full Member
  • *
  • Posts: 1129
    • MiniJoomla
  • Skype Name: support-easysoftware
  • VirtueMart Version: 3
Re: Adding multiple products to cart with one button
« Reply #5 on: April 29, 2021, 12:12:00 pm »
Quote
the 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.
www.minijoomla.org  - new portal for Joomla!, Virtuemart and other extensions
XML Easy Feeder - feeds from products, orders and database table
Virtuemart Email Manager - customs email templates

ermes

  • 3rd party VirtueMart Developer
  • Jr. Member
  • *
  • Posts: 110
Re: Adding multiple products to cart with one button
« Reply #6 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".

webgobe

  • Advanced
  • Full Member
  • *****
  • Posts: 542
  • Follow me on Twitter! http://twitter.com/webgobe
    • Internet craftsman carrying on the heritage of European manufacturing traditions through original Web designs.
Re: Adding multiple products to cart with one button
« Reply #7 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!
Like a fine wine... Good from the start and getting better over time.
Donations are welcome!

pinochico

  • 3rd party VirtueMart Developer
  • Full Member
  • *
  • Posts: 1129
    • MiniJoomla
  • Skype Name: support-easysoftware
  • VirtueMart Version: 3
Re: Adding multiple products to cart with one button
« Reply #8 on: April 29, 2021, 21:06:54 pm »
Quote
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!

Closed without a description of the solution for others?
It may not be right, but it can be an inspiration for the future.
www.minijoomla.org  - new portal for Joomla!, Virtuemart and other extensions
XML Easy Feeder - feeds from products, orders and database table
Virtuemart Email Manager - customs email templates

webgobe

  • Advanced
  • Full Member
  • *****
  • Posts: 542
  • Follow me on Twitter! http://twitter.com/webgobe
    • Internet craftsman carrying on the heritage of European manufacturing traditions through original Web designs.
Re: Adding multiple products to cart with one button
« Reply #9 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
Like a fine wine... Good from the start and getting better over time.
Donations are welcome!

pinochico

  • 3rd party VirtueMart Developer
  • Full Member
  • *
  • Posts: 1129
    • MiniJoomla
  • Skype Name: support-easysoftware
  • VirtueMart Version: 3
Re: Adding multiple products to cart with one button
« Reply #10 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.
www.minijoomla.org  - new portal for Joomla!, Virtuemart and other extensions
XML Easy Feeder - feeds from products, orders and database table
Virtuemart Email Manager - customs email templates

webgobe

  • Advanced
  • Full Member
  • *****
  • Posts: 542
  • Follow me on Twitter! http://twitter.com/webgobe
    • Internet craftsman carrying on the heritage of European manufacturing traditions through original Web designs.
Re: Adding multiple products to cart with one button
« Reply #11 on: April 30, 2021, 18:29:11 pm »
BTW, the promised solution I was looking for:
Code: [Select]
<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+.
Like a fine wine... Good from the start and getting better over time.
Donations are welcome!

pinochico

  • 3rd party VirtueMart Developer
  • Full Member
  • *
  • Posts: 1129
    • MiniJoomla
  • Skype Name: support-easysoftware
  • VirtueMart Version: 3
Re: Adding multiple products to cart with one button
« Reply #12 on: May 01, 2021, 09:58:56 am »
Quote
ModVMCDHelper::getProduct($id)

I think similiar function exist in core VM, or not?
www.minijoomla.org  - new portal for Joomla!, Virtuemart and other extensions
XML Easy Feeder - feeds from products, orders and database table
Virtuemart Email Manager - customs email templates

Studio 42

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 4448
  • Joomla & Virtuemart developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3
Re: Adding multiple products to cart with one button
« Reply #13 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

balai

  • 3rd party VirtueMart Developer
  • Full Member
  • *
  • Posts: 1445
Re: Adding multiple products to cart with one button
« Reply #14 on: May 01, 2021, 23:26:51 pm »