Jump to content

Coupon Excludes Item but Still Works


bsmither

Recommended Posts

In CubeCart 520, a feature was added that allowed for a coupon to optionally and explicitly include or exclude products from it discounting the subtotal of the shopping cart. However, a bug exists (bug #597).

 

If a shopping basket contains only the one item "Widget", and a coupon is used that explicitly excludes "Widget", CubeCart will still apply the discount that this coupon provides. (More experiments are needed to verify, but I think that if there is also something else, like "Doodad", in the shopping basket, this bug does not happen.)

 

Bug 597 has been reported as Resolved. (And maybe, if you email CubeCart Sales and ask for the fix, they may send it to you, but if not...)

 

If you need an experimental fix now, so that your store can offer discounts in time for the next major holiday, try these edits in the following posts (soon to be posted).

 

Here are some parameters I found while going through the code:

* only one coupon can be added by the customer per order (future fix)

* that coupon can apply to the sub-total of eligible products, or to the shipping, but not both

* the coupon applies to the line-item subtotal, whatever that may be (e.g., sale price, quantity point price, options price)

* the coupon's number of uses is not handled correctly (bug)

* there is no rejection of an excluding coupon even if that coupon cannot be applied to some other product (bug)

* there is no capability to offer a coupon based on options of a product, that is, 20% off Large size only (future feature)

Link to comment
Share on other sites

The following edits have not been extensively tested. Use at your own risk. This was developed on CC522 code.

 

In the file /classes/cart.class.php, find near line 1125:

} else { // Process coupons

Add the following after that line:

$sum_of_unexcluded_items = $this->_subtotal; // Set this and will be reset if necessary
$product_ids = unserialize($data['product']);
$incexc = array_shift($product_ids);
if( $incexc == 'exclude' ) {
  $sum_of_unexcluded_items = 0; // We need to be recalculating the sub-total
  foreach($this->basket['contents'] as $hash => $item)
    $tmp_basket_contents_ids[$hash] = $item['id'];
  $result_array = array_diff($tmp_basket_contents_ids, $product_ids);
  if( count($result_array) > 0 ) {
    foreach($result_array as $hash => $item_id)
      $sum_of_unexcluded_items += $thisbasket['contents'][$hash]['quantity'] * $thisbasket['contents'][$hash]['total_price_each'];
  }
}

Change this line:

$discount = ($$this->_subtotal-$this->_discount)*($data['value']/100);

to:

$discount = ($sum_of_unexcluded_items-$this->_discount)*($data['value']/100);  //$this->_subtotal-$this->_discount)*($data['value']/100);

 

Change these two lines:

} else if ($this->_subtotal < $discount) {

   $discount = $this->_subtotal;

to:

} else if ($sum_of_unexcluded_items < $discount) { // $this->_subtotal < $discount) {

$discount = $sum_of_unexcluded_items; //$this->_subtotal;

 

Change these two lines:

}

$this->save();

to these three lines:

}

}

$this->save();

 

I will need to check if this breaks the calculation of general-purpose coupons.

 

Yup, it did. More in a moment.

 

Edit: A few changes have been made to the new code above.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...