public function postToCart($r) { $u = $this->user; $u->expireDataCache($r->getCache()); $tag = new Dase_DBO_Tag($this->db); $tag->dase_user_id = $u->id; $tag->type = 'cart'; if ($tag->findOne()) { $tag_item = new Dase_DBO_TagItem($this->db); $item_uniq = str_replace($r->app_root . '/', '', $r->getBody()); list($coll, $sernum) = explode('/', $item_uniq); //todo: compat $item = Dase_DBO_Item::get($this->db, $coll, $sernum); $tag_item->item_id = $item->id; $tag_item->p_collection_ascii_id = $coll; $tag_item->p_serial_number = $sernum; $tag_item->tag_id = $tag->id; $tag_item->updated = date(DATE_ATOM); $tag_item->sort_order = 99999; if ($tag_item->insert()) { //will not need this when we use item_unique: //writes are expensive ;-) //$tag_item->persist(); $tag->updateItemCount(); $r->renderResponse("added cart item {$tag_item->id}"); } else { $r->renderResponse("add to cart failed"); } } else { $r->renderResponse("no such cart"); } }
function addItem($item_unique, $updateCount = false) { $tag_item = new Dase_DBO_TagItem($this->db); $tag_item->tag_id = $this->id; list($coll, $sernum) = explode('/', $item_unique); //todo: compat (but handy anyway) $item = Dase_DBO_Item::get($this->db, $coll, $sernum); if (!$item) { return; } $tag_item->item_id = $item->id; $tag_item->p_collection_ascii_id = $coll; $tag_item->p_serial_number = $sernum; $tag_item->updated = date(DATE_ATOM); $tag_item->sort_order = 99999; try { $tag_item->insert(); //this is too expensive when many items are being added in one request if ($updateCount) { $this->updateItemCount(); } } catch (Exception $e) { throw new Exception($e->getMessage()); } }