__construct($id, $data); } public function __construct($id = NULL, $data = NULL){ $this->conn = db_connect(); $this->id = $id; if ($id == NULL){// Order $this->order_status_id = 1;//New empty order created $this->comment = "Order created."; $this->user_id = getCurrentUser(); }else {//ID set, existing article if ($data != NULL){//Update existing article }else {//Retrieve data from backend for display or other actions $data = $this->_retrieveData(); $this->user_id = $data['user_id']; $this->timestamp = $data['timestamp']; $this->order_status_id = $data['order_status_id']; $this->order_status_value = $data['order_status_value']; $this->comment = $data['comment']; } } //Common initializations } public function store(){ if ($this->id == NULL){ $this->id = getNextId("din_order"); $sql = sprintf("INSERT INTO din_order (id, user_id, timestamp, comment) VALUES (%s, %s, NOW(), %s)", $this->conn->quoteSmart($this->id), $this->conn->quoteSmart($this->user_id), $this->conn->quoteSmart($this->comment) ); $result = $this->conn->query($sql); if (DB::isError($result) != true){ //notify("Ny ordre lagret."); }else { error("New order: " . $result->toString()); } } } public function setStatus($value) { $sql = "UPDATE din_order SET order_status_id = $value WHERE " . " id = $this->id"; $result = $this->conn->query($sql); if (DB::isError($result) != true){ //notify("Orderstatus oppdatert ($value)"); }else { error("Set status - order: " . $result->toString()); } } public function addOrderItem($data) { $data['order_id'] = $this->id; $data['discount'] = 0; $added = false; // fetch items in order and check if item allready is in order $items = $this->getItems(); while ($row =& $items->fetchRow(DB_FETCHMODE_ASSOC)){ $item = new OrderItem($row['id']); if ($item->product_id == $data['product_id']) { // item already exists in order, update quantity $item->setQuantity($item->quantity + $data['quantity']); $added = true; } } // new product id for this order, add order item if (!$added) { if($data['product_id'] == 27) { $user = new User($this->user_id); if($user->expires != '2011-12-31') { notify('Du ser ikke ut til å ha hatt medlemskap for 2011 - vennligst kontakt billettluka om du mener dette er en feil'); return false; } } $item = new OrderItem(NULL, $data); $item->store(); } return true; } public function _updateTotalPrice(){ } public function _retrieveData(){ $sql = "SELECT o.*, os.value AS order_status_value FROM din_order o, din_order_status os WHERE o.id = $this->id " . "AND o.order_status_id = os.id"; $result =& $this->conn->query($sql); if (DB::isError($result) != true){ if ($row =& $result->fetchRow(DB_FETCHMODE_ASSOC)){ return $row; } }else { error("Order: " . $result->toString()); } } public /*static*/ function delete($id){ $order = new Order($id); $order->setStatus(5); } public function getItems() { $sql = "SELECT oi.id " . "FROM din_order_item oi " . "WHERE oi.order_id = $this->id"; $result =& $this->conn->query($sql); return $result; } public function calculateTotalAmount() { $items = $this->getItems(); $amount = 0; while ($row =& $items->fetchRow(DB_FETCHMODE_ASSOC)){ $item = new OrderItem($row['id']); $product = new Product($item->product_id); $amount = $amount + $item->quantity * $product->price; } return $amount; } public function display(){ $items = $this->getItems(); ?>

Din handlekurv

numRows() > 0){?>
fetchRow(DB_FETCHMODE_ASSOC)){ $item = new OrderItem($row['id']); $item->displayList(); } ?>
vare pris antall

Har du gjort endringer? oppdatér

Handle mer? tilbake til produkter

Er du ferdig? gå til betaling

toString()); } ?>
getItems(); ?>

Handlekurv #id; ?>

fetchRow(DB_FETCHMODE_ASSOC)){ $item = new OrderItem($row['id']); $item->displayShortList(); } ?>
vare pris antall

Ordrestatus: order_status_value; ?> order_status_id < 3) { ?>

rediger ordre slett ordre gå til betaling

toString()); } ?>
getItems(); $text = ""; while ($row =& $items->fetchRow(DB_FETCHMODE_ASSOC)){ $item = new OrderItem($row['id']); $text .= $item->getConfirmationText(); } return $text; } public function displayConfirmation(){ $items = $this->getItems(); ?> numRows() > 0){?> fetchRow(DB_FETCHMODE_ASSOC)){ $item = new OrderItem($row['id']); $item->displayShortList(); } ?>
vare pris antall
toString()); } } public function performOperations() { $items = $this->getItems(); while ($row =& $items->fetchRow(DB_FETCHMODE_ASSOC)){ $item = new OrderItem($row['id']); if ($item->product_id == 1) { // new membership $user = new User($this->user_id); $cardno = $user->cardno; if ($cardno == NULL) { if (!$user->registerMembershipPayex()){ return false; } } else { if(!$user->renewMembershipPayex()){ return false; } } } elseif ($item->product_id == 12) { // send new membercard $user = new User($this->user_id); if (!$user->renewMembercardPayex()) { return false; } } else if($item->product_id == 27) { $user = new User($this->user_id); if($user->expires == '2011-12-31') { if(!$user->renewMembershipPayex()) { return false; } } else return false; } } } } ?>