Added support for postage and packaging costs.
This commit is contained in:
parent
f920adfa66
commit
b2c27dc34f
154
modules/basket/controllers/admin_postage_bands.php
Normal file
154
modules/basket/controllers/admin_postage_bands.php
Normal file
@ -0,0 +1,154 @@
|
|||||||
|
<?php defined("SYSPATH") or die("No direct script access.");
|
||||||
|
/**
|
||||||
|
* Gallery - a web based photo album viewer and editor
|
||||||
|
* Copyright (C) 2000-2009 Bharat Mediratta
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
class Admin_Postage_Bands_Controller extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* the index page of the user homes admin
|
||||||
|
*/
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$view = new Admin_View("admin.html");
|
||||||
|
$view->content = new View("admin_postage_bands.html");
|
||||||
|
$view->content->postage_bands = ORM::factory("postage_band")->orderby("name")->find_all();
|
||||||
|
|
||||||
|
print $view;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function add_postage_band_form() {
|
||||||
|
print postage_band::get_add_form_admin();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function add_postage_band() {
|
||||||
|
access::verify_csrf();
|
||||||
|
|
||||||
|
$form = postage_band::get_add_form_admin();
|
||||||
|
$valid = $form->validate();
|
||||||
|
$name = $form->add_postage->inputs["name"]->value;
|
||||||
|
$postage = ORM::factory("postage_band")->where("name", $name)->find();
|
||||||
|
if ($postage->loaded) {
|
||||||
|
$form->add_postage->inputs["name"]->add_error("in_use", 1);
|
||||||
|
$valid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($valid) {
|
||||||
|
$postage = postage_band::create(
|
||||||
|
$name,
|
||||||
|
$form->add_postage->flat_rate->value,
|
||||||
|
$form->add_postage->per_item->value
|
||||||
|
);
|
||||||
|
|
||||||
|
$postage->save();
|
||||||
|
message::success(t("Created postage band %postage_name", array(
|
||||||
|
"postage_name" => html::clean($postage->name))));
|
||||||
|
print json_encode(array("result" => "success"));
|
||||||
|
} else {
|
||||||
|
print json_encode(array("result" => "error",
|
||||||
|
"form" => $form->__toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete_postage_band_form($id) {
|
||||||
|
$postage = ORM::factory("postage_band", $id);
|
||||||
|
if (!$postage->loaded) {
|
||||||
|
kohana::show_404();
|
||||||
|
}
|
||||||
|
print postage_band::get_delete_form_admin($postage);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete_postage_band($id) {
|
||||||
|
access::verify_csrf();
|
||||||
|
|
||||||
|
if ($id == user::active()->id || $id == user::guest()->id) {
|
||||||
|
access::forbidden();
|
||||||
|
}
|
||||||
|
|
||||||
|
$postage = ORM::factory("postage_band", $id);
|
||||||
|
if (!$postage->loaded) {
|
||||||
|
kohana::show_404();
|
||||||
|
}
|
||||||
|
|
||||||
|
$form = postage_band::get_delete_form_admin($postage);
|
||||||
|
if($form->validate()) {
|
||||||
|
$name = $postage->name;
|
||||||
|
$postage->delete();
|
||||||
|
} else {
|
||||||
|
print json_encode(array("result" => "error",
|
||||||
|
"form" => $form->__toString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
$message = t("Deleted user %postage_band", array("postage_band" => html::clean($name)));
|
||||||
|
log::success("user", $message);
|
||||||
|
message::success($message);
|
||||||
|
print json_encode(array("result" => "success"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function edit_postage_band($id) {
|
||||||
|
access::verify_csrf();
|
||||||
|
|
||||||
|
$postage = ORM::factory("postage_band", $id);
|
||||||
|
if (!$postage->loaded) {
|
||||||
|
kohana::show_404();
|
||||||
|
}
|
||||||
|
|
||||||
|
$form = postage_band::get_edit_form_admin($postage);
|
||||||
|
$valid = $form->validate();
|
||||||
|
if ($valid) {
|
||||||
|
$new_name = $form->edit_postage->inputs["name"]->value;
|
||||||
|
if ($new_name != $postage->name &&
|
||||||
|
ORM::factory("postage_band")
|
||||||
|
->where("name", $new_name)
|
||||||
|
->where("id !=", $postage->id)
|
||||||
|
->find()
|
||||||
|
->loaded) {
|
||||||
|
$form->edit_postage->inputs["name"]->add_error("in_use", 1);
|
||||||
|
$valid = false;
|
||||||
|
} else {
|
||||||
|
$postage->name = $new_name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($valid) {
|
||||||
|
$postage->flat_rate = $form->edit_postage->flat_rate->value;
|
||||||
|
$postage->per_item = $form->edit_postage->per_item->value;
|
||||||
|
$postage->save();
|
||||||
|
|
||||||
|
message::success(t("Changed postage band %postage_name",
|
||||||
|
array("postage_name" => html::clean($postage->name))));
|
||||||
|
print json_encode(array("result" => "success"));
|
||||||
|
} else {
|
||||||
|
print json_encode(array("result" => "error",
|
||||||
|
"form" => $form->__toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function edit_postage_band_form($id) {
|
||||||
|
$postage = ORM::factory("postage_band", $id);
|
||||||
|
if (!$postage->loaded) {
|
||||||
|
kohana::show_404();
|
||||||
|
}
|
||||||
|
|
||||||
|
$form = postage_band::get_edit_form_admin($postage);
|
||||||
|
|
||||||
|
print $form;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -51,7 +51,11 @@ class Admin_Product_Lines_Controller extends Controller
|
|||||||
|
|
||||||
if ($valid) {
|
if ($valid) {
|
||||||
$product = product::create(
|
$product = product::create(
|
||||||
$name, $form->add_product->cost->value, $form->add_product->description->value);
|
$name,
|
||||||
|
$form->add_product->cost->value,
|
||||||
|
$form->add_product->description->value,
|
||||||
|
$form->add_product->postage_band->value
|
||||||
|
);
|
||||||
|
|
||||||
$product->save();
|
$product->save();
|
||||||
message::success(t("Created product %product_name", array(
|
message::success(t("Created product %product_name", array(
|
||||||
@ -83,7 +87,7 @@ class Admin_Product_Lines_Controller extends Controller
|
|||||||
kohana::show_404();
|
kohana::show_404();
|
||||||
}
|
}
|
||||||
|
|
||||||
$form = user::get_delete_form_admin($product);
|
$form = product::get_delete_form_admin($product);
|
||||||
if($form->validate()) {
|
if($form->validate()) {
|
||||||
$name = $product->name;
|
$name = $product->name;
|
||||||
$product->delete();
|
$product->delete();
|
||||||
@ -126,6 +130,7 @@ class Admin_Product_Lines_Controller extends Controller
|
|||||||
if ($valid) {
|
if ($valid) {
|
||||||
$product->cost = $form->edit_product->cost->value;
|
$product->cost = $form->edit_product->cost->value;
|
||||||
$product->description = $form->edit_product->description->value;
|
$product->description = $form->edit_product->description->value;
|
||||||
|
$product->postage_band_id = $form->edit_product->postage_band->value;
|
||||||
$product->save();
|
$product->save();
|
||||||
|
|
||||||
message::success(t("Changed product %product_name",
|
message::success(t("Changed product %product_name",
|
||||||
|
@ -110,6 +110,8 @@ class Basket_Controller extends Controller {
|
|||||||
$basket = Session_Basket::get();
|
$basket = Session_Basket::get();
|
||||||
|
|
||||||
//$admin_address = basket::getEmailAddress();
|
//$admin_address = basket::getEmailAddress();
|
||||||
|
$postage = $basket->postage_cost();
|
||||||
|
$product_cost = $basket->cost();
|
||||||
|
|
||||||
$admin_email = "Order for :
|
$admin_email = "Order for :
|
||||||
".$basket->name."
|
".$basket->name."
|
||||||
@ -121,7 +123,9 @@ class Basket_Controller extends Controller {
|
|||||||
".$basket->email."
|
".$basket->email."
|
||||||
".$basket->phone."
|
".$basket->phone."
|
||||||
Placed at ".date("d F Y - H:i" ,time())."
|
Placed at ".date("d F Y - H:i" ,time())."
|
||||||
Total Owed ".$basket->cost()." in ".basket::getCurrency()."
|
Cost of Ordered Products = ".$product_cost."
|
||||||
|
Postage and Packaging Costs + ".$postage."
|
||||||
|
Total Owed ".($product_cost+$postage)." Total in ".basket::getCurrency()."
|
||||||
|
|
||||||
Items Ordered:
|
Items Ordered:
|
||||||
|
|
||||||
|
@ -42,9 +42,9 @@ class basket_Core {
|
|||||||
static $format= array(
|
static $format= array(
|
||||||
"AUD" => "$",
|
"AUD" => "$",
|
||||||
"CAD" => "$",
|
"CAD" => "$",
|
||||||
"EUR" => "€",
|
"EUR" => "€",
|
||||||
"GBP" => "£",
|
"GBP" => "£",
|
||||||
"JPY" => "¥",
|
"JPY" => "¥",
|
||||||
"USD" => "$",
|
"USD" => "$",
|
||||||
"NZD" => "$",
|
"NZD" => "$",
|
||||||
"CHF" => "",
|
"CHF" => "",
|
||||||
@ -114,7 +114,7 @@ class basket_Core {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static function formatMoney($money){
|
static function formatMoney($money){
|
||||||
return self::$format[self::getCurrency()].number_format($money);
|
return self::$format[self::getCurrency()].number_format($money,2);
|
||||||
}
|
}
|
||||||
|
|
||||||
static function setEmailAddress($email){
|
static function setEmailAddress($email){
|
||||||
@ -141,6 +141,12 @@ class basket_Core {
|
|||||||
<input type=\"hidden\" name=\"currency_code\" value=\"".self::getCurrency()."\">
|
<input type=\"hidden\" name=\"currency_code\" value=\"".self::getCurrency()."\">
|
||||||
<input type=\"hidden\" name=\"business\" value=\"".self::getPaypalAccount()."\"/>";
|
<input type=\"hidden\" name=\"business\" value=\"".self::getPaypalAccount()."\"/>";
|
||||||
|
|
||||||
|
$postage = $session_basket->postage_cost();
|
||||||
|
if ($postage > 0) {
|
||||||
|
$form = $form."
|
||||||
|
<input type=\"hidden\" name=\"shipping_1\" value=\"".$postage."\">";
|
||||||
|
}
|
||||||
|
|
||||||
$id = 1;
|
$id = 1;
|
||||||
foreach ($session_basket->contents as $key => $basket_item){
|
foreach ($session_basket->contents as $key => $basket_item){
|
||||||
$form = $form."
|
$form = $form."
|
||||||
@ -149,6 +155,7 @@ class basket_Core {
|
|||||||
<input type=\"hidden\" name=\"quantity_$id\" value=\"$basket_item->quantity\"/>";
|
<input type=\"hidden\" name=\"quantity_$id\" value=\"$basket_item->quantity\"/>";
|
||||||
$id++;
|
$id++;
|
||||||
}
|
}
|
||||||
|
|
||||||
$form = $form."</form>";
|
$form = $form."</form>";
|
||||||
|
|
||||||
return $form;
|
return $form;
|
||||||
|
@ -38,6 +38,11 @@ class basket_event_Core{
|
|||||||
->id("product_line")
|
->id("product_line")
|
||||||
->label(t("Product Lines"))
|
->label(t("Product Lines"))
|
||||||
->url(url::site("admin/product_lines")));
|
->url(url::site("admin/product_lines")));
|
||||||
|
$basket_menu->append(
|
||||||
|
Menu::factory("link")
|
||||||
|
->id("postage_bands")
|
||||||
|
->label(t("Postage Bands"))
|
||||||
|
->url(url::site("admin/postage_bands")));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,17 +21,15 @@
|
|||||||
class basket_installer
|
class basket_installer
|
||||||
{
|
{
|
||||||
static function install(){
|
static function install(){
|
||||||
module::set_version("basket", 1);
|
|
||||||
}
|
|
||||||
static function activate() {
|
|
||||||
|
|
||||||
$db = Database::instance();
|
$db = Database::instance();
|
||||||
|
|
||||||
$db->query("CREATE TABLE IF NOT EXISTS {products} (
|
$db->query("CREATE TABLE IF NOT EXISTS {products} (
|
||||||
`id` int(9) NOT NULL auto_increment,
|
`id` int(9) NOT NULL auto_increment,
|
||||||
`name` TEXT NOT NULL,
|
`name` TEXT NOT NULL,
|
||||||
`cost` INTEGER(9) default 0,
|
`cost` DECIMAL(10,2) default 0,
|
||||||
`description` varchar(1024),
|
`description` varchar(1024),
|
||||||
|
`postage_band_id` int(9) default 1,
|
||||||
PRIMARY KEY (`id`))
|
PRIMARY KEY (`id`))
|
||||||
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
|
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
|
||||||
|
|
||||||
@ -47,20 +45,57 @@ class basket_installer
|
|||||||
`product_override_id` int(9) NOT NULL,
|
`product_override_id` int(9) NOT NULL,
|
||||||
`product_id` int(9) NOT NULL,
|
`product_id` int(9) NOT NULL,
|
||||||
`include` BOOLEAN default false,
|
`include` BOOLEAN default false,
|
||||||
`cost` INTEGER(9) default -1,
|
`cost` DECIMAL(10,2) default -1,
|
||||||
PRIMARY KEY (`id`))
|
PRIMARY KEY (`id`))
|
||||||
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
|
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
|
||||||
|
|
||||||
product::create("4x6",5,"4\"x6\" print");
|
$db->query("CREATE TABLE IF NOT EXISTS {postage_bands} (
|
||||||
product::create("8x10",25,"8\"x10\" print");
|
`id` int(9) NOT NULL auto_increment,
|
||||||
product::create("8x12",30,"8\"x12\" print");
|
`name` TEXT NOT NULL,
|
||||||
|
`flat_rate` DECIMAL(10,2) default 0,
|
||||||
|
`per_item` DECIMAL(10,2) default 0,
|
||||||
|
PRIMARY KEY (`id`))
|
||||||
|
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
|
||||||
|
|
||||||
|
postage_band::create("No Postage",0,0);
|
||||||
|
|
||||||
|
product::create("4x6",5,"4\"x6\" print",1);
|
||||||
|
product::create("8x10",25,"8\"x10\" print",1);
|
||||||
|
product::create("8x12",30,"8\"x12\" print",1);
|
||||||
|
|
||||||
|
|
||||||
|
module::set_version("basket", 2);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static function deactivate(){
|
static function upgrade($version) {
|
||||||
|
$db = Database::instance();
|
||||||
|
if ($version == 1) {
|
||||||
|
|
||||||
|
// fix for allowing decimel place in money
|
||||||
|
$db->query("ALTER TABLE {products} CHANGE COLUMN `cost` `cost` DECIMAL(10,2) default 0;");
|
||||||
|
$db->query("ALTER TABLE {item_products} CHANGE COLUMN `cost` `cost` DECIMAL(10,2) default -1;");
|
||||||
|
|
||||||
|
// postage bands
|
||||||
|
$db->query("ALTER TABLE {products} ADD COLUMN `postage_band_id` int(9) default 1");
|
||||||
|
$db->query("CREATE TABLE IF NOT EXISTS {postage_bands} (
|
||||||
|
`id` int(9) NOT NULL auto_increment,
|
||||||
|
`name` TEXT NOT NULL,
|
||||||
|
`flat_rate` DECIMAL(10,2) default 0,
|
||||||
|
`per_item` DECIMAL(10,2) default 0,
|
||||||
|
PRIMARY KEY (`id`))
|
||||||
|
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
|
||||||
|
postage_band::create("No Postage",0,0);
|
||||||
|
|
||||||
|
module::set_version("basket", $version = 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static function uninstall(){
|
||||||
$db = Database::instance();
|
$db = Database::instance();
|
||||||
$db->query("DROP TABLE IF EXISTS {products}");
|
$db->query("DROP TABLE IF EXISTS {products}");
|
||||||
$db->query("DROP TABLE IF EXISTS {product_overrides}");
|
$db->query("DROP TABLE IF EXISTS {product_overrides}");
|
||||||
$db->query("DROP TABLE IF EXISTS {item_products}");
|
$db->query("DROP TABLE IF EXISTS {item_products}");
|
||||||
|
$db->query("DROP TABLE IF EXISTS {postage_bands}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
99
modules/basket/helpers/postage_band.php
Normal file
99
modules/basket/helpers/postage_band.php
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
<?php defined("SYSPATH") or die("No direct script access.");
|
||||||
|
/**
|
||||||
|
* Gallery - a web based photo album viewer and editor
|
||||||
|
* Copyright (C) 2000-2009 Bharat Mediratta
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
class postage_band_Core {
|
||||||
|
|
||||||
|
static function get_add_form_admin() {
|
||||||
|
$form = new Forge("admin/postage_bands/add_postage_band", "", "post", array("id" => "gAddPostageForm"));
|
||||||
|
$group = $form->group("add_postage")->label(t("Add Postage Band"));
|
||||||
|
$group->input("name")->label(t("Name"))->id("gPostageName")
|
||||||
|
->error_messages("in_use", t("There is already a postage band with that name"));
|
||||||
|
$group->input("flat_rate")->label(t("Flat Rate"))->id("gFlatRate");
|
||||||
|
$group->input("per_item")->label(t("Per Item"))->id("gPetItem");
|
||||||
|
$group->submit("")->value(t("Add Postage Band"));
|
||||||
|
$postage = ORM::factory("postage_band");
|
||||||
|
$form->add_rules_from($postage);
|
||||||
|
return $form;
|
||||||
|
}
|
||||||
|
|
||||||
|
static function get_edit_form_admin($postage) {
|
||||||
|
$form = new Forge("admin/postage_bands/edit_postage_band/$postage->id", "", "post",
|
||||||
|
array("id" => "gEditPostageForm"));
|
||||||
|
$group = $form->group("edit_postage")->label(t("Edit Postage Band"));
|
||||||
|
$group->input("name")->label(t("Name"))->id("gPostageName")->value($postage->name);
|
||||||
|
$group->inputs["name"]->error_messages(
|
||||||
|
"in_use", t("There is already a postage band with that name"));
|
||||||
|
$group->input("flat_rate")->label(t("Flat Rate"))->id("gFlatRate")->value($postage->flat_rate);
|
||||||
|
$group->input("per_item")->label(t("Per Item"))->id("gPetItem")->
|
||||||
|
value($postage->per_item);
|
||||||
|
|
||||||
|
$group->submit("")->value(t("Modify Postage Band"));
|
||||||
|
$form->add_rules_from($postage);
|
||||||
|
return $form;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static function get_delete_form_admin($postage) {
|
||||||
|
$form = new Forge("admin/postage_bands/delete_postage_band/$postage->id", "", "post",
|
||||||
|
array("id" => "gDeletePostageForm"));
|
||||||
|
$group = $form->group("delete_postage")->label(
|
||||||
|
t("Are you sure you want to delete postage band %name?", array("name" => $postage->name)));
|
||||||
|
$group->submit("")->value(t("Delete postage band %name", array("name" => $postage->name)));
|
||||||
|
return $form;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new postage band
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* @param string $full_name
|
||||||
|
* @param string $password
|
||||||
|
* @return User_Model
|
||||||
|
*/
|
||||||
|
static function create($name, $flatrate, $peritemcost) {
|
||||||
|
$postage = ORM::factory("postage_band")->where("name", $name)->find();
|
||||||
|
if ($postage->loaded) {
|
||||||
|
throw new Exception("@todo postage already EXISTS $name");
|
||||||
|
}
|
||||||
|
|
||||||
|
$postage->name = $name;
|
||||||
|
$postage->flat_rate = $flatrate;
|
||||||
|
$postage->per_item = $peritemcost;
|
||||||
|
|
||||||
|
$postage->save();
|
||||||
|
return $postage;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns the array of postage bands
|
||||||
|
* @return an array of postage bands
|
||||||
|
*/
|
||||||
|
static function getPostageArray(){
|
||||||
|
$postagea = array();
|
||||||
|
|
||||||
|
$postages = ORM::factory("postage_band")->find_all();
|
||||||
|
foreach ($postages as $postage){
|
||||||
|
$show = true;
|
||||||
|
$postagea[$postage->id] = $postage->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $postagea;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -26,6 +26,9 @@ class product_Core {
|
|||||||
->error_messages("in_use", t("There is already a product with that name"));
|
->error_messages("in_use", t("There is already a product with that name"));
|
||||||
$group->input("cost")->label(t("Cost"))->id("gCost");
|
$group->input("cost")->label(t("Cost"))->id("gCost");
|
||||||
$group->input("description")->label(t("Description"))->id("gDescription");
|
$group->input("description")->label(t("Description"))->id("gDescription");
|
||||||
|
$group->dropdown("postage_band")
|
||||||
|
->label(t("Postage Band"))
|
||||||
|
->options(postage_band::getPostageArray());
|
||||||
$group->submit("")->value(t("Add Product"));
|
$group->submit("")->value(t("Add Product"));
|
||||||
$product = ORM::factory("product");
|
$product = ORM::factory("product");
|
||||||
$form->add_rules_from($product);
|
$form->add_rules_from($product);
|
||||||
@ -42,6 +45,10 @@ class product_Core {
|
|||||||
$group->input("cost")->label(t("Cost"))->id("gCost")->value($product->cost);
|
$group->input("cost")->label(t("Cost"))->id("gCost")->value($product->cost);
|
||||||
$group->input("description")->label(t("Description"))->id("gDescription")->
|
$group->input("description")->label(t("Description"))->id("gDescription")->
|
||||||
value($product->description);
|
value($product->description);
|
||||||
|
$group->dropdown("postage_band")
|
||||||
|
->label(t("Postage Band"))
|
||||||
|
->options(postage_band::getPostageArray())
|
||||||
|
->selected($product->postage_band_id);
|
||||||
|
|
||||||
$group->submit("")->value(t("Modify Product"));
|
$group->submit("")->value(t("Modify Product"));
|
||||||
$form->add_rules_from($product);
|
$form->add_rules_from($product);
|
||||||
@ -66,7 +73,7 @@ class product_Core {
|
|||||||
* @param string $password
|
* @param string $password
|
||||||
* @return User_Model
|
* @return User_Model
|
||||||
*/
|
*/
|
||||||
static function create($name, $cost, $description) {
|
static function create($name, $cost, $description, $postage_band) {
|
||||||
$product = ORM::factory("product")->where("name", $name)->find();
|
$product = ORM::factory("product")->where("name", $name)->find();
|
||||||
if ($product->loaded) {
|
if ($product->loaded) {
|
||||||
throw new Exception("@todo USER_ALREADY_EXISTS $name");
|
throw new Exception("@todo USER_ALREADY_EXISTS $name");
|
||||||
@ -75,7 +82,7 @@ class product_Core {
|
|||||||
$product->name = $name;
|
$product->name = $name;
|
||||||
$product->cost = $cost;
|
$product->cost = $cost;
|
||||||
$product->description = $description;
|
$product->description = $description;
|
||||||
|
$product->postage_band_id = $postage_band;
|
||||||
$product->save();
|
$product->save();
|
||||||
return $product;
|
return $product;
|
||||||
}
|
}
|
||||||
|
@ -64,6 +64,11 @@ class basket_item
|
|||||||
return $prod->description;
|
return $prod->description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getProduct(){
|
||||||
|
$prod = ORM::factory("product", $this->product);
|
||||||
|
return $prod;
|
||||||
|
}
|
||||||
|
|
||||||
public function getCode(){
|
public function getCode(){
|
||||||
$photo = ORM::factory("item", $this->item);
|
$photo = ORM::factory("item", $this->item);
|
||||||
$prod = ORM::factory("product", $this->product);
|
$prod = ORM::factory("product", $this->product);
|
||||||
@ -122,6 +127,32 @@ class Session_Basket_Core {
|
|||||||
unset($this->contents[$key]);
|
unset($this->contents[$key]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function postage_cost(){
|
||||||
|
$postage_cost = 0;
|
||||||
|
$postage_bands = array();
|
||||||
|
$postage_quantities = array();
|
||||||
|
if (isset($this->contents)){
|
||||||
|
// create array of postage bands
|
||||||
|
foreach ($this->contents as $product => $basket_item){
|
||||||
|
$postage_band = $basket_item->getProduct()->postage_band;
|
||||||
|
if (isset($postage_bands[$postage_band->id]))
|
||||||
|
{
|
||||||
|
$postage_quantities[$postage_band->id] += $basket_item->quantity;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$postage_quantities[$postage_band->id] = $basket_item->quantity;
|
||||||
|
$postage_bands[$postage_band->id] = $postage_band;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($postage_bands as $id => $postage_band){
|
||||||
|
$postage_cost += $postage_band->flat_rate + ($postage_band->per_item * $postage_quantities[$id]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $postage_cost;
|
||||||
|
}
|
||||||
|
|
||||||
public function cost(){
|
public function cost(){
|
||||||
$cost = 0;
|
$cost = 0;
|
||||||
if (isset($this->contents)){
|
if (isset($this->contents)){
|
||||||
|
26
modules/basket/models/postage_band.php
Normal file
26
modules/basket/models/postage_band.php
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<?php defined("SYSPATH") or die("No direct script access.");
|
||||||
|
/**
|
||||||
|
* Gallery - a web based photo album viewer and editor
|
||||||
|
* Copyright (C) 2000-2009 Bharat Mediratta
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
class Postage_Band_Model extends ORM {
|
||||||
|
var $rules = array(
|
||||||
|
"name" => "length[1,32]");
|
||||||
|
|
||||||
|
protected $has_many=array('products');
|
||||||
|
|
||||||
|
}
|
@ -21,4 +21,6 @@ class Product_Model extends ORM {
|
|||||||
var $rules = array(
|
var $rules = array(
|
||||||
"name" => "length[1,32]",
|
"name" => "length[1,32]",
|
||||||
"description" => "length[0,255]");
|
"description" => "length[0,255]");
|
||||||
|
protected $belongs_to=array('postage_band');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
name = "Shopping Basket"
|
name = "Shopping Basket"
|
||||||
description = "Provides a simple shopping basket and checkout with paypal integration"
|
description = "Provides a simple shopping basket and checkout with paypal integration"
|
||||||
version = 1
|
version = 2
|
||||||
|
70
modules/basket/views/admin_postage_bands.html.php
Normal file
70
modules/basket/views/admin_postage_bands.html.php
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
<?php defined("SYSPATH") or die("No direct script access.")
|
||||||
|
/**
|
||||||
|
* Gallery - a web based photo album viewer and editor
|
||||||
|
* Copyright (C) 2000-2009 Bharat Mediratta
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
?>
|
||||||
|
<div class="gBlock">
|
||||||
|
|
||||||
|
<a href="<?= url::site("admin/postage_bands/add_postage_band_form") ?>"
|
||||||
|
class="gDialogLink gButtonLink right ui-icon-left ui-state-default ui-corner-all"
|
||||||
|
title="<?= t("Create a new Postage Band") ?>">
|
||||||
|
<span class="ui-icon ui-icon-circle-plus"></span>
|
||||||
|
<?= t("Add a new Postage Band") ?>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<h2>
|
||||||
|
<?= t("Postage Bands") ?>
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
<div class="gBlockContent">
|
||||||
|
<table id="gPostageAdminList">
|
||||||
|
<tr>
|
||||||
|
<th><?= t("Name") ?></th>
|
||||||
|
<th><?= t("Flat Rate") ?></th>
|
||||||
|
<th><?= t("Per Item") ?></th>
|
||||||
|
<th><?= t("Actions") ?></th>
|
||||||
|
|
||||||
|
</tr>
|
||||||
|
<? foreach ($postage_bands as $i => $postage_band): ?>
|
||||||
|
<tr id="gProduct-<?= $postage_band->id ?>" class="<?= text::alternate("gOddRow", "gEvenRow") ?>">
|
||||||
|
<td id="product-<?= $postage_band->id ?>" class="core-info ">
|
||||||
|
<?= html::clean($postage_band->name) ?>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<?= basket::formatMoney($postage_band->flat_rate) ?>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<?= basket::formatMoney($postage_band->per_item) ?>
|
||||||
|
</td>
|
||||||
|
<td class="gActions">
|
||||||
|
<a href="<?= url::site("admin/postage_bands/edit_postage_band_form/$postage_band->id") ?>"
|
||||||
|
open_text="<?= t("close") ?>"
|
||||||
|
class="gPanelLink gButtonLink ui-state-default ui-corner-all ui-icon-left">
|
||||||
|
<span class="ui-icon ui-icon-pencil"></span><span class="gButtonText"><?= t("edit") ?></span></a>
|
||||||
|
|
||||||
|
<a href="<?= url::site("admin/postage_bands/delete_postage_band_form/$postage_band->id") ?>"
|
||||||
|
class="gDialogLink gButtonLink ui-state-default ui-corner-all ui-icon-left">
|
||||||
|
<span class="ui-icon ui-icon-trash"></span><?= t("delete") ?></a>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
</tr>
|
||||||
|
<? endforeach ?>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
@ -37,6 +37,7 @@
|
|||||||
<th><?= t("Name") ?></th>
|
<th><?= t("Name") ?></th>
|
||||||
<th><?= t("Cost") ?></th>
|
<th><?= t("Cost") ?></th>
|
||||||
<th><?= t("Description") ?></th>
|
<th><?= t("Description") ?></th>
|
||||||
|
<th><?= t("Postage Band") ?></th>
|
||||||
<th><?= t("Actions") ?></th>
|
<th><?= t("Actions") ?></th>
|
||||||
|
|
||||||
</tr>
|
</tr>
|
||||||
@ -51,6 +52,11 @@
|
|||||||
<td>
|
<td>
|
||||||
<?= html::clean($product->description) ?>
|
<?= html::clean($product->description) ?>
|
||||||
</td>
|
</td>
|
||||||
|
<td>
|
||||||
|
<?= html::clean($product->postage_band->name) ?>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
|
||||||
<td class="gActions">
|
<td class="gActions">
|
||||||
<a href="<?= url::site("admin/product_lines/edit_product_form/$product->id") ?>"
|
<a href="<?= url::site("admin/product_lines/edit_product_form/$product->id") ?>"
|
||||||
open_text="<?= t("close") ?>"
|
open_text="<?= t("close") ?>"
|
||||||
|
@ -52,8 +52,14 @@ function so(){document.confirm.submit();}
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<? endforeach ?>
|
<? endforeach ?>
|
||||||
|
<? $postage = $basket->postage_cost();?>
|
||||||
|
<? if ($postage > 0):?>
|
||||||
<tr id="" class="<?= text::alternate("gOddRow", "gEvenRow") ?>">
|
<tr id="" class="<?= text::alternate("gOddRow", "gEvenRow") ?>">
|
||||||
<td></td><td></td><td>Total Cost</td><td><?= html::clean($basket->cost())?></td>
|
<td></td><td></td><td>Postage and Packaging</td><td><?= html::clean(basket::formatMoney($postage))?></td><td></td>
|
||||||
|
</tr>
|
||||||
|
<? endif;?>
|
||||||
|
<tr id="" class="<?= text::alternate("gOddRow", "gEvenRow") ?>">
|
||||||
|
<td></td><td></td><td>Total Cost</td><td><?= html::clean(basket::formatMoney($basket->cost() + $postage))?></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
</table>
|
</table>
|
||||||
|
@ -88,8 +88,14 @@
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<? endforeach ?>
|
<? endforeach ?>
|
||||||
|
<? $postage = $basket->postage_cost();?>
|
||||||
|
<? if ($postage > 0):?>
|
||||||
<tr id="" class="<?= text::alternate("gOddRow", "gEvenRow") ?>">
|
<tr id="" class="<?= text::alternate("gOddRow", "gEvenRow") ?>">
|
||||||
<td></td><td></td><td>Total Cost</td><td><?= html::clean(basket::formatMoney($total))?></td><td></td>
|
<td></td><td></td><td>Postage and Packaging</td><td><?= html::clean(basket::formatMoney($postage))?></td><td></td>
|
||||||
|
</tr>
|
||||||
|
<? endif;?>
|
||||||
|
<tr id="" class="<?= text::alternate("gOddRow", "gEvenRow") ?>">
|
||||||
|
<td></td><td></td><td>Total Cost</td><td><?= html::clean(basket::formatMoney($total + $postage))?></td><td></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
</table>
|
</table>
|
||||||
|
Reference in New Issue
Block a user