/** * adds a product to the cart * * @param float $cost cost of the product * @param int $amt how many to add * @param string $short_desc short description of the product * @param string $long_desc long description of the product * @param string $md5 a unique key for this product in the session * @param string $url URL where the product can be viewed * @param boolean $vat does VAT apply to this product * @param int $id the product's ID, if there is one * @param boolean $delivery_free is this product's delivery free * @param boolean $no_discount does this product ignore discounts * @param int $max_allowed max allowed per purchase * @param string $stock_number company stock code of the product * * @return null */ function OnlineStore_addToCart($cost = 0, $amt = 0, $short_desc = '', $long_desc = '', $md5 = '', $url = '', $vat = true, $id = 0, $delivery_free = false, $no_discount = false, $max_allowed = 0, $stock_number = '') { // { add item to session if (!isset($_SESSION['online-store'])) { $_SESSION['online-store'] = array('items' => array(), 'total' => 0); } $item = isset($_SESSION['online-store']['items'][$md5]) ? $_SESSION['online-store']['items'][$md5] : array('cost' => 0, 'amt' => 0, 'short_desc' => $short_desc, 'long_desc' => preg_replace('/\\|.*/', '', $long_desc), 'url' => $url); $item['cost'] = $cost; $item['amt'] += $amt; if ($max_allowed && $item['amt'] > $max_allowed) { $item['amt'] = $max_allowed; } $item['short_desc'] = $short_desc; $item['url'] = $url; $item['vat'] = $vat; $item['id'] = $id; $item['delivery_free'] = $delivery_free; $item['not_discountable'] = $no_discount; $item['stock_number'] = $stock_number; $_SESSION['online-store']['items'][$md5] = $item; // } require SCRIPTBASE . 'ww.plugins/online-store/libs.php'; OnlineStore_calculateTotal(); }
* @author Kae Verens <*****@*****.**> * @license GPL 2.0 * @link None */ require_once $_SERVER['DOCUMENT_ROOT'] . '/ww.incs/basics.php'; $md5 = $_REQUEST['md5']; $id = preg_replace('/^products_([0-9]*)(,.*)?$/', '\\1', $md5); $md5 = preg_replace('/^products_[0-9]*/', '', $md5); if (!isset($_SESSION['online-store']['items']['products_' . $id . $md5])) { // TODO: translation needed die(__('No such item')); } $product = Product::getInstance($id); require_once '../libs.php'; $amount = (int) $_REQUEST['amt'] - $_SESSION['online-store']['items']['products_' . $id . $md5]['amt']; // { does the amount requested bring it over the maximum allowed per purchase $max_allowed = isset($product->vals['os_amount_allowed_per_purchase']) ? (int) $product->vals['os_amount_allowed_per_purchase'] : 0; // } list($price, $amount, $vat) = Products_getProductPrice($product, $amount, $md5, false); if ($max_allowed && $amount > $max_allowed) { $amount = $max_allowed; } if ($amount < 1) { unset($_SESSION['online-store']['items']['products_' . $id . $md5]); } else { $_SESSION['online-store']['items']['products_' . $id . $md5]['cost'] = $price; $_SESSION['online-store']['items']['products_' . $id . $md5]['amt'] = $amount; } $total = OnlineStore_calculateTotal(); $item_total = $amount ? $_SESSION['online-store']['items']['products_' . $id . $md5]['cost'] * $amount : 0; echo '{' . '"md5": "' . 'products_' . $id . $md5 . '",' . '"amt":' . $amount . ',' . '"item_total":' . $item_total . ',' . '"total":' . $total . '}';