function saveOrder($orderData, $session_id, $user_id = null) { $time = new TimeHelper(); //shrani Order v orders table $orderData['Order']['od_date'] = $time->format("Y-m-d H:i:s", time()); $orderData['Order']['od_payment_tax'] = 0.0; $this->save($orderData); //pridobimo ID pravkar vnesenega narocila, za nadaljno manipulacijo $order_id = $this->getInsertID(); //pridobivanje IDjev produktov iz vozicka if (!empty($user_id)) { $result = $this->Product->Cart->getCartContent($session_id, $user_id); } else { $result = $this->Product->Cart->getCartContent($session_id); } //shranjevanje IDjev produktov in narocene kolicine $product_ids = array(); $orderQty = array(); $i = 0; foreach ($result as $item) { $product_ids[$i] = $item['Product']['id']; $orderQty[$i] = $item['Cart']['ct_qty']; $i++; } //tu shranimo podatke v vmesno tabelo (hack) $this->addAssoc('Product', $product_ids, $order_id, $orderQty); //updatanje zaloge v tabeli products $products = array(); foreach ($result as $item) { array_push($products, $item['Product']); $value = $item['Product']['pd_qty'] - $item['Cart']['ct_qty']; $this->Product->id = $item['Cart']['product_id']; $this->Product->saveField('pd_qty', $value); } //brisanje vsebine kosarice foreach ($result as $item) { $this->Product->Cart->emptyCart($item['Cart']['id']); } $order = $this->findById($order_id); return $order; }
function admin_feature_product($id = null) { if (!$id) { $this->Session->setFlash('Invalid id for a product'); $this->redirect(array('action' => 'admin_show_all_products')); } $this->Product->id = $this->data['Product']['id']; if ($this->Product->saveField('featured', 1)) { $this->Session->setFlash('Product was featured successfully!'); $this->redirect(array('action' => 'admin_show_all_products')); } $this->Session->setFlash('Product was not featured!'); $this->redirect(array('action' => 'admin_show_all_products')); }