28 replies [Last post]
WesleyTx's picture
Offline
Bug Finder
Joined: 09/14/2007
Juice: 89
Was this information Helpful?

Has anyone figured out a way to add a quantity field to the add-to-cart form when listing products in a table view? I was hoping the "Display an optional quantity field in the Add to Cart form" setting under Product Settings would do it, but alas, it does not.

Is there any option short of violating module code?

Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6846
Re: Quantity Field in Table View

TAPIr has it's own table settings under "Site configuration" called "Configure tables" that lets you disable or rearrange columns. The table you're looking for is 'uc_product_table'.

WesleyTx's picture
Offline
Bug Finder
Joined: 09/14/2007
Juice: 89
Re: Re: Quantity Field in Table View

Well, I set up a taxonomy term, set that as the catalog, and made sure the add-to-cart form was turned on in uc_product_table, but I still didn't get a quantity field. (I made sure the aforementioned "Display an optional quantity field" setting was on.) Am I missing something?

Anyway, I'm using a custom View at the moment to list all my products, since I only have 3 and don't need to categorize them with the built-in catalog. (Seems silly to have to click on Catalog, then an "All Products" subcategory. Unless there's a way around that?)

Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6846
Re: Re: Re: Quantity Field in Table View

Sorry, I misunderstood what you were asking for.

There are basically two different add to cart forms. One is on the product page, and one is on the catalog pages. The one on the product page has the optional quantity field and the attribute select fields, and should be available to Views as a node field. The catalog version is just the button that redirects to the product page if the customer has to choose any attribute options.

WesleyTx's picture
Offline
Bug Finder
Joined: 09/14/2007
Juice: 89
Re: Re: Re: Re: Quantity Field in Table View

It appears, though, that, at least when using a View, the add-to-cart form actually does add the product to the cart, rather than redirecting to the product page. The attribute options are also available. That's why it seemed to make sense that a quantity field might be available there, too.

(Just to be clear, I'm talking about the field "Product: Add to cart link" when creating a view.)

Might I recommend a change that would allow users to enable the quantity field there, also?

incaic's picture
Offline
Joined: 10/13/2007
Juice: 115
Re: Re: Re: Re: Re: Quantity Field in Table View

Is there a solution to this?
I'm looking for the exact same capability.
Basically I'm using contemplate and am modifying
the display, but the "Add to cart link" doesn't
show an input box for quantity. How can I make
this input un-hidden?

incaic's picture
Offline
Joined: 10/13/2007
Juice: 115
Re: Re: Re: Re: Re: Re: Quantity Field in Table View

OK, I see that uc_product_add_to_cart_qty has to be set in order to display the quantity input box. I see this as part of the only qualifier inside the uc_product_add_to_cart_form function in uc_product.module.

As a test, if I removed the second half of the qualifier and got the input box to appear just like I wanted.

Any help as to how to set the uc_product_add_to_cart_qty variable would be greatly appreciated.

Thanks!

incaic's picture
Offline
Joined: 10/13/2007
Juice: 115
Found it! Should've guessed,

Found it!

Should've guessed, it's one of the many config options for product.
It's under: admin/store/settings/products

Hope this helps someone out.

Mintsauce's picture
Offline
Joined: 12/26/2007
Juice: 2
Or

Home > Administer > Store administration > Configuration > Product Settings

Jay August's picture
Offline
Joined: 01/19/2010
Juice: 46
Can't seem to get it to work

I'm losing it here... I want to add the Quantity field to my Catalog, in table view, but it doesn't work. No qty field is showing up, while in Grid view this works good.

I'm using Drupal 6.x and UC 2.2, and this is my setting:
http://ep2up.com/uploads/1267533070.jpg

However, this is the result:
http://ep2up.com/uploads/1267533161.jpg

So, what am I doing wrong here? I need the table view, not the grid view. Thanks for any assistance!

t1000's picture
Offline
Joined: 05/17/2010
Juice: 12
ditto

I have the exact same need, this doesn't seem like it should be such a huge issue, but I can't seem to find an answer for it.

What would be ideal is in the catalog view, right next to the add to cart button there would be a quantity drop down.

Does anyone know how to accomplish this?

thanks!

Z1rra's picture
Offline
Joined: 10/03/2009
Juice: 9
Re: ditto

I have the same thing though i tracked down the problem to default quantity field being set to 0. It needs to be 1 or something else. My problem is that I can't think of any easy way to change all those fields to 1 on all my products (I have 3500+ of them). I tested it by setting it manually on some of the products and it appeared just fine. So is there an easy way to change this field or do i have to find a way to set it when uploading my products?

daveX99's picture
Offline
Joined: 03/20/2010
Juice: 31
Quantity Field does not appear unless default_qty != 0

Man, I've been going around in circles trying to figure out why one of my custom product types wouldn't show a quantity field on the Node Page for a particular product, but it would appear for the others. Finally, I came across Z1rra's post above. I'm just going to spell it all out here so it will maybe show up in the search a litlle more clearly.

It is not enough to simply check the 'Enable Add to cart forms in product node teasers' box in the Products Settings page.

In order for the quantity field to appear on a product's page, the field labeled "Default quantity to add to cart" must be set to something other than zero. I had entered most of the products using a script, and I guess neglected to set that field when creating this particular group of products.

Although it's been 11 months since Z1rra's post, I'd like to repay him/her by answering the question as to how to change that setting on a bunch of products at once (Sorry it couldn't be more timely!). To do it requires that you run the following SQL update query against the Drupal database:

update `uc_products` set `default_qty` = 1 WHERE `default_qty` = '0'

Of course, if you want a different default quantity (e.g. you sell things in groups of 5 or something), you'd use that instead.

Hope this helps somebody solve this issue faster than I did! Smiling

-dave.

brandonratz's picture
Offline
Joined: 03/18/2009
Juice: 21
Re: Quantity Field does not appear unless default_qty != 0

Thank you for this. Very good clarification. Now we need to get default_qty into feed mappers.

denniemans's picture
Offline
Joined: 10/02/2010
Juice: 20
Re: Quantity Field in Table View

anyone figured this out... I've got the same problem

jasonabc's picture
Offline
Uber Donor
Joined: 05/05/2008
Juice: 573
Re: Re: Quantity Field in Table View

I need this also. The quantity field appears if the product display is set to Grid view - but if it's set to display products in a list - the quantity field disappears.

denniemans's picture
Offline
Joined: 10/02/2010
Juice: 20
Re: Re: Re: Quantity Field in Table View

use the form hook with:

$form['qty'] = array(
'#type' => 'textfield',
'#default_value' => 1,
'#size' => 1,
'#maxlength' => 6,
'#weight' => 3,
'#attributes' => array('class' => 'input-qty')
);
jasonabc's picture
Offline
Uber Donor
Joined: 05/05/2008
Juice: 573
Re: Re: Re: Re: Quantity Field in Table View

Hi denniemans - many thanks. Not sure where to put this in the code though? Can you give us non-programmers some pointers? thanks so much

denniemans's picture
Offline
Joined: 10/02/2010
Juice: 20
Sure create a new custom

Sure Smiling create a new custom module (http://www.coderintherye.com/creating-a-new-custom-module-in-drupal-6) and put the code below in your .module file. Change the

function <YOUR_MODULE_NAME>_form_alter(&$form, &$form_state, $form_id) {
if (preg_match('/uc_product_add_to_cart_form/', $form_id)) {
$form['qty'] = array(
'#type' => 'textfield',
'#default_value' => 1,
'#size' => 1,
'#maxlength' => 6,
'#weight' => 3,
'#attributes' => array('class' => 'input-qty')
);
}
}
johandenhollander's picture
Offline
Joined: 09/27/2007
Juice: 79
Denniemans, I tried creating

Denniemans,

I tried creating a custom module with above code. The module installation etc went well.
However still no quantity field on the catalog page.

Part of your comment is missing, perhaps you could give a further explanation?

Kind regards,
Johan

everything27's picture
Offline
Joined: 02/16/2011
Juice: 42
Re: Denniemans, I tried creating

+1

ndit's picture
Offline
Joined: 02/03/2011
Juice: 6
in case someone needs

In case someone still needs this, denniemans' missing comment refers to changing the function name YOUR_MODULE_NAME (including the angled brackets).

You'll also need to change the line:

if (preg_match('/uc_product_add_to_cart_form/', $form_id)) {

to:

if (preg_match('/uc_catalog_buy_it_now_form/', $form_id)) {

as this is the form id on the product listing page with table view.

denniemans's picture
Offline
Joined: 10/02/2010
Juice: 20
Re: Quantity Field in Table View

I've created a small module that should do the trick Smiling click for uc_input_qty

Example where this module is in use: http://www.slagerijvanderzon.nl/vleeswaren

Good luck!

everything27's picture
Offline
Joined: 02/16/2011
Juice: 42
Re: Re: Quantity Field in Table View

Great, thank you for doing this, I have installed, where can I set to show the quantity now that it is installed? Looked around store admin but maybe i missed something?

thanks!

johandenhollander's picture
Offline
Joined: 09/27/2007
Juice: 79
Re: Re: Re: Quantity Field in Table View

There is no setting as far as I can see.

When this module is enabled the default
Quantity:
[input field]

on the product page is replaced by only a input form.

In the Catalog in table view no change is visible.

johandenhollander's picture
Offline
Joined: 09/27/2007
Juice: 79
Re: Re: Re: Re: Quantity Field in Table View

There is a difference. You use the "uc-product-add-to-cart-form" and we use the "uc_catalog_buy_it_now_form"

</div></form>
</td> </tr>
<tr class="even"><td width="100%" class="active"><a href="/node/88">Pistoletje rosbief</a></td><td nowrap="nowrap"><span class="uc-price-product uc-price-sell uc-price">€2,95</span></td><td><form action="/catalog/17"  accept-charset="UTF-8" method="post" id="uc-catalog-buy-it-now-form-88">

<div><input type="hidden" name="nid" id="edit-nid-5" value="88"  />
<input type="submit" name="op" id="edit-submit-88" value="Toevoegen"  class="form-submit list-add-to-cart" />
<input type="hidden" name="form_build_id" id="form-5f46b89f54b472be5fedfd00dfb74464" value="form-5f46b89f54b472be5fedfd00dfb74464"  />
<input type="hidden" name="form_token" id="edit-uc-catalog-buy-it-now-form-88-form-token" value="8e38799c314d4bba0e0d3b991726d718"  />
<input type="hidden" name="form_id" id="edit-uc-catalog-buy-it-now-form-88" value="uc_catalog_buy_it_now_form_88"  />

</div>          </td>
              </tr>
          <tr class="even">
                  <td class="views-field views-field-title active">
            Arrosto          </td>

                  <td class="views-field views-field-sell-price">
            <span class="uc-price-product uc-price-sell_price uc-price">€2.30</span><span class="prijs-per-value">- 100 gram</span>          </td>
                  <td class="views-field views-field-addtocartlink">
            <div class="add-to-cart"><form action="/vleeswaren"  accept-charset="UTF-8" method="post" id="uc-product-add-to-cart-form-62" class=" ajax-cart-form ajax-cart-form-kit">
<div><div class="attributes"><div class="attribute attribute-1 odd"><div class="form-item" id="edit-attributes-1-1-wrapper">
<select name="attributes[1]" class="form-select required" id="edit-attributes-1-1" ><option value="" selected="selected">Gewicht</option><option value="1">100 gr, €2.30</option><option value="2">150 gr, €3.45</option><option value="3">200 gr, €4.60</option><option value="6">250 gr, €5.75</option></select>

</div>
</div></div><input type="hidden" name="form_build_id" id="form-6b5c5baf633ae29acfeda81b504951b1" value="form-6b5c5baf633ae29acfeda81b504951b1"  />
<input type="hidden" name="form_id" id="edit-uc-product-add-to-cart-form-62" value="uc_product_add_to_cart_form_62"  />
<input type="hidden" name="pnid" id="edit-pnid-1" value="62"  />
<div class="form-item" id="edit-qty-1-wrapper">
<input type="text" maxlength="6" name="qty" id="edit-qty-1" size="1" value="1" class="form-text input-qty" />
</div>
<input type="image" name="op" value="In winkelmandje"  src="/sites/all/themes/zon/images/incart.jpg" alt="Zoeken" class="form-image  ajax-submit-form" add_to_cart="{ &quot;qty&quot;: null, &quot;nid&quot;: &quot;62&quot; }" />

</div></form>

everything27's picture
Offline
Joined: 02/16/2011
Juice: 42
Re: Re: Re: Re: Re: Quantity Field in Table View

Once again, thanks for working on the module, but I was hoping to add the quantity field to the catalog itself, any advice?

thanks!

denniemans's picture
Offline
Joined: 10/02/2010
Juice: 20
Re: Quantity Field in Table View

Just change the form id in the module to the form id that's used in the catelog page. That should work.

edit: looking at the post of johandenhollander the form id should be changed in 'uc_catalog_buy_it_now_form'

Thomas Brix's picture
Offline
Joined: 07/27/2011
Juice: 9
changing the submit handler

You will also need to change the submit handler, as the submit handler from catalog set the quantity to 1. Otherwise you will just see the option to edit quatity, but adding to cart, will only add ONE item.

This is how the submit hanlder looks in uc_product_module v1.14.2.43
---
function uc_catalog_buy_it_now_form_submit($form, &$form_state) {
$form_state['redirect'] = uc_cart_add_item($form_state['values']['nid'], 1, module_invoke_all('add_to_cart_data', $form_state['values']), NULL, variable_get('uc_cart_add_item_msg', TRUE));
}
---

So to make the uc_input_qty module work, it will have to implement a custom submithandler. Something like this:

---
/**
* Implementation of hook_uc_form_alter().
*
*/
function uc_input_qty_form_alter(&$form, &$form_state, $form_id) {

if (preg_match('/uc_catalog_buy_it_now_form/', $form_id)) {
$form['qty'] = array(
'#type' => 'textfield',
'#default_value' => 1,
'#size' => 1,
'#maxlength' => 6,
'#weight' => -1,
'#attributes' => array('class' => 'input-qty')
);
$form['#submit'] = array('uc_input_qty_uc_catalog_buy_it_now_form_submit');
}
}

/**
* @see uc_catalog_buy_it_now_form()
*/
function uc_input_qty_uc_catalog_buy_it_now_form_submit($form, &$form_state) {
$form_state['redirect'] = uc_cart_add_item($form_state['values']['nid'], $form_state['values']['qty'], module_invoke_all('add_to_cart_data', $form_state['values']), NULL, variable_get('uc_cart_add_item_msg', TRUE));
}

---

I just installed this and it seems to be working. Hope this is usefull.

/T