Commit 17280c9b by amal

initial

parents
NODE_ENV=development
PROTOCOL=http://
APIURL=http://localhost.com:3000
\ No newline at end of file
node_modules/
package-lock.json
{
"editor.formatOnSave": true
}
\ No newline at end of file
(function() {
"use strict";
// *** dependencies *** //
const express = require("express");
const appConfig = require("./config/main-config.js");
const routeConfig = require("./config/route-config.js");
const errorConfig = require("./config/error-config.js");
// *** express instance *** //
const app = express();
// *** config *** //
appConfig.init(app, express);
routeConfig.init(app);
errorConfig.init(app);
module.exports = app;
})();
#!/usr/bin/env node
/**
* Module dependencies.
*/
var app = require("../app");
var debug = require("debug")("valuecart-web:server");
var https = require("https");
const fs = require("fs");
/**
* Get port from environment and store in Express.
*/
var port = normalizePort(process.env.PORT || "5555");
app.set("port", port);
/**
* Create https server.
*/
const sslCreds = {
key: fs.readFileSync("sslforfree/private.key"),
cert: fs.readFileSync("sslforfree/certificate.crt"),
ca: fs.readFileSync("sslforfree/ca_bundle.crt")
};
var server = https.createServer(sslCreds, app);
// var server = https.createServer(app);
/**
* Listen on provided port, on all network interfaces.
*/
server.listen(port);
server.on("error", onError);
server.on("listening", onListening);
/**
* Normalize a port into a number, string, or false.
*/
function normalizePort(val) {
var port = parseInt(val, 10);
if (isNaN(port)) {
// named pipe
return val;
}
if (port >= 0) {
// port number
return port;
}
return false;
}
/**
* Event listener for https server "error" event.
*/
function onError(error) {
if (error.syscall !== "listen") {
throw error;
}
var bind = typeof port === "string" ? "Pipe " + port : "Port " + port;
// handle specific listen errors with friendly messages
switch (error.code) {
case "EACCES":
console.error(bind + " requires elevated privileges");
process.exit(1);
break;
case "EADDRINUSE":
console.error(bind + " is already in use");
process.exit(1);
break;
default:
throw error;
}
}
/**
* Event listener for https server "listening" event.
*/
function onListening() {
var addr = server.address();
var bind = typeof addr === "string" ? "pipe " + addr : "port " + addr.port;
debug("Listening on " + bind);
}
let instance = {
baseURL: process.env.APIURL,
timeout: 200000,
headers: { "Content-Type": "application/json" }
};
module.exports = {
instance
};
(function(errorConfig) {
"use strict";
// *** error handling *** //
errorConfig.init = function(app) {
// catch 404 and forward to error handler
app.use(function(req, res, next) {
const err = new Error("Not Found");
err.status = 404;
res.render("404");
});
// development error handler (will print stacktrace)
if (app.get("env") === "development") {
app.use(function(err, req, res, next) {
res.status(err.status || 500).json({
message: err.message,
error: err
});
});
}
// production error handler (no stacktraces leaked to user)
app.use(function(err, req, res, next) {
res.status(err.status || 500).json({
message: err.message,
error: {}
});
});
app.post("/", function(req, res) {
console.log(req.body);
});
};
})(module.exports);
error_404 = function(res) {
res.render("404");
};
(function(appConfig) {
"use strict";
// *** main dependencies *** //
const createError = require("http-errors");
const express = require("express");
const path = require("path");
const cookieParser = require("cookie-parser");
const logger = require("morgan");
const bodyParser = require("body-parser");
var flash = require("connect-flash");
var session = require("express-session");
var moment = require("moment");
var _ = require("lodash");
// *** load environment variables *** //
require("dotenv").config();
appConfig.init = function(app, express) {
// view engine setup
app.set("views", path.join(__dirname, "../views"));
app.set("view engine", "ejs");
app.use(logger("dev"));
app.use(express.json());
app.use(
express.urlencoded({
extended: true
})
);
app.use(
bodyParser.urlencoded({
extended: true
})
);
app.use(cookieParser("secret"));
app.use(
session({
secret: "valucart",
proxy: true,
resave: true,
saveUninitialized: true
})
);
app.use(flash());
/**bodyParser.json(options)
* Parses the text as JSON and exposes the resulting object on req.body.
*/
app.use(function(req, res, next) {
res.locals.flashdata = req.flash();
res.locals.moment = moment;
res.locals._ = _;
res.locals.baseURL = req.headers.host;
next();
});
app.use(bodyParser.json());
app.use(express.static(path.join(__dirname, "../public")));
};
})(module.exports);
(function (routeConfig) {
"use strict";
routeConfig.init = function (app) {
// *** routes *** //
const cityRouter = require("../routes/select_city");
const areaRouter = require("../routes/select_area");
const landingpageRouter = require("../routes/intro");
const homeRouter = require("../routes/home");
const cartRouter = require("../routes/cart");
const checkoutRouter = require("../routes/checkout");
const bundlelistRouter = require("../routes/bundle_list");
const bundledetailRouter = require("../routes/bundle_details");
const changepasswordRouter = require("../routes/change_password");
const cancelorderRouter = require("../routes/cancelorder");
const createbundleRouter = require("../routes/create-bundle");
const productlistingRouter = require("../routes/product-listing");
const productdetailsRouter = require("../routes/product-detail");
const profileRouter = require("../routes/profile");
const editprofileRouter = require("../routes/edit-profile");
const mybundlesRouter = require("../routes/mybundles");
const myordersRouter = require("../routes/myorders");
const myorderdetailsRouter = require("../routes/myorder-details");
const myshoppingRouter = require("../routes/myshopping");
const myshoppingdashboardRouter = require("../routes/myshopping-dashboard");
const newaddressRouter = require("../routes/new-address");
const ordertrackingRouter = require("../routes/order-tracking");
const otpRouter = require("../routes/otp");
const replacementRouter = require("../routes/request-replacement");
const replacementsuccessRouter = require("../routes/replacement-success");
const servicerequestRouter = require("../routes/service-request");
const subscribeRouter = require("../routes/subscribe");
const wishlistRouter = require("../routes/mywishlist");
const addressbookRouter = require("../routes/addressbook");
const category = require("../routes/category.js");
const schedule = require("../routes/schedule.js");
const aboutusRouter = require("../routes/about-us.js");
const faqRouter = require("../routes/faq.js");
const termsRouter = require("../routes/terms.js");
const privacyRouter = require("../routes/privacy-policy.js");
const returnRouter = require("../routes/return-policy.js");
const searchRouter = require("../routes/search.js");
const contactUs = require("../routes/contact-us.js");
// *** register routes *** //
app.use("/city", cityRouter);
app.use("/area", areaRouter);
app.use("/intro", landingpageRouter);
app.use("/", homeRouter);
app.use("/cart", cartRouter);
app.use("/checkout", checkoutRouter);
/*** Bundle and product routes ***/
app.use("/bundle-list", bundlelistRouter);
app.use("/bundle-detail", bundledetailRouter);
app.use("/product-listing", productlistingRouter);
app.use("/product-detail", productdetailsRouter);
app.use("/category", category);
app.use("/schedule-bundle", schedule);
/*** Myaccount routes ***/
app.use("/change-password", changepasswordRouter);
app.use("/cancel-order", cancelorderRouter);
app.use("/create-bundle", createbundleRouter);
app.use("/profile", profileRouter);
app.use("/edit-profile", editprofileRouter);
app.use("/mybundles", mybundlesRouter);
app.use("/myorders", myordersRouter);
app.use("/myorder-details", myorderdetailsRouter);
app.use("/schedule-detail", myshoppingRouter);
app.use("/schedule-list", myshoppingdashboardRouter);
app.use("/new-address", newaddressRouter);
app.use("/order-tracking", ordertrackingRouter);
app.use("/otp", otpRouter);
app.use("/request-replacement", replacementRouter);
app.use("/replacement-success", replacementsuccessRouter);
app.use("/service-request", servicerequestRouter);
app.use("/subscribe", subscribeRouter);
app.use("/mywishlist", wishlistRouter);
app.use("/addressbook", addressbookRouter);
app.use("/about-us", aboutusRouter);
app.use("/faq", faqRouter);
app.use("/terms-and-conditions", termsRouter);
app.use("/privacy-policy", privacyRouter);
app.use("/return-policy", returnRouter);
app.use("/search", searchRouter);
app.use("/contact-us", contactUs);
};
})(module.exports);
const axios_config = require("../config/axios-config.js").instance;
const axios = require("axios");
let get_address = async (cookies, address_id) => {
try {
let getparam = axios_config;
getparam["headers"] = {
Authorization: "Bearer " + cookies.token
};
if (address_id != "") {
getparam["params"] = { id: address_id };
$url = "/userProfile/getuseraddress";
} else {
$url = "/userProfile/useraddresslist";
}
let response = await axios.get($url, getparam);
return response.data.results;
} catch (error) {
throw error;
}
};
module.exports = {
get_address
};
const axios_config = require("../config/axios-config.js").instance;
const axios = require("axios");
// const Logger = require("../lib/logger").Logger;
let get_data = async (pb_id, cookies) => {
try {
axios_config["params"] = { product_id: pb_id };
if (cookies) {
var userData = JSON.parse(cookies);
axios_config["headers"] = {
Authorization: "Bearer " + userData.token
};
}
let response = await axios.get(`/product/details_pb/get`, axios_config);
if (response.data.results.status != "404") {
return response.data.results;
} else {
throw "error";
}
} catch (error) {
throw error;
}
};
module.exports = {
get_data
};
const axios_config = require("../config/axios-config.js").instance;
const axios = require("axios");
// const Logger = require("../lib/logger").Logger;
let get_data = async (querydata, cat_id) => {
try {
querydata["cat_id"] = cat_id;
let response = {};
let getparam = axios_config;
getparam["params"] = { cat_id: cat_id };
let product_filter = await axios.get("product/filter/bundle/get", getparam);
response["product_config"] = product_filter.data.results.response;
response["querydata"] = querydata;
return response;
} catch (error) {
throw error;
}
};
let get_datav2 = async querydata => {
try {
// querydata["cat_id"] = cat_id;
let response = {};
let getparam = axios_config;
// getparam["params"] = { cat_id: cat_id };
let product_filter = await axios.get(
"product/filter/bundle/get/v2",
getparam
);
response["product_config"] = product_filter.data.results.response;
response["querydata"] = querydata;
return response;
} catch (error) {
throw error;
}
};
module.exports = {
get_data,
get_datav2
};
const axios_config = require("../config/axios-config.js").instance;
const axios = require("axios");
// const Logger = require("../lib/logger").Logger;
let get_data = async cookies => {
try {
let getparam = axios_config;
getparam["headers"] = {
Authorization: "Bearer " + cookies.token
};
let cartdata = await axios.get("cart/listV2", getparam);
response = cartdata.data.results.response;
return response;
} catch (error) {
throw error;
}
};
module.exports = {
get_data
};
const axios_config = require("../config/axios-config.js").instance;
const axios = require("axios");
let get_menulist = async () => {
try {
let response = await axios.get("/category/main_sub/get", axios_config);
return response.data.results;
} catch (error) {
throw error;
}
};
module.exports = {
get_menulist
};
const axios_config = require("../config/axios-config.js").instance;
const axios = require("axios");
// const Logger = require("../lib/logger").Logger;
let orderInit = async (cookies, data) => {
try {
let getparam = axios_config;
getparam["headers"] = {
Authorization: "Bearer " + cookies.token
};
let order = await axios.post("order/initV2/post", data, getparam);
response = order.data.results.response;
return response;
} catch (error) {
// console.log(error);
throw error;
}
};
module.exports = {
orderInit
};
const axios_config = require("../config/axios-config.js").instance;
const axios = require("axios");
// const Logger = require("../lib/logger").Logger;
let get_data = async cookies => {
try {
let getparam = axios_config;
if (cookies) {
getparam["headers"] = {
Authorization: "Bearer " + cookies.token
};
}
let response = await axios.get("/dashboard/get/v2", getparam);
return response.data.results;
} catch (error) {
throw error;
}
};
module.exports = {
get_data
};
const axios_config = require("../config/axios-config.js").instance;
const axios = require("axios");
let get_data = async (cookies, order_id) => {
try {
let getparam = axios_config;
getparam["headers"] = {
Authorization: "Bearer " + cookies.token
};
let data = await axios.get(
"/order/details/get?order_id=" + order_id.order_id,
getparam
);
response = data.data.results.response;
if (response) {
return response;
} else {
throw "error";
}
} catch (error) {
throw error;
}
};
module.exports = {
get_data
};
const axios_config = require("../config/axios-config.js").instance;
const axios = require("axios");
let get_data = async cookies => {
try {
let getparam = axios_config;
getparam["headers"] = {
Authorization: "Bearer " + cookies.token
};
let myorders = await axios.get("/order/list/get", getparam);
response = myorders.data.results.response;
return response;
} catch (error) {
throw error;
}
};
module.exports = {
get_data
};
const axios_config = require("../config/axios-config.js").instance;
const axios = require("axios");
let getshoppinglist = async (cookies, list_id) => {
try {
let getparam = axios_config;
getparam["headers"] = {
Authorization: "Bearer " + cookies.token
};
var lid = list_id != "" ? list_id : "";
let response = await axios.get("/shopping_list/" + lid, getparam);
response = response.data.results.response;
if (response) {
return response;
} else {
throw "error";
}
} catch (error) {
throw error;
}
};
/**
*
* @param {object} cookies
* @param {number} list_id
*/
let createShoppingList = async (cookies, list_id) => {
try {
let getparam = axios_config;
getparam["headers"] = {
Authorization: "Bearer " + cookies.token
};
let response = await axios.post(
"/shopping_list",
{ order_id: list_id },
getparam
);
response = response.data.results.response;
if (response) {
return response;
} else {
throw "error";
}
} catch (error) {
throw error;
}
};
/**
*
* @param {object} cookies
* @param {number} list_id
*/
let createShoppingListv2 = async (cookies, postdata) => {
try {
let getparam = axios_config;
getparam["headers"] = {
Authorization: "Bearer " + cookies.token
};
let response = await axios.post("/shopping_list/v2", postdata, getparam);
response = response.data.results.response;
if (response) {
return response;
} else {
throw "error";
}
} catch (error) {
throw error;
}
};
module.exports = {
getshoppinglist,
createShoppingList,
createShoppingListv2
};
const axios_config = require("../config/axios-config.js").instance;
const axios = require("axios");
let get_mywishlist = async cookies => {
try {
let getparam = axios_config;
getparam["headers"] = {
Authorization: "Bearer " + cookies.token
};
let response = await axios.get("/wishList/getwishlist", getparam);
return response.data;
} catch (error) {
throw error;
}
};
module.exports = {
get_mywishlist
};
const axios_config = require("../config/axios-config.js").instance;
const axios = require("axios");
// const Logger = require("../lib/logger").Logger;
let get_data = async (pd_id, cookies) => {
try {
axios_config["params"] = { product_id: pd_id };
if (cookies) {
var userData = JSON.parse(cookies);
axios_config["headers"] = {
Authorization: "Bearer " + userData.token
};
}
let response = await axios.get("/product/details/get", axios_config);
if (response.data.results.status != "404") {
return response.data.results;
} else {
throw "error";
}
} catch (error) {
throw error;
}
};
module.exports = {
get_data
};
const axios_config = require("../config/axios-config.js").instance;
const axios = require("axios");
var _ = require("lodash");
// const Logger = require("../lib/logger").Logger;
let get_data = async (querydata, cat_id, cookies) => {
try {
querydata["cat_id"] = cat_id;
let response = {};
let getparam = axios_config;
if (cookies) {
getparam["headers"] = {
Authorization: "Bearer " + cookies.token
};
} else {
delete getparam["headers"];
}
let product_filter = await axios.get(
"product/filter/get?cat_id=" + cat_id,
getparam
);
if (_.isEmpty(product_filter.data.results.response) == true) {
// throw product_filter;
}
response["product_config"] = product_filter.data.results.response;
response["product_type"] =
product_filter.data.results.msg == "VCGT" ? "Bundle" : "Valuecart";
response["querydata"] = querydata;
return response;
} catch (error) {
throw error;
}
};
let get_datav2 = async (querydata, cookies) => {
try {
let response = {};
let getparam = axios_config;
if (cookies) {
getparam["headers"] = {
Authorization: "Bearer " + cookies.token
};
} else {
delete getparam["headers"];
}
let product_filter = await axios.get("product/filter/get/v2", getparam);
if (_.isEmpty(product_filter.data.results.response) == true) {
// throw product_filter;
}
response["product_config"] = product_filter.data.results.response;
response["product_type"] =
product_filter.data.results.msg == "VCGT" ? "Bundle" : "ValuCart";
response["querydata"] = querydata;
return response;
} catch (error) {
throw error;
}
};
let get_datave = async querydata => {
try {
let response = {};
let getparam = axios_config;
let product_filter = await axios.get(
"product/filter/valuecartexclusive/get",
getparam
);
if (_.isEmpty(product_filter.data.results.response) == true) {
// throw product_filter;
}
response["product_config"] = product_filter.data.results.response;
response["querydata"] = querydata;
return response;
} catch (error) {
throw error;
}
};
module.exports = {
get_data,
get_datav2,
get_datave
};
const axios_config = require("../config/axios-config.js").instance;
const axios = require("axios");
let get_data = async cookies => {
try {
let getparam = axios_config;
getparam["headers"] = {
Authorization: "Bearer " + cookies.token
};
getparam["params"] = { id: cookies.user_id };
let response = await axios.get(`/userProfile/get`, getparam);
//console.log(response.data.results);
return response.data.results;
} catch (error) {
throw error;
}
};
module.exports = {
get_data
};
const axios_config = require("../config/axios-config.js").instance;
const axios = require("axios");
// const Logger = require("../lib/logger").Logger;
let get_data = async (cookies, id) => {
try {
let getparam = axios_config;
if (cookies) {
getparam["headers"] = {
Authorization: "Bearer " + cookies.token
};
}
let response = await axios.get(
"user_bundle/details/get?ub_id=" + id,
getparam
);
return response.data.results;
} catch (error) {
throw error;
}
};
let savedata = async (cookies, payload) => {
try {
let getparam = axios_config;
if (cookies) {
getparam["headers"] = {
Authorization: "Bearer " + cookies.token
};
}
let response = await axios.post(
"user_bundle/scheduleBundle/post",
{
time_period: payload.bundles,
no_days: payload.bundles1,
ub_id: payload.ub_id
},
getparam
);
return response.data.results;
} catch (error) {
throw error;
}
};
module.exports = {
get_data,
savedata
};
const axios_config = require("../config/axios-config.js").instance;
const axios = require("axios");
// const Logger = require("../lib/logger").Logger;
let get_data = async data => {
try {
let getparam = axios_config;
let response = await axios.get("/search?q=" + data, getparam);
return response.data.results;
} catch (error) {
throw error;
}
};
module.exports = {
get_data
};
const axios_config = require("../config/axios-config.js").instance;
const axios = require("axios");
// const Logger = require("../lib/logger").Logger;
let get_data = async city_id => {
try {
axios_config["params"] = { city_id: city_id };
let response = await axios.get("/userProfile/getarealist", axios_config);
return response.data.results;
} catch (error) {
throw error;
}
};
module.exports = {
get_data
};
const axios_config = require("../config/axios-config.js").instance;
const axios = require("axios");
// const Logger = require("../lib/logger").Logger;
let get_data = async () => {
try {
let response = await axios.get("/userProfile/getcitylist", axios_config);
return response.data.results;
} catch (error) {
throw error;
}
};
module.exports = {
get_data
};
const axios_config = require("../config/axios-config.js").instance;
const axios = require("axios");
/**
*
* @param {object} cookies
*/
let get_mybundle = async cookies => {
try {
let getparam = axios_config;
getparam["headers"] = {
Authorization: "Bearer " + cookies.token
};
let response = await axios.get("user_bundle/list/get", getparam);
return response.data.results.response;
} catch (error) {
throw error;
}
};
/**
*
* @param {object} cookies
* @param {Number} bundleId
*/
let deleteBundle = async (cookies, bundleId) => {
try {
let getparam = axios_config;
getparam["headers"] = {
Authorization: "Bearer " + cookies.token
};
getparam["params"] = {
ub_id: bundleId
};
let response = await axios.delete(
"user_bundle/bundleDelete/delete",
getparam
);
return response.data.results.status;
} catch (error) {
throw error;
}
};
/**
*
* @param {object} cookies
* @param {Number} bundleId
*/
let get_mybundle_details = async (cookies, bundleId) => {
try {
let getparam = axios_config;
getparam["headers"] = {
Authorization: "Bearer " + cookies.token
};
getparam["params"] = {
ub_id: bundleId
};
let response = await axios.get("user_bundle/details/get", getparam);
return response.data.results.status;
} catch (error) {
throw error;
}
};
/**
*
* @param {*} cookies
* @param {*} bundleId
*/
let create_bundle_withname = async (cookies, bundlename) => {
try {
let getparam = axios_config;
getparam["headers"] = {
Authorization: "Bearer " + cookies.token
};
let response = await axios.post(
"user_bundle/createWithName/post",
{ bundle_name: bundlename },
getparam
);
return response.data.results.status;
} catch (error) {
throw error;
}
};
/**
*
* @param {*} cookies
* @param {*} bundleId
*/
let checkpendingBundle = async (cookies, bundlename) => {
try {
let getparam = axios_config;
getparam["headers"] = {
Authorization: "Bearer " + cookies.token
};
let response = await axios.get(
"user_bundle/checkPendingBundles/get",
getparam
);
return response.data;
} catch (error) {
return error;
}
};
module.exports = {
get_mybundle,
deleteBundle,
get_mybundle_details,
create_bundle_withname,
checkpendingBundle
};
function ensureAuthenticated(req, res, next) {
let cookies = !req.cookies.vcartAuth ? false : req.cookies.vcartAuth;
if (cookies == false) {
res.redirect("/");
res.end();
} else {
next();
}
}
module.exports = {
ensureAuthenticated
};
const winston = require("winston");
require("winston-mongodb");
const logger = winston.add(winston.transports.MongoDB, {
// TODO: Have to make this work from dot env
db: `mongodb://localhost:27017/valuecart`,
collection: `weblogs`,
capped: true
});
module.exports.Logger = logger;
{
"name": "valuecart-web",
"version": "0.0.0",
"private": true,
"scripts": {
"dev": "nodemon start",
"start": "node ./bin/www"
},
"dependencies": {
"axios": "^0.18.0",
"body-parser": "^1.18.3",
"connect-flash": "^0.1.1",
"cookie-parser": "~1.4.3",
"debug": "~2.6.9",
"dotenv": "^6.0.0",
"ejs": "~2.5.7",
"express": "~4.16.0",
"express-session": "^1.15.6",
"http-errors": "~1.6.2",
"lodash": "^4.17.10",
"moment": "^2.22.2",
"morgan": "^1.9.0",
"winston": "^3.0.0",
"winston-mongodb": "^4.0.0-rc1"
},
"devDependencies": {
"nodemon": "^1.18.2"
}
}
var app = angular
.module("myapp", ["ngRoute", "ngMessages", "ngSanitize"])
.directive("onFinishRender", function($timeout) {
return {
restrict: "A",
link: function(scope, element, attr) {
if (scope.$last === true) {
$timeout(function() {
scope.$emit(
attr.broadcasteventname
? attr.broadcasteventname
: "ngRepeatFinished"
);
});
}
}
};
})
.directive("ngConfirmClick", [
function() {
return {
link: function(scope, element, attr) {
var msg = attr.ngConfirmClick || "Are you sure?";
var clickAction = attr.confirmedClick;
element.bind("click", function(event) {
if (window.confirm(msg)) {
scope.$eval(clickAction);
}
});
}
};
}
]);
var baseurl = APIURL;
app.constant("config", {
baseURL: baseurl,
getproduct_list: baseurl + "/product/list/product/post",
getbundleList: baseurl + "/product/list/product_bundle/post",
getbundleDetail: baseurl + "/product/details_pb/get",
submitBundle_review: baseurl + "/product/review/post",
unsubscribeBundle: baseurl + "/user_bundle/unSubscribeUserBundle",
updateBundleName: baseurl + "/user_bundle/reNameUserBundle",
addToCart: baseurl + "/cart/add",
cartupdate: baseurl + "/cart/quantity",
cartRemove: baseurl + "/cart/remove",
addWishList: baseurl + "/wishList/addproducttowishlist",
removeWishList: baseurl + "/wishList/removewishlist",
change_password: baseurl + "/auth/resetpassword",
addAddress: baseurl + "/userProfile/addnewaddress/v2",
updateAddress: baseurl + "/userProfile/updateaddress/v2",
changeDefaultAddress: baseurl + "/userProfile/makedefaultaddress",
removeAddress: baseurl + "/userProfile/deleteaddress",
user_profileUpdate: baseurl + "/userProfile/update",
mybundel_list: baseurl + "/user_bundle/list/get",
view_mybundle: baseurl + "/user_bundle/details/get",
edit_mybundle: baseurl + "/user_bundle/edit/put",
update_mybundle_single: baseurl + "/user_bundle/addProductToUserBundle",
shppingListUrl: baseurl + "/shopping_list",
addressList: baseurl + "/userProfile/useraddresslist",
emailVerify: baseurl + "/auth/otpverify",
orderList: baseurl + "/order/list/get",
orderDetails: baseurl + "/order/details/get",
create_user_bundle: baseurl + "/user_bundle/create/post",
forgotpassword: baseurl + "/auth/forgetpassword",
sentotptoemail: baseurl + "/auth/sentotptoemail",
checkCoupon: baseurl + "/coupon/applyCoupon",
deleteUserBundle: baseurl + "/user_bundle/bundleDelete/delete",
createWithproduct: baseurl + "/user_bundle/createWithproduct/post",
cancelorder: baseurl + "/order/",
getcityarealist: baseurl + "/userProfile/getcityarealist",
update_mybundle_singlewithoutbundleid:
baseurl + "/user_bundle/addProductToUserBundleWithoutBundleId",
adduserbundletocart: baseurl + "/cart/adduserbundletocart",
settings: baseurl + "/settings"
});
app.config(function($routeProvider, $locationProvider, $httpProvider) {
// $locationProvider.html5Mode(true);
});
app.filter("spaceless", function() {
return function(input) {
if (input) {
return input.replace(/\s+/g, "-");
}
};
});
app.filter("toster"),
function() {
return function(type, msg) {
// Display a success toast, with a title
toastr.success("Have fun storming the castle!", "Miracle Max Says");
};
};
app.controller("add_address", function(
$scope,
$rootScope,
$location,
$http,
$timeout,
$filter,
config,
addNewAddress,
address
) {
addNewAddress
.cityarea_get()
.then(function(response) {
$scope.city = response.data.results;
if (address.data != "") {
console.log(address.data.a_city_id);
$timeout(function() {}, 3000);
$scope.getarea(address.data.a_city_id);
}
})
.catch(function(response) {
console.log(response);
});
$scope.getarea = function(index) {
let i = _.findIndex($scope.city, function(o) {
return o.city_id == index;
});
$scope.area = $scope.city[i].area;
};
//Profile Update//
var cp = document.forms.newAddress,
elem = cp.elements;
cp.onsubmit = function() {
var a = 0;
if (!elem.address_name.value) {
toastr.error("Name is required");
elem.address_name.focus();
a = 1;
}
if (!elem.phone_no.value) {
toastr.error("Phone Number is Required");
elem.phone_no.focus();
a = 1;
}
if (!elem.flat.value) {
toastr.error("FLAT/HOUSE/FLOOR/BUILDING is Required");
elem.flat.focus();
a = 1;
}
if (!elem.street.value) {
toastr.error("STREET/LOCALITY");
elem.street.focus();
a = 1;
}
if (!elem.city_id.value) {
toastr.error("City is Required");
elem.city_id.focus();
a = 1;
}
if (!elem.area_id.value) {
toastr.error("Area is Required");
elem.area_id.focus();
a = 1;
}
// if (!elem.postalcode.value) {
// toastr.error("Postalcode is Required");
// elem.postalcode.focus();
// a = 1;
// }
if (a == 1) {
return false;
} else {
var userAuth = typeof $.cookie("vcartAuth")
? JSON.parse($.cookie("vcartAuth"))
: "";
var userToken = userAuth != "" ? userAuth.token : "";
let userData = {
a_id: elem.address_id.value,
a_name: elem.address_name.value,
a_phone: elem.phone_no.value,
a_address_1: elem.flat.value,
a_address_2: elem.street.value,
a_city_id: _.trimStart(elem.city_id.value, "number:"),
a_area_id: _.trimStart(elem.area_id.value, "number:"),
a_pincode: elem.postalcode.value
};
addNewAddress
.add_address(userData, userToken)
.then(function(response) {
console.log(response);
var res = response.data.results;
toastr.success(response.data.results);
var base_url = window.location.origin;
window.location.replace(base_url + "/addressbook");
})
.catch(function(response) {
console.log(response);
});
}
};
});
app.controller("bundle_listing", function (
$scope,
$rootScope,
$location,
$http,
$timeout,
$filter,
config,
querydata,
getbundleList,
getWishList
) {
$scope.loadon = false;
$scope.productData = [];
$scope.page = 0;
$scope.sub_cat_active = 0;
$scope.nextcall = 1;
$scope.queryparam = querydata.queryparam;
$scope.filters_apply = function () {
let filterdata = $location.search();
if (filterdata.sub_cat) {
$scope.sub_cat_active = filterdata.sub_cat;
}
if (filterdata.price_start || filterdata.price_end) {
let start = filterdata.price_start ? filterdata.price_start : "";
let end = filterdata.price_end ? filterdata.price_end : "";
$(".pri_" + start + "_" + end).prop("checked", true);
}
if (filterdata.discount_start || filterdata.discount_end) {
let start = filterdata.discount_start ? filterdata.discount_start : "";
let end = filterdata.discount_end ? filterdata.discount_end : "";
$(".dis_" + start + "_" + end).prop("checked", true);
}
if (filterdata.brand) {
let object = filterdata.brand.split(",");
$scope.c = {};
for (const key in object) {
if (object.hasOwnProperty(key)) {
const element = object[key];
$scope.c[element] = parseInt(element);
}
}
}
if (filterdata.order_by) {
$scope.sort = filterdata.order_by;
}
};
$scope.getlist = function () {
$scope.loadon = true;
let queryparams = $location.search();
for (const key in queryparams) {
if (queryparams.hasOwnProperty(key)) {
const element = queryparams[key];
$scope.queryparam[key] = element;
}
}
var apidata = queryparams;
apidata.cat_id = querydata.queryparam.cat_id;
getbundleList
.getlist(apidata, $scope.page)
.then(function (response) {
var userAuth = $.cookie("vcartAuth")
? JSON.parse($.cookie("vcartAuth"))
: "";
$scope.loggedStatus = userAuth.status == "success" ? true : false;
$scope.liststate = response.data.results.msg;
let listdata = response.data.results.response;
if (listdata != "") {
angular.forEach(listdata, function (value, key) {
$scope.productData.push(value);
});
$scope.nextcall = 1;
$scope.page++;
} else {
$scope.nextcall = 0;
}
$scope.loadon = false;
})
.catch(function (response) {
console.log(response.status);
});
};
$scope.filters_apply();
$scope.getlist();
$(window).scroll(function () {
var bodypos = $("body")[0].scrollHeight;
var windowh = $(window).height();
bodypos = bodypos - windowh;
var windowpos = $(window).scrollTop();
var persentage = Math.round((windowpos / bodypos) * 100);
if (Math.round(persentage) > 80 && $scope.nextcall == 1) {
$scope.nextcall = 0;
$scope.getlist();
}
});
$scope.qty_plus = function (fieldName, index) {
var currentVal = parseInt($("input[name=" + fieldName + index + "]").val());
$scope.qty = currentVal + 1;
if (parseInt(currentVal) >= 5) {
toastr.warning("Cannot add more than 5 items of same product.");
return
}
// If is not undefined
if (!isNaN(currentVal)) {
// Increment
$("input[name=" + fieldName + index + "]").val(currentVal + 1);
} else {
// Otherwise put a 0 there
$("input[name=" + fieldName + index + "]").val(1);
}
};
// This button will decrement the value till 0
$scope.qty_minus = function (fieldName, index) {
var currentVal = parseInt($("input[name=" + fieldName + index + "]").val());
$scope.qty = currentVal - 1;
// If is not undefined
if (!isNaN(currentVal) && currentVal > 1) {
// Increment
$("input[name=" + fieldName + index + "]").val(currentVal - 1);
} else {
// Otherwise put a 0 there
$("input[name=" + fieldName + index + "]").val(1);
}
};
$scope.filters = function (type, p1, p2) {
$scope.productData = [];
$scope.page = 0;
$scope.nextcall = 1;
switch (type) {
case "sub_cat":
$location.search("sub_cat", p1);
$scope.getlist();
break;
case "price":
var dataChecked = $(
".pri_" + (p1 == 0 ? "" : p1) + "_" + (p2 == 0 ? "" : p2)
).prop("checked");
$('input[name="price"]').prop("checked", false);
if (dataChecked) {
$(".pri_" + (p1 == 0 ? "" : p1) + "_" + (p2 == 0 ? "" : p2)).prop(
"checked",
true
);
if (p1) {
$location.search("price_start", p1);
} else {
$location.search("price_start", null);
}
if (p2) {
$location.search("price_end", p2);
} else {
$location.search("price_end", null);
}
$scope.getlist();
} else {
$location.search("price_end", null);
$location.search("price_start", null);
$scope.getlist();
}
break;
case "discount":
if (p1) {
$location.search("discount_start", p1);
} else {
$location.search("discount_start", null);
}
if (p2) {
$location.search("discount_end", p2);
} else {
$location.search("discount_end", null);
}
$scope.getlist();
break;
case "brand":
let element = "";
for (const key in $scope.c) {
if ($scope.c.hasOwnProperty(key)) {
if ($scope.c[key]) {
element += $scope.c[key] + ",";
}
}
}
let elements = element.replace(/(^,)|(,$)/g, "");
$location.search("brand", elements);
$scope.getlist();
break;
case "sort":
$location.search("order_by", p1);
$scope.getlist();
break;
default:
}
};
// Wishlist Add and Remove
$scope.addwish = function (product_id, item, index) {
var userAuth = $.cookie("vcartAuth")
? JSON.parse($.cookie("vcartAuth"))
: "";
if (userAuth.status != "success") {
$("#myModal").modal("show");
console.log("Not logged in");
return false;
}
let productData = {
product_id: product_id,
is_bundle: true,
wish_type: item ? "remove" : "add"
};
var userAuth = typeof $.cookie("vcartAuth")
? JSON.parse($.cookie("vcartAuth"))
: "";
var usertoken = userAuth != "" ? userAuth.token : "";
getWishList
.addWish(productData, usertoken)
.then(function (response) {
var res = response.data.msg;
if (res == "success") {
$scope.productData[index].wishlist = item ? false : true;
if (item == false) {
toastr.success(response.data.results);
} else {
toastr.warning(response.data.results);
}
}
})
.catch(function (response) {
console.log(response);
});
};
$scope.addToBundleWithoutBundleId = function ($event, pb_id) {
var qty = parseInt($("input[name=qty_" + pb_id + "]").val());
//console.log(pb_id);
bundle_details
.getBundleDetail(pb_id)
.then(function (response) {
if (response.data.results.status != "200") {
toastr.warning(response.data.results.msg);
} else {
let alter = [];
var proList = response.data.results.response[0].product;
if (proList) {
angular.forEach(proList, function (value, key) {
let is_alternaitve = value.pbm_is_alternative == 0 ? false : true;
var pd_id = "";
var alternatives = value.alternatives;
if (is_alternaitve) {
angular.forEach(alternatives, function (val, i) {
if (val.pba_is_default == 1) {
var pd_id = {
p_id: parseInt(value.pd_id),
is_alternaitve: true
};
}
});
} else {
var pd_id = {
p_id: parseInt(value.pd_id),
is_alternaitve: false
};
}
alter.push(pd_id);
});
}
let productData = {
product_id: pb_id,
product_qty: qty,
is_bundle: true,
bundel_items: alter
};
userbundle
.updateBundleWithoutBundleId(productData)
.then(function (response) {
console.log(response);
var res = response.data;
if (response.status == "200") {
toastr.success(res.results.msg);
var cartOldQty = localStorage.getItem("bundleCount");
var newCartQty = parseInt(cartOldQty) + parseInt(1);
localStorage.setItem("bundleCount", newCartQty);
$(".cart-label").text(newCartQty);
} else {
toastr.warning(res.error.msg);
}
})
.catch(function (response) {
toastr.warning(response.data.error.msg);
});
}
})
.catch(function (response) {
toastr.warning(response.data.results.msg);
});
};
});
app.controller("cancelorder", function(
$scope,
$rootScope,
$location,
$http,
$timeout,
$filter,
config
) {
$(document).ready(function() {
$("#sel1").on("change", function() {
var c_msg = $(this).val();
if (c_msg == "Others") {
$("#custom_reason").removeClass("hide");
} else {
$("#other_reason").val("");
$("#custom_reason").addClass("hide");
}
});
});
/**
* Order Cancellation
*/
var co = document.forms.cancel_order,
elem = co.elements;
co.onsubmit = function() {
var a = 0;
if (!elem.cancelmsg.value) {
toastr.error("Select the reason for cancellation");
elem.cancelmsg.focus();
a = 1;
}
if (elem.cancelmsg.value == "Others" && !elem.other_reason.value) {
toastr.error("Enter the reason for cancellation");
elem.other_reason.focus();
a = 1;
}
if (a == 1) {
return false;
} else {
var suggestURL = config.cancelorder + elem.order_id.value;
let data = {};
if (elem.other_reason.value != "") {
data = {
cancel_msg: elem.other_reason.value
};
} else {
data = {
cancel_msg: elem.cancelmsg.value
};
}
let token = JSON.parse($.cookie("vcartAuth"));
$http({
method: "PUT",
url: suggestURL,
type: "json",
data: data,
headers: {
Authorization: "Bearer " + token.token,
"Content-Type": "application/json"
}
})
.then(function(success) {
if (success.data.results.status == 200) {
toastr.success(success.data.results.msg);
window.location = "/myorders";
} else {
toastr.warning(success.data.results.msg);
}
})
.catch(function(failure) {
toastr.error(failure.data.error);
});
}
};
});
app.controller("change_default_address", function(
$scope,
$rootScope,
$location,
$http,
$timeout,
$filter,
config,
addNewAddress
) {
//Profile Update//
var cp = document.forms.defaultAddress,
elem = cp.elements;
cp.onsubmit = function() {
var a = 0;
if (!elem.address_id.value) {
toastr.error("Please Select Any One, To Make It As Your Default Address.");
a = 1;
}
if (a == 1) {
return false;
}
else {
var userAuth = typeof $.cookie("vcartAuth") ? JSON.parse($.cookie("vcartAuth")) : "";
var userToken= (userAuth!="")?userAuth.token: "";
let userData = {
a_id: elem.address_id.value,
};
addNewAddress
.change_default_address(userData, userToken)
.then(function(response) {
console.log(response);
var res= response.data.results;
toastr.success(response.data.results);
})
.catch(function(response) {
console.log(response);
});
}
};
$scope.removeAddress = function(address_id, target) {
var elem= angular.element(target);
//console.log(wtype);
let addressData = {
a_id: address_id
};
var userAuth = typeof $.cookie("vcartAuth") ? JSON.parse($.cookie("vcartAuth")) : "";
var usertoken= (userAuth!="")?userAuth.token: "";
addNewAddress
.remove_address(addressData, usertoken)
.then(function(response) {
console.log(response);
var res= response.data.msg;
if(res=="success"){
elem.closest(".pannel_addressbook").remove();
var numItems = $('.pannel_addressbook').length;
if(numItems<=1){
$(".empty-address").removeClass("hidden");
}
toastr.success(response.data.results);
}
})
.catch(function(response) {
console.log(response);
});
};
});
\ No newline at end of file
app.controller("change_password", function(
$scope,
$rootScope,
$location,
$http,
$timeout,
$filter,
config
) {
/**
* Change password function
*/
var cp = document.forms.change_password,
elem = cp.elements;
cp.onsubmit = function() {
var a = 0;
if (!elem.cnew_password.value) {
toastr.error("Confirm new password is required");
elem.cnew_password.focus();
a = 1;
}
if (!elem.new_password.value) {
toastr.error("New password is required");
elem.new_password.focus();
a = 1;
}
if (!elem.current_password.value) {
toastr.error("Current password is required");
elem.current_password.focus();
a = 1;
}
if (
elem.new_password.value != elem.cnew_password.value &&
elem.cnew_password.value != elem.new_password.value
) {
toastr.error("New password or Confirm new password is mismatch");
a = 1;
}
if (a == 1) {
return false;
} else {
var suggestURL = config.change_password;
let data = {
old_password: elem.current_password.value,
new_password: elem.new_password.value
};
let token = JSON.parse($.cookie("vcartAuth"));
$http({
method: "POST",
url: suggestURL,
type: "json",
data: data,
headers: {
Authorization: "Bearer " + token.token,
"Content-Type": "application/json"
}
})
.then(function(success) {
toastr.success(success.data.result);
$("#current_password, #new_password, #cnew_password").val("");
})
.catch(function(failure) {
toastr.error(failure.data.error);
});
}
};
});
app.controller("checkout", function(
$scope,
$rootScope,
$location,
$http,
$timeout,
$filter,
config,
addNewAddress,
cart,
cartData
) {
$scope.applied = 1;
$scope.qty = 1;
$scope.disabled = "";
$scope.address_id = "";
$scope.cartGrand = parseFloat(cartData.cartSum.toFixed(2));
$scope.subTotal = parseFloat(cartData.cartSum.toFixed(2));
$scope.dc = parseFloat(cartData.dc.toFixed(2));
$scope.addresschange = function(data) {
$scope.address_id = data;
};
cart
.getsetting()
.then(function(response) {
if (response.data.results.status != "200") {
console.log(response.data.results);
$scope.dc =
$scope.cartGrand > parseFloat(response.data.results.deliveryFreePrice)
? 0
: parseFloat(response.data.results.deliveryCharge);
$scope.deliveryFreePrice = parseFloat(
response.data.results.deliveryFreePrice
);
$scope.deliveryCharge = parseFloat(
response.data.results.deliveryCharge
);
$scope.minOrderAmt = parseFloat(response.data.results.minOrderAmt);
} else {
$scope.deliveryFreePrice = 250;
$scope.deliveryCharge = 10;
$scope.minOrderAmt = 50;
}
})
.catch(function(response) {
// toastr.warning(response.data.results.msg);
$scope.deliveryFreePrice = 250;
$scope.deliveryCharge = 10;
});
addNewAddress
.cityarea_get()
.then(function(response) {
$scope.city = response.data.results;
})
.catch(function(response) {
console.log(response);
});
$scope.getarea = function(index) {
let i = _.findIndex($scope.city, function(o) {
return o.city_id == index;
});
$scope.area = $scope.city[i].area;
};
addNewAddress
.getlist()
.then(function(response) {
var addArr = response.data.results.response;
var addlist = [];
var no = 0;
angular.forEach(addArr, function(value, key) {
if (value.a_name && value.a_phone && value.a_address_1) {
addlist.push(value);
}
});
$scope.addresslist = addlist;
console.log($scope.addresslist);
})
.catch(function(response) {
console.log(response);
});
$scope.onloadFOrmElement = function() {
var cp = document.forms.newAddress;
var elem = cp.elements;
cp.onsubmit = function() {
// $(".loader").removeClass("hidden");
console.log(elem.is_default.checked);
var a = 0;
if (!elem.address_name.value) {
toastr.error("Name is required");
elem.address_name.focus();
a = 1;
}
if (!elem.phone_no.value) {
toastr.error("Phone Number is Required");
elem.phone_no.focus();
a = 1;
}
if (!elem.flat.value) {
toastr.error("FLAT/HOUSE/FLOOR/BUILDING is Required");
elem.flat.focus();
a = 1;
}
if (!elem.street.value) {
toastr.error("STREET/LOCALITY");
elem.street.focus();
a = 1;
}
if (!elem.city_id.value) {
toastr.error("City is Required");
elem.city_id.focus();
a = 1;
}
if (!elem.area_id.value) {
toastr.error("Area is Required");
elem.area_id.focus();
a = 1;
}
// if (!elem.postalcode.value) {
// toastr.error("ZIP is Required");
// elem.postalcode.focus();
// a = 1;
// }
if (a == 1) {
// $(".loader").addClass("hidden");
return false;
} else {
var userAuth = typeof $.cookie("vcartAuth")
? JSON.parse($.cookie("vcartAuth"))
: "";
var userToken = userAuth != "" ? userAuth.token : "";
let userData = {
a_id: "",
a_name: elem.address_name.value,
a_phone: elem.phone_no.value,
a_address_1: elem.flat.value,
a_address_2: elem.street.value,
a_city_id: _.trimStart(elem.city_id.value, "number:"),
a_area_id: _.trimStart(elem.area_id.value, "number:"),
a_pincode: elem.postalcode.value,
a_is_default: elem.is_default.checked
};
addNewAddress
.add_address(userData, userToken)
.then(function(response) {
var res = response.data.id;
userData["a_id"] = res;
$scope.addresslist.push(userData);
toastr.success("Address added successfully!");
$('form[name="newAddress"]').each(function() {
this.reset();
});
$("#collapse2").removeClass("in");
if ($scope.address_id != "") {
$(".bill.pay").trigger("click");
}
// $("#add_address").trigger("click");
// $(".loader").addClass("hidden");
$scope.continuebtn();
})
.catch(function(response) {
// $(".loader").addClass("hidden");
console.log(response);
});
}
};
};
$scope.verifyToken = function(coupon) {
// $(".loader").removeClass("hidden");
var userAuth = typeof $.cookie("vcartAuth")
? JSON.parse($.cookie("vcartAuth"))
: "";
var usertoken = userAuth != "" ? userAuth.token : "";
cart
.verifyCoupon(coupon, $scope.cartGrand, usertoken)
.then(function(response) {
$("#couponapplied").removeClass("hide");
if (response.status == 200) {
toastr.success("Coupon valid and applied");
let data = response.data.results;
$scope.applied = 0;
$scope.couponInfo = data.msg;
$scope.cartGrand = Number(
parseFloat(data.response.discounted_price).toFixed(2)
);
if ($scope.cartGrand < $scope.deliveryFreePrice) {
$scope.dc = $scope.deliveryCharge;
} else {
$scope.dc = 0;
}
$scope.cartsaving = parseFloat(data.response.discount).toFixed(2);
} else {
toastr.info("Coupon not valid");
}
})
.catch(function(response) {
// $(".loader").addClass("hidden");
let data = response.data.error;
toastr.info(data.msg);
});
};
$scope.removeCoupon = function() {
$("#couponapplied").addClass("hide");
// delete $scope.cartsaving;
$scope.cartGrand = parseFloat(
Number($scope.cartGrand) + Number($scope.cartsaving)
);
if ($scope.cartGrand < $scope.deliveryFreePrice) {
$scope.dc = $scope.deliveryCharge;
} else {
$scope.dc = 0;
}
delete $scope.cartsaving;
$scope.applied = 1;
$scope.coupon = "";
};
$scope.ctnpay = function() {
if ($scope.address_id != "") {
$(".bill.pay").trigger("click");
} else {
toastr.error("Please Select the address");
}
};
// };
$scope.savecontinue = function() {
$("#collapse2").removeClass("in");
$(".btncontinue").removeClass("hide");
$(".btnsc").addClass("hide");
var d = $("#collapse1").hasClass("in");
};
$scope.continuebtn = function() {
$("#collapse1").removeClass("in");
$(".btncontinue").addClass("hide");
$(".btnsc").removeClass("hide");
var c = $("#collapse2").hasClass("in");
if (c == true) {
$(".btncontinue").removeClass("hide");
//check address form filled
if ($("#address_name").val() != "") {
$("#newAddress_submit").trigger("click");
// addnewaddress()
} else {
toastr.error("Please Select the address");
}
}
};
$scope.checkorder_value = function(order_value) {
if (order_value < $scope.minOrderAmt) {
toastr.warning(
`Order Value should be more then ${$scope.minOrderAmt} AED!`
);
} else {
$("#cartsubmit").submit();
}
};
});
app.controller("createUserBundle", function (
$scope,
$rootScope,
$location,
$window,
$http,
$timeout,
$filter,
$routeParams,
config,
order_id,
createUserbundle
) {
$scope.mybundle_name = "";
$scope.edit_title = 0;
$scope.init = function () {
// $(".loader").removeClass("hidden");
createUserbundle
.getDetails(order_id.order_id)
.then(function (response) {
// $(".loader").addClass("hidden");
$scope.mybundle = response.data.results.response.order_products;
$scope.mybundle_name = querydata.bundlename;
})
.catch(function (response) {
// $(".loader").addClass("hidden");
console.log(response);
});
};
$scope.init();
$scope.qty_plus = function (fieldName, index) {
var currentVal = parseInt($("input[name=" + fieldName + index + "]").val());
$scope.qty = currentVal + 1;
if (parseInt(currentVal) >= 5) {
toastr.warning("Cannot add more than 5 items of same product.");
return
}
// If is not undefined
if (!isNaN(currentVal)) {
// Increment
$("input[name=" + fieldName + index + "]").val(currentVal + 1);
$("input[name=" + fieldName + index + "]").attr(
"data-qty",
currentVal + 1
);
} else {
// Otherwise put a 0 there
$("input[name=" + fieldName + index + "]").val(1);
$("input[name=" + fieldName + index + "]").attr("data-qty", 1);
}
$scope.cartTotal();
};
// This button will decrement the value till 0
$scope.qty_minus = function (fieldName, index) {
var currentVal = parseInt($("input[name=" + fieldName + index + "]").val());
$scope.qty = currentVal - 1;
// If is not undefined
if (!isNaN(currentVal) && currentVal > 1) {
// Increment
$("input[name=" + fieldName + index + "]").val(currentVal - 1);
$("input[name=" + fieldName + index + "]").attr(
"data-qty",
currentVal - 1
);
} else {
// Otherwise put a 0 there
$("input[name=" + fieldName + index + "]").val(1);
$("input[name=" + fieldName + index + "]").attr("data-qty", 1);
}
$scope.cartTotal();
};
$scope.cartTotal = function () {
var subtotal = 0,
savingstotal = 0;
angular.forEach(angular.element(".productcount"), function (value, key) {
var a = angular.element(value);
subtotal +=
parseFloat(a.attr("data-price")) * parseFloat(a.attr("data-qty"));
savingstotal +=
parseFloat(a.attr("data-savings")) * parseFloat(a.attr("data-qty"));
});
var delivery_price = parseInt(15);
var grandtotal = parseFloat(subtotal) + parseFloat(delivery_price);
$(".subTotal").html(subtotal + " AED");
$(".savingsTotal").html(subtotal + " AED");
$(".grandTotal").html(grandtotal + " AED");
$scope.grandTotal = grandtotal;
};
$scope.change_title = function () {
if ($scope.edit_title == 0) {
$scope.edit_title = 1;
} else {
$scope.edit_title = 0;
}
};
// //user_bundle Update//
// var cp = document.forms.createBundle,
// elem = cp.elements;
// cp.onsubmit = function() {
// let product_ids = [];
// let proceed = 0;
// $scope.mybundle.forEach(element => {
// if ($("#brand_" + element.op_id).is(":checked") == true) {
// proceed = 1;
// let bundle_data = [];
// if (element.ct_is_bundel == 1) {
// element.product.forEach(ele => {
// let bd = {
// pd_id: ele.ctb_pd_id,
// is_alternative: ele.ctb_is_alternative == 1 ? 1 : 0
// };
// bundle_data.push(bd);
// });
// }
// let data = {
// product_id: element.ct_pd_id,
// quantity: $("input[name=qty_" + element.op_id + "]").val(),
// is_bundel: element.ct_is_bundel == true ? 1 : 0,
// bundel_items: bundle_data
// };
// element.quantity = $("input[name=qty_" + element.op_id + "]").val();
// product_ids.push(data);
// }
// });
// let querydata = $location.search();
// let insertdata = {
// bundle_name: $scope.mybundle_name,
// no_days: querydata.end_period,
// time_period: querydata.time_interval,
// product_ids: product_ids
// };
// if (proceed == 1) {
// createUserbundle
// .insertBundle(insertdata)
// .then(function(response) {
// var res = response.data.results;
// if (res.msg == "success") {
// toastr.success("Created Successfully..!");
// $window.location.href = "/mybundles";
// }
// })
// .catch(function(response) {
// console.log(response);
// });
// } else {
// toastr.warning("Product should not be empty..!");
// }
// };
// });
//user_bundle Update//
var cp = document.forms.createBundle,
elem = cp.elements;
cp.onsubmit = function () {
// $(".loader").removeClass("hidden");
let product_ids = [];
let proceed = 0;
if ($scope.mybundle_name == "") {
$(".loader").addClass("hidden");
toastr.warning("Bundle Name is required");
return false;
}
var typeSubmit = $(".typeSubmit").val();
//console.log(typeSubmit);
$scope.mybundle.forEach(element => {
if ($("#brand_" + element.op_id).is(":checked") == true) {
proceed = 1;
let bundle_data = [];
if (element.ct_is_bundel == true) {
element.product.forEach(ele => {
let bd = {
pd_id: ele.ctb_pd_id,
is_alternative: ele.ctb_is_alternative == 1 ? 1 : 0
};
bundle_data.push(bd);
});
}
let data = {
product_id: element.ct_pd_id,
quantity: $("input[name=qty_" + element.op_id + "]").val(),
is_bundel: element.ct_is_bundel == true ? 1 : 0,
bundel_items: bundle_data
};
element.quantity = $("input[name=qty_" + element.op_id + "]").val();
product_ids.push(data);
}
});
let insertdata = {
bundle_name: $scope.mybundle_name,
product_ids: product_ids
};
if (proceed == 1) {
createUserbundle
.insertBundleWithProduct(insertdata)
.then(function (response) {
var res = response.data.results;
if (res.msg == "success") {
// $(".loader").addClass("hidden");
toastr.success("Created Successfully..!");
if (typeSubmit == "continue") {
$window.location.href = "/";
} else {
$window.location.href =
"/create-bundle/success/" + res.response[0];
}
}
})
.catch(function (response) {
// $(".loader").addClass("hidden");
console.log(response);
});
} else {
// $(".loader").addClass("hidden");
toastr.warning("Product should not be empty..!");
}
};
});
// app.config(function($routeProvider, $locationProvider, $httpProvider) {
// $locationProvider.html5Mode(true);
// });
app.controller("home", function (
$scope,
$rootScope,
$location,
$http,
$timeout,
$filter,
product_details,
getWishList,
userbundle
) {
var userAuth = $.cookie("vcartAuth") ? JSON.parse($.cookie("vcartAuth")) : "";
$scope.loggedStatus = userAuth.status == "success" ? true : false;
/**
*
* @param {*} data
*/
$scope.addtocart = function (data) {
var currentVal = parseInt($("input[name=qty_" + data + "]").val());
if (currentVal > 0) {
product_details
.addToCart(currentVal, data)
.then(function (response) {
if (response.data.results.status != "200") {
toastr.warning(response.data.results.msg);
} else {
toastr.success(response.data.results.msg);
var cartOldQty = localStorage.getItem("cartCount");
var newCartQty = parseInt(cartOldQty) + parseInt(1);
localStorage.setItem("cartCount", newCartQty);
$(".cart-label").text(newCartQty);
}
})
.catch(function (response) {
toastr.warning(response.data.results.msg);
});
} else {
toastr.error("Please check the quantity");
}
};
/**
* Cart Qty Plus
* @param {Number} fieldName
* @param {Number} index
*/
$scope.qty_plus = function (fieldName, index) {
var currentVal = parseInt($("input[name=" + fieldName + index + "]").val());
$scope.qty = currentVal + 1;
if (parseInt(currentVal) >= 5) {
toastr.warning("Cannot add more than 5 items of same product.");
return
}
// If is not undefined
if (!isNaN(currentVal)) {
// Increment
$("input[name=" + fieldName + index + "]").val(currentVal + 1);
} else {
// Otherwise put a 0 there
$("input[name=" + fieldName + index + "]").val(1);
}
};
/**
* Cart Qty minus
* @param {Number} fieldName
* @param {Number} index
*/
// This button will decrement the value till 0
$scope.qty_minus = function (fieldName, index) {
var currentVal = parseInt($("input[name=" + fieldName + index + "]").val());
$scope.qty = currentVal - 1;
// If is not undefined
if (!isNaN(currentVal) && currentVal > 1) {
// Increment
$("input[name=" + fieldName + index + "]").val(currentVal - 1);
} else {
// Otherwise put a 0 there
$("input[name=" + fieldName + index + "]").val(1);
}
};
// Wishlist Add and Remove
$scope.addwish = function (product_id, item, index) {
var userAuth = $.cookie("vcartAuth") ? JSON.parse($.cookie("vcartAuth")) : "";
if (userAuth.status != "success") {
$('#myModal').modal("show")
console.log("Not logged in")
return false;
}
var elem = angular.element(item);
var wtype = elem.attr("data-type");
//console.log(wtype);
let productData = {
product_id: product_id,
is_bundle: false,
wish_type: wtype
};
var userAuth = typeof $.cookie("vcartAuth") ?
JSON.parse($.cookie("vcartAuth")) :
"";
var usertoken = userAuth != "" ? userAuth.token : "";
if (usertoken != "") {
getWishList
.addWish(productData, usertoken)
.then(function (response) {
console.log(response);
var res = response.data.msg;
if (res == "success") {
var wishvalue = wtype == "add" ? "remove" : "add";
elem.attr("data-type", wishvalue);
if (wishvalue == "remove") {
elem.addClass("wishheartt");
toastr.success(response.data.results);
} else {
elem.removeClass("wishheartt");
toastr.warning(response.data.results);
}
}
})
.catch(function (response) {
console.log(response);
});
} else {
toastr.error("Login first to use this option");
}
};
$scope.mybundles = [];
$scope.userBundlelist = function () {
userbundle
.getList()
.then(function (response) {
console.log(response);
let listdata = response.data.results.response;
if (listdata != "") {
angular.forEach(listdata, function (value, key) {
$scope.mybundles.push(value);
});
}
console.log($scope.mybundles);
})
.catch(function (response) {
console.log(response);
});
};
$scope.userBundlelist();
$scope.addToBundle = function ($event, bundleId, productId, bundleQty) {
var productQty = parseInt($("input[name=qty_" + productId + "]").val());
let productData = {
user_bundle: bundleId,
product_id: productId,
product_qty: productQty,
is_bundle: false
};
userbundle
.updateBundle(productData)
.then(function (response) {
var res = response.data;
if (response.status == "200") {
toastr.success(res.results.msg);
angular
.element($event.currentTarget)
.find("span")
.html(parseInt(bundleQty) + 1);
} else {
toastr.warning(res.error.msg);
}
})
.catch(function (response) {
console.log(response);
toastr.warning(response.data.error.msg);
});
};
});
\ No newline at end of file
app.controller("myBundles", function(
$scope,
$rootScope,
$location,
$http,
$timeout,
$filter,
config,
mybundle_addtocart
) {
var userAuth = $.cookie("vcartAuth") ? JSON.parse($.cookie("vcartAuth")) : "";
$scope.loggedStatus = userAuth.status == "success" ? true : false;
// $scope.bundle_addtocart = function(data) {
// mybundle_addtocart
// .getBundleData(data)
// .then(function(response) {
// console.log(response);
// if (response.status == "200") {
// const bundleProducts = response.data.results.response.product;
// bundleProducts.forEach(pro => {
// let data = {
// product_id: pro.ubp_pd_id,
// quantity: pro.ubp_qty,
// is_bundel: pro.ubp_p_is_bundle == 0 ? false : true
// };
// /** For Bundles **/
// if (pro.ubp_p_is_bundle == 1) {
// let alter = [];
// let alternative = pro.product;
// alternative.forEach(ele => {
// let alter_data = {
// pd_id: parseInt(ele.p_pd_id),
// is_alternaitve: ele.ubbp_is_alternative
// };
// alter.push(alter_data);
// });
// data.bundel_items = alter;
// }
// mybundle_addtocart
// .addToCart(data)
// .then(function(response) {
// if (response.data.results.status != "200") {
// toastr.warning(response.data.results.msg);
// } else {
// toastr.success(response.data.results.msg);
// var cartOldQty = localStorage.getItem("cartCount");
// var newCartQty = parseInt(cartOldQty) + parseInt(1);
// localStorage.setItem("cartCount", newCartQty);
// $(".cart-label").text(newCartQty);
// }
// })
// .catch(function(response) {
// toastr.warning(response.data.results.msg);
// });
// });
// //window.location = "/cart";
// }
// })
// .catch(function(response) {
// //toastr.warning(response.data.results.msg);
// });
// };
/**
* Add Mybundle to Cart
*/
$scope.bundle_addtocart = function(data) {
mybundle_addtocart
.addToCart(data)
.then(function(response) {
if (response.data.results.status != "200") {
toastr.warning(response.data.results.msg);
} else {
toastr.success(response.data.results.msg);
var cartOldQty = localStorage.getItem("cartCount");
var newCartQty = parseInt(cartOldQty) + parseInt(1);
localStorage.setItem("cartCount", newCartQty);
$(".cart-label").text(newCartQty);
}
})
.catch(function(response) {
toastr.warning(response.data.error.response);
toastr.warning(response.data.results.msg);
});
};
$scope.bundle_unsbuscribe = function(data) {
mybundle_addtocart
.unSubscribe(data)
.then(function(response) {
console.log(response);
if (response.data.results.status != "200") {
toastr.warning("Somthing Went Wrong..!");
} else {
location.reload();
}
})
.catch(function(response) {
toastr.warning(response);
});
};
});
app.controller("order_list", function(
$scope,
$rootScope,
$location,
$http,
$timeout,
$filter,
config,
getMyorderlist
) {
$scope.orderData = [];
$scope.page = 1;
$scope.nextcall = 1;
/**
* get product list for onload and as well in scroll
*/
$scope.getlist = function() {
var userAuth = typeof $.cookie("vcartAuth")
? JSON.parse($.cookie("vcartAuth"))
: "";
var usertoken = userAuth != "" ? userAuth.token : "";
getMyorderlist
.getlist($scope.page, usertoken)
.then(function(response) {
let listdata = response.data.results.response;
if (listdata != "") {
angular.forEach(listdata, function(value, key) {
const ordDate = new Date(value.o_added_dt);
value.o_delivery_dt = moment(ordDate)
.add("days", 2)
.format("MMM Do YYYY");
$scope.orderData.push(value);
});
$scope.nextcall = 1;
$scope.page++;
} else {
$scope.nextcall = 0;
}
})
.catch(function(response) {
console.log(response.status);
});
};
$scope.getlist();
/**
* scroll listener
*/
$(window).scroll(function() {
var bodypos = $("body")[0].scrollHeight;
var windowh = $(window).height();
bodypos = bodypos - windowh;
var windowpos = $(window).scrollTop();
var persentage = Math.round((windowpos / bodypos) * 100);
if (Math.round(persentage) > 80 && $scope.nextcall == 1) {
$scope.nextcall = 0;
$scope.getlist();
}
});
});
app.controller("myshippingList", function (
$scope,
$rootScope,
$location,
$http,
$timeout,
$filter,
config,
myShipping
) {
//Prdouct Review Controler
$scope.removeShippingList = function (shipping_id, item) {
var elem = angular.element(item);
var userAuth = typeof $.cookie("vcartAuth") ? JSON.parse($.cookie("vcartAuth")) : "";
var usertoken = (userAuth != "") ? userAuth.token : "";
myShipping
.removeShipping(shipping_id, usertoken)
.then(function (response) {
console.log(response);
var res = response.data.results;
if (res == true) {
elem.closest(".shiplist_block").remove();
var numItems = $('.shiplist_block').length;
if (numItems < 1) {
$(".empty-panel").removeClass("hidden");
}
toastr.success("Deleted Successfully!!");
}
})
.catch(function (response) {
console.log(response);
});
};
$scope.qty_plus = function (fieldName, index) {
var currentVal = parseInt($("input[name=" + fieldName + index + "]").val());
$scope.qty = currentVal + 1;
if (parseInt(currentVal) >= 5) {
toastr.warning("Cannot add more than 5 items of same product.");
return
}
// If is not undefined
if (!isNaN(currentVal)) {
// Increment
$("input[name=" + fieldName + index + "]").val(currentVal + 1);
$("input[name=" + fieldName + index + "]").attr("data-qty", currentVal + 1);
} else {
// Otherwise put a 0 there
$("input[name=" + fieldName + index + "]").val(1);
$("input[name=" + fieldName + index + "]").attr("data-qty", 1);
}
$scope.cartTotal();
};
// This button will decrement the value till 0
$scope.qty_minus = function (fieldName, index) {
var currentVal = parseInt($("input[name=" + fieldName + index + "]").val());
$scope.qty = currentVal - 1;
// If is not undefined
if (!isNaN(currentVal) && currentVal > 1) {
// Increment
$("input[name=" + fieldName + index + "]").val(currentVal - 1);
$("input[name=" + fieldName + index + "]").attr("data-qty", currentVal - 1);
} else {
// Otherwise put a 0 there
$("input[name=" + fieldName + index + "]").val(1);
$("input[name=" + fieldName + index + "]").attr("data-qty", 1);
}
$scope.cartTotal();
};
$scope.cartTotal = function () {
var subtotal = 0, savingstotal = 0;
angular.forEach(angular.element(".productcount"), function (value, key) {
var a = angular.element(value);
subtotal += parseFloat(a.attr("data-price")) * parseFloat(a.attr("data-qty"));
savingstotal += parseFloat(a.attr("data-savings")) * parseFloat(a.attr("data-qty"));
});
var delivery_price = parseInt(15);
var grandtotal = parseFloat(subtotal) + parseFloat(delivery_price);
$(".subTotal").html(subtotal + " AED");
$(".savingsTotal").html(subtotal + " AED");
$(".grandTotal").html(grandtotal + " AED");
$scope.grandTotal = grandtotal;
};
$scope.updateShiplist = function (listData, listId) {
var userAuth = typeof $.cookie("vcartAuth") ? JSON.parse($.cookie("vcartAuth")) : "";
var usertoken = (userAuth != "") ? userAuth.token : "";
myShipping
.updateShipping(listData, listId, usertoken)
.then(function (response) {
console.log(response);
var res = response.data.results;
if (res == true) {
toastr.success(response.data.results);
}
})
.catch(function (response) {
console.log(response);
});
};
$scope.getshiplist = function () {
var sTitle = $(".shiplistTitle").val();
var sList = [];
angular.forEach(angular.element(".productcount"), function (value, key) {
var a = angular.element(value);
var pdata = { "slprod_id": a.data("id"), "qty": a.attr("data-qty") }
sList.push(pdata);
});
var sData = { "sl_name": sTitle, "item": sList };
var sId = $(".shiplistId").val();
//console.log(sList);
$scope.updateShiplist(sData, sId);
};
$scope.change_title = function () {
if ($scope.edit_title == 0) {
$scope.edit_title = 1;
} else {
$scope.edit_title = 0;
}
};
});
app.controller("mywishlist", function(
$scope,
$rootScope,
$location,
$http,
$timeout,
$filter,
config,
getWishList
) {
//Prdouct Review Controler
$scope.removeWish = function(product_id, is_bundle, item) {
var elem= angular.element(item);
var wtype= elem.attr('data-type');
//console.log(wtype);
let productData = {
product_id: product_id,
is_bundle: is_bundle,
wish_type: wtype
};
var userAuth = typeof $.cookie("vcartAuth") ? JSON.parse($.cookie("vcartAuth")) : "";
var usertoken= (userAuth!="")?userAuth.token: "";
getWishList
.addWish(productData, usertoken)
.then(function(response) {
console.log(response);
var res= response.data.msg;
if(res=="success"){
elem.closest(".productpanel").remove();
var numItems = $('.productpanel').length;
if(numItems<1){
$(".empty-panel").removeClass("hidden");
}
toastr.success(response.data.results);
}
})
.catch(function(response) {
console.log(response);
});
};
});
app.controller("product_details", function (
$scope,
$rootScope,
$location,
$http,
$timeout,
$filter,
config,
product_details,
getWishList,
userbundle,
myrev
) {
$scope.rating = myrev.data.prr_ratting;
$scope.title = myrev.data.prr_title;
$scope.review = myrev.data.prr_comment;
$scope.qty = 1;
var userAuth = $.cookie("vcartAuth") ? JSON.parse($.cookie("vcartAuth")) : "";
$scope.loggedStatus = userAuth.status == "success" ? true : false;
$scope.addtocart = function (data) {
product_details
.addToCart($scope.qty, data)
.then(function (response) {
if (response.data.results.status != "200") {
toastr.warning(response.data.results.msg);
} else {
window.location = "/cart";
var cartOldQty = localStorage.getItem("cartCount");
var newCartQty = parseInt(cartOldQty) + parseInt(1);
localStorage.setItem("cartCount", newCartQty);
$(".cart-label").text(newCartQty);
}
})
.catch(function (response) {
toastr.warning(response.data.results.msg);
});
};
//Offline Addtocart functionality
$scope.cartList = [];
$scope.addtocartOffline = function (data) {
var getList = JSON.parse(localStorage.getItem("cartList"));
$("#myModal").modal("show");
// $scope.cartList = getList;
// var currentVal = $scope.qty;
// var cartData = { product_id: data, qty: currentVal, is_bundle: false };
// if (getList) {
// var uniquePro = true;
// angular.forEach(getList, function(value, key) {
// if (value.product_id == data) {
// uniquePro = false;
// return;
// }
// });
// if (uniquePro) $scope.cartList.push(cartData);
// } else {
// $scope.cartList.push(cartData);
// }
// localStorage.setItem("cartList", JSON.stringify($scope.cartList));
// var getList = localStorage.getItem("cartList");
// console.log(getList);
};
$scope.qty_plus = function (fieldName, index) {
var currentVal = parseInt($("input[name=" + fieldName + index + "]").val());
$scope.qty = currentVal + 1;
if (parseInt(currentVal) >= 5) {
toastr.warning("Cannot add more than 5 items of same product.");
return
}
// If is not undefined
if (!isNaN(currentVal)) {
// Increment
$("input[name=" + fieldName + index + "]").val(currentVal + 1);
} else {
// Otherwise put a 0 there
$("input[name=" + fieldName + index + "]").val(1);
}
};
// This button will decrement the value till 0
$scope.qty_minus = function (fieldName, index) {
var currentVal = parseInt($("input[name=" + fieldName + index + "]").val());
$scope.qty = currentVal - 1;
// If is not undefined
if (!isNaN(currentVal) && currentVal > 1) {
// Increment
$("input[name=" + fieldName + index + "]").val(currentVal - 1);
} else {
// Otherwise put a 0 there
$("input[name=" + fieldName + index + "]").val(1);
}
};
var postReview = function (postData, userAuth) {
product_details
.postReview(postData, userAuth)
.then(function (response) {
console.log(postData);
var postResult = response.data;
if (postResult.results.status == 200) {
var reviewStatus = postResult.results.response.msg;
$scope.postReviewstatus = reviewStatus;
var userName = JSON.parse($.cookie("vcartAuth")).username;
var userId = JSON.parse($.cookie("vcartAuth")).user_id;
var date = moment().format("MMM Do YYYY");
var newRev =
'<div class="review"><p class="userdate">' +
userName +
", " +
date +
'</p><p class="star"><span class="stars"><i class="fa fa-star filled"></i><i class="fa fa-star filled"></i><i class="fa fa-star filled"></i><i class="fa fa-star filled"></i><i class="fa fa-star filled"></i></span> ' +
postData.rating +
" out of 5</p><h5>" +
postData.title +
"</h5><p>" +
postData.review +
"</p></div>";
$scope.newReview = postData;
var el = angular.element(document.querySelector(".review"));
if (postResult.results.msg == "updated") {
console.log(".review_" + userId);
var dEl = angular.element(
document.querySelector(".review_" + userId)
);
dEl.html("");
}
el.prepend(newRev);
angular.element("#closebtn").triggerHandler("click");
} else {
var reviewStatus = postResult.results.response.msg;
var myEl = angular.element(document.querySelector("#rstatus"));
myEl.addClass("has-error");
$scope.postReviewstatus = reviewStatus;
}
})
.catch(function (response) {
console.log(response);
});
};
$scope.submitReviewbundle = function () {
var product_id = $("#product_id").val();
var userAuth = typeof $.cookie("vcartAuth")
? JSON.parse($.cookie("vcartAuth"))
: "";
var usertoken = userAuth != "" ? userAuth.token : "";
if ($scope.rating != undefined) {
$scope.ratingError = "";
$scope.data = {
rating: $scope.rating,
title: $scope.title,
review: $scope.review,
is_product_bundle: 0,
product_id: product_id
};
var postStatus = postReview($scope.data, usertoken);
} else {
$scope.ratingError = "It is required";
}
};
//Prdouct Review Controler
$scope.addwish = function (product_id, is_bundle, item) {
var userAuth = $.cookie("vcartAuth")
? JSON.parse($.cookie("vcartAuth"))
: "";
if (userAuth.status != "success") {
$("#myModal").modal("show");
console.log("Not logged in");
return false;
}
var elem = angular.element(item);
var wtype = elem.attr("data-type");
//console.log(wtype);
let productData = {
product_id: product_id,
is_bundle: is_bundle,
wish_type: wtype
};
var userAuth = typeof $.cookie("vcartAuth")
? JSON.parse($.cookie("vcartAuth"))
: "";
var usertoken = userAuth != "" ? userAuth.token : "";
getWishList
.addWish(productData, usertoken)
.then(function (response) {
console.log(response);
var res = response.data.msg;
if (res == "success") {
var wishvalue = wtype == "add" ? "remove" : "add";
elem.attr("data-type", wishvalue);
if (wishvalue == "remove") {
elem.addClass("wishheartt");
toastr.success(response.data.results);
} else {
elem.removeClass("wishheartt");
toastr.warning(response.data.results);
}
}
})
.catch(function (response) {
console.log(response);
});
};
$scope.mybundles = [];
$scope.userBundlelist = function () {
userbundle
.getList()
.then(function (response) {
console.log(response);
let listdata = response.data.results.response;
if (listdata != "") {
angular.forEach(listdata, function (value, key) {
$scope.mybundles.push(value);
});
//console.log($scope.mybundles);
}
})
.catch(function (response) {
console.log(response);
});
};
$scope.userBundlelist();
$scope.addToBundle = function ($event, bundleId, productId, bundleQty) {
var productQty = parseInt($("input[name=qty_" + productId + "]").val());
let productData = {
user_bundle: bundleId,
product_id: productId,
product_qty: productQty,
is_bundle: false
};
userbundle
.updateBundle(productData)
.then(function (response) {
var res = response.data;
if (response.status == "200") {
toastr.success(res.results.msg);
angular
.element($event.currentTarget)
.find("span")
.html(parseInt(bundleQty) + 1);
} else {
toastr.warning(res.error.msg);
}
})
.catch(function (response) {
console.log(response);
toastr.warning(response.data.error.msg);
});
};
$scope.addToBundleWithoutid = function (productId) {
var productQty = parseInt($("input[name=qty_" + productId + "]").val());
let productData = {
product_id: productId,
product_qty: productQty,
is_bundle: false
};
userbundle
.updateBundleWithoutBundleId(productData)
.then(function (response) {
var res = response.data;
if (response.status == "200") {
toastr.success(res.results.msg);
var cartOldQty = localStorage.getItem("bundleCount");
var newCartQty = parseInt(cartOldQty) + parseInt(1);
localStorage.setItem("cartCount", newCartQty);
$(".cart-label").text(newCartQty);
} else {
toastr.warning(res.error.msg);
}
})
.catch(function (response) {
console.log(response);
toastr.warning(response.data.error.msg);
});
};
});
app.controller("select_area", function(
$scope,
$rootScope,
$location,
$http,
$timeout,
$filter,
config
) {
//////select_area/////////
var select_area = document.forms.selectArea;
select_area.onsubmit = function() {
var selectedArea = $("#selectedarea").val();
if (typeof selectedArea == "undefined" || selectedArea == "") {
// if (typeof $scope.area == "undefined" || $scope.area == "") {
toastr.warning("Please select area!");
} else {
localStorage.setItem("area", $scope.area);
window.location.href = "/";
}
};
});
app.controller("select_city", function(
$scope,
$rootScope,
$location,
$http,
$timeout,
$filter,
config
) {
//////select_city/////////
var select_city = document.forms.selectCity;
select_city.onsubmit = function() {
if (typeof $scope.city_selected == "undefined") {
toastr.warning("Please select the city");
} else {
var selected_city = $scope.city_selected.split("-");
localStorage.setItem("city", selected_city[0]);
localStorage.setItem("city_name", selected_city[1]);
window.location.href = "/area/" + selected_city[0];
}
};
});
app.controller("update_profile", function(
$scope,
$rootScope,
$location,
$http,
$timeout,
$filter,
config,
updateProfile
) {
//Profile Update//
var cp = document.forms.profileForm,
elem = cp.elements;
cp.onsubmit = function() {
var a = 0;
if (!elem.user_name.value) {
toastr.error("Name is required");
elem.name.focus();
a = 1;
}
if (!elem.mobile.value) {
toastr.error("Mobile Number is Required");
elem.mobile.focus();
a = 1;
}
if (!elem.postalcode.value) {
toastr.error("Postal Address is Required");
elem.postalcode.focus();
a = 1;
}
if (!elem.city.value) {
toastr.error("City is Required");
elem.city.focus();
a = 1;
}
if (a == 1) {
return false;
} else {
var userAuth = typeof $.cookie("vcartAuth")
? JSON.parse($.cookie("vcartAuth"))
: "";
var userid = userAuth != "" ? userAuth.user_id : "";
var userToken = userAuth != "" ? userAuth.token : "";
let userData = {
id: userid,
username: elem.user_name.value,
user_phone_no: elem.mobile.value,
postal_code: elem.postalcode.value,
city: elem.city.value
};
updateProfile
.update_profile(userData, userToken)
.then(function(response) {
//console.log(response);
var res = response.data.results;
toastr.success(response.data.results);
var base_url = window.location.origin;
window.location.replace(base_url + "/profile");
})
.catch(function(response) {
console.log(response);
});
}
};
});
app.controller("userbundle", function (
$scope,
$rootScope,
$location,
$window,
$http,
$timeout,
$filter,
$routeParams,
config,
dataset,
userbundle,
mybundle_addtocart
) {
$scope.edit_title = 0;
userbundle
.getDetails(dataset.bundleId)
.then(function (response) {
$scope.mybundle_detail = response.data.results.response;
$scope.mybundle = response.data.results.response.product;
$scope.mybundle_dates = response.data.results.response;
$scope.mybundle_name = response.data.results.response.ub_name;
$scope.ub_id = response.data.results.response.ub_id;
})
.catch(function (response) {
console.log(response);
});
$scope.qty_plus = function (fieldName, index) {
var currentVal = parseInt($("input[name=" + fieldName + index + "]").val());
$scope.qty = currentVal + 1;
if (parseInt(currentVal) >= 5) {
toastr.warning("Cannot add more than 5 items of same product.");
return
}
// If is not undefined
if (!isNaN(currentVal)) {
// Increment
$("input[name=" + fieldName + index + "]").val(currentVal + 1);
$("input[name=" + fieldName + index + "]").attr(
"data-qty",
currentVal + 1
);
} else {
// Otherwise put a 0 there
$("input[name=" + fieldName + index + "]").val(1);
$("input[name=" + fieldName + index + "]").attr("data-qty", 1);
}
$scope.cartTotal();
};
// This button will decrement the value till 0
$scope.qty_minus = function (fieldName, index) {
var currentVal = parseInt($("input[name=" + fieldName + index + "]").val());
$scope.qty = currentVal - 1;
// If is not undefined
if (!isNaN(currentVal) && currentVal > 1) {
// Increment
$("input[name=" + fieldName + index + "]").val(currentVal - 1);
$("input[name=" + fieldName + index + "]").attr(
"data-qty",
currentVal - 1
);
} else {
// Otherwise put a 0 there
$("input[name=" + fieldName + index + "]").val(1);
$("input[name=" + fieldName + index + "]").attr("data-qty", 1);
}
$scope.cartTotal();
};
$scope.cartTotal = function () {
var subtotal = 0,
savingstotal = 0;
angular.forEach(angular.element(".productcount"), function (value, key) {
var a = angular.element(value);
subtotal +=
parseFloat(a.attr("data-price")) * parseFloat(a.attr("data-qty"));
savingstotal +=
parseFloat(a.attr("data-savings")) * parseFloat(a.attr("data-qty"));
});
var delivery_price = parseInt(10);
var grandtotal = parseFloat(subtotal) + parseFloat(delivery_price);
$(".subTotal").html(subtotal.toFixed(2) + " AED");
$(".savingsTotal").html(subtotal.toFixed(2) + " AED");
$(".grandTotal").html(grandtotal.toFixed(2) + " AED");
$scope.grandTotal = grandtotal.toFixed(2);
};
$scope.change_title = function () {
if ($scope.edit_title == 0) {
$scope.edit_title = 1;
} else {
$scope.edit_title = 0;
}
};
//user_bundle Update//
var cp = document.forms.user_bundle,
elem = cp.elements;
cp.onsubmit = function () {
let product_ids = [];
let proceed = 0;
$scope.mybundle.forEach(element => {
//console.log(element.ubp_id);
if ($("#brand_" + element.ubp_id).is(":checked") == true) {
proceed = 1;
let bundle_data = [];
if (element.ubp_p_is_bundle == 1) {
element.product.forEach(ele => {
let bd = {
pd_id: ele.ubbp_pd_id,
is_alternative: ele.ubbp_is_alternative
};
bundle_data.push(bd);
});
}
let data = {
product_id: element.ubp_pd_id,
quantity: $("input[name=qty_" + element.ubp_id + "]").val(),
is_bundel: element.ubp_p_is_bundle,
bundel_items: bundle_data
};
element.quantity = $("input[name=qty_" + element.ubp_id + "]").val();
product_ids.push(data);
}
});
let editdata = {
bundle_name: $scope.mybundle_name,
ub_id: $scope.ub_id,
product_ids: product_ids
};
if (proceed == 1) {
userbundle
.editBundle(editdata)
.then(function (response) {
var res = response.data.results;
if (res.msg == "success") {
// toastr.success("Update Successfully..!");
$("#bundle_options").modal({
backdrop: "static",
keyboard: false
});
// $window.location.href = "/mybundles";
}
})
.catch(function (response) {
console.log(response);
});
} else {
toastr.warning("Product should not be empty..!");
}
};
var userAuth = $.cookie("vcartAuth") ? JSON.parse($.cookie("vcartAuth")) : "";
$scope.loggedStatus = userAuth.status == "success" ? true : false;
// $scope.bundle_addtocart = function(data) {
// mybundle_addtocart
// .getBundleData(data)
// .then(function(response) {
// console.log(response);
// if (response.status == "200") {
// const bundleProducts = response.data.results.response.product;
// bundleProducts.forEach(pro => {
// let data = {
// product_id: pro.ubp_pd_id,
// quantity: pro.ubp_qty,
// is_bundel: pro.ubp_p_is_bundle == 0 ? false : true
// };
// /** For Bundles **/
// if (pro.ubp_p_is_bundle == 1) {
// let alter = [];
// let alternative = pro.product;
// alternative.forEach(ele => {
// let alter_data = {
// pd_id: parseInt(ele.p_pd_id),
// is_alternaitve: ele.ubbp_is_alternative
// };
// alter.push(alter_data);
// });
// data.bundel_items = alter;
// }
// mybundle_addtocart
// .addToCart(data)
// .then(function(response) {
// if (response.data.results.status != "200") {
// toastr.warning(response.data.results.msg);
// } else {
// toastr.success(response.data.results.msg);
// var cartOldQty = localStorage.getItem("cartCount");
// var newCartQty = parseInt(cartOldQty) + parseInt(1);
// localStorage.setItem("cartCount", newCartQty);
// $(".cart-label").text(newCartQty);
// }
// })
// .catch(function(response) {
// toastr.warning(response.data.results.msg);
// });
// });
// //window.location = "/cart";
// }
// })
// .catch(function(response) {
// //toastr.warning(response.data.results.msg);
// });
// };
$scope.bundle_addtocart = function (data) {
mybundle_addtocart
.addToCart(data)
.then(function (response) {
if (response.data.results.status != "200") {
toastr.warning(response.data.results.msg);
} else {
toastr.success(response.data.results.msg);
var cartOldQty = localStorage.getItem("cartCount");
var newCartQty = parseInt(cartOldQty) + parseInt(1);
localStorage.setItem("cartCount", newCartQty);
$(".cart-label").text(newCartQty);
}
})
.catch(function (response) {
toastr.warning(response.data.error.response);
});
};
/**
* Add to cart functionality for checkout button on the popup
*/
$scope.bundle_checkout = function (data) {
mybundle_addtocart
.addToCart(data)
.then(function (response) {
if (response.data.results.status != "200") {
toastr.warning(response.data.results.msg);
} else {
toastr.success(response.data.results.msg);
var cartOldQty = localStorage.getItem("cartCount");
var newCartQty = parseInt(cartOldQty) + parseInt(1);
localStorage.setItem("cartCount", newCartQty);
$(".cart-label").text(newCartQty);
$window.location.href = "/cart";
}
})
.catch(function (response) {
$window.location.href = "/cart";
toastr.warning(response.data.error.response);
});
};
$scope.bundle_unsbuscribe = function (data) {
mybundle_addtocart
.unSubscribe(data)
.then(function (response) {
console.log(response);
if (response.data.results.status != "200") {
toastr.warning("Somthing Went Wrong..!");
} else {
location.reload();
}
})
.catch(function (response) {
toastr.warning(response);
});
};
});
app.controller("otpVerify", function(
$scope,
$rootScope,
$location,
$window,
$http,
$timeout,
$filter,
config,
otpVerify
) {
let token = JSON.parse($.cookie("vcartAuth"));
$scope.email = token.email;
var cp = document.forms.formOtp,
elem = cp.elements;
cp.onsubmit = function() {
var otp = "";
angular.forEach(angular.element(elem.otpvalue), function(data, key) {
otp += data.value;
});
if (otp.length == 6) {
var userAuth = typeof $.cookie("vcartAuth")
? JSON.parse($.cookie("vcartAuth"))
: "";
var userEmail = userAuth != "" ? userAuth.useremail : "";
var userToken = userAuth != "" ? userAuth.token : "";
let userData = {
email: userEmail,
otp: otp
};
otpVerify
.email_verify(userData, userToken)
.then(function(response) {
if (response.data.error) {
$(".otpvalue").val("");
console.log($(".otpvalue"));
toastr.error(response.data.error);
} else {
var loc = JSON.parse($.cookie("vcartAuth"));
loc.is_email_verified = true;
$.cookie("vcartAuth", JSON.stringify(loc), {
expires: 7,
path: "/"
});
toastr.success(response.data.result);
$window.location.href = "/";
}
})
.catch(function(response) {
$(".otpvalue").val("");
toastr.error(response.data.error);
});
} else {
toastr.error("OTP should have 6 numbers");
return false;
}
};
$scope.resendotp = function() {
$(".resend-btn").text("Sending...");
otpVerify
.resent_otp()
.then(function(response) {
console.log(response);
if (response.data.error) {
toastr.error(response.data.error);
} else {
toastr.success(response.data.results);
$(".resend-btn").text("Resend OTP");
$(".otpvalue").val("");
//$window.location.href = "/";
}
})
.catch(function(response) {
console.log(response);
});
};
});
app.factory("addNewAddress", function($http, config, $q) {
return {
add_address: function(formData, userToken) {
//console.log(formData);
var q = $q.defer();
var addURL = config.addAddress;
var updateURL = config.updateAddress;
let suggestURL = formData.a_id != "" ? updateURL : addURL;
let data = formData;
$http({
method: "POST",
url: suggestURL,
type: "json",
data: data,
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + userToken
}
})
.then(function(success) {
q.resolve(success);
})
.catch(function(err) {
q.reject(err);
});
return q.promise;
},
change_default_address: function(formData, userToken) {
//console.log(formData);
var q = $q.defer();
var suggestURL = config.changeDefaultAddress;
let data = formData;
$http({
method: "POST",
url: suggestURL,
type: "json",
data: data,
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + userToken
}
})
.then(function(success) {
q.resolve(success);
})
.catch(function(err) {
q.reject(err);
});
return q.promise;
},
remove_address: function(formData, userToken) {
//console.log(formData);
var q = $q.defer();
var suggestURL = config.removeAddress;
let data = formData;
let addressDeleteUrl = suggestURL + "?id=" + formData.a_id;
$http({
method: "GET",
url: addressDeleteUrl,
type: "json",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + userToken
}
})
.then(function(success) {
q.resolve(success);
})
.catch(function(err) {
q.reject(err);
});
return q.promise;
},
getlist: function() {
var userAuth = typeof $.cookie("vcartAuth")
? JSON.parse($.cookie("vcartAuth"))
: "";
var userToken = userAuth != "" ? userAuth.token : "";
var q = $q.defer();
var suggestURL = config.addressList;
$http({
method: "GET",
url: suggestURL,
type: "json",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + userToken
}
})
.then(function(success) {
q.resolve(success);
})
.catch(function(err) {
q.reject(err);
});
return q.promise;
},
cityarea_get: function() {
//console.log(formData);
var q = $q.defer();
var suggestURL = config.getcityarealist;
$http({
method: "GET",
url: suggestURL,
type: "json",
headers: {
"Content-Type": "application/json"
}
})
.then(function(success) {
q.resolve(success);
})
.catch(function(err) {
q.reject(err);
});
return q.promise;
}
};
});
app.factory("bundle_details", function($http, config, $q) {
return {
addToCart: function(qty, alternative, pd_id) {
var q = $q.defer();
var suggestURL = config.addToCart;
let data = {
product_id: pd_id,
quantity: qty,
is_bundel: true
};
console.log(alternative);
let alter = [];
for (const key in alternative) {
if (alternative.hasOwnProperty(key)) {
const element = alternative[key];
let is_alternaitve = element == key ? false : true;
let alter_data = {
pd_id: parseInt(element),
is_alternaitve: is_alternaitve
};
alter.push(alter_data);
}
}
data.bundel_items = alter;
let token = $.cookie("vcartAuth")
? JSON.parse($.cookie("vcartAuth"))
: "";
$http({
method: "POST",
url: suggestURL,
type: "json",
data: data,
headers: {
Authorization: "Bearer " + token.token,
"Content-Type": "application/json"
}
})
.then(function(success) {
q.resolve(success);
})
.catch(function(err) {
q.reject(err);
});
return q.promise;
},
listAddToCart: function(qty, alter, pd_id) {
var q = $q.defer();
var suggestURL = config.addToCart;
let data = {
product_id: pd_id,
quantity: qty,
is_bundel: true,
bundel_items: alter
};
let token = $.cookie("vcartAuth")
? JSON.parse($.cookie("vcartAuth"))
: "";
$http({
method: "POST",
url: suggestURL,
type: "json",
data: data,
headers: {
Authorization: "Bearer " + token.token,
"Content-Type": "application/json"
}
})
.then(function(success) {
q.resolve(success);
})
.catch(function(err) {
q.reject(err);
});
return q.promise;
},
getBundleDetail: function(pd_id) {
var q = $q.defer();
var suggestURL = config.getbundleDetail + "?product_id=" + pd_id;
let token = $.cookie("vcartAuth")
? JSON.parse($.cookie("vcartAuth"))
: "";
$http({
method: "GET",
url: suggestURL,
type: "json",
headers: {
Authorization: "Bearer " + token.token,
"Content-Type": "application/json"
}
})
.then(function(success) {
q.resolve(success);
})
.catch(function(err) {
q.reject(err);
});
return q.promise;
}
};
});
app.factory("getbundleList", function($http, config, $q) {
return {
getlist: function(queryParam, page) {
var q = $q.defer();
var suggestURL = config.getbundleList;
let data = {
cat_id: queryParam.cat_id,
page_no: page
};
if (queryParam.sub_cat) {
data["sub_cat_id"] = queryParam.sub_cat;
}
if (queryParam.price_start) {
data["price_start"] = queryParam.price_start;
}
if (queryParam.price_end) {
data["price_end"] = queryParam.price_end;
}
if (queryParam.discount_start) {
data["discount_start"] = queryParam.discount_start;
}
if (queryParam.discount_end) {
data["discount_end"] = queryParam.discount_end;
}
// if (queryParam.brand) {
// data["brand"] = queryParam.brand.split(",");
// }
if (queryParam.order_by) {
data["order_by"] = queryParam.order_by;
}
var headers={};
headers["Content-Type"]= "application/json";
var userAuth = $.cookie("vcartAuth") ? JSON.parse($.cookie("vcartAuth")) : "";
if(userAuth.status=="success"){
headers["Authorization"]="Bearer " + userAuth.token;
}
$http({
method: "POST",
url: suggestURL,
type: "json",
data: data,
headers: headers
})
.then(function(success) {
q.resolve(success);
})
.catch(function(err) {
q.reject(err);
});
return q.promise;
}
};
});
app.factory("getbundleList", function($http, config, $q) {
return {
getlist: function(queryParam, page) {
var q = $q.defer();
var suggestURL = config.getbundleList;
let data = {
page_no: page
};
console.log(queryParam);
if (queryParam.cat) {
data["cat_id"] = queryParam.cat;
}
if (queryParam.sub_cat) {
data["sub_cat_id"] = queryParam.sub_cat;
}
if (queryParam.price_start) {
data["price_start"] = queryParam.price_start;
}
if (queryParam.price_end) {
data["price_end"] = queryParam.price_end;
}
if (queryParam.discount_start) {
data["discount_start"] = queryParam.discount_start;
}
if (queryParam.discount_end) {
data["discount_end"] = queryParam.discount_end;
}
// if (queryParam.brand) {
// data["brand"] = queryParam.brand.split(",");
// }
if (queryParam.order_by) {
data["order_by"] = queryParam.order_by;
}
var headers = {};
headers["Content-Type"] = "application/json";
var userAuth = $.cookie("vcartAuth")
? JSON.parse($.cookie("vcartAuth"))
: "";
if (userAuth.status == "success") {
headers["Authorization"] = "Bearer " + userAuth.token;
}
$http({
method: "POST",
url: suggestURL,
type: "json",
data: data,
headers: headers
})
.then(function(success) {
q.resolve(success);
})
.catch(function(err) {
q.reject(err);
});
return q.promise;
}
};
});
app.factory("postBundleReview", function($http, config, $q) {
return {
postReview: function(formData, userData) {
//console.log(formData);
var q = $q.defer();
var suggestURL = config.submitBundle_review;
let data = formData;
$http({
method: "POST",
url: suggestURL,
type: "json",
data: data,
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + userData
}
})
.then(function(success) {
q.resolve(success);
})
.catch(function(err) {
q.reject(err);
});
return q.promise;
}
};
});
app.factory("cart", function($http, config, $q) {
return {
quantityUpdate: function(qty, cart_id) {
var q = $q.defer();
var suggestURL = config.cartupdate;
let data = {
cart_id: cart_id,
quantity: qty
};
let token = $.cookie("vcartAuth")
? JSON.parse($.cookie("vcartAuth"))
: "";
$http({
method: "POST",
url: suggestURL,
type: "json",
data: data,
headers: {
Authorization: "Bearer " + token.token,
"Content-Type": "application/json"
}
})
.then(function(success) {
q.resolve(success);
})
.catch(function(err) {
q.reject(err);
});
return q.promise;
},
removeCart: function(productData, userData) {
var q = $q.defer();
var suggestURL = config.cartRemove;
var data = productData;
$http({
method: "DELETE",
url: suggestURL,
type: "json",
data: data,
headers: {
Authorization: "Bearer " + userData,
"Content-Type": "application/json"
}
})
.then(function(success) {
q.resolve(success);
})
.catch(function(err) {
q.reject(err);
});
return q.promise;
},
verifyCoupon: function(coupon, total, userData) {
var q = $q.defer();
var suggestURL =
config.checkCoupon + "?coupon_code=" + coupon + "&grand_total=" + total;
$http({
method: "GET",
url: suggestURL,
type: "json",
headers: {
Authorization: "Bearer " + userData,
"Content-Type": "application/json"
}
})
.then(function(success) {
q.resolve(success);
})
.catch(function(err) {
q.reject(err);
});
return q.promise;
},
removeUserbundle: function(id, userData) {
var q = $q.defer();
var suggestURL = config.deleteUserBundle + "?ub_id=" + id;
$http({
method: "DELETE",
url: suggestURL,
type: "json",
headers: {
Authorization: "Bearer " + userData,
"Content-Type": "application/json"
}
})
.then(function(success) {
q.resolve(success);
})
.catch(function(err) {
q.reject(err);
});
return q.promise;
},
updateBundleName: function(data, userData) {
var q = $q.defer();
var suggestURL = config.updateBundleName;
$http({
method: "PATCH",
url: suggestURL,
data: data,
type: "json",
headers: {
Authorization: "Bearer " + userData,
"Content-Type": "application/json"
}
})
.then(function(success) {
q.resolve(success);
})
.catch(function(err) {
q.reject(err);
});
return q.promise;
},
getsetting: function() {
var q = $q.defer();
var suggestURL = config.settings;
$http({
method: "GET",
url: suggestURL,
type: "json",
headers: {
"Content-Type": "application/json"
}
})
.then(function(success) {
q.resolve(success);
})
.catch(function(err) {
q.reject(err);
});
return q.promise;
}
};
});
app.factory("createUserbundle", function($http, config, $q) {
return {
getDetails: function(order_id) {
var q = $q.defer();
let token = JSON.parse($.cookie("vcartAuth"));
$http({
method: "GET",
url: config.orderDetails + "?order_id=" + order_id,
type: "json",
headers: {
Authorization: "Bearer " + token.token
}
})
.then(function(success) {
q.resolve(success);
})
.catch(function(err) {
q.reject(err);
});
return q.promise;
},
insertBundle: function(data) {
var q = $q.defer();
let token = $.cookie("vcartAuth")
? JSON.parse($.cookie("vcartAuth"))
: "";
$http({
method: "POST",
url: config.create_user_bundle,
type: "json",
data: data,
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + token.token
}
})
.then(function(success) {
q.resolve(success);
})
.catch(function(err) {
q.reject(err);
});
return q.promise;
},
insertBundleWithProduct: function(data) {
var q = $q.defer();
let token = $.cookie("vcartAuth")
? JSON.parse($.cookie("vcartAuth"))
: "";
$http({
method: "POST",
url: config.createWithproduct,
type: "json",
data: data,
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + token.token
}
})
.then(function(success) {
q.resolve(success);
})
.catch(function(err) {
q.reject(err);
});
return q.promise;
}
};
});
app.factory("mybundle_addtocart", function($http, config, $q) {
return {
getBundleData: function(bundleId) {
var q = $q.defer();
let token = $.cookie("vcartAuth")
? JSON.parse($.cookie("vcartAuth"))
: "";
$http({
method: "GET",
url: config.view_mybundle,
type: "json",
params: { ub_id: bundleId },
headers: {
Authorization: "Bearer " + token.token
}
})
.then(function(success) {
q.resolve(success);
})
.catch(function(err) {
q.reject(err);
});
return q.promise;
},
addToCart: function(data) {
var q = $q.defer();
// var suggestURL = config.addToCart;
var data = {
ub_id: data
};
var suggestURL = config.adduserbundletocart;
let token = $.cookie("vcartAuth")
? JSON.parse($.cookie("vcartAuth"))
: "";
$http({
method: "POST",
url: suggestURL,
type: "json",
data: data,
headers: {
Authorization: "Bearer " + token.token,
"Content-Type": "application/json"
}
})
.then(function(success) {
q.resolve(success);
})
.catch(function(err) {
q.reject(err);
});
return q.promise;
},
unSubscribe: function(bundleId) {
var q = $q.defer();
let token = $.cookie("vcartAuth")
? JSON.parse($.cookie("vcartAuth"))
: "";
$http({
method: "PATCH",
url: config.unsubscribeBundle + "?ub_id=" + bundleId,
type: "json",
headers: {
Authorization: "Bearer " + token.token
}
})
.then(function(success) {
q.resolve(success);
})
.catch(function(err) {
q.reject(err);
});
return q.promise;
}
};
});
app.factory("getMyorderlist", function($http, config, $q) {
return {
getlist: function(pageNO, userData) {
var q = $q.defer();
var suggestURL = config.orderList;
let listUrl = suggestURL + "?page_no=" + pageNO;
$http({
method: "GET",
url: listUrl,
type: "json",
headers: {
Authorization: "Bearer " + userData
}
})
.then(function(success) {
q.resolve(success);
})
.catch(function(err) {
q.reject(err);
});
return q.promise;
}
};
});
app.factory("myShipping", function($http, config, $q) {
return {
removeShipping: function(shipping_id, userData) {
var q = $q.defer();
let suggestURL= config.shppingListUrl+"/"+shipping_id;
$http({
method: "DELETE",
url: suggestURL,
type: "json",
headers: {
Authorization: "Bearer " + userData
}
})
.then(function(success) {
q.resolve(success);
})
.catch(function(err) {
q.reject(err);
});
return q.promise;
},
updateShipping: function(listData, shipping_id, userData) {
var q = $q.defer();
let suggestURL= config.shppingListUrl+"/"+shipping_id;
$http({
method: "PUT",
url: suggestURL,
data: listData,
type: "json",
headers: {
Authorization: "Bearer " + userData
}
})
.then(function(success) {
q.resolve(success);
})
.catch(function(err) {
q.reject(err);
});
return q.promise;
}
};
});
\ No newline at end of file
app.factory("product_details", function($http, config, $q) {
return {
addToCart: function(qty, pd_id) {
var q = $q.defer();
var suggestURL = config.addToCart;
let data = {
product_id: pd_id,
quantity: qty,
is_bundel: false
};
let token = $.cookie("vcartAuth")
? JSON.parse($.cookie("vcartAuth"))
: "";
$http({
method: "POST",
url: suggestURL,
type: "json",
data: data,
headers: {
Authorization: "Bearer " + token.token,
"Content-Type": "application/json"
}
})
.then(function(success) {
q.resolve(success);
})
.catch(function(err) {
q.reject(err);
});
return q.promise;
},
postReview: function(formData, userData) {
//console.log(formData);
var q = $q.defer();
var suggestURL = config.submitBundle_review;
let data = formData;
$http({
method: "POST",
url: suggestURL,
type: "json",
data: data,
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + userData
}
})
.then(function(success) {
q.resolve(success);
})
.catch(function(err) {
q.reject(err);
});
return q.promise;
}
};
});
app.factory("getProductList", function($http, config, $q) {
return {
getlist: function(queryParam, page) {
var q = $q.defer();
var data = {};
console.log(queryParam);
var suggestURL = config.getproduct_list;
data = {
cat_id: queryParam.cat_id,
page_no: page
};
if (queryParam.sub_cat) {
data["sub_cat_id"] = queryParam.sub_cat;
}
if (queryParam.price_start) {
data["price_start"] = queryParam.price_start;
}
if (queryParam.price_end) {
data["price_end"] = queryParam.price_end;
}
if (queryParam.discount_start) {
data["discount_start"] = queryParam.discount_start;
}
if (queryParam.discount_end) {
data["discount_end"] = queryParam.discount_end;
}
if (queryParam.brand) {
data["brand"] = queryParam.brand.split(",");
}
if (queryParam.order_by) {
data["order_by"] = queryParam.order_by;
}
var headers = {};
headers["Content-Type"] = "application/json";
var userAuth = $.cookie("vcartAuth")
? JSON.parse($.cookie("vcartAuth"))
: "";
if (userAuth.status == "success") {
headers["Authorization"] = "Bearer " + userAuth.token;
}
$http({
method: "POST",
url: suggestURL,
type: "json",
data: data,
headers: headers
})
.then(function(success) {
q.resolve(success);
})
.catch(function(err) {
q.reject(err);
});
return q.promise;
}
};
});
app.factory("getProductList", function($http, config, valuecartex, $q) {
return {
getlist: function(queryParam, page) {
var q = $q.defer();
var suggestURL = config.getproduct_list;
let data = {
exclusive: valuecartex.data,
page_no: page
};
if (queryParam.cat) {
data["cat_id"] = queryParam.cat;
}
if (queryParam.sub_cat) {
data["sub_cat_id"] = queryParam.sub_cat;
}
if (queryParam.price_start) {
data["price_start"] = queryParam.price_start;
}
if (queryParam.price_end) {
data["price_end"] = queryParam.price_end;
}
if (queryParam.discount_start) {
data["discount_start"] = queryParam.discount_start;
}
if (queryParam.discount_end) {
data["discount_end"] = queryParam.discount_end;
}
if (queryParam.brand) {
data["brand"] = queryParam.brand.split(",");
}
if (queryParam.order_by) {
data["order_by"] = queryParam.order_by;
}
var headers = {};
headers["Content-Type"] = "application/json";
var userAuth = $.cookie("vcartAuth")
? JSON.parse($.cookie("vcartAuth"))
: "";
if (userAuth.status == "success") {
headers["Authorization"] = "Bearer " + userAuth.token;
}
$http({
method: "POST",
url: suggestURL,
type: "json",
data: data,
headers: headers
})
.then(function(success) {
q.resolve(success);
})
.catch(function(err) {
q.reject(err);
});
return q.promise;
}
};
});
app.factory("updateProfile", function($http, config, $q) {
return {
update_profile: function(formData, userData) {
//console.log(formData);
var q = $q.defer();
var suggestURL = config.user_profileUpdate;
let data = formData;
$http({
method: "POST",
url: suggestURL,
type: "json",
data: data,
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + userData
}
})
.then(function(success) {
q.resolve(success);
})
.catch(function(err) {
q.reject(err);
});
return q.promise;
}
};
});
app.factory("userbundle", function($http, config, $q) {
return {
getDetails: function(bundleId) {
var q = $q.defer();
let token = $.cookie("vcartAuth")
? JSON.parse($.cookie("vcartAuth"))
: "";
$http({
method: "GET",
url: config.view_mybundle,
type: "json",
params: { ub_id: bundleId },
headers: {
Authorization: "Bearer " + token.token
}
})
.then(function(success) {
q.resolve(success);
})
.catch(function(err) {
q.reject(err);
});
return q.promise;
},
editBundle: function(data) {
var q = $q.defer();
let token = $.cookie("vcartAuth")
? JSON.parse($.cookie("vcartAuth"))
: "";
$http({
method: "PUT",
url: config.edit_mybundle,
type: "json",
data: data,
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + token.token
}
})
.then(function(success) {
q.resolve(success);
})
.catch(function(err) {
q.reject(err);
});
return q.promise;
},
getList: function() {
var q = $q.defer();
let token = $.cookie("vcartAuth")
? JSON.parse($.cookie("vcartAuth"))
: "";
$http({
method: "GET",
url: config.mybundel_list,
type: "json",
headers: {
Authorization: "Bearer " + token.token
}
})
.then(function(success) {
q.resolve(success);
})
.catch(function(err) {
q.reject(err);
});
return q.promise;
},
updateBundle: function(data) {
var q = $q.defer();
let token = $.cookie("vcartAuth")
? JSON.parse($.cookie("vcartAuth"))
: "";
$http({
method: "POST",
url: config.update_mybundle_single,
type: "json",
data: data,
headers: {
Authorization: "Bearer " + token.token
}
})
.then(function(success) {
q.resolve(success);
})
.catch(function(err) {
q.reject(err);
});
return q.promise;
},
updateBundleWithoutBundleId: function(data) {
var q = $q.defer();
let token = $.cookie("vcartAuth")
? JSON.parse($.cookie("vcartAuth"))
: "";
$http({
method: "POST",
url: config.update_mybundle_singlewithoutbundleid,
type: "json",
data: data,
headers: {
Authorization: "Bearer " + token.token
}
})
.then(function(success) {
q.resolve(success);
})
.catch(function(err) {
q.reject(err);
});
return q.promise;
}
};
});
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed. Click to expand it.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment