diff --git a/inside/Order.php b/inside/Order.php index b605d98..21b090e 100644 --- a/inside/Order.php +++ b/inside/Order.php @@ -19,7 +19,7 @@ class Order { $this->__construct($id, $data); } - public + public function __construct($id = NULL, $data = NULL){ $this->conn = db_connect(); @@ -40,7 +40,7 @@ class Order { $this->order_status_id = $data['order_status_id']; $this->order_status_value = $data['order_status_value']; $this->comment = $data['comment']; - + } } //Common initializations @@ -50,10 +50,10 @@ class Order { function store(){ if ($this->id == NULL){ $this->id = getNextId("din_order"); - $sql = sprintf("INSERT INTO din_order + $sql = sprintf("INSERT INTO din_order (id, user_id, timestamp, comment) - VALUES - (%s, %s, NOW(), %s)", + VALUES + (%s, %s, NOW(), %s)", $this->conn->quoteSmart($this->id), $this->conn->quoteSmart($this->user_id), $this->conn->quoteSmart($this->comment) @@ -63,41 +63,58 @@ class Order { //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; + $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) { $item = new OrderItem(NULL, $data); $item->store(); - return true; - //$this->_updateTotalPrice(); + } + + return true; } - public + public function _updateTotalPrice(){ } - - public + + public function _retrieveData(){ $sql = "SELECT o.*, os.value AS order_status_value FROM din_order o, din_order_status os @@ -115,21 +132,21 @@ class Order { } public - /*static*/ + /*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); + $result =& $this->conn->query($sql); return $result; } - + public function calculateTotalAmount() { $items = $this->getItems(); @@ -142,8 +159,8 @@ class Order { } return $amount; } - - public + + public function display(){ $items = $this->getItems(); ?> @@ -152,19 +169,19 @@ class Order { numRows() > 0){?> - +
- + -fetchRow(DB_FETCHMODE_ASSOC)){ $item = new OrderItem($row['id']); @@ -192,11 +209,11 @@ class Order { } ?> - + getItems(); ?> @@ -204,14 +221,14 @@ class Order {

Handlekurv #id; ?>

+?>
vare pris antall
-fetchRow(DB_FETCHMODE_ASSOC)){ $item = new OrderItem($row['id']); $item->displayShortList(); @@ -227,17 +244,17 @@ class Order {

rediger ordre slett ordre - gå til betaling + gå til betaling

toString()); } ?> - + getItems(); @@ -248,24 +265,24 @@ class Order { } return $text; } - - public + + public function displayConfirmation(){ $items = $this->getItems(); ?> numRows() > 0){?> - +
vare pris antall
-fetchRow(DB_FETCHMODE_ASSOC)){ @@ -283,12 +300,12 @@ class Order { error("Items: " . $result->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); @@ -300,7 +317,7 @@ class Order { } else { if(!$user->renewMembershipPayex()){ return false; - } + } } } elseif ($item->product_id == 12) { // send new membercard diff --git a/inside/OrderItem.php b/inside/OrderItem.php index db9fba9..b75df40 100644 --- a/inside/OrderItem.php +++ b/inside/OrderItem.php @@ -19,7 +19,7 @@ class OrderItem { $this->__construct($id, $data); } - public + public function __construct($id = NULL, $data = NULL){ $this->conn = db_connect(); @@ -34,21 +34,25 @@ class OrderItem { $data = $this->_retrieveData(); } } + //Common initializations - $this->product_id = $data['product_id']; - $this->quantity = $data['quantity']; - $this->order_id = $data['order_id']; - $this->discount = $data['discount']; - $this->comment = isset($data['comment']) ? $data['comment'] : ''; + $this->product_id = $data['product_id']; + $this->quantity = $data['quantity']; + $this->order_id = $data['order_id']; + $this->discount = $data['discount']; + $this->comment = isset($data['comment']) ? $data['comment'] : ''; + + // only allow purchase of one membership + if ($this->product_id == 1) $this->quantity = 1; } public function store(){ if ($this->id == NULL){ $this->id = getNextId("din_order_item"); - $sql = sprintf("INSERT INTO din_order_item + $sql = sprintf("INSERT INTO din_order_item (id, product_id, quantity, order_id, discount, comment) - VALUES - (%s, %s, %s, %s, %s, %s)", + VALUES + (%s, %s, %s, %s, %s, %s)", $this->conn->quoteSmart($this->id), $this->conn->quoteSmart($this->product_id), $this->conn->quoteSmart($this->quantity), @@ -61,11 +65,11 @@ class OrderItem { //notify("Nytt ordreelement lagret."); }else { error("New order_item: " . $result->toString()); - } + } } } - - + + public function _retrieveData(){ $sql = "SELECT * FROM din_order_item t @@ -83,17 +87,17 @@ class OrderItem { public function setQuantity($value) { - $sql = "UPDATE din_order_item SET - quantity = $value - WHERE " . - " id = $this->id"; - + // only allow purchase of one membership + if ($this->product_id == 1) $value = 1; + + $sql = "UPDATE din_order_item SET quantity = " . $value . " WHERE id = " . $this->id; + $result = $this->conn->query($sql); if (DB::isError($result) != true){ //notify("Orderstatus oppdatert ($value)"); }else { error("Set quantity - order_item: " . $result->toString()); - } + } } public @@ -102,34 +106,34 @@ class OrderItem { comment = '$value' WHERE " . " id = $this->id"; - + $result = $this->conn->query($sql); if (DB::isError($result) != true){ //notify("Orderstatus oppdatert ($value)"); }else { error("Set comment - order_item: " . $result->toString()); - } + } } public - /*static*/ + /*static*/ function delete($id){ $conn = db_connect(); - $sql = "DELETE FROM din_order_item - WHERE id = $id + $sql = "DELETE FROM din_order_item + WHERE id = $id LIMIT 1"; $result = $conn->query($sql); if (DB::isError($result) != true){ if ($conn->affectedRows() > 0){ //notify("Varen er slettet fra handlekurven."); }else { - //notify("Ugyldig order_itemid, ingen handling utført."); + //notify("Ugyldig order_itemid, ingen handling utført."); } }else { error($result->toString()); } } - + public function display(){ $product = new Product($this->product_id); ?> @@ -146,17 +150,17 @@ class OrderItem {
vare pris antall
title; ?>
description; ?>
price); ?>
- +

Du vil få tilsendt medlemskort i posten i løpet av 6-12 dager.

Om du allerede har medlemskort vil du kun få tilsendt nytt oblat for inneværende år.

For spørsmål vedrørende medlemskapet eller transaksjonen kan du kontakte support@studentersamfundet.no.

- + - + product_id); ?> @@ -172,9 +176,9 @@ class OrderItem { product_id); ?> @@ -184,13 +188,13 @@ class OrderItem { quantity; ?> product_id); $text = $this->quantity . " " . $product->title . " á " . formatPrice($product->price) . "\n"; - return $text; + return $text; } } diff --git a/inside/images/products/1.png b/inside/images/products/1.png new file mode 100644 index 0000000..c006bc3 Binary files /dev/null and b/inside/images/products/1.png differ diff --git a/inside/images/products/12.png b/inside/images/products/12.png new file mode 100644 index 0000000..c006bc3 Binary files /dev/null and b/inside/images/products/12.png differ