Download & Extend

Ubercart Discounts

Project:UberPOS
Version:6.x-1.0-alpha1
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active

Issue Summary

I'm currently using http://drupal.org/project/uc_discounts_alt on my site to give discount based on certain product combinations.

Does anyone know how I'd get these discounts to works in uberpos as well? Can't really think where to start.

Comments

#1

This patch adds a very simple sub-module to UberPOS that provides integration with UC Discounts Alt. The module adds a button DISC and a command DC. When preceded by a discount code, the commant attempts to apply the discount code to the order. If no code is provided, it tries to apply any possible codeless discounts to the order. UC Discounts ALT does all the heavy lifting.

AttachmentSize
uc_discounts_integration-1110428-1.patch 2.08 KB

#2

This is an updated patch. Re-applies and re-calculates order-wide discounts as products are added/removed.

AttachmentSize
uc_discounts_alt-integration-1110428-2.patch 2.82 KB

#3

Category:support request» feature request
Status:active» needs review

#4

Status:needs review» fixed

Committed!

#5

Thanks a lot for this!

However, "[re-applying]and [re-calculating] order-wide discounts as products are added/removed" does not work 100% yet. If you have site wide discounts (for certain user roles, say), this does not happen as the implementation of hook_order checks for presence of discount codes before it tries to apply discounts. For site wide discounts, there is no discount code, so nothing happens.

To fix this, the function up_discounts_order should simply be:

/**
* Implementation of hook_order().
*/
function up_discounts_order($op, &$order, $arg2) {
  global $up_discounts_recalc;
  if ($op == 'save') {
    up_discounts_process($order);
  }
}

Unfortunately, if you do this and no discounts were applied, which is usually the case, a warning message appears. This warning message needs to be suppressed (I think), so the function up_discounts_process needs to be rewritten to:

function up_discounts_process($order, $discount_code = '') {
  $codes = array();
  if ($discount_code) {
    $codes[] = $discount_code;
  }
  if (!empty($order->uc_discounts_codes)) {
    $codes += $order->uc_discounts_codes;
  }
  $codes = implode("\r", $codes);

  uc_discounts_order_pane_callback(t('Apply discounts'), array('order_id' => $order->order_id, 'uc-discounts-codes' => $codes));
 
  // Clear status messages.
  drupal_get_messages('status', TRUE);
 
  // Display errors.
  $errors = drupal_get_messages('error', TRUE);
  $warnings = drupal_get_messages('warning', TRUE);
  $message .= implode(' ', $errors['error']);
  // since we're attempting to apply discounts every time the order is saved,
  // it's not a problem if no discount is applied. Suppress the warning
  // that says no discounts were applied
  $relevant_warnings = array();
  foreach($warnings['warning'] as $warning) {
    if($warning == t('The code(s) did not yield a discount for this order.')) {
      continue;
    };
    $relevant_warnings[] = $warning;
  };
  $message .= implode(' ', $relevant_warnings);
  //$message .= implode(' ', $warnings['warning']);
  if ($message)
    uberpos_clear_message($message);
}

The drawback to this suppression is that if a user explicitly calls the DC command and nothing happens, no warning appears. There's probably a (convoluted) way around that, however, but since I don't need it, I haven't implemented it.

Could the changes above please be added to the code for the up_discounts module?

Thanks!

#6

Status:fixed» active

It's also probably a good idea to apply discounts in the uberpos code itself, using the new uc_discounts_apply() function (see http://drupal.org/node/1166912)

#7

That all makes sense to me. Thanks for getting jrust to add that api function! I should get this reviewed and committed this weekend.

#8

Now that there is a uc_discounts_apply() function in UC Discounts Alt (albeit only in the dev version) the code needs to be patched according to the attached, ehm, patch.

AttachmentSize
apply.discounts.using_.uc_discounts_apply.patch 1.85 KB

#9

Woops. There was a typo in the patch. Sorry. Here's the fixed one.

AttachmentSize
apply.discounts.using_.uc_discounts_apply.patch 1.85 KB

#10

Has this last patch been committed?

nobody click here