Hi,
I'm reviewing Ubercart modules to decide if I can use Drupal 7+Ubercart 3 for a new client site. One of my requirements is to allow for discounts and other features found in this module. It looks really awesome, but are there any plans to port it to 7?

Comments

jrust’s picture

Status: Active » Postponed

If someone builds it there will be one sooner than later, but at this point there is no development in that direction since Ubercart 3 hasn't been released.

RikiB’s picture

I am also very looking forward to a D7 version.

OldAccount’s picture

I'd also be very interested in a D7 version.

jerry’s picture

So would I; subscribing.

mattm007’s picture

subscribing, this is really needed

jpdaut’s picture

I need it too. Subscribing

jens peter’s picture

I would be interested in a Drupal 7 + Ubercart 2 version.
Do anyone plan on making this version any time soon? I am planning a new shop and would like to go from Drupal 6 to 7 and this is the only module (or a similar discount module) I am missing to be able to do so.

strep’s picture

Will continue development of the module? Need for Drupal 7 discount. Will the patch at least in the near future?

landylan’s picture

StatusFileSize
new35.33 KB

Since I like this module very much and need it to be on D7, I tried to make some modification with the help of Corer module.

Here's the modified code...

BTW, I've modified some code which I think there're bugs. I'm not so sure, maybe need some discuss later....

landylan’s picture

I didn't use "'UC discount Coupon" module before, but I guess that the "'UC discount Coupon" module could almost be replaced by "UC discounts alt" module. Is it right?

jrust’s picture

I've never used the coupon module, but I have to imagine it could be given how robust the coded discount feature is in discounts alt.

Please let us know what the bugs are that you fixed. I would rather those be posted as seperate issues if possible so that 6.x and 7.x can be kept as in sync as possible and so that we know exactly what is changing. This module, is unfortunately so complex that small changes can easily affect certain types of discounts.

jrust’s picture

Status: Postponed » Needs review
landylan’s picture

I'm working on an urgent case, so I'll leave message here and hope it helps.... ^_^

uc_discounts_alt.module:

L1008:   if ($exclude_all_products) {
==>      if ($exclude_all_terms) {
L1027:   if ($exclude_all_products) {
==>      if ($exclude_all_skus) {
L1046:   if ($exclude_all_products) {
==>      if ($exclude_all_classes) {
L1065:   if ($exclude_all_products) {
==>      if ($exclude_all_authors) {
L1084:   if ($exclude_all_products) {
==>      if ($exclude_all_roles) {
L1490:   if ($order_product_id_subtotal_map[$product_id] >= $order->qualifying_amount) {
==>      if ($order_product_id_subtotal_map[$product_id] >= $discount->qualifying_amount) {
L1615~L1652
        while ($free_items_remaining > 0) {
          //Determine cheapest remaining qualifying item
          $cheapest_product = NULL;
          foreach ($order_and_discount_products as $product) {
            //If this product has been fully discounted, continue
            if ($product->uc_discounts_is_fully_discounted) {
              continue;
            }

            //If no current cheapest product exists, use this product
            if (is_null($cheapest_product)) {
              $cheapest_product = $product;
            }
            else {
              //If this product is cheaper than the current cheapest product,
              //use this product instead
              if ($product->price < $cheapest_product->price) {
                $cheapest_product = $product;
              }
            }
          }

          //If no cheapest product could be found, there are no more products to
          //discount, break
          if (is_null($cheapest_product))
          break;

          //Discount up to the lesser of cheapest product quantity and free_items_remaining
          $discount_count = min($cheapest_product->qty, $free_items_remaining);

          //Add current discount amount to running total
          $discount_amount += $discount_count * $cheapest_product->price;

          //Mark item fully discounted
          $cheapest_product->uc_discounts_is_fully_discounted = TRUE;

          $free_items_remaining -= $discount_count;
        }
==>

        while ($free_items_remaining > 0) {
          //Determine cheapest remaining qualifying item
          $cheapest_product = NULL;
          $cheapest_product_key = NULL;
          foreach ($order_and_discount_products as $key=>$product) {
            //If this product has been fully discounted, continue
            if ($product->uc_discounts_is_fully_discounted) {
              continue;
            }

            //If no current cheapest product exists, use this product
            if (is_null($cheapest_product)) {
              $cheapest_product = $product;
              $cheapest_product_key = $key;
            }
            else {
              //If this product is cheaper than the current cheapest product,
              //use this product instead
              if ($product->price < $cheapest_product->price) {
                $cheapest_product = $product;
                $cheapest_product_key = $key;
              }
            }
          }

          //If no cheapest product could be found, there are no more products to
          //discount, break
          if (is_null($cheapest_product)) {
            break;
          }

          //Discount up to the lesser of cheapest product quantity and free_items_remaining
          $discount_count = min($cheapest_product->qty, $free_items_remaining);

          //Add current discount amount to running total
          $discount_amount += $discount_count * $cheapest_product->price;

          //Mark item fully discounted
          $order_and_discount_products[$cheapest_product_key]->uc_discounts_is_fully_discounted = TRUE;

          $free_items_remaining -= $discount_count;
        }

That's it.

landylan’s picture

Oh, there's a bug in uc_discounts_alt.admin.inc:

L768:    drupal_write_record('uc_discounts', $discount);
==>      unset($discount->discount_id);   // otherwise there will be an error about same discount_id
           drupal_write_record('uc_discounts', $discount);

BTW, I use 6.x-2.x-dev as my reference.

And here are some question....

1. get_role_ids_for_discount() was not used in get_product_ids_for_discount_object(). Is there any concern?

2. In order to avoid "discounts more than 100%" for each product, could we add a variable $order_product_id_total_discount_amount_map in the begining of function get_discount_for_order(), to record the total discount amount of each product and check later if there's product got discount more than 100%? $total_discount_amount do the simular jobs. I know that some discounts was for entire order, but we can take the average and put it into each product...

I did not look through all the open issue of this module. Sorry if I mention some duplicated issue...

jrust’s picture

Thanks for the updates.

1. I'm not sure about the get_role_ids_for_discount() without testing -- but if it's working without it then I imagine it's fine to remove.

2. That is a longstanding issue (#502212: Don't Allow Negative Balances), so if you find a good solution that works for all the discount types all the better.

landylan’s picture

I'll put my opinions to that post. Thanks.

strep’s picture

I tried this package for Drupal 7 from #9. I need to set a percent discount customer group, which is deducted from the total purchase. Unfortunately, after setting the discount does not apply.
My settings:

1. Is active
2. CONDITIONS OF QUALIFICATION -> Qualification type -> Minimum Quantity; Minimum qualification amount -> 1; Qualification by Role(s) and I have choose role.
3. REQUIRED PRODUCTS -> Filter Type -> Filter By Products; I have choos all products.
4.DISCOUNT APPLICATION -> Discount type -> Percentage off; Discount amount -> 0.2; DISCOUNTED PRODUCTS -> Filter By Products -> All Products
5. I have choose Add "Discounted products" to cart. Maximum applications -> 0. Max uses -> 0. Max uses per user -> 0. Max uses per code ->0.

Thanks for your help!

RKS’s picture

@ladylan

Can you provide more context for your post in #14. Trying to make the change but L768 isn't the line you've posted and there are a few instances of the drupal_write_record near to that line. So if you could post what is before and after the line where we are to add the unset it would be helpful.

Thanks.

landylan’s picture

I've checked and there's no mistake. It's L768 of "uc_discounts_alt.admin.inc" for both 6.x-2.x-dev and 6.x-2.4.

RKS’s picture

Ok. I was going off the module you posted in #9. So are we talking bugs in general in this thread (i.e. bugs against the 6x branch or are we testing and talking bugs from the port to 7 you posted in #9?)

Also, I'm trying to figure out what my site is doing as the admin UI doesn't exist after I enable the module. amin/store/uc_discounts doesn't appear and neither does the other paths listed in admin.inc. The database appears to have added the tables needed for the module, but nothing in errors.

strep’s picture

For my test (# 17) ... After switching on the module will block the last step in the checkout. URL / cart / checkout / complete writes an error and can not complete the purchase. After switching off the module checkout works again. Sorry for my bad English. Perhaps I mean the developers in the mistakes, which I write ...

At what stage is the development of the module now?

thank you

landylan’s picture

StatusFileSize
new16.3 KB

Since Ubercart3 namespace has changed, I modified the related hook. Here's the code...

landylan’s picture

StatusFileSize
new16.09 KB

I've modified some bugs....

1. use isset(variable) to check before use it.
2. don't use uc_price()
3. change db name from taxonomy_term_node to taxonomy_index

And there're still some bugs...

1. discounts doesn't be chosen and shown correctly during cart/checkout/review/complete stage.
2. Cart block shows nothing during checkout stage.

In a word, the code is still not workable....

RKS’s picture

"Not workable" is two words...jk.

The first bug I don't know but the cart block problem you're having is due to the way UC handles the cart. There is a (load) an (update) and a (save) and you're probably having the discount inserted before the update and after load. That doesn't work because update will discard and then save will just save the update. So you have to insert the discount or line item that you want included AFTER the update. That way the save will get it in there correctly.

I could be wrong and have it confused because it might be AFTER the save and not after the update. But I think it's the first way and if it doesn't work you can try after the save instead and see if that works.

I spent the first three weeks of this past October trying to get a discount module working with UC.

As for namespace, I also ran into that issue. If I would have saw this when you first posted i could have told you that but all functions like hook_cart or hook_order etc are all changed to hook_uc_cart and hook_uc_order. Those are actually all relatively easy to fix since many of the functions haven't changed at all.

The real challenge you're facing is getting the discount to appear and save and that is something that is difficult.

landylan’s picture

StatusFileSize
new15.9 KB

I guess I found the problem.

Problem:
1. discounts doesn't be chosen and shown correctly during cart/checkout/review/complete stage.
2. Cart block shows nothing during checkout stage.

Solution:
I just modified some query string and theme-related code, then the discounts "were chosen" correctly. But the discounts will not "be shown" until order is created. That's why it is not shown at cart page and checkout page(if you press ctrl+F5 at checkout page, you'll see the discounts). I guess it is problem about javascript (the original idea seems use javascript to show something before the order is created).

By the way, I also find a little bug at uc_discounts.module:L1904 ==> The variable $time_string seems useless and it is not defined. Undefined variable seems not allowed by Drupal7, so I remark this line.

"@time_string" => $time_string,
==> //"@time_string" => $time_string,

Here's the code...

landylan’s picture

The javascript problem is cleared. I think it's workable now.... ^_^

landylan’s picture

StatusFileSize
new15.9 KB

Here's the code.

mr.BF’s picture

Thanks for your code. But I have a troubles:
1. when I add product in a cart:
PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens: SELECT sku FROM {uc_discounts_skus} WHERE discount_id = :discount_id AND grouping = :grouping AND sku <> ":sku"; Array ( [:discount_id] => 1 [:grouping] => 2 [:sku] => ) в функции get_skus_for_discount() (line 1108 in file Z:\home\ortotop.loc\www\sites\all\modules\custom\uc_discounts\uc_discounts.module).
2. The 'uc_discounts_classes' table 'class' field contains value 'Array' - it's wrong, isn't it?
Can you help me? Thank you.
P.S. sorry for my english

landylan’s picture

StatusFileSize
new15.86 KB

To: mr.BF,

Thanks for your testing. I've update for problem1, and here's the updated code...

I don't really understand the problem #2. Would you please tell me more details...

mr.BF’s picture

StatusFileSize
new21.53 KB

See attached file please. (Table "uc_discounts_classes").
I think the trouble in a line 838 (file uc_discounts.admin.inc).

landylan’s picture

StatusFileSize
new10.41 KB

To mr.BF:

Thanks for your testing. You are right, that should not be an array. I also check all the 'class' assignment of whole module, and I find the same bugs appear in L838 and L939 (it become L839 & L940 since I modified another bugs.). Those error are all fixed. Thank you very much!!

To jrust:

As I said above, I found a bug in the original Drupal6 code. It's L719 of uc_discounts_alt.admin.inc:

$new_sku = array('discount_id' => $discount->discount_id, 'sku' => $id, 'grouping', $grouping);
==>
$new_sku = array('discount_id' => $discount->discount_id, 'sku' => $id, 'grouping' => $grouping);

it was also fixed in my new attached file(L826 & L827).

that's it. ^_^

tazir1’s picture

Thanks all,
Is it workable now = could I use this code for D7 + UC3?
If so, could you put the module on the project page (at least as dev ver.)?
I'm also need such module.

tazir1’s picture

StatusFileSize
new32.83 KB

I just packed landylan module (comment: 9, 29 & 31)

dominik__w’s picture

StatusFileSize
new3.33 KB

Drupal 7 version

jens peter’s picture

It might only be me but why is this one uploaded?
I don't seem to find any reference for "product price alterer field" in this issue.
I ask because I am using the module on a live site.

dominik__w’s picture

StatusFileSize
new39.18 KB

Packed tazir1 + taxonomy term support + product_price_alterer_field

christelle41’s picture

Just after the install, I had the following error :
Notice : Undefined index: desc dans uc_order_field_extra_fields() (line 587 in /serverpath/sites/all/modules/ubercart/uc_order/uc_order.module).

bartolomae’s picture

You have to add the 'desc' index in the uc_discounts_uc_order_pane function.

function uc_discounts_uc_order_pane() {
  $panes['uc_discounts'] = array(
    'callback' => 'uc_discounts_uc_order_pane_callback',
    'title' => t('Discount codes'),
    'desc' => t("Manage the discount codes."),
    'weight' => 8,
    'show' => array('edit'),
  );

  return $panes;
}

I have another problem. The discount is not showing as a line item and I get following error on cart review:

Undefined property: UcOrder::$uc_discounts_line_items_need_updating in uc_discounts_uc_order() (Line 255 of /serverpath/sites/all/modules/uc_discounts/uc_discounts.module)

Any idea how to fix it?

christelle41’s picture

When clicking on "modify" in the order list, I have the following error :
Fatal error: Cannot use object of type stdClass as array in serverpath/sites/all/modules/uc_discounts_alt/uc_discounts.module on line 405

tazir1’s picture

The line is:

      $form_rendered = drupal_render($arg1['uc-discounts']);

Probably need to change to:

      $form_rendered = drupal_render($arg1->uc-discounts);

Also in lines 412 & 413 (Similar to line 592).
Could somebody confirm this?

christelle41’s picture

It's worse than before. I have the following fatal error :
Fatal error: Only variables can be passed by reference in serverpath/sites/all/modules/uc_discounts_alt/uc_discounts.module on line 406

enrikito’s picture

Error in: example.com/cart

PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'database.prefix_' doesn't exist: SELECT DISTINCT tid FROM { taxonomy_index} WHERE nid IN(:nid); Array ( [:nid] => 120 ) en get_discounts_for_order() (línea 1314 de modules/uc_discounts_alt/uc_discounts.module).

omnius’s picture

Great to see work is being done on porting to D7. Seems to work fine for me, so far, after adding 'desc' index in the uc_discounts_uc_order_pane function.
Would it be possible to integrate with Rules in the future to make it even more super powerful? I suppose that is very complicated, just asking....very humbly (and fittingly prostrating myself while humbly asking).

josebrito’s picture

For the #42 comment .
That's easy.
Just remove the space on line 1312.
Instead of: FROM { tanonomy index}
Should be: FROM {taxonomy index}

patoshi’s picture

im on the latest D7 and Ubercart. I just want to be able to do volume discounts. have anyone tried it on this already?

geoffAuthor’s picture

This seems to add the discount to the price on cart & panel on the top of the check out, but doesn't do anything to the final total. It also shows following alert on Check out:
Notice: Undefined property: stdClass::$uc_discounts_line_items_need_updating in uc_discounts_uc_order() (line 255 of /sites/all/modules/uc_discounts_alt/uc_discounts.module).
I added #38 'desc' index to the zip file from #36.
Am I doing something wrong, or do I still need to apply some patches to the code?

geoffAuthor’s picture

Omnius (#43) - which zip on this thread you used? Just doing that 'desc' index doesn't seem to do the trick for me.

mr.BF’s picture

Hi! I try to add a product with the discount to the cart and have:
Notice: Undefined property: stdClass::$uc_discounts_is_fully_discounted в функции get_discounts_for_order() (lime 1726 в in uc_discounts.module.
Help, please!

occucopy’s picture

Is there any way to get a roll/port of the patch here: http://drupal.org/node/900010#comment-5135344 for the D7 port in progress? Would be awesome to get a fix for the bug where the discounts don't apply to any attribute options.

aacraig’s picture

#40, I can confirm this, but your fix is only 98% correct.

    case 'edit-theme':
      $form_rendered = drupal_render($arg1->uc_discounts);
      return $form_rendered;
sslam’s picture

Will be Uc_3 support?

philpro’s picture

This may already be known, emails and the order review pages do not show discounts. A summary of discounts applied to orders appears in the log.

This path, admin/store/orders/#/edit, displays:
Fatal error: Cannot use object of type stdClass as array in .../public_html/sites/all/modules/uc_discounts_alt/uc_discounts.module on line 405

a.knutson’s picture

any updates on an official UC3 D7 port?

jawi’s picture

The ported version"uc_discounts_alt.zip" doesn't work at our drupal 7 installation

stecrv’s picture

I'm interested in D7 version

hockey2112’s picture

I'm also very interested in the D7/U3 version. Is it forthcoming?

sustainablesolutions.co.nz’s picture

Any progress?
I've tried the ported versions and get errors or they simply don't work. A proper D7/U3 version seems to be the only option.

blacklabel_tom’s picture

Would the maintainer(s) be interested in porting the module to D7 people chipped in a few quid each? Looking at the number of people interested I'm sure they could get a good amount of money.

Just an idea.

Cheers

Tom

Andreyy’s picture

Hi
We are going to port this module to D7. Can anybody join and help? It may be more quickly.

Andrey.

blacklabel_tom’s picture

I'll be happy to help where I can, let me know when you start!

piyuesh23’s picture

StatusFileSize
new37.61 KB

Hi,

I have ported a pretty stable version of this module for drupal-7. The patches provided above are using js files for handling stuffs on admin form which can be controlled in drupal 7 via for states api. Also, ubercart 3.x uses rules instead of conditional actions( module provides two conditional actions useful while caculating shipping quotes i.e., calculate shipping cost on the discounted price and check if a discount has been applied to a product or no). These have also been ported to use rules.

Attaching a zip file for the ported module. Feel free to check it out and lemme know your reviews..:)

Andreyy’s picture

Wow! Cool! Thank you very much. We will test it soon.

Slacky08’s picture

Hey piyuesh23,

Thanks for the hard work and submitting the D7 version. I have downloaded it and I can report the following:

1) I can add the discount and set it up as I like which works great
2) When I visited my cart after adding the discount to my products, I received an error which I traced to line 1314 of "uc_discounts.module" where it was "FROM { taxonomy_index}" and I changed to "FROM {taxonomy_index}" which fixed the problem (removed the leading space, not sure if it is do with this particular Drupal installation being in a subfolder). The cart is now accessible, and the discount is correctly applied.
3) Then, when I visit the checkout page I get another error:
"Notice: Undefined property: stdClass::$uc_discounts_line_items_need_updating in uc_discounts_uc_order() (line 255 of /sites/all/modules/uc_discounts/uc_discounts.module)" and it lists at the top that the discount has been applied and gives a new subtotal. However, further down in the Payment Method section where it gives the final price, it does not include the discount - can you help?
4) Feature Request: I would like to be able to limit the discount to apply to products with particular attribute options - is that possible?

Thanks again, and let me know if you want me to test anything further.

UPDATE: Just noticed on item (3) that when I choose a different shipping method and therefore the price gets updated, it now adds the discount at the "Payment Method" part of the Checkout page and so correctly calculates the final price. Obviously something isn't quite right as that error still appears and the discount isn't applied correctly on first load of the Checkout page.

Thanks,

Rich

jrust’s picture

Status: Needs review » Fixed

Thanks for you work on this piyuesh23. I've pushed up your changes as an alpha 7.x release (along with the #2 fix from Rich). New issues on 7.x can be posted as new issues.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

mauro_ptt’s picture

Here's a quick one FOR DRUPAL 7 VERSION, for getting the discounts in the checkout page (table and totals):
Go to uc_discounts_uc_order function (make sure $arg not beeing called by reference, this version of the hook has no referenced arguments) and add this case into switch ($op):

case 'total': 
      // Regenerate discount amounts
      $errors    = array();
      $warnings  = array();
      $messages  = array();
      $discounts = get_discounts_for_order($arg1, $errors, $warnings, $messages);

      add_discount_line_items_to_order($arg1, $discounts);
      
      if (!empty($messages)) {
        $arg1->uc_discounts_line_items_need_updating = true;
      } else {
        $arg1->uc_discounts_line_items_need_updating = false;        
      }
      break;

This regenerates the order info with the current discounts and gets rid of the error in line 255: "Notice: Undefined property: stdClass::$uc_discounts_line_items_need_updating in uc_discounts_uc_order() (line 255 of /sites/all/modules/uc_discounts/uc_discounts.module)", because the else is telling if there are no discounts, uc_discounts_line_items_need_updating is false.

Hope this fix is useful for you

thanks

hockey2112’s picture

The fix in #66 worked for my particular issue. Thanks!

nvidian’s picture

fix in #66 also worked for me, it now show the discount at checkout total (Payment pane). Thanks.

neorg’s picture

Issue summary: View changes
StatusFileSize
new453.47 KB

First of all: Thanks for porting this module to D7U3
Great work!

Using the module from #61 (also tried module from #33)

My problem:
I use the module to apply quantity discount if a customer buys a full box. Not all product have the same number of items in a full box. Terms are used for the number of items in a full box for each product. A customer get 8% discount on a full box of that single SKU. Discount is only granted on SKU's if they order a full box ore more.

Product X: has 27 pieces in a box
Product Y: has 18 pieces in a box

Discount 1 box of one SKU -> 8%
Discount 2 boxes of one SKU -> 10%

Sample order:
SKU X 27 pieces = 8% discount on this SKU only
SKU Y 36 pieces = 10% discount on this SKU only

This works fine if I place one of the SKU's in the cart. (screenshot 1 & 2) If I add the second SKU Only one discount is used (Screenshot 3)

These are my discount setting ( [x]= checked, [ ]= not checked ):
[x] Is active
[x] Can be combined with other discounts
[ ] Discount activates
[ ] Discount expires
Weight = 0
Qualification type = Minimum quantity
Minimum qualification amount = 27
[x] Has max qualifying amount
Maximum qualifying amount = 53
[ ] Require code to activate discount.
[ ] Qualification by Role(s)
[x] Require single product SKU to qualify.
[ ] Use only Discounted Products to determine if 'Minimum qualification amount' is met.
Required products
Filter by Terms -> 27 pieces
Discount Application
Discount type -> Percentage off per qualifying item
Discount amount -> 0.08
Discounted products
Filter Type -> Filter By Terms -> 27 pieces
[ ] Add "Discounted products" to cart.
Maximum applications -> 0
[ ] Further limit maximum applications to number of Required Products in cart.
Max uses -> 0
Max uses per user -> 0
Max uses per code -> 0

I have "Can be combined with other discounts" checked, but only one discount is used in cart.
When I change the "Discounted products -> Filter By Terms -> 27 pieces" to a filter not using Terms like "Discounted products -> Filter By Products -> " (Screenshot 4) than I get two Discount lines but than the discount is calculated twice on all products (like the config says). So it looks like there is a bug in the "Discounted products -> Filter By Terms" part.

Am I using a wrong config for what I want? Or is it a bug?
Can someone give me a hint where to look for a solution please?

I really need this feature. I will appreciate every help you can give me.

Tnx!