[eluser]mighty_falcon[/eluser]
Not quite. I ended up adding the following functions to the extended multi_cart library that was posted here on the forum sometime ago. For those that may be interested in the future here are the functions i added:
Code:
function coupon($coupon = array(), $cart = 'default') {
// does the requested cart exist
if ( ! isset($this->_cart_contents[$cart]) ) {
log_message('error', 'The requested cart is not created yet.');
return FALSE;
}
$this->_cart_contents[$cart]['coupon'] = $coupon;
if($this->_save_cart($cart)) {
return TRUE;
}
else return FALSE;
}
function has_coupon($cart = 'default') {
// does the requested cart exist
if ( ! isset($this->_cart_contents[$cart]) ) {
log_message('error', 'The requested cart is not created yet.');
return FALSE;
}
if(isset($this->_cart_contents[$cart]['coupon'])) {
return $this->_cart_contents[$cart]['coupon'];
}
else return FALSE;
}
function sub_total($cart = 'default') {
// does the requested cart exist
if ( ! isset($this->_cart_contents[$cart]) ) {
log_message('error', 'The requested cart is not created yet.');
return FALSE;
}
return $this->_cart_contents[$cart]['cart_total'];
}
The changed the total function to
Code:
function total($cart = 'default') {
// does the requested cart exist
if ( ! isset($this->_cart_contents[$cart]) ) {
log_message('error', 'The requested cart is not created yet.');
return FALSE;
}
if(isset($this->_cart_contents[$cart]['coupon']['discount'])) $total = $this->_cart_contents[$cart]['cart_total'] * (1 + $this->_cart_contents[$cart]['coupon']['discount']/100);
else $total = $this->_cart_contents[$cart]['cart_total'];
return $total;
}
So now you have a sub-total to display to the user if they have applied a coupon and in the end a final total.
Also in the constructor, under the last if make sure you set the index for the coupon:
Code:
$this->_cart_contents['default']['coupon'] = array();