Merge branch 'master' of git://github.com/Glooper/gallery3-contrib
Conflicts: modules/basket/helpers/basket_installer.php
This commit is contained in:
commit
8760cbe45d
@ -151,14 +151,14 @@ Items Ordered:
|
||||
print $template;
|
||||
}
|
||||
|
||||
private function getAddToBasketForm(){
|
||||
private function getAddToBasketForm($id){
|
||||
|
||||
$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());
|
||||
->options(product::getProductArray($id));
|
||||
$group->input("quantity")->label(t("Quantity"))->id("gQuantity");
|
||||
$group->submit("")->value(t("Add"));
|
||||
//$group->submit("proceedToCheckout")->value(t("Proceed To Checkout"));
|
||||
@ -170,7 +170,12 @@ Items Ordered:
|
||||
|
||||
access::verify_csrf();
|
||||
|
||||
$form = self::getAddToBasketForm();
|
||||
|
||||
if (!isset($_POST['id']))
|
||||
{
|
||||
die("no id");
|
||||
}
|
||||
$form = self::getAddToBasketForm($_POST['id']);
|
||||
$valid = $form->validate();
|
||||
|
||||
if ($valid){
|
||||
@ -203,9 +208,10 @@ Items Ordered:
|
||||
}
|
||||
|
||||
// get the basket to add to
|
||||
$form = self::getAddToBasketForm();
|
||||
$form = self::getAddToBasketForm($id);
|
||||
$form->add_to_basket->id->value($id);
|
||||
$form->add_to_basket->quantity->value(1);
|
||||
|
||||
$view->form = $form;
|
||||
$view->item = $item;
|
||||
|
||||
|
@ -40,16 +40,16 @@ class basket_Core {
|
||||
"MXN" => "Mexican Peso");
|
||||
|
||||
static $format= array(
|
||||
"AUD" => "$",
|
||||
"CAD" => "$",
|
||||
"EUR" => "€",
|
||||
"GBP" => "£",
|
||||
"JPY" => "¥",
|
||||
"USD" => "$",
|
||||
"NZD" => "$",
|
||||
"AUD" => "$",
|
||||
"CAD" => "$",
|
||||
"EUR" => "€",
|
||||
"GBP" => "£",
|
||||
"JPY" => "¥",
|
||||
"USD" => "$",
|
||||
"NZD" => "$",
|
||||
"CHF" => "",
|
||||
"HKD" => "$",
|
||||
"SGD" => "$",
|
||||
"HKD" => "$",
|
||||
"SGD" => "$",
|
||||
"SEK" => "",
|
||||
"DKK" => "",
|
||||
"PLN" => "",
|
||||
@ -63,12 +63,13 @@ class basket_Core {
|
||||
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->input("email")->label(t("Offline Paying Email Address"))->id("gOrderEmailAddress");
|
||||
$group->dropdown("currency")
|
||||
->label(t("Currency"))
|
||||
->options(self::$currencies);
|
||||
|
||||
$group->checkbox("paypal")->label(t("Use Paypal"))->id("gPaypal");
|
||||
$group->input("paypal_account")->label(t("Paypal E-Mail Address"))->id("gPaypalAddress");
|
||||
$group->submit("")->value(t("Save"));
|
||||
return $form;
|
||||
}
|
||||
|
@ -40,4 +40,69 @@ class basket_event_Core{
|
||||
->url(url::site("admin/product_lines")));
|
||||
|
||||
}
|
||||
|
||||
static function item_edit_form($item, $form){
|
||||
$group = $form->group("products")->label(t("Available Products"));
|
||||
|
||||
$product_override = ORM::factory("product_override")->where('item_id', $item->id)->find();
|
||||
$group->checkbox("all")->label("No products except..");
|
||||
if ($product_override->loaded){
|
||||
$group->all->checked($product_override->none);
|
||||
}
|
||||
|
||||
$products = ORM::factory("product")->find_all();
|
||||
foreach ($products as $product){
|
||||
$p_group = $group->group("product_$product->id")->label(t("$product->description"));
|
||||
|
||||
$description = $product->description;
|
||||
$cost = $product->cost;
|
||||
$checked = false;
|
||||
|
||||
if ($product_override->loaded){
|
||||
$item_product = ORM::factory("item_product")
|
||||
->where('product_override_id', $product_override->id)
|
||||
->where('product_id', $product->id)->find();
|
||||
if ($item_product->loaded){
|
||||
$checked = $item_product->include;
|
||||
if ($item_product->cost != -1){
|
||||
$cost = $item_product->cost;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$p_group->checkbox("exclude_$product->id")->label($description)->checked($checked);
|
||||
$p_group->input("cost_$product->id")->label("Cost")->value($cost);
|
||||
//$producta[$product->id] = $product->description." (".basket::formatMoney($product->cost).")";
|
||||
}
|
||||
}
|
||||
|
||||
static function item_edit_form_completed($item, $form){
|
||||
$product_override = ORM::factory("product_override")->where('item_id', $item->id)->find();
|
||||
|
||||
if ($form->products->all->checked)
|
||||
{
|
||||
$product_override->none = $form->products->all->checked;
|
||||
$product_override->item_id=$item->id;
|
||||
$product_override->save();
|
||||
$products = ORM::factory("product")->find_all();
|
||||
foreach ($products as $product){
|
||||
$p_group = $form->products->__get("product_$product->id");
|
||||
$item_product = ORM::factory("item_product")
|
||||
->where('product_override_id', $product_override->id)
|
||||
->where('product_id', $product->id)->find();
|
||||
|
||||
$item_product->include = $p_group->__get("exclude_$product->id")->checked;
|
||||
$item_product->cost = $p_group->__get("cost_$product->id")->value;
|
||||
$item_product->product_id = $product->id;
|
||||
$item_product->product_override_id = $product_override->id;
|
||||
$item_product->save();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($product_override->loaded){
|
||||
$product_override->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -27,6 +27,23 @@ class basket_installer {
|
||||
`description` varchar(1024),
|
||||
PRIMARY KEY (`id`))
|
||||
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
|
||||
|
||||
$db->query("CREATE TABLE IF NOT EXISTS {product_overrides} (
|
||||
`id` int(9) NOT NULL auto_increment,
|
||||
`item_id` int(9) NOT NULL,
|
||||
`none` BOOLEAN default false,
|
||||
PRIMARY KEY (`id`))
|
||||
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
|
||||
|
||||
$db->query("CREATE TABLE IF NOT EXISTS {item_products} (
|
||||
`id` int(9) NOT NULL auto_increment,
|
||||
`product_override_id` int(9) NOT NULL,
|
||||
`product_id` int(9) NOT NULL,
|
||||
`include` BOOLEAN default false,
|
||||
`cost` INTEGER(9) default -1,
|
||||
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");
|
||||
@ -37,5 +54,7 @@ class basket_installer {
|
||||
static function uninstall() {
|
||||
$db = Database::instance();
|
||||
$db->query("DROP TABLE IF EXISTS {products}");
|
||||
$db->query("DROP TABLE IF EXISTS {product_overrides}");
|
||||
$db->query("DROP TABLE IF EXISTS {item_products}");
|
||||
}
|
||||
}
|
||||
|
@ -35,12 +35,14 @@ class basket_theme_Core {
|
||||
$theme->script("gallery.panel.js");
|
||||
}
|
||||
}
|
||||
static function photo_top($theme)
|
||||
{
|
||||
$view = new View("add_to_basket.html");
|
||||
static function photo_top($theme){
|
||||
if ( product::isForSale($theme->item()->id)){
|
||||
$view = new View("add_to_basket.html");
|
||||
|
||||
$view->item = $theme->item();
|
||||
$view->item = $theme->item();
|
||||
|
||||
return $view->render();
|
||||
return $view->render();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
@ -80,12 +80,95 @@ class product_Core {
|
||||
return $product;
|
||||
}
|
||||
|
||||
static function getProductArray(){
|
||||
static function getProductArray($id){
|
||||
$producta = array();
|
||||
// check for product override
|
||||
$product_override = ORM::factory("product_override")->where('item_id', $id)->find();
|
||||
|
||||
if (!$product_override->loaded){
|
||||
// no override found so check parents
|
||||
// check parents for product override
|
||||
$item = ORM::factory("item",$id);
|
||||
|
||||
$parents = $item->parents();
|
||||
foreach ($parents as $parent){
|
||||
// check for product override
|
||||
$product_override = ORM::factory("product_override")->where('item_id', $parent->id)->find();
|
||||
if ($product_override->loaded){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$products = ORM::factory("product")->find_all();
|
||||
foreach ($products as $product){
|
||||
$producta[$product->id] = $product->description." (".basket::formatMoney($product->cost).")";
|
||||
$show = true;
|
||||
$cost = $product->cost;
|
||||
if ($product_override->loaded){
|
||||
$show = !$product_override->none;
|
||||
$item_product = ORM::factory("item_product")
|
||||
->where('product_override_id', $product_override->id)
|
||||
->where('product_id', $product->id)->find();
|
||||
|
||||
if ($item_product->loaded){
|
||||
$cost = $item_product->cost;
|
||||
if (!$show){
|
||||
$show = $item_product->include;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($show)
|
||||
{
|
||||
$producta[$product->id] = $product->description." (".basket::formatMoney($cost).")";
|
||||
}
|
||||
}
|
||||
|
||||
return $producta;
|
||||
}
|
||||
|
||||
static function isForSale($id){
|
||||
|
||||
// check for product override
|
||||
$product_override = ORM::factory("product_override")->where('item_id', $id)->find();
|
||||
|
||||
if (!$product_override->loaded){
|
||||
// no override found so check parents
|
||||
// check parents for product override
|
||||
$item = ORM::factory("item",$id);
|
||||
|
||||
$parents = $item->parents();
|
||||
foreach ($parents as $parent){
|
||||
// check for product override
|
||||
$product_override = ORM::factory("product_override")->where('item_id', $parent->id)->find();
|
||||
if ($product_override->loaded){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$products = ORM::factory("product")->find_all();
|
||||
|
||||
if ($product_override->loaded && $product_override->none){
|
||||
|
||||
foreach ($products as $product){
|
||||
|
||||
$item_product = ORM::factory("item_product")
|
||||
->where('product_override_id', $product_override->id)
|
||||
->where('product_id', $product->id)->find();
|
||||
|
||||
if ($item_product->loaded){
|
||||
|
||||
if ($item_product->include){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
} else {
|
||||
return count($products) > 0;
|
||||
}
|
||||
}
|
||||
}
|
@ -17,7 +17,6 @@
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
class basket_item
|
||||
{
|
||||
public $product;
|
||||
|
22
modules/basket/models/item_product.php
Normal file
22
modules/basket/models/item_product.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?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 Item_Product_Model extends ORM {
|
||||
protected $belongs_to= array('product_override');
|
||||
}
|
22
modules/basket/models/product_override.php
Normal file
22
modules/basket/models/product_override.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?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 Product_Override_Model extends ORM {
|
||||
protected $has_many=array('item_products');
|
||||
}
|
@ -18,18 +18,13 @@
|
||||
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
?>
|
||||
<div id="basket">
|
||||
<? if ($theme->page_type != 'basket'): ?>
|
||||
<? if (isset($basket) && isset($basket->contents)): ?>
|
||||
<? if (isset($basket) && isset($basket->contents) && ($basket->size() > 0)): ?>
|
||||
<div id="basket">
|
||||
<a href="<?= url::site("basket/view_basket") ?>"
|
||||
title="<?= t("View Basket") ?>">
|
||||
<img src="<?= url::file("modules/basket/images/basket.png") ?>"><br/>
|
||||
<?= $basket->size()?> items</a>
|
||||
<? else: ?>
|
||||
<a href="<?= url::site("basket/view_basket") ?>"
|
||||
title="<?= t("View Basket") ?>">
|
||||
<img src="<?= url::file("modules/basket/images/basket.png") ?>"><br/>
|
||||
<?= t("Empty") ?></a>
|
||||
<? endif ?>
|
||||
<? endif ?>
|
||||
</div>
|
||||
<? endif ?>
|
||||
<? endif ?>
|
||||
|
@ -48,12 +48,12 @@ function so(){document.confirm.submit();}
|
||||
<?= html::clean($prod_details->quantity) ?>
|
||||
</td>
|
||||
<td>
|
||||
<?= basket::formatMoney($prod_details->cost) ?>
|
||||
<?= html::clean(basket::formatMoney($prod_details->cost)) ?>
|
||||
</td>
|
||||
</tr>
|
||||
<? endforeach ?>
|
||||
<tr id="" class="<?= text::alternate("gOddRow", "gEvenRow") ?>">
|
||||
<td></td><td></td><td>Total Cost</td><td><?= $basket->cost()?></td>
|
||||
<td></td><td></td><td>Total Cost</td><td><?= html::clean($basket->cost())?></td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
|
@ -74,7 +74,7 @@
|
||||
</td>
|
||||
<td>
|
||||
<? $total += $prod_details->cost?>
|
||||
<?= basket::formatMoney($prod_details->cost) ?>
|
||||
<?= html::clean(basket::formatMoney($prod_details->cost)) ?>
|
||||
</td>
|
||||
<td class="gActions">
|
||||
<!-- a href="<?= url::site("admin/product_lines/edit_product_form/") ?>"
|
||||
@ -89,7 +89,7 @@
|
||||
</tr>
|
||||
<? endforeach ?>
|
||||
<tr id="" class="<?= text::alternate("gOddRow", "gEvenRow") ?>">
|
||||
<td></td><td></td><td>Total Cost</td><td><?= basket::formatMoney($total)?></td><td></td>
|
||||
<td></td><td></td><td>Total Cost</td><td><?= html::clean(basket::formatMoney($total))?></td><td></td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
|
Reference in New Issue
Block a user