Welcome Guest, Not a member yet? Register   Sign In
Better update function for the cart class
#1

[eluser]Unknown[/eluser]
If you've ever tried to use the cart class, you probably notice the update function is pretty useless - it lets you update the quantity of items in a row, but not change things like options or custom fields.

Here is a method you can add to custom cart class that inherits from the base:

public function update($record){

$contents = $this->contents();

$rowid = @$record['rowid'];

if(!$rowid) return;

if(!$contents[$rowid]) return;

$new_record = $contents[$rowid];

foreach($record as $k => $v)
$new_record[$k] = $v;

parent::update( array('rowid' => $rowid, 'qty' => 0) );

$this->insert($new_record);
}

Basically, it takes the row at rowid and saves it as an array. Then, it updates / adds the new keys specified in record, then it removes the existing row by setting the quantity to 0, then it re-adds the row to cart.

Seems like how this is how it should function by default, although I don't think very much time or thought was put into the cart class (doesn't even have an add method :/ )




Theme © iAndrew 2016 - Forum software by © MyBB