From 6a86b4854c805e3d8df16abc5a911065eb36e813 Mon Sep 17 00:00:00 2001 From: Abhishek Sinha Date: Thu, 6 Feb 2020 20:45:38 +0530 Subject: [PATCH] added buyer functions --- city e-commerce 0.0.1.html | 169 +++++++++++++++++++++++++++++++------ 1 file changed, 145 insertions(+), 24 deletions(-) diff --git a/city e-commerce 0.0.1.html b/city e-commerce 0.0.1.html index 6c89c6f..fd027e4 100644 --- a/city e-commerce 0.0.1.html +++ b/city e-commerce 0.0.1.html @@ -9931,6 +9931,7 @@ blocked_flo_ids: [], users: {}, products: {}, + ui: {}, }; ecommerce.actions = { @@ -10078,7 +10079,7 @@ flo_id: myFloID, }); - deepFreeze(ecommerce.loggedInUser.user_info); + //deepFreeze(ecommerce.loggedInUser.user_info); const LIVE_USER = ecommerce.loggedInUser; @@ -10088,7 +10089,8 @@ await this.retrieveLatestContent(); - ecommerce.products.create_approved_products_id_list(); + await ecommerce.products.create_approved_products_id_list(); + await ecommerce.products.get_approved_products_list(); }, @@ -10170,7 +10172,11 @@ } this.flo_id = myFloID; this.user_role = "BUYER"; - this.buy_list = []; + this.buy_list = []; // tentative to change + this.shopping_bill = { // final buy order + shopping_list: [], + total_amount: 0, + }; this.total_buying_price = 0; }, sellers: function Seller(seller_details={}) { @@ -10214,8 +10220,23 @@ this.user_role = "MANAGER"; }, }, + } + ecommerce.ui = { + BUYER: function() { + this.ui_data = {}; + }, + SELLER: function() { + this.ui_data = {}; + }, + CASHIER: function() { + this.ui_data = {}; + }, + COURIER: function() { + this.ui_data = {}; + }, + } @@ -10275,7 +10296,7 @@ return new Promise((resolve)=>{ resolve(ecommerce.products.get_approved_products_id()) }).then(approved_products=>{ - Object.defineProperty(ecommerce, "approved_products", + Object.defineProperty(ecommerce, "approved_products_ids", { value: approved_products, writable: false, @@ -10284,6 +10305,53 @@ }); }) }, + + // Segregate admin approved products from general objects + get_approved_products_list: function() { + return new Promise((resolve, reject)=>{ + try { + + const generalData = floGlobals.generalData[JSON.stringify( + { application: floGlobals.application, + type: ecommerce.master_configurations.DATA_TYPE.SELLING_PRODUCTS + })]; + + const certified_products = generalData + .map(m=>m.message[Object.keys(m.message)[0]]) + .filter(f=>ecommerce.approved_products_ids + .includes(f.product_info.product_static_information.product_flo_id)); + + Object.defineProperty(ecommerce, "approved_products_list", + { + value: certified_products, + writable: false, + configurable: false, + enumerable: true + }); + + resolve(ecommerce.approved_products_list); + + } catch (error) { + reject(error); + } + }); + }, + + get_product_details_by_floId: function(productFloId='') { + return new Promise((resolve, reject) => { + try { + const filtered_product = ecommerce.approved_products_list + .filter(f=>f.product_info.product_static_information.product_flo_id===productFloId); + + if(filtered_product.length!==1) return reject("Product not found."); + resolve(filtered_product); + + } catch (error) { + showMessage('Failed to get any product with id '+productFloId, 'ERROR'); + reject('Failed to get any product with id '+productFloId); + } + }); + }, } @@ -10342,29 +10410,27 @@