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.
| Comment | File | Size | Author |
|---|---|---|---|
| #26 | attributes_quantities-782154-26.patch | 9.33 KB | jeffam |
| #20 | attributes_quantities-782154-20.patch | 9.28 KB | dkingofpa |
| #17 | attributes_quantities-782154-17.patch | 8.99 KB | dkingofpa |
| #9 | attributes_quantities-782154-9.patch | 9.2 KB | dkingofpa |
| #1 | 782154-attributes-quantities_1.patch | 8.93 KB | willieseabrook |
Comments
Comment #1
willieseabrook commentedUse 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.
Comment #2
FranCarstens commentedThanks Willie, I finally had someone develop a new module, UC Attribute Quantities.
Comment #3
alobamor commentedHello mintsauce, I'm also interested on this feature, are you going to publish that module? thanks
Comment #4
D1m0k commentedAfter patching, cyrillic symbols in attribute options looks like a rhombus with question mark (in admin/store/orders/XX)
cyrillic names of attributes looks correctly
Comment #6
D1m0k commented#1: 782154-attributes-quantities_1.patch queued for re-testing.
Comment #8
tr commentedTestbot 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.
Comment #9
dkingofpa commentedI re-rolled the patch from #1 against 6.x-2.7 using git.
Comment #10
dkingofpa commentedComment #11
tr commentedStatus has to be set to "needs review" to get the bot to test the patch ...
Comment #13
tr commentedLet's try on -dev.
Comment #14
tr commented#9: attributes_quantities-782154-9.patch queued for re-testing.
Comment #16
tr commentedOK, 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.
Comment #17
dkingofpa commented@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.
Comment #19
tr commentedEasy solution. You need to add the following line to your patch (in uc_attribute.module):
Can you roll a new patch with this included?
Comment #20
dkingofpa commentedUpdated patch attached.
@TR Thanks. How did you find that? Familiarity with the codebase or some special technique using SimpleTest?
Comment #21
FranCarstens commentedSorry, I didn't keep an eye on this thread.
http://www.ubercart.org/project/uc_attribute_quantity
Comment #22
dkingofpa commented@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.
Comment #23
FranCarstens commentedAah... nice. :)
Comment #24
longwaveComment #25
JoshOrndorff commentedThis looks awesome; are there plans to include it in ubercart core, or maybe 3.x core? Or should I patch the file manually?
-Josh
Comment #26
jeffamThe 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.
Comment #27
vathanan commentedHi. Anyone converted this patch to Ubercart 7.x? I would very much like to use this in 7.x.
Comment #28
archunan commentedHi 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
Comment #29
bradnovation commentedI would also be very interested in a D7 / UC3 patch - Subscribing
Comment #30
ivanatrix commentedPatch 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.
Comment #31
arvind.kinjaHi ivanatrix, I updated this patch code for drupal 7 with uc3 and it works fine.
Comment #32
iyyappan.govindsubscribed
Comment #33
iyyappan.govindArvind, Can you please provide the patch you created for Drupal 7
Comment #34
arvind.kinjaSure I will provide you patch for drupal 7.
Comment #35
userspan commentedYou can share Patch for Drupal 7 please
Comment #36
iyyappan.govind@arvind.kinja Please share your patch for D7
Comment #37
mauiluau commented@arvind.kinja Please share your patch for D7. Thank you!
Comment #38
webdesgnr14 commented@arvind.kinja still no patch for 7.x-3.11?
figured it out with stock... thanks!
Comment #39
tr commentedComment #40
jvieille commented#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));
}