Welcome Guest, Not a member yet? Register   Sign In
Cart class discount
#1

[eluser]BrainCatcher[/eluser]
Hey there,

I want to give a customer the ability to achieve a discount when paying online. When im adding a product to the cart which is actually the discount. It has an negative number(price). The minus doesn't work the total price is increased not decreased. It's not an option to first remove a product, recalculate the discount and then adding the product again with the new price.

Code:
$data = array(
                            'id' => $product->p_id,
                            'price' => '-2.00',
                            'qty' => 1,
                            'name' => $product->nameProduct,
                            'order_id' => $orderid
                        );

$this->cart->insert($data);

I need some help!
#2

[eluser]BrainCatcher[/eluser]
Hi there,

I solved it msyself. I don't know of it's an proper solution but it works!

In the cart class i changed:
Code:
$items['price'] = trim(preg_replace('/([^0-9\.])/i', '', $items['price']));
to this:
Code:
$items['price'] = trim(preg_replace('/([^0-9\.\-])/i', '', $items['price']));

So the cart class is now accepting negative values as a discount.
#3

[eluser]Cristian Gilè[/eluser]
If you need to add some functionality to an existing library the best practice it to extend the class.

In your MY_Cart library you could ovveride the total() method to get the total amount from cart and subtract the discount (if present) from it.


Cristian Gilè




Theme © iAndrew 2016 - Forum software by © MyBB