Ubercart Attribute Quantity

Contrib type: 
Module
Status: 
Uploaded for testing
Moderation: 
Awaiting moderation

Downloads

Compatibility: 
Ubercart 2.x

This module was created to allow attribute options to have quantities assigned to them at the add to cart stage. An example of how to use this module would be: a store, which allows you to create your own book. The book is the product and certain attribute options can be chosen, in this case: Binding Type, Cover Colour and Pages. We could add the attribute quantitiy field to the pages option and allow users to choose a type of page eg: white, cream, gold edged and input an amount for it.

This module is compatible with uc_aac, uc_dependant_attributes & uc_node_checkout.

Now Available!


PreviewAttachmentSize
Sample ScreenshotSample Screenshot72.12 KB
UC Attribute Quantity (tar)34.5 KB
drupup's picture
Offline
Joined: 12/21/2009
Juice: 9
Slight tweak required on current version

I had to make a change to lines 78, 84 and 346 of the .module file to get this to work without throwing errors. In each case you had:

"SELECT [field] {FROM [table]} WHERE aid = %d LIMIT 1;"

which I changed to:

"SELECT [field] FROM {[table]} WHERE aid = %d LIMIT 1;"

at which point it worked great. Nice addition. Very useful.

luketarplin's picture
Offline
Joined: 04/26/2010
Juice: 203
Re: Slight tweak required on current version

Hi Drupup, Well spotted, drawback of using phpeclipse as an IDE, I'm afraid! Will add the change to the module, although I think it should probably read "SELECT [field] FROM {table} WHERE aid = %d LIMIT 1;" the double curly braces was a mistake.

drupup's picture
Offline
Joined: 12/21/2009
Juice: 9
Even better! Really nice to

Even better!

Really nice to have this feature in the mix. Can't believe some of the torturous workarounds I was using before.

joeredhat's picture
Offline
Joined: 12/29/2009
Juice: 65
SQL syntax not compatible with PostgreSQL

The "CREATE TABLE" statement in the .install file and several other SQL queries in the .module file are incompatible with PostgreSQL.

* The queries use backticks (`) around column names
* The column type is listed as INT(10), where an INT would suffice

I'd be happy to help supply patches to make this module work with both MySQL and PostgreSQL

luketarplin's picture
Offline
Joined: 04/26/2010
Juice: 203
Hi Joeredhat, Thanks for

Hi Joeredhat,

Thanks for getting in touch, to be honest I never wrote the SQL statements to work with Postgres only Mysql. When I get time I will replace the install sql with a proper hook_schema function.

Regards Luke

grindflow's picture
Offline
Joined: 12/15/2010
Juice: 105
Awesome module, long overdue, thank you

I found that it does not work when used creating orders (admin/store/orders/create).... the attribute quantity box appears, but does not calculate the appropriate total when it adds the product to the order =(

is that an easy fix?

xomby's picture
Offline
Joined: 04/13/2011
Juice: 4
Warning when adding item to cart

Using this module, I get warnings when adding to cart. Latest versions of DP + views + ctools + panels + UC.

warning: Illegal offset type in /home/content/h/p/r/hprwebadmin/html/modules/uc_attribute_quantity/uc_attribute_quantity.module on line 281.

OK as nobody posted after me, I'm just going to edit this post from here on out. Above is the error I was getting, and I thought my original fix would do the trick, but it turns out it wasn't updating the total $$ based on the QTY posted. so here is my revised function uc_attribute_quantity_cart_item() (circa line 276 in uc_attribute_quantity.module). I also added support for 0 qty in attributes, although that requires slight tweaking elsewhere as well (hint: set default to 0 at line 57, and required to 0 at 59, and check if(QTY>0) inside the foreach that digs down to $qty circa line 323 before outputting " X " . $qty).

<?php
function uc_attribute_quantity_cart_item($op, &$item){
    if(
$op == "load"){
        if(!empty(
$item->data['attr-qty'])){
            foreach(
$item->data['attr-qty'] as $key => $qty){
                if(
$qty >= 1){ //XOMBY MOD HERE START with support for 0 qty
                   
$attr = uc_attribute_load($key);
                   
                   
$opt = $attr->options[end($item->data['attributes'][$key])]; //XOMBY MOD THIS LINE WITH end()
                   
                   
$item->price -= $opt->price;
                   
$item->price += ($qty * $opt->price);

                   

$item->cost -= $opt->cost;
                   
$item->cost += ($qty * $opt->cost);

                   

$item->weight -= $opt->weight;
                   
$item->weight += ($qty * $opt->weight);
                }
//XOMBY MOD HERE END
           
}
        }
    }
}
?>
greg420blues's picture
Offline
Joined: 05/08/2011
Juice: 56
Can't seem to enable??

Howdy all,
Not a Drupal newb, but am an Ubercart newb so forgive me if I'm asking something that's obvious here.

I downloaded and installed this potentially-life-saving module. Can't seem to figure out how/where to get the quantity fields to show up with the attribute options. In the Attributes overview, I still only get the display options for "Text Field, Select Box, Radio Buttons, Checkboxes" for my attribute. Am I missing something? Seems that the option to use a quantity field would appear here.

Can anyone lend an assist on this???

djg_tram's picture
Offline
Joined: 06/26/2011
Juice: 26
Problem with invoice

I'm working on another attribute module and while testing that, I realized that neither this one nor mine appears on the invoice. The function hook_product_description_alter() doesn't get called at all when preparing the invoice. If this is so, this might be a serious core bug, actually. Any of you had experience with this?

luketarplin's picture
Offline
Joined: 04/26/2010
Juice: 203
Re: Problem with invoice

I'm not sure if you are talking about showing the attribute quantity on the invoices, which are shown on a store admin's dashboard, however I can see the quantity being added to test orders I have created, see attached.

AttachmentSize
attribute_quantities.png 59.23 KB
djg_tram's picture
Offline
Joined: 06/26/2011
Juice: 26
Re: Ubercart Attribute Quantity

Then I don't understand at all. I'm on Drupal 6, UC 6.x-2.4, the latest stable.

/user/#/order/#: your X10 doesn't show, mine shows*
/admin/store/orders/#: both show
/admin/store/orders/#/invoice: neither shows

*mine is not yet completely finished but stores an array. Hook_product_description_alter() turns the array into a string representation. In cases where I noted 'doesn't show', I got the "Array" string instead of the string I would create myself.

Then off I go to try to find out the cause...

luketarplin's picture
Offline
Joined: 04/26/2010
Juice: 203
Re: Re: Ubercart Attribute Quantity

Mine shows on admin/store/orders/%/invoice It shows under the products on order! See attached.

You are correct about it not showing on user/%/orders/% must be a permissions thing, as it works when I am the SU admin user, will revisit it as and when I get chance.

AttachmentSize
attribute_quantities_1.png 12.77 KB
djg_tram's picture
Offline
Joined: 06/26/2011
Juice: 26
Re: Ubercart Attribute Quantity

I didn't have time to look into that in more detail because I have a more pressing thing to do with the module... Smiling Before I delve deep into the code, it might be easier for you to know: is there a way to specify the attr quantity programmatically? Passing the following array to uc_cart_add_item() gives warnings and doesn't actually calculate with the quantities (although it does appear in the cart in the product description):

$data = array(
  'attributes' => array($aid => $oid),
  'attr-qty' => array($aid => $quantity),
);

If not yet solved, I'll have to modify the code to do so but I might have overlooked some simpler but obvious solution. I hope so...

luketarplin's picture
Offline
Joined: 04/26/2010
Juice: 203
Re: Re: Ubercart Attribute Quantity

Hi, to be honest to answer your question I would have to look back over the code myself and try to understand it again, the best thing would be to have a search around the API documentation and see if you can find anything useful.

luketarplin's picture
Offline
Joined: 04/26/2010
Juice: 203
Re: Warning when adding item to cart

Hi Xomby, thanks for this patch, I will roll it in when I get 5mins, off on holiday now so don't have chance right now.

djg_tram's picture
Offline
Joined: 06/26/2011
Juice: 26
Hold your horses, Luke! I

Hold your horses, Luke! Smiling

I tried the code segment I quoted on a different site and much to my surprise, it worked flawlessly. Upon comparing the two sites, it turned out that the failing one is just the one where I did apply Xomby's patch. It's just that end() that makes the uc_cart_add_item() fail. In the setup I have the $item->data['attributes'][$key] seems to return a single string all the time. It might be cases where it is an array but that case should be checked in order to not use end() without distinction.

And then you can actually add that original code to the documentation, it not only looks logical, it is... Smiling

Surf New Media's picture
Offline
Joined: 07/12/2011
Juice: 42
Node Checkout with Quantity

I am not sure if anyone else has had this problem, but when using Node Checkout along with this module, the quantity field disappears ... I am not sure how to fix it. Otherwise, it works fine when the attribute is not attached to a product via node checkout.

John Sokolich
Surf New Media

www.surfnewmedia.com
www.newspaperwebdesign.com

emilacosta's picture
Offline
Joined: 09/26/2009
Juice: 25
Missing node ID

Hi,

I have a common setup UC 2.x, uc_aac and uc_aq. I use the attribute and I add the quantity to the attribute, but from time to time the node ID is missing some how that I get this error:

call_user_func_array() [<a href='function.call-user-func-array'>function.call-user-func-array</a>]: First argument is expected to be a valid callback, 'uc_product_add_to_cart_form_' was given in /home/site/public_html/includes/form.inc on line 377.

After some digging I locate the problem in the function uc_attribute_quantity_option() in the line:

$nid = array_pop(explode('_',$_POST['form_id']));

If I hard code the node ID the problem goes away for good. I am running Drupal 6.22.

Any ideas?

Emil Acosta

"In the computer business you are either a one or a zero and I am determined never to be zero."

djg_tram's picture
Offline
Joined: 06/26/2011
Juice: 26
Re: Warning when adding item to cart

Sorry to say, this patch has even more problems, it seems, than I previously thought. Just think about it, with a quantity of zero, this will not compensate for the original attribute module adding the attribute cost superfluously. Consequently, a quantity of zero will still add the cost once.

djg_tram's picture
Offline
Joined: 06/26/2011
Juice: 26
Re: Ubercart Attribute Quantity

Luke, do you plan to go ahead to Drupal 7 and its UC? If you do, I'd like to discuss some issues. When I tried to integrate your module into my site, I found rather serious conceptual issue. As long as you use it as is, it works all right but when you need to interact with other modules and workflows (eg. populating the quantity fields programmatically), some of your approaches make it very painful. I'd be willing to contribute, not only to criticize... Laughing out loud

gaslamp's picture
Offline
Joined: 11/02/2011
Juice: 3
a solution

I recently had this problem and found a relatively simple fix. It requires knowing how to set up a custom module, but the code is very simple:

http://www.gaslampmedia.com/blog/node-checkout-quantities

ribo's picture
Offline
Joined: 05/19/2011
Juice: 37
Does it work if i overwrite the price in product level?

Hello everyone. I downloaded and installed the module.

In my ubercart site i have an ubercart product class named weddingcake.
For weddingcake class i have set up an attribute for the shape with some default price values.
I have enabled the quantity for that field in order to put the number of guests.

For the default values of the attribute, the calculation ShapeValue x guests is done correct.
If i change the Shape price attribute at weddingcake level, then the calculation ShapeValue x guests is not correct.

Can anybody verify this?

ribo's picture
Offline
Joined: 05/19/2011
Juice: 37
Attributes Quantities Module

Hello again,

I think that the module does not make the correct calclulations if i change the price of an attribute in product/product-class level.

it works for the default price attributes, but not when you change it at product level. Is there anybody that can verify this?

ribo's picture
Offline
Joined: 05/19/2011
Juice: 37
Attribute Quantity Module - Solved my Problem

Hello everyone,

I think i solved my problem for this module. My setup is ubercart-2.7 and drupal 6.22. The code in function uc_attribute_quantity_cart_item($op, &$item) {line 276 of ubercart quantiy module} makes a call to uc_attribute_load usiing only $key as a parameter.

The signature for this function at http://api.ubercart.org/api/function/uc_attribute_load says that $type parameter Determines whether $nid refers to a node or product class. $nid is ignored if $type is not 'product' or 'class'.

So if i call uc_attribute_load($key) i get the price value of the base attribute, not the the price value of the attribute that has been overrided at product/class level.

the function call should be $attr = uc_attribute_load($key,$item->nid,'product'); in order to take as price the correct value.

Can anybody confirm this? In my case solved the problem

emilacosta's picture
Offline
Joined: 09/26/2009
Juice: 25
Quantity missing in order & invoice

Hi,

For some odd reason I can not figure out why the quantity is not been print on the invoice or order. The attribute name prints, but not the " x 123". Any ideas?

Emil Acosta

"In the computer business you are either a one or a zero and I am determined never to be zero."

bhans's picture
Offline
Joined: 05/03/2012
Juice: 10
UC 3?

Is there a port or one in progress for UC 3?

texanontour's picture
Offline
Joined: 08/01/2010
Juice: 12
I also need this for 3.x (Drupal 7)

I am also interested in a port of this to version 3.

Cheers.

wehehehek's picture
Offline
Joined: 01/18/2013
Juice: 31
Re: I also need this for 3.x (Drupal 7)

Hello! I'm a newbie to developing modules but I've been trying to port this to Drupal 7. I kept on hitting a wall though. Let us know if someone had a success on porting this to 3.x. Thanks!

zeegogz's picture
Offline
Joined: 02/25/2013
Juice: 9
i manage to install it on drupal7 with uc3

I change the line 78 on uc_attribute_quantity.module to
$res = db_query('SELECT id FROM {uc_attribute_quantity} where aid = :aid', array('aid' => $aid))->fetchField();
and seems to work but i guess there is a lot to be change...
if anyone is interested i have attached the files

AttachmentSize
uc_attribute_quantity.zip 8.26 KB
janette's picture
Offline
Joined: 06/22/2009
Juice: 37
D7 U3

Not quite ready for drupal 7/ubercart 3 yet: PHP Fatal error: Call to undefined function db_last_insert_id() in /var/www/sites/all/modules/uc_attribute_quantity/uc_attribute_quantity.module on line 355

janette's picture
Offline
Joined: 06/22/2009
Juice: 37
oops

duplicate

zeegogz's picture
Offline
Joined: 02/25/2013
Juice: 9
Re: D7 U3

yeah...the problem is that db_last_insert_id() is not suported anymore in drupal 7 ....

Francois's picture
Offline
Joined: 08/19/2008
Juice: 390
Did you ever solve this problem

Emilacosta, were you ever able to solve this problem. We have a situation where the x10 is showing on the admin view, but no on the invoice.

Frustrating. Sad

--------
'Twas the end of the world, and you didn't even know it.

RobertoGuzman's picture
Offline
Joined: 12/13/2007
Juice: 20
any news?

any fix in this error ?

Roberto Guzman

RobertoGuzman's picture
Offline
Joined: 12/13/2007
Juice: 20
any news?

any fix in this error ?

Roberto Guzman

dbrandusa's picture
Offline
Joined: 08/14/2013
Juice: 4
Quantity not showing in admin panel

The quantity does not show to the admin to know how many items need to be fulfilled. It shows the dropdown menu results (like your screenshot) but no data is displayed for quantity.

Thanks.

SurajHo's picture
Offline
Joined: 05/05/2014
Juice: 3
Drupal 7, Ubercart 3

Has anyone managed to successfully port this to Drupal 7 and Ubercart 3 yet?

grindflow's picture
Offline
Joined: 12/15/2010
Juice: 105
ignore

duplicate

grindflow's picture
Offline
Joined: 12/15/2010
Juice: 105
D7 UC3

There's an untested contrib here:
https://drupal.org/node/1530752

grindflow's picture
Offline
Joined: 12/15/2010
Juice: 105
Re: D7 UC3

If anyone is interested in sponsoring the port to UC3, we could facilitate this port in the coming weeks