Page 1 of 1

Setting a maximum cart discount value

Posted: Mon Nov 29, 2021 8:41 am
by drgl1966

Code: Select all

// Discount Code
                    if (isset($_SESSION['disccode']) && !empty($_SESSION['disccode'])) {
                        $this->mDiscountCode = strtoupper($_SESSION['disccode']);
                        if (!isset($_SESSION['discmin']) || $_SESSION['discmin'] == "") {
                            $_SESSION['discmin'] = 0;
                        }
                        if ($_SESSION['discmin'] <= $this->mTotals['sub']) {
                            if (isset($_SESSION['disctype'])) {
                                switch ($_SESSION['disctype']) {
                                    case 1:
                                        if (isset($_SESSION['discvalue'])) {
                                            $this->mTotals['discount'] = $_SESSION['discvalue'];
                                            if ($this->mTotals['net'] < $this->mTotals['discount']) {
                                                $this->mTotals['discount'] = $this->mTotals['net'];
                                            }
                                        }
                                        break;
                                    case 2:
                                        if (isset($_SESSION['discvalue'])) {
                                            $this->mTotals['discount'] = ($_SESSION['discvalue'] / 100) * $this->mTotals['net'];
                                        }
                                        break;
                                    case 3:
                                        $this->mTotals['discount'] = $this->mTotals['shipping_standard'];
                                        break;
                                }
                            }
                        }
                    }
I have the above code for cart discounts, what I want to do is add the ability to set a maximum discount amount, eg, discount is set to be 20% of cart product value with a minimum spend of $30.00 required but I want this discount to only apply to the first $100 of product value (so max saving of $20.00). I guess something like this : -

f (!isset($_SESSION['discmax']) || $_SESSION['discmax'] == "") {
$_SESSION['discmax'] = 0;
}
if ($_SESSION['discmax'] <= $this->mTotals['discount']) {

But not sure how to tie it all together? Or am I looking at this from the wrong angle? Thanks for any help.