From e9a46ca3cbac88471ed39bce557dcf28dd91f4d5 Mon Sep 17 00:00:00 2001 From: Ben Smith Date: Sun, 30 Aug 2009 19:10:45 +1200 Subject: [PATCH] Initial commit of basket module. --- .../basket/controllers/admin_configure.php | 55 +++++ .../controllers/admin_product_lines.php | 151 ++++++++++++ modules/basket/controllers/basket.php | 222 ++++++++++++++++++ modules/basket/css/basket.css | 5 + modules/basket/helpers/basket.php | 156 ++++++++++++ modules/basket/helpers/basket_event.php | 43 ++++ modules/basket/helpers/basket_installer.php | 93 ++++++++ modules/basket/helpers/basket_theme.php | 46 ++++ modules/basket/helpers/product.php | 91 +++++++ modules/basket/images/basket.png | Bin 0 -> 424 bytes modules/basket/libraries/session_basket.php | 151 ++++++++++++ modules/basket/models/product.php | 24 ++ modules/basket/module.info | 3 + modules/basket/views/add_to_basket.html.php | 8 + .../basket/views/add_to_basket_ajax.html.php | 9 + modules/basket/views/admin_configure.html.php | 8 + .../basket/views/admin_product_lines.html.php | 70 ++++++ modules/basket/views/basket.html.php | 35 +++ modules/basket/views/checkout.html.php | 64 +++++ modules/basket/views/confirm_order.html.php | 82 +++++++ modules/basket/views/order_complete.html.php | 24 ++ modules/basket/views/view_basket.html.php | 112 +++++++++ 22 files changed, 1452 insertions(+) create mode 100644 modules/basket/controllers/admin_configure.php create mode 100644 modules/basket/controllers/admin_product_lines.php create mode 100644 modules/basket/controllers/basket.php create mode 100644 modules/basket/css/basket.css create mode 100644 modules/basket/helpers/basket.php create mode 100644 modules/basket/helpers/basket_event.php create mode 100644 modules/basket/helpers/basket_installer.php create mode 100644 modules/basket/helpers/basket_theme.php create mode 100644 modules/basket/helpers/product.php create mode 100644 modules/basket/images/basket.png create mode 100644 modules/basket/libraries/session_basket.php create mode 100644 modules/basket/models/product.php create mode 100644 modules/basket/module.info create mode 100644 modules/basket/views/add_to_basket.html.php create mode 100644 modules/basket/views/add_to_basket_ajax.html.php create mode 100644 modules/basket/views/admin_configure.html.php create mode 100644 modules/basket/views/admin_product_lines.html.php create mode 100644 modules/basket/views/basket.html.php create mode 100644 modules/basket/views/checkout.html.php create mode 100644 modules/basket/views/confirm_order.html.php create mode 100644 modules/basket/views/order_complete.html.php create mode 100644 modules/basket/views/view_basket.html.php diff --git a/modules/basket/controllers/admin_configure.php b/modules/basket/controllers/admin_configure.php new file mode 100644 index 00000000..58a246ea --- /dev/null +++ b/modules/basket/controllers/admin_configure.php @@ -0,0 +1,55 @@ +validate()) { + + basket::extractForm($form); + message::success(t("Basket Module Configured!")); + //url::redirect("admin/recaptcha"); + } + } + else + { + basket::populateForm($form); + } + + $view = new Admin_View("admin.html"); + $view->content = new View("admin_configure.html"); + + + + $view->content->form = $form; + //$view->content->products = ORM::factory("product")->orderby("name")->find_all(); + + print $view; + } +} diff --git a/modules/basket/controllers/admin_product_lines.php b/modules/basket/controllers/admin_product_lines.php new file mode 100644 index 00000000..c238080d --- /dev/null +++ b/modules/basket/controllers/admin_product_lines.php @@ -0,0 +1,151 @@ +content = new View("admin_product_lines.html"); + $view->content->products = ORM::factory("product")->orderby("name")->find_all(); + + print $view; + } + + public function add_product_form() { + print product::get_add_form_admin(); + } + + + public function add_product() { + access::verify_csrf(); + + $form = product::get_add_form_admin(); + $valid = $form->validate(); + $name = $form->add_product->inputs["name"]->value; + $product = ORM::factory("product")->where("name", $name)->find(); + if ($product->loaded) { + $form->add_product->inputs["name"]->add_error("in_use", 1); + $valid = false; + } + + if ($valid) { + $product = product::create( + $name, $form->add_product->cost->value, $form->add_product->description->value); + + $product->save(); + message::success(t("Created product %product_name", array( + "product_name" => p::clean($product->name)))); + print json_encode(array("result" => "success")); + } else { + print json_encode(array("result" => "error", + "form" => $form->__toString())); + } + } + + public function delete_product_form($id) { + $product = ORM::factory("product", $id); + if (!$product->loaded) { + kohana::show_404(); + } + print product::get_delete_form_admin($product); + } + + public function delete_product($id) { + access::verify_csrf(); + + if ($id == user::active()->id || $id == user::guest()->id) { + access::forbidden(); + } + + $product = ORM::factory("product", $id); + if (!$product->loaded) { + kohana::show_404(); + } + + $form = user::get_delete_form_admin($product); + if($form->validate()) { + $name = $product->name; + $product->delete(); + } else { + print json_encode(array("result" => "error", + "form" => $form->__toString())); + } + + $message = t("Deleted user %product_name", array("product_name" => p::clean($name))); + log::success("user", $message); + message::success($message); + print json_encode(array("result" => "success")); + } + + public function edit_product($id) { + access::verify_csrf(); + + $product = ORM::factory("product", $id); + if (!$product->loaded) { + kohana::show_404(); + } + + $form = product::get_edit_form_admin($product); + $valid = $form->validate(); + if ($valid) { + $new_name = $form->edit_product->inputs["name"]->value; + if ($new_name != $product->name && + ORM::factory("product") + ->where("name", $new_name) + ->where("id !=", $product->id) + ->find() + ->loaded) { + $form->edit_product->inputs["name"]->add_error("in_use", 1); + $valid = false; + } else { + $product->name = $new_name; + } + } + + if ($valid) { + $product->cost = $form->edit_product->cost->value; + $product->description = $form->edit_product->description->value; + $product->save(); + + message::success(t("Changed product %product_name", + array("product_name" => p::clean($product->name)))); + print json_encode(array("result" => "success")); + } else { + print json_encode(array("result" => "error", + "form" => $form->__toString())); + } + } + + public function edit_product_form($id) { + $product = ORM::factory("product", $id); + if (!$product->loaded) { + kohana::show_404(); + } + + $form = product::get_edit_form_admin($product); + + print $form; + } + +} \ No newline at end of file diff --git a/modules/basket/controllers/basket.php b/modules/basket/controllers/basket.php new file mode 100644 index 00000000..00f07c3e --- /dev/null +++ b/modules/basket/controllers/basket.php @@ -0,0 +1,222 @@ +basket = Session_Basket::get(); + + $template->content = $view; + + print $template; + } + + private function getCheckoutForm(){ + $form = new Forge("basket/confirm", "", "post", array("id" => "checkout", "name" =>"checkout")); + $group = $form->group("contact")->label(t("Contact Details")); + $group->input("fullname")->label(t("Name"))->id("fullname"); + $group->input("house")->label(t("House Number / Name"))->id("house"); + $group->input("street")->label(t("Street"))->id("street"); + $group->input("suburb")->label(t("Suburb"))->id("suburb"); + $group->input("town")->label(t("Town or City"))->id("town"); + $group->input("postcode")->label(t("Postcode"))->id("postcode"); + $group->input("email")->label(t("E-Mail Address"))->id("email"); + $group->input("phone")->label(t("Telephone Number"))->id("phone"); + + return $form; + } + + public function checkout () { + + $template = new Theme_View("page.html", "basket"); + + $view = new View("checkout.html"); + + $basket = Session_Basket::get(); + + $form = self::getCheckoutForm(); + $form->contact->fullname->value($basket->name); + $form->contact->house->value($basket->house); + $form->contact->street->value($basket->street); + $form->contact->suburb->value($basket->suburb); + $form->contact->town->value($basket->town); + $form->contact->postcode->value($basket->postcode); + $form->contact->email->value($basket->email); + $form->contact->phone->value($basket->phone); + $view->form = $form; + + $template->content = $view; + + + print $template; + } + + public function confirm () { + access::verify_csrf(); + + $form = $this->getCheckoutForm(); + + $valid = $form->validate(); + + if ($valid){ + $basket = Session_Basket::get(); + $basket->name = $form->contact->fullname->value; + $basket->house = $form->contact->house->value; + $basket->street = $form->contact->street->value; + $basket->suburb = $form->contact->suburb->value; + $basket->town = $form->contact->town->value; + $basket->postcode = $form->contact->postcode->value; + $basket->email = $form->contact->email->value; + $basket->phone = $form->contact->phone->value; + + $template = new Theme_View("page.html", "basket"); + + $form = new Forge("basket/complete", "", "post", array("id" => "confirm", "name" =>"confirm")); + $view = new View("confirm_order.html"); + $view->basket = $basket; + $template->content = $view; + $view->form = $form; + print $template; + } + else + { + die("Invalid confirmation!"); + + } + } + + public function complete () { + access::verify_csrf(); + $basket = Session_Basket::get(); + + //$admin_address = basket::getEmailAddress(); + + $admin_email = "Order for : +".$basket->name." +".$basket->house." +".$basket->street." +".$basket->suburb." +".$basket->town." +".$basket->postcode." +".$basket->email." +".$basket->phone." +Placed at ".date("d F Y - H:i" ,time())." +Total Owed ".$basket->cost()." in ".basket::getCurrency()." + +Items Ordered: + +"; + + // create the order items + foreach ($basket->contents as $basket_item){ + $item = $basket_item->getItem(); + $prod = ORM::factory("product", $basket_item->product); + $admin_email = $admin_email." +".$item->title." - ".$item->url()." +".$prod->name." - ".$prod->description." +".$basket_item->quantity." @ ".$prod->cost." + +"; + } + + + $from = "From: ".basket::getEmailAddress(); + mail(basket::getEmailAddress(), "Order from ".$basket->name, $admin_email, $from); + + $basket->clear(); + + $template = new Theme_View("page.html", "basket"); + $view = new View("order_complete.html"); + $template->content = $view; + print $template; + } + + private function getAddToBasketForm(){ + + $form = new Forge("basket/add_to_basket", "", "post", array("id" => "gAddToBasketForm")); + $group = $form->group("add_to_basket")->label(t("Add To Basket")); + $group->hidden("id"); + $group->dropdown("product") + ->label(t("Product")) + ->options(product::getProductArray()); + $group->input("quantity")->label(t("Quantity"))->id("gQuantity"); + $group->submit("")->value(t("Add")); + //$group->submit("proceedToCheckout")->value(t("Proceed To Checkout")); + + return $form; + } + + public function add_to_basket(){ + + access::verify_csrf(); + + $form = self::getAddToBasketForm(); + $valid = $form->validate(); + + if ($valid){ + $basket = Session_Basket::getOrCreate(); + $basket->add( + $form->add_to_basket->id->value, + $form->add_to_basket->product->value, + $form->add_to_basket->quantity->value); + + print json_encode(array("result" => "success")); + } + else + { + log_error("invalid form!"); + + } + + } + + public function add_to_basket_ajax($id) { + + $view = new View("add_to_basket_ajax.html"); + + // get the item to add + $item = ORM::factory("item", $id); + if (!$item->loaded) + { + //TODO + die("Not loaded id"); + } + + // get the basket to add to + $form = self::getAddToBasketForm(); + $form->add_to_basket->id->value($id); + $form->add_to_basket->quantity->value(1); + $view->form = $form; + $view->item = $item; + + print $view; + } + + public function remove_item($key) { + + $basket = Session_Basket::getOrCreate(); + $basket->remove($key); + url::redirect("basket/view_basket"); + } + +} diff --git a/modules/basket/css/basket.css b/modules/basket/css/basket.css new file mode 100644 index 00000000..f660685d --- /dev/null +++ b/modules/basket/css/basket.css @@ -0,0 +1,5 @@ +#basket {float:right;} +#add_to_basket {float:right} +#basketForm {max-width:200px} +#basketThumb {float:left; padding:10px 10px 0 0;} +#basketThumb img{max-width:100px;} diff --git a/modules/basket/helpers/basket.php b/modules/basket/helpers/basket.php new file mode 100644 index 00000000..70dd3f44 --- /dev/null +++ b/modules/basket/helpers/basket.php @@ -0,0 +1,156 @@ + "Australian Dollars", + "CAD" => "Canadian Dollars", + "EUR" => "Euros", + "GBP" => "Pounds Sterling", + "JPY" => "Yen", + "USD" => "U.S. Dollars", + "NZD" => "New Zealand Dollar", + "CHF" => "Swiss Franc", + "HKD" => "Hong Kong Dollar", + "SGD" => "Singapore Dollar", + "SEK" => "Swedish Krona", + "DKK" => "Danish Krone", + "PLN" => "Polish Zloty", + "NOK" => "Norwegian Krone", + "HUF" => "Hungarian Forint", + "CZK" => "Czech Koruna", + "ILS" => "Israeli Shekel", + "MXN" => "Mexican Peso"); + + static $format= array( + "AUD" => "$", + "CAD" => "$", + "EUR" => "€", + "GBP" => "£", + "JPY" => "¥", + "USD" => "$", + "NZD" => "$", + "CHF" => "", + "HKD" => "$", + "SGD" => "$", + "SEK" => "", + "DKK" => "", + "PLN" => "", + "NOK" => "", + "HUF" => "", + "CZK" => "", + "ILS" => "", + "MXN" => ""); + + + static function get_configure_form() { + $form = new Forge("admin/configure", "", "post", array("id" => "gConfigureForm")); + $group = $form->group("configure")->label(t("Configure Basket")); + $group->input("email")->label(t("Order Email Address"))->id("gOrderEmailAddress"); + $group->checkbox("paypal")->label(t("Use Paypal"))->id("gPaypal"); + $group->input("paypal_account")->label(t("Paypal Account"))->id("gPaypalAddress"); + $group->dropdown("currency") + ->label(t("Currency")) + ->options(self::$currencies); + $group->submit("")->value(t("Save")); + return $form; + } + + static function populateForm($form){ + $form->configure->email->value(basket::getEmailAddress()); + $form->configure->paypal->checked(basket::isPaypal()); + $form->configure->paypal_account->value(basket::getPaypalAccount()); + $form->configure->currency->selected(basket::getCurrency()); + } + + static function extractForm($form){ + $email = $form->configure->email->value; + $isPaypal = $form->configure->paypal->value; + $paypal_account = $form->configure->paypal_account->value; + $currency = $form->configure->currency->selected; + basket::setEmailAddress($email); + basket::setPaypal($isPaypal); + basket::setPaypalAccount($paypal_account); + basket::setCurrency($currency); + } + + static function getEmailAddress(){ + return module::get_var("basket","email"); + } + + static function isPaypal(){ + return module::get_var("basket","paypal"); + } + + static function getPaypalAccount(){ + return module::get_var("basket","paypal_account"); + } + + static function getCurrency(){ + $cur = module::get_var("basket","currency"); + if (!isset($cur)) + { + $cur = "USD"; + } + return $cur; + } + + static function formatMoney($money){ + return self::$format[self::getCurrency()].number_format($money); + } + + static function setEmailAddress($email){ + module::set_var("basket","email",$email); + } + + static function setPaypal($paypal){ + module::set_var("basket","paypal",$paypal); + } + + static function setPaypalAccount($paypal_account){ + module::set_var("basket","paypal_account",$paypal_account); + } + + static function setCurrency($currency){ + module::set_var("basket","currency",$currency); + } + + static function generatePaypalForm($session_basket){ + $form = " +
+ + + +"; + + $id = 1; + foreach ($session_basket->contents as $key => $basket_item){ + $form = $form." +getCode()."\"/> +cost_per\"/> +quantity\"/>"; + $id++; + } + $form = $form."
"; + + return $form; + } + +} \ No newline at end of file diff --git a/modules/basket/helpers/basket_event.php b/modules/basket/helpers/basket_event.php new file mode 100644 index 00000000..12377439 --- /dev/null +++ b/modules/basket/helpers/basket_event.php @@ -0,0 +1,43 @@ +add_after("users_groups", + $basket_menu = Menu::factory("submenu") + ->id("basket_menu") + ->label(t("Basket"))); + $basket_menu->append( + Menu::factory("link") + ->id("configure") + ->label(t("Configure")) + ->url(url::site("admin/configure"))); + $basket_menu->append( + Menu::factory("link") + ->id("product_line") + ->label(t("Product Lines")) + ->url(url::site("admin/product_lines"))); + + } +} \ No newline at end of file diff --git a/modules/basket/helpers/basket_installer.php b/modules/basket/helpers/basket_installer.php new file mode 100644 index 00000000..3a725c45 --- /dev/null +++ b/modules/basket/helpers/basket_installer.php @@ -0,0 +1,93 @@ +query("CREATE TABLE IF NOT EXISTS {products} ( + `id` int(9) NOT NULL auto_increment, + `name` TEXT NOT NULL, + `cost` INTEGER(9) default 0, + `description` varchar(1024), + PRIMARY KEY (`id`)) + ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + + + + /* + $db->query("CREATE TABLE IF NOT EXISTS {orders} ( + `id` int(9) NOT NULL auto_increment, + `name` varchar(1024), + `house` varchar(255), + `street` varchar(255), + `suburb` varchar(255), + `town` varchar(255), + `postcode` varchar(255), + `email` varchar(255), + `phone` varchar(255), + `status` char(1), + `activity_time` int(9), + `created` int(9), + `total` int(9), + PRIMARY KEY (`id`)) + ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + + $db->query("CREATE TABLE IF NOT EXISTS {order_details} ( + `id` int(9) NOT NULL auto_increment, + `order_id` int(9) NOT NULL, + `item_id` int(9) NOT NULL, + `product_name` TEXT NOT NULL, + `product_cost` INTEGER(9) default 0, + `product_description` varchar(1024), + `quantity` INTEGER(9) default 1, + PRIMARY KEY (`id`)) + ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + + $db->query("CREATE TABLE IF NOT EXISTS {order_histories} ( + `id` int(9) NOT NULL auto_increment, + `order_id` int(9) NOT NULL, + `status_from` char(1), + `status_to` char(1), + `public` boolean, + `date` int(9), + `notes` TEXT default null, + PRIMARY KEY (`id`)) + ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + */ + product::create("4x6",5,"4\"x6\" print"); + product::create("8x10",25,"8\"x10\" print"); + product::create("8x12",30,"8\"x12\" print"); + + } + + static function deactivate(){ + $db = Database::instance(); + $db->query("DROP TABLE IF EXISTS {products}"); + //$db->query("DROP TABLE IF EXISTS {orders}"); + //$db->query("DROP TABLE IF EXISTS {order_details}"); + //$db->query("DROP TABLE IF EXISTS {order_histories}"); + } +} diff --git a/modules/basket/helpers/basket_theme.php b/modules/basket/helpers/basket_theme.php new file mode 100644 index 00000000..bc3b369a --- /dev/null +++ b/modules/basket/helpers/basket_theme.php @@ -0,0 +1,46 @@ +css("basket.css"); + } + + static function header_top($theme) { + $view = new View("basket.html"); + + $view->basket = Session_Basket::get(); + return $view->render(); + } + + static function admin_head($theme) { + if (strpos(Router::$current_uri, "admin/product_lines") !== false) { + $theme->script("lib/gallery.panel.js"); + } + } + static function photo_top($theme) + { + $view = new View("add_to_basket.html"); + + $view->item = $theme->item(); + + return $view->render(); + } +} \ No newline at end of file diff --git a/modules/basket/helpers/product.php b/modules/basket/helpers/product.php new file mode 100644 index 00000000..3131c229 --- /dev/null +++ b/modules/basket/helpers/product.php @@ -0,0 +1,91 @@ + "gAddProductForm")); + $group = $form->group("add_product")->label(t("Add Product")); + $group->input("name")->label(t("Name"))->id("gProductName") + ->error_messages("in_use", t("There is already a product with that name")); + $group->input("cost")->label(t("Cost"))->id("gCost"); + $group->input("description")->label(t("Description"))->id("gDescription"); + $group->submit("")->value(t("Add Product")); + $product = ORM::factory("product"); + $form->add_rules_from($product); + return $form; + } + + static function get_edit_form_admin($product) { + $form = new Forge("admin/product_lines/edit_product/$product->id", "", "post", + array("id" => "gEditProductForm")); + $group = $form->group("edit_product")->label(t("Edit Product")); + $group->input("name")->label(t("Name"))->id("gProductName")->value($product->name); + $group->inputs["name"]->error_messages( + "in_use", t("There is already a product with that name")); + $group->input("cost")->label(t("Cost"))->id("gCost")->value($product->cost); + $group->input("description")->label(t("Description"))->id("gDescription")-> + value($product->description); + + $group->submit("")->value(t("Modify Product")); + $form->add_rules_from($product); + return $form; + } + + + static function get_delete_form_admin($product) { + $form = new Forge("admin/product_lines/delete_product/$product->id", "", "post", + array("id" => "gDeleteProductForm")); + $group = $form->group("delete_product")->label( + t("Are you sure you want to delete product %name?", array("name" => $product->name))); + $group->submit("")->value(t("Delete product %name", array("name" => $product->name))); + return $form; + } + + /** + * Create a new product + * + * @param string $name + * @param string $full_name + * @param string $password + * @return User_Model + */ + static function create($name, $cost, $description) { + $product = ORM::factory("product")->where("name", $name)->find(); + if ($product->loaded) { + throw new Exception("@todo USER_ALREADY_EXISTS $name"); + } + + $product->name = $name; + $product->cost = $cost; + $product->description = $description; + + $product->save(); + return $product; + } + + static function getProductArray(){ + $products = ORM::factory("product")->find_all(); + foreach ($products as $product){ + $producta[$product->id] = $product->description." (".basket::formatMoney($product->cost).")"; + } + + return $producta; + } +} \ No newline at end of file diff --git a/modules/basket/images/basket.png b/modules/basket/images/basket.png new file mode 100644 index 0000000000000000000000000000000000000000..168bef64c3830fc2e9ea9886a963fa9e6b6226f2 GIT binary patch literal 424 zcmV;Z0ayNsP)4B1{9e^0{F3;`2g3(fCw{Qk!u4?6EHMOT4~P{!Bj4w z9ZRV@Cw>DKc&O0#&$I!;RF$P_8f;BSDRr$Ku!v3Bsoa}v=_xFL4YI;dx&a+-K$1L4 z>S4P=Jr-~YASqT;vNeJ-bJI26BI2t-m;C!YjHY$Kr&nXy6P4d~iaw3p6)@%};Mv^( zs1elN0j?)y`Af?Y?tqOOF5qZDyaOproduct = $aProduct; + $this->item = $aItem; + $this->quantity = $aQuantity; + $this->calculate_cost(); + } + + private function calculate_cost(){ + $prod = ORM::factory("product", $this->product); + $this->cost = $prod->cost * $this->quantity; + $this->cost_per = $prod->cost; + } + + public function add($quantity){ + $this->quantity += $quantity; + $this->calculate_cost(); + } + + public function size(){ + return $this->quantity; + } + + public function getItem(){ + $photo = ORM::factory("item", $this->item); + return $photo; + } + + public function product_description(){ + $prod = ORM::factory("product", $this->product); + return $prod->description; + } + + public function getCode(){ + $photo = ORM::factory("item", $this->item); + $prod = ORM::factory("product", $this->product); + return $photo->id." - ".$photo->title." - ".$prod->name; + } + +} + +class Session_Basket_Core { + + public $contents = array(); + + public $name = ""; + public $house = ""; + public $street = ""; + public $suburb = ""; + public $town = ""; + public $postcode = ""; + public $email = ""; + public $phone = ""; + + public function clear(){ + if (isset($this->contents)){ + foreach ($this->contents as $key => $item){ + unset($this->contents[$key]); + } + } + } + + private function create_key($product, $id){ + return "$product _ $id"; + } + + public function size(){ + $size = 0; + if (isset($this->contents)){ + foreach ($this->contents as $product => $basket_item){ + $size += $basket_item->size(); + } + } + return $size; + } + + public function add($id, $product, $quantity){ + + $key = $this->create_key($product, $id); + if (isset($this->contents[$key])){ + $this->contents[$key]->add($id, $quantity); + } + else { + $this->contents[$key] = new basket_item($product, $id, $quantity); + } + } + + public function remove($key){ + unset($this->contents[$key]); + } + + public function cost(){ + $cost = 0; + if (isset($this->contents)){ + foreach ($this->contents as $product => $basket_item){ + $cost += $basket_item->cost; + } + } + return $cost; + } + + public static function get(){ + return Session::instance()->get("basket"); + } + + public static function getOrCreate(){ + $session = Session::instance(); + + $basket = $session->get("basket"); + if (!$basket) + { + $basket = new Session_Basket(); + $session->set("basket", $basket); + } + return $basket; + } + +} \ No newline at end of file diff --git a/modules/basket/models/product.php b/modules/basket/models/product.php new file mode 100644 index 00000000..c89c7254 --- /dev/null +++ b/modules/basket/models/product.php @@ -0,0 +1,24 @@ + "length[1,32]", + "description" => "length[0,255]"); +} diff --git a/modules/basket/module.info b/modules/basket/module.info new file mode 100644 index 00000000..426ff687 --- /dev/null +++ b/modules/basket/module.info @@ -0,0 +1,3 @@ +name = "Shopping Basket" +description = "Provides a simple shopping basket and checkout with paypal integration" +version = 1 diff --git a/modules/basket/views/add_to_basket.html.php b/modules/basket/views/add_to_basket.html.php new file mode 100644 index 00000000..aad7f892 --- /dev/null +++ b/modules/basket/views/add_to_basket.html.php @@ -0,0 +1,8 @@ + + + \ No newline at end of file diff --git a/modules/basket/views/add_to_basket_ajax.html.php b/modules/basket/views/add_to_basket_ajax.html.php new file mode 100644 index 00000000..f4e38d83 --- /dev/null +++ b/modules/basket/views/add_to_basket_ajax.html.php @@ -0,0 +1,9 @@ + +
+
+ <?= $item->title?> +
+
+ +
+
\ No newline at end of file diff --git a/modules/basket/views/admin_configure.html.php b/modules/basket/views/admin_configure.html.php new file mode 100644 index 00000000..5f3ae012 --- /dev/null +++ b/modules/basket/views/admin_configure.html.php @@ -0,0 +1,8 @@ + +
+

+

+ +

+ +
\ No newline at end of file diff --git a/modules/basket/views/admin_product_lines.html.php b/modules/basket/views/admin_product_lines.html.php new file mode 100644 index 00000000..e2b37072 --- /dev/null +++ b/modules/basket/views/admin_product_lines.html.php @@ -0,0 +1,70 @@ + + \ No newline at end of file diff --git a/modules/basket/views/basket.html.php b/modules/basket/views/basket.html.php new file mode 100644 index 00000000..3198d4fa --- /dev/null +++ b/modules/basket/views/basket.html.php @@ -0,0 +1,35 @@ + +
+ page_type != 'basket'): ?> + + " + title=""> + ">
+ size()?> items
+ + " + title=""> + ">
+
+ + +
diff --git a/modules/basket/views/checkout.html.php b/modules/basket/views/checkout.html.php new file mode 100644 index 00000000..f651d633 --- /dev/null +++ b/modules/basket/views/checkout.html.php @@ -0,0 +1,64 @@ + + +
+ +

Payment Details

+

After you have confirmed the order we will get in contact with you to arrange payment.

+" class="left gButtonLink ui-state-default ui-corner-all ui-icon-left"> + + + +
diff --git a/modules/basket/views/confirm_order.html.php b/modules/basket/views/confirm_order.html.php new file mode 100644 index 00000000..35266c01 --- /dev/null +++ b/modules/basket/views/confirm_order.html.php @@ -0,0 +1,82 @@ + + + +
+

Basket Summary

+
+ + + + + + + + contents as $key => $prod_details): ?> + "> + + + + + + + + "> + + + +
+ getItem(); ?> +
+ title) ?> +
+
+ product_description()) ?> + + quantity) ?> + + cost) ?> +
Total Costcost()?>
+
+ + + +
+

Delivery Address

+name ?>
+house ?>, +street ?>
+suburb ?>
+town ?>
+postcode ?>
+
+

Contact Details

+E-mail : email ?>
+Telephone : phone ?> +
+" class="left gButtonLink ui-state-default ui-corner-all ui-icon-left"> + + + + +
diff --git a/modules/basket/views/order_complete.html.php b/modules/basket/views/order_complete.html.php new file mode 100644 index 00000000..1287f058 --- /dev/null +++ b/modules/basket/views/order_complete.html.php @@ -0,0 +1,24 @@ + +
+

Thankyou for your order

+You will be contacted soon to arrange payment and delivery. +
\ No newline at end of file diff --git a/modules/basket/views/view_basket.html.php b/modules/basket/views/view_basket.html.php new file mode 100644 index 00000000..0b792c2e --- /dev/null +++ b/modules/basket/views/view_basket.html.php @@ -0,0 +1,112 @@ + +
+ + + + + + " + class="right gButtonLink ui-state-default ui-corner-all ui-icon-right"> + + + " + class="right gButtonLink ui-state-default ui-corner-all ui-icon-right"> + + + +

+ +

+ +
+ contents ) && count($basket->contents) > 0): ?> + + + + + + + + + + + + + contents as $key => $prod_details): ?> + "> + + + + + + + + + "> + + + +
+ getItem(); ?> +
+ <?= $item->title?> +
+
+ product_description()) ?> + + quantity) ?> + + cost?> + cost) ?> + + + + " + class="gButtonLink ui-state-default ui-corner-all ui-icon-left"> + +
Total Cost
+ + Shopping Basket is Empty + + +
+ + + + + " + class="right gButtonLink ui-state-default ui-corner-all ui-icon-right"> + + + " + class="right gButtonLink ui-state-default ui-corner-all ui-icon-right"> + + +
\ No newline at end of file