Fixed price for attribute option combinations

Contrib type: 
Module
Status: 
Uploaded for testing
Moderation: 
Failed code review

Downloads

Compatibility: 
Ubercart 1.x

While it's possible to give a specific attribute option combination an alternate SKU, you can not give it a fixed price. This module makes it possible to give each attribute option combination a fixed price. This can be done in the 'Adjustments' tab when editing a product.


PreviewAttachmentSize
uc_fixed_price.zip2.93 KB
uc_aac_ALTERED.zip4 KB
RaF
RaF's picture
Offline
Joined: 07/24/2008
Juice: 32
Re: Fixed price for attribute option combinations

A little more information about this module:
This is my first module for Drupal, ever. I have re-used some code from other modules and added some of my own. I'd appreciate it if some experienced developers would review my code and give some feedback.

About uc_acc_ALTERED.zip:
At first sight, this module is not compatible with Ajax Attribute Calculations. Initially, changing attributes when viewing a certain product will not update it's displayed price to the fixed price, it's updated price will only be visible at checkout. To counter this, I have made some alterations to the AAC-module (you can find the altered version in the zip file). I know this is bad practice (since I actually hacked the uc_aac module), but I have no idea how to make the alterations through my module. Any help for this would be truely appreciated.

This is my first contribution (if you can call it that at least) and I surely plan to make some more.

crooke's picture
Offline
Joined: 03/15/2008
Juice: 77
Great Module!

It's a fantastic module, thanks ever so much for spending the time on it!

I tested it and it does update the price in the cart, but not on the product page (using your modification of uc_aac.module). Please let me know how I could help you investigate this issue.

Thanks

Rob

crooke's picture
Offline
Joined: 03/15/2008
Juice: 77
Correction

The module and uc_aac.module works great. I had Inventory API and Simple Stock levels enabled (which first of all I don't need at all), that seems to have caused the issue.

Thanks again for this module! Great work!

Rob

Dubs's picture
Offline
Joined: 11/20/2007
Juice: 79
Fixed price in order editing

Hi there,

Thanks for your module...

Is is possible to add the correct prices when editing / adding an order via the admin area. Currently, the fixed price options are ignored.

Many thanks,

David

wastrilith2k's picture
Offline
Joined: 05/15/2009
Juice: 29
Thank you!

I was stressing about this for hours til I came upon this module!

What I'd like to do to expand it (and I'm in a time crunch on this) is set it so that an attribute can be marked as price impacting or not. For instance, if Color doesn't impact price, let's not show it. i have a feeling this will involve modifying the uc_attribute module. and then this code.

Any ideas?

Thank you,

James

wastrilith2k's picture
Offline
Joined: 05/15/2009
Juice: 29
Drupal 6 and UC2

Anyone have something like this for Drupal 6?

James

GAR
GAR's picture
Offline
Joined: 09/04/2009
Juice: 14
Fixed price for attribute option combinations for Drupal 6

Without AAC.
Just converted with Deadwood, and change db_num_rows($result); to mysql_num_rows($result);
Works for me, but not good tested.

AttachmentSize
uc_fixed_price.tar.gz 2.71 KB
daddison's picture
Offline
Joined: 01/07/2010
Juice: 4
Re: Fixed price for attribute option combinations for Drupal 6

I got it to work by changing line 24 in the Deadwood-converted version

from $num_prod_attr = mysql_num_rows($result);

to $num_prod_attr = db_result($result);

joachim@drupal.org's picture
Offline
Joined: 10/16/2008
Juice: 31
Re: Fixed price for attribute option combinations

This doesn't work at all I'm afraid.

The adjustments page produces this error:


* user warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 query: SELECT COUNT(*) FROM W ORDER BY in /Users/joachim/Sites/event-drupal/sites/all/modules/uc_fixed_price/uc_fixed_price.module on line 57.
* user warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM W ORDER BY LIMIT 0, 20' at line 1 query: SELECT DISTINCT FROM W ORDER BY LIMIT 0, 20 in /Users/joachim/Sites/event-drupal/sites/all/modules/uc_fixed_price/uc_fixed_price.module on line 57.

The problem is that the code is trying to do two things with the $result from a query. You can't do that -- once you've a db_result() on it, it's gone.

The code is extremely messy and jumps through all sorts of hoops to build that query. I'm not even sure what it's trying to do, as there aren't any comments to explain. Looks like it's trying to join the tables to themselves multiple times to get all possibilities of attributes. Rather than all those rtrim(), it would be much clearer to build up an array of pieces and implode it.

mpkpm's picture
Offline
Joined: 06/07/2010
Juice: 71
Re: Fixed price for attribute option combinations

Does anyone has a working version of this module..i also need this functionality of giving price per SKU

mromansis's picture
Offline
Joined: 10/06/2010
Juice: 3
Tested in D 6.x

I tested the uc_fixed_price.zip with the fix from http://www.ubercart.org/comment/49194 at D 6.19 and ubercart 2.4. The module has no bugs but there is an error in the fileds! It displays only 6 values for price and an error in the columns. See the image attached. If anyone can solve this problem and set this working for D6.x I would pay for it.

AttachmentSize
uc_fixed_price_D6.19.jpg 53.51 KB
reservedparking's picture
Offline
Joined: 08/25/2010
Juice: 10
uc_fixed_price fix

I fixed this and it works fine with the Drupal 6.16, Ubercart 6.x-2.4 and AAC 6.x-2.1.

AttachmentSize
uc_fixed_price.zip 3.05 KB
milojes's picture
Offline
Joined: 06/25/2011
Juice: 9
Error with drupal 6.22 and ub 2.4

I get this error on Adjustments tab

warning: mysql_num_rows() expects parameter 1 to be resource, object given in /Applications/MAMP/htdocs/www.newprintshop.it/sitodrupal/sites/all/modules/ubercart/uc_fixed_price/uc_fixed_price.module on line 25.

the query at line 25 have some problem
SELECT pa.*, a.*, COUNT(po.oid) FROM {uc_product_attributes} AS pa LEFT JOIN {uc_attributes} AS a ON pa.aid = a.aid LEFT JOIN {uc_attribute_options} AS ao ON a.aid = ao.aid LEFT JOIN {uc_product_options} AS po ON ao.oid = po.oid AND po.nid = %d WHERE pa.nid = %d GROUP BY ao.aid HAVING count(po.oid) > 0 ORDER BY pa.ordering, a.ordering

i get from phpmyadmin
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '} AS pa LEFT JOIN {uc_attributes} AS a ON pa.aid = a.aid LEFT JOIN {uc_attribute' at line 1

Apache/2.0.64 (Unix)
PHP/5.3.5 DAV/2
Versione MySQL client: 5.5.9

Somebody can help me?
Thanks

milojes's picture
Offline
Joined: 06/25/2011
Juice: 9
other problem

ok this help
http://www.ubercart.org/comment/49194

but i insert the prices in combination Adjustments and nothing change?? The price alwys 0.00 i cant change.

Some ideas?

Then the input for price, of the last 5 row there isnt??

Thanks

martinbutt's picture
Offline
Joined: 05/08/2012
Juice: 19
Fixed and verified on: Drupal

Fixed and verified on:

Drupal 6.22
Ubercart: 2.2

This should work fine on newer versions of 6.x.

AttachmentSize
uc_fixed_price.zip 180 bytes
GAR
GAR's picture
Offline
Joined: 09/04/2009
Juice: 14
Archive is empty

Archive contain no files.
Please, upload again.
Thank you!

martinbutt's picture
Offline
Joined: 05/08/2012
Juice: 19
Re: Fixed price for attribute option combinations

Oops. Here's the correct zip.

AttachmentSize
uc_fixed_price.zip 3.36 KB
GAR
GAR's picture
Offline
Joined: 09/04/2009
Juice: 14
It works!

Thanks!!!
It works!
But Ubercart Ajax Attribute Calculations does not show a price.

martinbutt's picture
Offline
Joined: 05/08/2012
Juice: 19
Re: Fixed price for attribute option combinations

I'm not using AAC, but I probably should be. I can try to get that working this weekend.

GAR
GAR's picture
Offline
Joined: 09/04/2009
Juice: 14
Re: Re: Fixed price for attribute option combinations

That would be great Smiling

martinbutt's picture
Offline
Joined: 05/08/2012
Juice: 19
Re: Fixed price for attribute option combinations

I had a look at the new AAC moule and also RaF's original changes. I am not going to have the time to work on the changes that need to be made, but I'd be happy to help someone that wanted to take on the project.

nstampler's picture
Offline
Joined: 05/20/2012
Juice: 10
Fixed Price Module for UC 3?

I am using UC 3 with Drupal 7 and I *really* need this feature.  Any suggestions?   

GAR
GAR's picture
Offline
Joined: 09/04/2009
Juice: 14
Publish this module on drupal.org

We should publish this module on drupal.org
More people learn about this useful module
Among them there are PHP programmers, who has time and skill to combine it with AAC and port to Drupal 7

martinbutt's picture
Offline
Joined: 05/08/2012
Juice: 19
Re: Fixed price for attribute option combinations

Here is a new version with some bug fixes / code clean-up.

I am happy for you to post this to Drupal.org. If you do, I will be the D6 maintainer.

AttachmentSize
uc_fixed_price.zip 3.19 KB
boboss's picture
Offline
Joined: 05/30/2012
Juice: 3
fix

Works like a charm but you have to change %d to %f in insert and update functions to support floating point values

change line 124 from

db_query("UPDATE {uc_product_fixed_price} SET fixed_price = %d WHERE nid = %d AND combination = '%s'", $value['fixedprice'], $form_state['values']['nid'], $value['combo_array']);
to db_query("UPDATE {uc_product_fixed_price} SET fixed_price = %f WHERE nid = %d AND combination = '%s'", $value['fixedprice'], $form_state['values']['nid'], $value['combo_array']);

and line 126 from
db_query("INSERT INTO {uc_product_fixed_price} (nid, combination, fixed_price) VALUES (%d, '%s', %d)", $form_state['values']['nid'], $value['combo_array'], $value['fixedprice']);
to db_query("INSERT INTO {uc_product_fixed_price} (nid, combination, fixed_price) VALUES (%d, '%s', %f)", $form_state['values']['nid'], $value['combo_array'], $value['fixedprice']);

martinbutt's picture
Offline
Joined: 05/08/2012
Juice: 19
Re: Fixed price for attribute option combinations

Good catch! Thanks.

martinbutt's picture
Offline
Joined: 05/08/2012
Juice: 19
Re: fix

Bug fix: uc_fixed_price.module line 83 should read:

if (count($comb_array) == count(array_intersect_assoc($ov_comb_array, $comb_array))) {

jestershoot's picture
Offline
Joined: 07/31/2013
Juice: 3
Drupal 7 version

Hello to all.

Here D7 module.
Not very good programming style. But may be will be useful for someone.

AttachmentSize
uc_fixed_price.zip 3.13 KB