Skip to content

Instantly share code, notes, and snippets.

@rsmarshall
Created February 18, 2015 15:16
Show Gist options
  • Select an option

  • Save rsmarshall/56d275ffbca8700e90ce to your computer and use it in GitHub Desktop.

Select an option

Save rsmarshall/56d275ffbca8700e90ce to your computer and use it in GitHub Desktop.
/**
* Add an item submitted via the app upload
*
* @param array $items An array of items for adding to the Trolley
*/
public function addFromApp($items)
{
$pdo = DB::getPdo();
$pdo->beginTransaction();
$statement = $pdo->prepare("INSERT INTO trolley_items ( `trolley_id`,`pack_id`,`price`,`quantity` )
VALUES
( ?, ?, ?, ? )
ON DUPLICATE KEY UPDATE `quantity` = `quantity` + 1");
foreach ($items as $item) {
$statement->execute(array($item->trolleyId, $item->packId, $item->price, $item->quantity));
}
$pdo->commit();
/*
DB::statement("INSERT INTO trolley_items ( `trolley_id`,`pack_id`,`price`,`quantity` )
VALUES
( ?, ?, ?, ? )
ON DUPLICATE KEY UPDATE `quantity` = `quantity` + 1", array($trolleyId, $packId, $price, $quantity));
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment