Welcome Guest, Not a member yet? Register   Sign In
cart problem
#1

[eluser]Unknown[/eluser]
I have a checkout section of my website where the user can apply coupons code to certain items in the cart. When the user enters a coupon code it changes the price of the item in the cart. Because you can't just update the price I am deleting the old cart item and then re inserting it. However when I do this some of the items don't seem to get re-inserted. I think it's the items with things like brackets in the product name. My code is below

Code:
//Create an array of product details
$newItem = array(
    'id' => $items['id'],
    'name' => $items['name'],
    'qty' => $items['qty'],
    'price' => number_format($newPrice, 2),
    'supplier' => $items['supplier'],
    'coupon' => $coupon,
    'full_price' => $items['price'],
     'type' => $items['type']
);

//Create an array to remove the item from the cart
$data = array(
    'rowid' => $items['rowid'],
    'qty'   => '0'
);
                                    
$this->cart->product_name_rules = '[:print:]';

//Remove the item then re-insert it
$this->cart->insert($newItem);
$this->cart->update($data);

Can anyone see what I'm doing wrong? Thanks for any help
#2

[eluser]ludo31[/eluser]
the problem is may be in your array $newItem
Code:
//Create an array of product details
$newItem = array(
    'id' => $items['id'],
    'name' => $items['name'],
    'qty' => $items['qty'],
    'price' => number_format($newPrice, 2),
    'supplier' => $items['supplier'],
    'coupon' => $coupon,
    'full_price' => $items['price'],
     'type' => $items['type']
);

try to make it like that :

Code:
$data = array(
            'id' => $this->uri->segment(5),
            'qty' => 1,
            'price' => $this->uri->segment(6),
            'name' => $this->uri->segment(7),
            'options' => array('quantite' => $quantif)
        );

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

id qty price name is required : and the rest we take it in options !!




Theme © iAndrew 2016 - Forum software by © MyBB