$action_url = $_SERVER['SERVER_PORT'] == "443" ? SECUREURL : URL . basename($_SERVER['PHP_SELF']); $product_rows[$i]['update_form'] = "<input type=\"hidden\" name=\"page\" value=\"" . $page . "\" />\r\n <input type=\"hidden\" name=\"func\" value=\"cartUpdate\" />\r\n <input type=\"hidden\" name=\"product_id\" value=\"" . $_SESSION['cart'][$i]["product_id"] . "\" />\r\n <input type=\"hidden\" name=\"Itemid\" value=\"" . $sess->getShopItemid() . "\" />\r\n <input type=\"hidden\" name=\"description\" value=\"" . $cart[$i]["description"] . "\" />\r\n <input type=\"image\" name=\"update\" title=\"" . $VM_LANG->_('PHPSHOP_CART_UPDATE') . "\" src=\"" . IMAGEURL . "ps_image/edit_f2.gif\" value=\"" . $VM_LANG->_('PHPSHOP_UPDATE') . "\" />\r\n </form>"; $product_rows[$i]['delete_form'] = "<form action=\"{$action_url}\" method=\"post\" name=\"delete\" />\r\n <input type=\"hidden\" name=\"option\" value=\"com_virtuemart\" />\r\n <input type=\"hidden\" name=\"page\" value=\"" . $page . "\" />\r\n <input type=\"hidden\" name=\"Itemid\" value=\"" . $sess->getShopItemid() . "\" />\r\n <input type=\"hidden\" name=\"func\" value=\"cartDelete\" />\r\n <input type=\"hidden\" name=\"product_id\" value=\"" . $_SESSION['cart'][$i]["product_id"] . "\" />\r\n <input type=\"hidden\" name=\"description\" value=\"" . $cart[$i]["description"] . "\" />\r\n <input type=\"image\" name=\"delete\" title=\"" . $VM_LANG->_('PHPSHOP_CART_DELETE') . "\" src=\"" . IMAGEURL . "ps_image/delete_f2.gif\" value=\"" . $VM_LANG->_('PHPSHOP_CART_DELETE') . "\" />\r\n </form>"; } // End of for loop through the Cart $total = $total_undiscounted = round($total, 5); $subtotal_display = $GLOBALS['CURRENCY_DISPLAY']->getFullValue($total); if ($_REQUEST["page"] == "checkout.index" && !empty($_POST["do_coupon"])) { /* process the coupon */ /* make sure they arent trying to run it twice */ if (@$_SESSION['coupon_redeemed'] == true) { $vmLogger->warning($VM_LANG->_('PHPSHOP_COUPON_ALREADY_REDEEMED', false)); } else { require_once CLASSPATH . "ps_coupon.php"; $vars["total"] = $total; ps_coupon::process_coupon_code($vars); } } // DISCOUNT $discount_word = ' '; $payment_discount_display = '0'; $payment_discount = $ps_checkout->get_payment_discount($payment_method_id, $total); if (PAYMENT_DISCOUNT_BEFORE == '1') { if ($payment_discount != 0.0) { $payment_discount_before = true; if ($payment_discount > 0.0) { $discount_word = $VM_LANG->_('PHPSHOP_PAYMENT_METHOD_LIST_DISCOUNT'); } else { $discount_word = $VM_LANG->_('PHPSHOP_FEE'); } $total -= $payment_discount;
/** * updates the quantity of a product_id in the cart * @author pablo * @param array $d * @return boolean result of the update */ function update(&$d) { global $VM_LANG, $vmLogger, $func, $page; include_class("product"); $product_id = (int) $d["prod_id"]; $quantity = isset($d["quantity"]) ? (int) $d["quantity"] : 1; $_SESSION['last_page'] = "shop.cart"; // Check for negative quantity if ($quantity < 0) { $vmLogger->warning($VM_LANG->_('PHPSHOP_CART_ERROR_NO_NEGATIVE', false)); return False; } if (!is_numeric($quantity)) { $vmLogger->warning($VM_LANG->_('PHPSHOP_CART_ERROR_NO_VALID_QUANTITY', false)); return False; } if (!$product_id) { return false; } $deleted_prod = 0; $updated_prod = 0; if ($quantity == 0 && strtolower($func) == "cartupdate") { $deleted_prod = $this->delete($d); } else { for ($i = 0; $i < $_SESSION['cart']["idx"]; $i++) { // modified for the advanced attribute modification if ($_SESSION['cart'][$i]["product_id"] == $product_id && $_SESSION['cart'][$i]["description"] == $d["description"]) { if (strtolower($func) == 'cartadd') { $quantity += $_SESSION['cart'][$i]["quantity"]; } // Get min and max order levels list($min, $max) = ps_product::product_order_levels($product_id); if ($min != 0 && $quantity < $min) { eval("\$msg = \"" . $VM_LANG->_('VM_CART_MIN_ORDER', false) . "\";"); $vmLogger->warning($msg); return false; } if ($max != 0 && $quantity > $max) { eval("\$msg = \"" . $VM_LANG->_('VM_CART_MAX_ORDER', false) . "\";"); $vmLogger->warning($msg); return false; } $quantity_options = ps_product::get_quantity_options($product_id); if (!empty($quantity_options) && !empty($quantity_options['quantity_step'])) { if ($quantity % $quantity_options['quantity_step'] > 0) { continue; } } // Remove deleted or unpublished products from the cart if (!ps_product::product_exists($product_id)) { $this->delete(array('product_id', $product_id)); continue; } // Check to see if checking stock quantity if (CHECK_STOCK) { $product_in_stock = ps_product::get_field($product_id, 'product_in_stock'); if (empty($product_in_stock)) { $product_in_stock = 0; } if ($quantity > $product_in_stock) { global $notify; $_SESSION['notify'] = array(); $_SESSION['notify']['idx'] = 0; $k = 0; $notify = $_SESSION['notify']; $_SESSION['notify'][$k]["prod_id"] = $product_id; $_SESSION['notify'][$k]["quantity"] = $quantity; $_SESSION['notify']['idx']++; $page = 'shop.waiting_list'; return true; } } $_SESSION['cart'][$i]["quantity"] = $quantity; $updated_prod++; } } } if (!empty($_SESSION['coupon_discount'])) { // Update the Coupon Discount !! require_once CLASSPATH . 'ps_coupon.php'; ps_coupon::process_coupon_code($d); } ps_cart::saveCart(); return array($updated_prod, $deleted_prod); }