$form_data['status'] = 'success'; $form_data['message'] = ""; //Add credit to the new signed-up account if there is credit sender information in session if (isset($_COOKIE["sender_email"])) { $sender_email = $_COOKIE["sender_email"]; $creditMgr->addCredit($sender_email, $email); $customerMgr->updateCredit($email, 10.0); $form_data['status'] = 'success'; $form_data['message'] = "Congratulations! You have got \$10 credits from your friend!"; setcookie('sender_email', '', time() - 1); } // Add cart item in temporary status into the cart of new signed-up account if (isset($_SESSION['temp_product_id_to_cart']) && !empty($_SESSION['temp_product_id_to_cart'])) { if ($productMgr->retrieveItemQtyInShoppingCart($userid, $_SESSION['temp_product_id_to_cart']) > 0) { $addedQty = $productMgr->retrieveItemQtyInShoppingCart($userid, $_SESSION['temp_product_id_to_cart']); $totalQty = $addedQty + $_SESSION['temp_product_qty_to_cart']; $productMgr->updateItemQty($userid, $_SESSION['temp_product_id_to_cart'], $totalQty); } else { $productMgr->addProductToShoppingCart($userid, $_SESSION['temp_product_id_to_cart'], $_SESSION['temp_product_qty_to_cart']); } unset($_SESSION['temp_product_id_to_cart']); unset($_SESSION['temp_product_qty_to_cart']); } if ($form_data['message'] != "") { header('location: index.php?status=' . $form_data['status'] . '&message=' . $form_data['message']); } else { header('location: index.php?'); } } else { header('location: test.php'); }
$addedQty = 0; $totalQty = 0; $qty_update = false; $cart_data = array(); if (!empty($_SESSION["userid"])) { // $userid is customer email address $userid = $_SESSION["userid"]; $cart_data['error_not_logged_in'] = false; //add product to the shopping cart if ($productMgr->retrieveItemQtyInShoppingCart($userid, $product_id, $color) > 0) { $addedQty = $productMgr->retrieveItemQtyInShoppingCart($userid, $product_id, $color); $totalQty = $addedQty + $qty; $productMgr->updateItemQty($userid, $color, $product_id, $totalQty); $qty_update = true; } else { $productMgr->addProductToShoppingCart($userid, $product_id, $qty, $color); } $photoList = $photoMgr->getPhotos($product_id); $photo_url = $photoList[$color]; //get the number of item in customer's shopping cart $cart_qty = $productMgr->retrieveTotalNumberOfItemsInShoppingCart($userid); $cart_unique_qty = $productMgr->retrieveTotalNumberOfUniqueItemsInShoppingCart($userid); $item_qty = $productMgr->retrieveItemQtyInShoppingCart($userid, $product_id, $color); $product_name = $productMgr->getProductName($product_id); $cart_data['cart_qty'] = $cart_qty; $cart_data['cart_unique_qty'] = $cart_unique_qty; $cart_data['add_item_id'] = $product_id; $cart_data['item_qty'] = $item_qty; $cart_data['product_name'] = $product_name; $cart_data['photo_url'] = $photo_url; $cart_data['userid'] = $userid;
$productMgr->updateProductColorOptionalCode($product_id, $imgColor, $_POST['edit_color_symbol_code4']); } break; } } } $colors = implode(",", $colorArr); $productMgr->updateProduct($product_id, $product_name, $symbol_code, $price, $colors, $description, $stock); header("Location: admin.php#viewProduct"); } elseif ($operation === "add_product_to_cart") { session_start(); $customer_id = $_SESSION["userid"]; //$customer_id = filter_input(INPUT_POST,'customer_id'); $product_id = filter_input(INPUT_POST, 'product_id'); $qty = filter_input(INPUT_POST, 'product_qty'); $productMgr->addProductToShoppingCart($customer_id, $product_id, $qty); //$_SESSION["message_add_cart"] = "Your Selected Prodcut has been added"; //header("Location: testAddToCart.php"); } elseif ($operation === "deletePhoto") { $product_id = addslashes(filter_input(INPUT_POST, 'product_id')); $photo_type = addslashes(filter_input(INPUT_POST, 'photo_type')); $photoMgr->deletePhoto($product_id, $photo_type); $color_str = $productMgr->getColor($product_id); $color_arr = explode(",", $color_str); if (($key = array_search($photo_type, $color_arr)) !== false) { unset($color_arr[$key]); } $new_color_str = implode(",", $color_arr); $productMgr->updateColor($product_id, $new_color_str); $productMgr->deleteColorOptionalCodeByProductColor($product_id, $photo_type); $return = [];