175 lines
5.6 KiB
PHP
175 lines
5.6 KiB
PHP
<?php
|
|
/*
|
|
* @package Easyway Shop 5.5
|
|
* @copyright Copyright (C) 2005 - 2012 TA-EDV
|
|
* @license proprietary
|
|
* @author Richard Kammermayer <rk@ta-edv.de>,
|
|
* John T. Daly <jd@ta-edv.de>
|
|
*
|
|
* Easyway Shop is a web e-commerce system
|
|
*/
|
|
|
|
include_once('./core/shoppingcart.class.php');
|
|
|
|
class website_shoppingcart {
|
|
|
|
|
|
private $base_object;
|
|
private $layout_object;
|
|
private $item_object;
|
|
|
|
|
|
public function __construct($base_object, $layout_object) {
|
|
$this->base_object = $base_object;
|
|
$this->layout_object = $layout_object;
|
|
$this->item_object = new Item($base_object);
|
|
$this->shoppingcart_object = new Shoppingcart($base_object);
|
|
}
|
|
|
|
|
|
function run() {
|
|
$action = '';
|
|
|
|
if (isset($_POST['update_item']) && $_POST['update_item']) {
|
|
$action = 'update_shoppingcart';
|
|
} elseif (isset($_POST['amount']) && $_POST['amount']) {
|
|
$action = 'add_item';
|
|
}
|
|
|
|
if ($action == 'update_shoppingcart') {
|
|
$this->update_shoppingcart();
|
|
} elseif ($action == 'add_item') {
|
|
$this->add_item();
|
|
}
|
|
|
|
return $this->show_shoppingcart();
|
|
} // end run
|
|
|
|
|
|
private function show_shoppingcart() {
|
|
if (isset($_POST['customer_info'])) {
|
|
$_SESSION['customer_info'] = trim((string)$_POST['customer_info']);
|
|
}
|
|
|
|
// 18.09.2026 -- Warenkorb ist EIN Formular: "Zur Kasse" und die Express-Knoepfe schicken
|
|
// es ab (Mengen + Anmerkung werden so mitgespeichert) und das Ziel steht in cart_goto.
|
|
if (isset($_POST['cart_goto']) && $_POST['cart_goto'] !== '') {
|
|
$goto = (string)$_POST['cart_goto'];
|
|
if ($goto === 'kasse') {
|
|
header('Location: /Kasse/');
|
|
exit;
|
|
}
|
|
// 27.09.2026: "Weiter einkaufen" geht ueber das Formular (Mengen werden mitgespeichert),
|
|
// festes Ziel Startseite -- kein offener Redirect.
|
|
if ($goto === 'weiter') {
|
|
header('Location: /');
|
|
exit;
|
|
}
|
|
if (preg_match('/^express:([a-z0-9_]{1,40})$/', $goto, $m)) {
|
|
header('Location: /Kasse/?payment_express_start='.$m[1]);
|
|
exit;
|
|
}
|
|
}
|
|
// Post-Redirect-Get fuer die neue Ansicht: nach Mengen-/Anmerkungsaenderung per GET neu
|
|
// laden, sonst fragt ein Reload "Formular erneut senden" und schickt die Mengen doppelt.
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['cart_goto']) && !$this->alte_ansicht()) {
|
|
header('Location: /Warenkorb/');
|
|
exit;
|
|
}
|
|
|
|
if (isset($_SESSION['customer_info']) && $_SESSION['customer_info']) {
|
|
$this->layout_object->assign('customer_info', $_SESSION['customer_info']);
|
|
}
|
|
|
|
$data = $this->shoppingcart_object->get_data();
|
|
|
|
$this->layout_object->assign('shoppingcart', $data);
|
|
$this->layout_object->assign('shoppingcartVATUsage', $this->base_object->customer_group->show_tax);
|
|
|
|
// 14.09.2026: Express-Buttons der Zahlungsanbieter ("Direkt mit PayPal bezahlen").
|
|
// Angezeigt, wenn der Anbieter Express kann und seine Zahlart aktiv ist.
|
|
$this->layout_object->assign('express_providers', $this->express_providers());
|
|
|
|
// 27.09.2026 -- die neue Ansicht (content_shoppingcart_neu.tpl) ist Standard.
|
|
// Rueckfall auf das alte Template: /Warenkorb/?ansicht=alt (siehe alte_ansicht()).
|
|
if ($this->alte_ansicht()) {
|
|
return $this->layout_object->_fetch('content_shoppingcart.tpl');
|
|
}
|
|
$this->layout_object->assign('site_type', 'full_width'); // ohne Navigation, mehr Breite (Tom, 18.09.)
|
|
return $this->layout_object->_fetch('content_shoppingcart_neu.tpl');
|
|
} // end show_shoppingcart
|
|
|
|
|
|
/**
|
|
* Rueckfall auf die alte Warenkorb-/Kassenansicht (27.09.2026, Go-Live der neuen Ansicht):
|
|
* ?ansicht=alt schaltet fuer die Sitzung auf die alten Templates, ?ansicht=neu hebt das auf.
|
|
* Haelt ueber die Formular-POSTs hinweg, weil die alten Templates keinen Parameter mitschicken.
|
|
* Dieselbe Weiche steht in website_cashdesk.php.
|
|
*/
|
|
private function alte_ansicht() {
|
|
if (isset($_GET['ansicht'])) {
|
|
$_SESSION['easyshop']['ansicht_alt'] = ($_GET['ansicht'] === 'alt') ? 1 : 0;
|
|
}
|
|
return !empty($_SESSION['easyshop']['ansicht_alt']);
|
|
}
|
|
|
|
|
|
/** @return array<int,array{module:string,label:string}> */
|
|
private function express_providers() {
|
|
$out = array();
|
|
$file = $_SERVER['DOCUMENT_ROOT'].'/core/payments/Registry.php';
|
|
if (!is_file($file)) {
|
|
return $out;
|
|
}
|
|
include_once $file;
|
|
$res = $this->base_object->db->query("SELECT module FROM payment_methods WHERE active=1 AND module<>''");
|
|
while ($res && ($row = $res->fetch_object())) {
|
|
$module = (string)$row->module;
|
|
if (!\Payments\Registry::has($module)) {
|
|
continue;
|
|
}
|
|
try {
|
|
$p = \Payments\Registry::get($module, $this->base_object);
|
|
if ($p && $p->supportsExpress()) {
|
|
$out[] = array('module' => $module, 'label' => $p->label());
|
|
}
|
|
} catch (Throwable $e) {
|
|
error_log('Payments express button '.$module.': '.$e->getMessage());
|
|
}
|
|
}
|
|
return $out;
|
|
}
|
|
|
|
private function update_shoppingcart() {
|
|
foreach ($_POST['update_item'] as $item => $quantity) {
|
|
if ($quantity > 0) {
|
|
$this->shoppingcart_object->update($item, $quantity);
|
|
} else {
|
|
$this->shoppingcart_object->remove($item);
|
|
}
|
|
}
|
|
} // end update_shoppingcart
|
|
|
|
|
|
private function add_item() {
|
|
$this->shoppingcart_object->add($_POST['item_id'], $_POST['amount'], $_POST['variant'][1], $_POST['variant'][2]);
|
|
$multiplier = 1;
|
|
if ($this->item_object->is_combination_item()) {
|
|
$multiplier = (int)$_POST['amount'];
|
|
}
|
|
|
|
if (is_array($_POST['additionalItems'])) {
|
|
foreach ($_POST['additionalItems'] as $addItem) {
|
|
if (is_array($addItem)) {
|
|
$this->shoppingcart_object->add($addItem['id'], ((int)$_POST['amount'] * $multiplier), $addItem['variant_1'], $addItem['variant_2']);
|
|
} else {
|
|
$this->shoppingcart_object->add($addItem, 1);
|
|
}
|
|
}
|
|
}
|
|
} // end add_item
|
|
|
|
|
|
} // end website_shoppingcart
|
|
|
|
/* EOF */ |