There's a Default quantity to add to cart" setting on the product edit form, but for reasons I don't quite get, this value is only effective if the quantity field is set to be shown (this option found by link in main settings).

Would there be any harm in allowing this default quantity to still apply even if this field isn't shown? The quantity field even seems to exist beside the button -- it's just hidden. But it's automatically set to "1" when not displayed.

Any thoughts? I think this is a change from older versions.

The below thread seemed to bring up the issue, but I think the issue became confused, with both parties talking about slightly different things :)
#352381-3: Default quantity to add to cart value not respected

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

patcon’s picture

Status: Active » Needs review

Oh hey, if anyone else is interested, just find function uc_product_add_to_cart_form() in uc_product.module and change

  else {
    $form['qty'] = array('#type' => 'hidden', '#value' => 1);
  }

to

  else {
    $form['qty'] = array('#type' => 'hidden', '#value' => $node->default_qty);
  }

Hopefully this helps someone else! Rock on, folks

patcon’s picture

And the reason I needed this was because I have a minimum for a certain product, so it made since to start with that in the cart (I use Add to cart tweaks to empty the cart with each addition). Maybe not, but I thought others might want something similar :)

sammys’s picture

Category: feature » bug
FileSize
828 bytes

I consider this a bug so I've switched it over to that. Created a patch so maintainers can easily test/commit the change.

patcon’s picture

Thanks Sammys. I've recently gotten into rolling patches, but hadn't at the time.

longwave’s picture

Version: 6.x-2.2 » 7.x-3.x-dev
Status: Needs review » Patch (to be ported)
FileSize
1.46 KB

Makes sense to me, but you can explicitly set default qty to 0 to hide the quantity field per-product, which would then add 0 products when the field is hidden. I committed the attached patch, which will use a quantity of 1 if the field was explicitly hidden, and the default otherwise.

Needs porting to 7.x.

longwave’s picture

Status: Patch (to be ported) » Fixed

Committed.

Status: Fixed » Closed (fixed)

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