function addOrderToSession($productid, $ingredients) { $product = getProduct($productid); if ($product == null) { return; } if ($product['price'] == 0 && (count($ingredients) == 0 || @trim($ingredients[0]) == '')) { global $lang; echo $lang->get('without_ingredients_not_addable'); return; } // Check if the same product is already in the cart $allreadythere = -1; if (isset($_SESSION['catering'])) { for ($i = 0; $i < count($_SESSION['catering']['order']['products']); $i++) { // Check if the product is the same if ($_SESSION['catering']['order']['products'][$i]['productid'] == $productid) { // If it has ingredients if (count($ingredients) > 0 && $ingredients[0] != "") { // Compare the number of ingredients if (count($_SESSION['catering']['order']['products'][$i]['ingredients']) == count($ingredients)) { $allreadythere = $i; foreach ($ingredients as $ingredient) { if (!in_array($ingredient, $_SESSION['catering']['order']['products'][$i]['ingredients'])) { $allreadythere = -1; } } if ($allreadythere != -1) { break 1; } } } else { $allreadythere = $i; } } } } if ($allreadythere != -1) { updateOrderQuantityInSession($allreadythere, $_SESSION['catering']['order']['products'][$allreadythere]['quantity'] + 1); } else { $newproduct = array(); $newproduct['productid'] = $productid; if (count($ingredients) != 0 && $ingredients[0] != "") { $newproduct['ingredients'] = $ingredients; } $newproduct['quantity'] = 1; $_SESSION['catering']['order']['products'][] = $newproduct; } }
<?php $lang->addModSpecificLocalization('catering'); $smarty->assign('lang', $lang->getAll()); $index = (int) $_GET['index']; $quantity = (int) $_GET['quantity']; require_once 'mod/default/catering/catering.function.php'; updateOrderQuantityInSession($index, $quantity); $smarty->assign('cart', getOrderFromSession()); $smarty->assign('submit_order', $lang->get('submit_order')); $smarty->display('../mod/default/catering/cart.tpl');