How difficult will it be to add "quantity" to attributes?

This is the scenario:
We're offering books in different sizes with a variable amount of pages. This can vary anything from 1 to 200 pages.

- The easy way but most laborious solution is to create 5 products (for each size) with a pages attribute at increments of 10 which will give you 20 options when selecting.
This would result in the customer choosing the book, from a selection of 5 of the same style. Once the product is open the customer can then select the amount of pages, but only in increments of 10.
Issues I have with this solution: (1) Will take very long to setup each product. (2) Will confuse the customer on the catalog page with 5 of the same product.
- The hard way but most practical is to have 1 product with an attribute of size an a dependent attribute of cost per page to which the customer can add amount of pages.
Reason I like the second solution. Even though the initial setup will require more brainpower the product setup will be easy as pie and the customer will have very little thinking to do as they are given 1 product at verious sizes with any quantity of pages.

For obvious reason I'm interested in going to second route.
I'm not too familiar with PHP, although I can follow instructions. Am I dreaming or can this be done?
Any ideas?


Having combed the interwebs for an answer I've found many answers to some of my older questions, but this one still has me stumped.
I've found no contributed modules for this either on Ubercart.org or on Drupal.org.
I've found many people asking for this kind of functionality.

• If this is an obvious solution I'd appreciate help.
• If this is a more complicated matter I'd appreciate a quote.

Francois.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

willieseabrook’s picture

Version: 6.x-2.2 » 6.x-2.4
Status: Active » Needs review
FileSize
23.22 KB
36.6 KB
48.88 KB
8.93 KB

Use case

You want a product where a user can order the graphic design of a brochure. The base cost is $200, plus $20 per page.

Old way:

Create selectboxes/options with hardcoded options e.g:

5 pages +$100
6 pages +$120
7 pages +$140
etc

I *believe* that was the old way, I don't know attributes, and I hope there isn't something I've missed with this like the old 'ohhh *thats* where that feature is'.

New way:
Create a "Quantity Grid" attribute type.
Set price = $20 (which means $20 * however much quantity is specified)

Patch Summary

This issue and solution is similar to what I needed for a project I'm doing.

See attached screenshots for functioning and attached patch for 2.4.

This is the first time I've used attributes at all, let alone getting deep into the attributes API. So I may have this way wrong.

1. Added to "Quantity Grid" type to attribute creation form
2. Created new element type quantity grid to mimic the checkboxes element type. Instead of expanding out to checkboxes, it expands out to textfields for entry of quantities for a particular attribute
3. Changed a few functions to add special conditions to account for the attribute type.
4. Adds theming function for the textfields used in the quantity grid (probably not actually necessary - but it's for my project, so it's in there)

The result of these changes is that a user can configure a product with options and quantities.

FranCarstens’s picture

Thanks Willie, I finally had someone develop a new module, UC Attribute Quantities.

alobamor’s picture

Hello mintsauce, I'm also interested on this feature, are you going to publish that module? thanks

D1m0k’s picture

After patching, cyrillic symbols in attribute options looks like a rhombus with question mark (in admin/store/orders/XX)
cyrillic names of attributes looks correctly

Status: Needs review » Needs work

The last submitted patch, 782154-attributes-quantities_1.patch, failed testing.

D1m0k’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 782154-attributes-quantities_1.patch, failed testing.

TR’s picture

Testbot doesn't function properly yet on fixed-point releases like 6.x-2.4, so you can ignore the test failure. I suggest running the tests locally to make sure they still work after the patch.

dkingofpa’s picture

Version: 6.x-2.4 » 6.x-2.7
FileSize
9.2 KB

I re-rolled the patch from #1 against 6.x-2.7 using git.

dkingofpa’s picture

Status: Needs work » Needs review
TR’s picture

Status has to be set to "needs review" to get the bot to test the patch ...

Status: Needs review » Needs work

The last submitted patch, attributes_quantities-782154-9.patch, failed testing.

TR’s picture

Version: 6.x-2.7 » 6.x-2.x-dev
Status: Needs work » Needs review

Let's try on -dev.

TR’s picture

Status: Needs review » Needs work

The last submitted patch, attributes_quantities-782154-9.patch, failed testing.

TR’s picture

OK, those error seem to be genuine PHP Notices caused by your patch. The patch needs to be cleaned up so that the tests run green. You can run the tests locally on your site if you want - that makes it easier to debug. You do this by enabling the (Drupal core) SimpleTest module then going to admin/config/development/testing to start the tests.

dkingofpa’s picture

Status: Needs work » Needs review
FileSize
8.99 KB

@TR - thanks for the SimpleTest tips. Hadn't done that before. Don't really want to do that again on Drupal 6.x...what a mess. Since I applied the 6.x patch from the SimpleTest module, I get a large amount of "Notice: Undefined property: stdClass..." messages.

I made one change that fixed most of the PHP notices. Re-testing locally still says there are a few left. However, I can't find them. Turning on the verbose option for SimpleTest just increases the number of errors. I've been using xdebug during development, but I can't get it to work as expected with SimpleTest. Even after trying all the tips here http://drupal.org/node/30011

I attached my latest patch. I'm just spinning my wheels at this point unless somebody can point me in a constructive direction. Ugh...time to go back out of this SimpleTest mess.

Status: Needs review » Needs work

The last submitted patch, attributes_quantities-782154-17.patch, failed testing.

TR’s picture

Easy solution. You need to add the following line to your patch (in uc_attribute.module):

@@ -1142,6 +1236,7 @@ function _uc_cart_product_get_options($item) {
         else {
           // Handle textfield attributes.
           $options[$index] = array(
+            'display' => $attribute->display,
             'attribute' => $name,
             'aid' => $aid,
             'oid' => 0,

Can you roll a new patch with this included?

dkingofpa’s picture

Status: Needs work » Needs review
FileSize
9.28 KB

Updated patch attached.

@TR Thanks. How did you find that? Familiarity with the codebase or some special technique using SimpleTest?

FranCarstens’s picture

Sorry, I didn't keep an eye on this thread.

http://www.ubercart.org/project/uc_attribute_quantity

dkingofpa’s picture

@FranCarstens Yes, I saw and tried that module. However, it only supports one quantity value per attribute. The patch in this thread supports one quantity value per attribute *option*. Two very different things.

FranCarstens’s picture

Aah... nice. :)

longwave’s picture

Category: support » feature
JoshOrndorff’s picture

This looks awesome; are there plans to include it in ubercart core, or maybe 3.x core? Or should I patch the file manually?

-Josh

jeffam’s picture

The patch in #20 wouldn't apply anymore, so I applied it to the 2.7 tag and then merged it into 6.x-2.x (the commit id at the time was a3b910b6). A quick test shows that it still seems to work.

vathanan’s picture

Hi. Anyone converted this patch to Ubercart 7.x? I would very much like to use this in 7.x.

archunan’s picture

Version: 6.x-2.x-dev » 7.x-3.x-dev

Hi All

We need converted this patch to Ubercart 7.x? can any one help us.

Please have look the patch and suggest those lines to be change to port in to d7 ubercart 3.

i am waiting for postive response from anyone(drupal master/experts).
Thanks

bradnovation’s picture

I would also be very interested in a D7 / UC3 patch - Subscribing

ivanatrix’s picture

Patch applied against 6.x-2.x but attribute details do not show properly on order page. Attribute name is trimmed to its first character. Cart and Cart checkout seems to be working pretty well. It does not however on Checkout review and order details at the backend.

UPDATE: Anyone having the same problem: By using hook_product_description_alter(), you can alter product attributes anyway you want to.

arvind.kinja’s picture

Hi ivanatrix, I updated this patch code for drupal 7 with uc3 and it works fine.

iyyappan.govind’s picture

subscribed

iyyappan.govind’s picture

Arvind, Can you please provide the patch you created for Drupal 7

arvind.kinja’s picture

Sure I will provide you patch for drupal 7.

userspan’s picture

You can share Patch for Drupal 7 please

iyyappan.govind’s picture

@arvind.kinja Please share your patch for D7

mauiluau’s picture

@arvind.kinja Please share your patch for D7. Thank you!

webdesgnr14’s picture

@arvind.kinja still no patch for 7.x-3.11?
figured it out with stock... thanks!

TR’s picture

Status: Needs review » Needs work
jvieille’s picture

#30 : I tried this patch, the problem with striped option names can be fixed this way:

--+ : added code to delete
++ : replacement code

in uc_attribute_admin.inc, from patch #26

function theme_uc_product_attributes($element) {
+ $product = $element['#product']['#value'];
$option_rows = array();
-
foreach (element_children($element) as $key) {
$optionstr = '';

- foreach ((array)$element[$key]['#options'] as $option) {
+ foreach ((array)$element[$key]['#options'] as $option_key => $option) {
--+ $append = $option['name'];
++ $append = $option;
+
+ // Show quantity for grid
+ if ($element[$key]['#display'] == 4) {
+ $context['type'] = 'amount';
+ $context['subject']['node'] = $product;
+ $price_info = array(
+ 'price' => $element[$key]['#options'][$option_key]['price_each'],
+ 'qty' => 1,
+ );
+
--+ $append = t('@qty×', array('@qty' => $element[$key]['#options'][$option_key]['quantity'])) . ' ' . $option['name'] . ' (' . uc_price($price_info, $context) . ' ' . t('each') . ')';
++ $append = t('@qty×', array('@qty' => $element[$key]['#options'][$option_key]['quantity'])) . ' ' . $option . ' (' . uc_price($price_info, $context) . ' ' . t('each') . ')';
+ }
+
// We only need to allow translation from the second option onward
if (empty($optionstr)) {
- $optionstr .= $option;
+ $optionstr .= $append;
}
else {
- $optionstr .= t(', !option', array('!option' => $option));
+ $optionstr .= t(', !option', array('!option' => $append));
}
}
- $option_rows[$key] = t('@attribute: @option', array('@attribute' => $element[$key]['#attribute_name'], '@option' => $optionstr));
+ $option_rows[$key] = t('@attribute: !option', array('@attribute' => $element[$key]['#attribute_name'], '!option' => $optionstr));
}