| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- <?php
- require_once("DataBase/database.php");
- require_once("DataBase/Product.php");
- require_once("DataBase/Priceset.php");
- require_once("DataBase/Price.php");
- require_once("DataBase/Customer.php");
- require_once("DataBase/Bill.php");
- require_once("DataBase/Tour.php");
- require_once("DataBase/Bill_Product.php");
- require_once("DataBase/Customer_Template.php");
- class ShoppingCart
- {
- function __construct($param_customer_id, $param_product_id_array = array(), $param_product_amount_array = array(), $param_product_hint_array = array())
- {
- $this->product = new Product();
- $this->customer = new Customer();
- $this->product = new Product();
- $this->price = new Price();
- $this->priceset = new Priceset();
- $this->customer_template = new Customer_Template();
- $this->product_id_array = $param_product_id_array;
- $this->product_amount_array = $param_product_amount_array;
- $this->product_hint_array = $param_product_hint_array;
- $this->customer_id = $param_customer_id;
- if(count($this->product_id_array) > count($this->product_amount_array))
- echo "<div class=\"error\">Fehler in Session, bitte neu anmelden</div><br>\n";
- $this->priceset_id = 0;
- $customer_data = $this->customer->get($param_customer_id);
- if(count($customer_data) > 0)
- $this->priceset_id = $customer_data[0][11];
- $tmp_priceset = $this->priceset->get($this->priceset_id);
- $this->netto = 0;
- if(count($tmp_priceset) > 0)
- $this->netto = $tmp_priceset[0][2];
- }
- function getItemCount()
- {
- return count($this->product_id_array);
- }
- function getPriceSum()
- {
- $ret = 0;
- for($i = 0; $i < count($this->product_id_array); $i++)
- {
- $price = $this->price->getPriceTax($this->priceset_id, $this->product_id_array[$i], $this->netto);
- $ret += $price * $this->product_amount_array[$i];
- }
- return $ret;
- }
- function addProduct($param_product_id, $param_amount, $param_hint = "")
- {
- $product_data = $this->product->get($param_product_id);
- if(count($product_data) == 0)
- {
- echo "ShoppingCart::addProduct()", $param_product_id;
- echo "<div class=\"error\">Fehler in Session, bitte neu anmelden</div><br>\n";
- return;
- }
- /* check if product already in cart */
- for($i = 0; $i < count($this->product_id_array); $i++)
- {
- if($this->product_id_array[$i] == $param_product_id)
- {
- $this->product_amount_array[$i] += $param_amount;
- $this->saveShoppingCartSession();
- return;
- }
- }
- /* new product in cart */
- $this->product_id_array []= $param_product_id;
- $this->product_amount_array []= $param_amount;
- $this->product_hint_array []= $param_hint;
- $this->saveShoppingCartSession();
- }
- function removeProduct($param_product_id)
- {
- $tmp_id_array = array();
- $tmp_amount_array = array();
- $tmp_hint_array = array();
- for($i = 0; $i < count($this->product_id_array); $i++)
- {
- if($this->product_id_array[$i] != $param_product_id)
- {
- $tmp_id_array []= $this->product_id_array[$i];
- $tmp_amount_array []= $this->product_amount_array[$i];
- $tmp_hint_array []= $this->product_hint_array[$i];
- }
- }
- $this->product_id_array = $tmp_id_array;
- $this->product_amount_array = $tmp_amount_array;
- $this->product_hint_array = $tmp_hint_array;
- $this->saveShoppingCartSession();
- }
- function editProduct($param_product_id, $param_amount, $param_hint = "")
- {
- for($i = 0; $i < count($this->product_id_array); $i++)
- {
- if($this->product_id_array[$i] == $param_product_id)
- {
- $this->product_amount_array[$i] = $param_amount;
- $this->product_hint_array[$i] = $param_hint;
- }
- }
- $this->saveShoppingCartSession();
- }
- function saveShoppingCartSession()
- {
- $_SESSION["cart_product_id_array"] = $this->product_id_array;
- $_SESSION["cart_product_amount_array"] = $this->product_amount_array;
- $_SESSION["cart_product_hint_array"] = $this->product_hint_array;
- }
- function clearShoppingCart()
- {
- unset($_SESSION["cart_product_id_array"]);
- unset($_SESSION["cart_product_amount_array"]);
- unset($_SESSION["cart_product_hint_array"]);
- }
- function saveShoppingCartDatabase()
- {
- }
- function saveTemplate()
- {
- $this->customer_template->clear($this->customer_id);
- $list = $this->getItems();
- for($i = 0; $i < count($list); $i++)
- $this->customer_template->set($this->customer_id, $list[$i][0], $list[$i][2], $list[$i][5]);
- }
- function loadTemplate()
- {
- $list = $this->customer_template->get($this->customer_id);
- for($i = 0; $i < count($list); $i++)
- $this->addProduct($list[$i][1], $list[$i][2], $list[$i][3]);
- $this->saveShoppingCartSession();
- }
- function getItems()
- {
- $ret = array();
- for($i = 0; $i < count($this->product_id_array); $i++)
- {
- $tmp_product = $this->product->get($this->product_id_array[$i]);
- if(count($tmp_product) == 0)
- {
- echo "<div class=\"error\">Fehler in Session, bitte neu anmelden</div><br>\n";
- return -1;
- }
- $price = $this->price->getPriceTax($this->priceset_id, $this->product_id_array[$i], $this->netto);
- $ret []= array($this->product_id_array[$i], $tmp_product[0][1], $this->product_amount_array[$i], $price, $tmp_product[0][2], $this->product_hint_array[$i]);
- }
- return $ret;
- }
- function createBill()
- {
- $bill = new Bill();
- $customer = new Customer();
- $tour = new Tour();
- $bill_product = new Bill_Product();
- $customer_data = $customer->get($this->customer_id);
- if(count($customer_data) == 0)
- {
- echo "<div class=\"error\">Fehler in Session, bitte neu anmelden</div><br>\n";
- return -1;
- }
- $tour_data = $tour->get($customer_data[0][12]);
- $bill_id = $bill->create($this->customer_id, $customer_data[0][12], $tour_data[0][2], -2);
- $list = $this->getItems();
- for($i = 0; $i < count($list); $i++) {
- if ($list[$i][2] > 0) {
- $bill_product->create($bill_id, $list[$i][0], $list[$i][2], $list[$i][5], 0, 0, 0);
- }
- }
- return 0;
- }
- }
- ?>
|