From 551175e36f8eb415bc338bab84afd00fbd151f13 Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 15 Dec 2020 22:32:19 +0200 Subject: [PATCH 01/91] Created model and prepared job to working with currency for a shop --- app/jobs/AdditionalSettingForShop.java | 30 +++++++++---------- app/jobs/GetDailyCurrency.java | 30 +++++++++++++++++++ app/jobs/MonthlyFee.java | 31 ++++---------------- app/jobs/WisehandsSetup.java | 2 +- app/models/CurrencyDTO.java | 26 +++++++++++++++++ app/models/CurrencyShopDTO.java | 40 ++++++++++++++++++++++++++ app/models/ShopDTO.java | 3 ++ app/services/ShopServiceImpl.java | 2 +- 8 files changed, 122 insertions(+), 42 deletions(-) create mode 100644 app/jobs/GetDailyCurrency.java create mode 100644 app/models/CurrencyDTO.java create mode 100644 app/models/CurrencyShopDTO.java diff --git a/app/jobs/AdditionalSettingForShop.java b/app/jobs/AdditionalSettingForShop.java index 3b197f963..e29f96748 100644 --- a/app/jobs/AdditionalSettingForShop.java +++ b/app/jobs/AdditionalSettingForShop.java @@ -14,38 +14,38 @@ public AdditionalSettingForShop(){ } - public void setWorkkingTime(ShopDTO shop){ + public void setWorkingTime(ShopDTO shop){ if(shop.monStartTime == null) { - shop.monStartTime = "1970-01-01T05:00:00.000Z"; - shop.monEndTime = "1970-01-01T15:00:00.000Z"; + shop.monStartTime = "04:20"; + shop.monEndTime = "16:21"; } if(shop.tueStartTime == null) { - shop.tueStartTime = "1970-01-01T05:00:00.000Z"; - shop.tueEndTime = "1970-01-01T15:00:00.000Z"; + shop.tueStartTime = "04:20"; + shop.tueEndTime = "16:21"; } if(shop.wedStartTime == null) { - shop.wedStartTime = "1970-01-01T05:00:00.000Z"; - shop.wedEndTime = "1970-01-01T15:00:00.000Z"; + shop.wedStartTime = "04:20"; + shop.wedEndTime = "16:21"; } if(shop.thuStartTime == null) { - shop.thuStartTime = "1970-01-01T05:00:00.000Z"; - shop.thuEndTime = "1970-01-01T15:00:00.000Z"; + shop.thuStartTime = "04:20"; + shop.thuEndTime = "16:21"; } if(shop.friStartTime == null) { - shop.friStartTime = "1970-01-01T05:00:00.000Z"; - shop.friEndTime = "1970-01-01T15:00:00.000Z"; + shop.friStartTime = "04:20"; + shop.friEndTime = "16:21"; } if(shop.satStartTime == null) { - shop.satStartTime = "1970-01-01T05:00:00.000Z"; - shop.satEndTime = "1970-01-01T15:00:00.000Z"; + shop.satStartTime = "04:20"; + shop.satEndTime = "16:21"; } if(shop.sunStartTime == null) { - shop.sunStartTime = "1970-01-01T05:00:00.000Z"; - shop.sunEndTime = "1970-01-01T15:00:00.000Z"; + shop.sunStartTime = "04:20"; + shop.sunEndTime = "16:21"; } } diff --git a/app/jobs/GetDailyCurrency.java b/app/jobs/GetDailyCurrency.java new file mode 100644 index 000000000..f534c9855 --- /dev/null +++ b/app/jobs/GetDailyCurrency.java @@ -0,0 +1,30 @@ +package jobs; + + +import models.ShopDTO; +import play.jobs.Job; +import play.jobs.On; + +import java.util.List; + +@On("0 0 12 * * ?") +public class GetDailyCurrency extends Job { + + public void doJob() throws Exception { + System.out.println("get currency for shop"); + + List shopList = ShopDTO.findAll(); + for (ShopDTO shop : shopList){ + if (shop.currencyShop.currency != null){ + getCurrencyList(shop); + } + } + + } + + private void getCurrencyList(ShopDTO shop) { + + } + + +} diff --git a/app/jobs/MonthlyFee.java b/app/jobs/MonthlyFee.java index 0f96b7002..2a8d1d63e 100644 --- a/app/jobs/MonthlyFee.java +++ b/app/jobs/MonthlyFee.java @@ -20,9 +20,6 @@ public class MonthlyFee extends Job { public void doJob() throws Exception { System.out.println("MonthlyFee job"); - DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss"); - - Calendar calendar = Calendar.getInstance(); // this takes current date calendar.set(Calendar.DAY_OF_MONTH, 1); @@ -37,34 +34,16 @@ public void doJob() throws Exception { List shopList = ShopDTO.findAll(); for (ShopDTO shop : shopList){ if (shop.pricingPlan != null){ - CoinAccountDTO coinAccount = CoinAccountDTO.find("byShop", shop).first(); - if(coinAccount == null) { - coinAccount = new CoinAccountDTO(shop); - coinAccount = coinAccount.save(); - } - CoinTransactionDTO transaction = new CoinTransactionDTO(); - transaction.type = TransactionType.MONTHLY_FEE; - transaction.status = TransactionStatus.OK; - transaction.account = coinAccount; - transaction.amount = -shop.pricingPlan.monthlyFee; - transaction.time = System.currentTimeMillis() / 1000L; - coinAccount.addTransaction(transaction); - coinAccount.balance += transaction.amount; - transaction.transactionBalance = coinAccount.balance; - transaction.save(); - coinAccount.save(); - System.out.println("paid a monthly fee!!!!!!!!!!!"); + setPricingPlan(shop); } } } } - public void getMonthlyFee(ShopDTO shop) { + public void setPricingPlan(ShopDTO shop) { CoinAccountDTO coinAccount = CoinAccountDTO.find("byShop", shop).first(); - Double commissionFee = shop.pricingPlan.commissionFee; - if(coinAccount == null) { coinAccount = new CoinAccountDTO(shop); coinAccount = coinAccount.save(); @@ -73,12 +52,14 @@ public void getMonthlyFee(ShopDTO shop) { transaction.type = TransactionType.MONTHLY_FEE; transaction.status = TransactionStatus.OK; transaction.account = coinAccount; - transaction.amount = -commissionFee; + transaction.amount = -shop.pricingPlan.monthlyFee; transaction.time = System.currentTimeMillis() / 1000L; - transaction = transaction.save(); coinAccount.addTransaction(transaction); coinAccount.balance += transaction.amount; + transaction.transactionBalance = coinAccount.balance; + transaction.save(); coinAccount.save(); + System.out.println("paid a monthly fee!!!!!!!!!!!"); } diff --git a/app/jobs/WisehandsSetup.java b/app/jobs/WisehandsSetup.java index 03377cfc7..381ce6c3c 100644 --- a/app/jobs/WisehandsSetup.java +++ b/app/jobs/WisehandsSetup.java @@ -44,7 +44,7 @@ public void doJob() throws Exception { boolean hasPages = listsPage.size() != 0; AdditionalSettingForShop additionalSettingForShop = new AdditionalSettingForShop(); - additionalSettingForShop.setWorkkingTime(shop); + additionalSettingForShop.setWorkingTime(shop); shop = shop.save(); if (!hasPages){ additionalSettingForShop.setPageListForFooter(shop); diff --git a/app/models/CurrencyDTO.java b/app/models/CurrencyDTO.java new file mode 100644 index 000000000..0293dca78 --- /dev/null +++ b/app/models/CurrencyDTO.java @@ -0,0 +1,26 @@ +package models; + +import com.google.gson.annotations.Expose; +import org.hibernate.annotations.GenericGenerator; +import play.db.jpa.GenericModel; + +import javax.persistence.*; + +@Entity +public class CurrencyDTO extends GenericModel { + + @GeneratedValue(generator = "system-uuid") + @GenericGenerator(name = "system-uuid", strategy = "uuid") + @Expose + public String uuid; + + @Expose + public double buy; + + @Expose + public double sale; + + @ManyToOne(cascade = CascadeType.ALL) + public CurrencyShopDTO currencyShop; + +} diff --git a/app/models/CurrencyShopDTO.java b/app/models/CurrencyShopDTO.java new file mode 100644 index 000000000..6d0779ddd --- /dev/null +++ b/app/models/CurrencyShopDTO.java @@ -0,0 +1,40 @@ +package models; + +import com.google.gson.annotations.Expose; +import org.hibernate.annotations.GenericGenerator; +import play.db.jpa.GenericModel; + +import javax.persistence.*; +import java.util.ArrayList; +import java.util.Currency; +import java.util.List; + +@Entity +public class CurrencyShopDTO extends GenericModel { + + @Id + @GeneratedValue(generator = "system-uuid") + @GenericGenerator(name = "system-uuid", strategy = "uuid") + @Expose + public String uuid; + + @Expose + public String currency; + + @Expose + @OneToMany(cascade=CascadeType.ALL) + List currencyList; + + @OneToOne(cascade=CascadeType.ALL) + public ShopDTO shop; + + public CurrencyShopDTO() { + if(currencyList == null) { + currencyList = new ArrayList(); + } + } + + + + +} diff --git a/app/models/ShopDTO.java b/app/models/ShopDTO.java index fd3be994f..d55ec4fcb 100644 --- a/app/models/ShopDTO.java +++ b/app/models/ShopDTO.java @@ -124,6 +124,9 @@ public class ShopDTO extends GenericModel { @Expose public String locale; + @OneToOne(cascade=CascadeType.ALL) + public CurrencyShopDTO currencyShop; + @OneToOne(cascade=CascadeType.ALL) public BalanceDTO balance; diff --git a/app/services/ShopServiceImpl.java b/app/services/ShopServiceImpl.java index 36ae698d3..384853f09 100644 --- a/app/services/ShopServiceImpl.java +++ b/app/services/ShopServiceImpl.java @@ -69,7 +69,7 @@ public ShopDTO createShop(String name, String domain, UserDTO user) { shop.googleMapsApiKey = WISEHANDS_MAPS_KEY; AdditionalSettingForShop additionalSettingForShop = new AdditionalSettingForShop(); - additionalSettingForShop.setWorkkingTime(shop); + additionalSettingForShop.setWorkingTime(shop); shop = shop.save(); additionalSettingForShop.setPageListForFooter(shop); From e2fbb7ab5c987cd80cf52795354becc1b25f8ff0 Mon Sep 17 00:00:00 2001 From: Alexander Date: Thu, 17 Dec 2020 19:44:43 +0200 Subject: [PATCH 02/91] Parsed json array for creating CurrencyDTO --- app/controllers/Application.java | 12 ++++++- app/jobs/GetDailyCurrency.java | 59 ++++++++++++++++++++++++++++---- app/models/CurrencyDTO.java | 7 ++++ app/models/CurrencyShopDTO.java | 14 ++++++-- 4 files changed, 83 insertions(+), 9 deletions(-) diff --git a/app/controllers/Application.java b/app/controllers/Application.java index 0eabf613b..ad7b2185e 100644 --- a/app/controllers/Application.java +++ b/app/controllers/Application.java @@ -3,10 +3,19 @@ import com.auth0.jwt.JWT; import com.auth0.jwt.algorithms.Algorithm; import com.auth0.jwt.exceptions.JWTCreationException; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; import enums.FeedbackRequestState; + +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; import play.Play; import play.i18n.Lang; import play.i18n.Messages; +import play.libs.WS; import play.mvc.*; import models.*; @@ -14,7 +23,9 @@ import services.translaiton.LanguageForShop; import services.translaiton.Translation; +import javax.validation.constraints.NotNull; import java.io.IOException; + import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.*; @@ -440,7 +451,6 @@ public static void product(String client, String uuid, String language){ render(product, category, categories, shop, language); } - private static void generateCookieIfNotPresent(ShopDTO shop) { String agent = request.headers.get("user-agent").value(); if (shop != null) { diff --git a/app/jobs/GetDailyCurrency.java b/app/jobs/GetDailyCurrency.java index f534c9855..938bc1d27 100644 --- a/app/jobs/GetDailyCurrency.java +++ b/app/jobs/GetDailyCurrency.java @@ -1,30 +1,77 @@ package jobs; +import com.google.gson.JsonElement; + +import com.google.gson.JsonObject; +import models.CurrencyShopDTO; import models.ShopDTO; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; +import play.jobs.Every; import play.jobs.Job; import play.jobs.On; +import play.libs.WS; +import services.translaiton.Translation; import java.util.List; -@On("0 0 12 * * ?") +//@On("0 0 12 * * ?") +@Every("1min") public class GetDailyCurrency extends Job { public void doJob() throws Exception { - System.out.println("get currency for shop"); + + + WS.HttpResponse response = WS.url("https://api.privatbank.ua/p24api/pubinfo?exchange&json&coursid=11").get(); + String currencyJson = response.getString(); + System.out.println(" Get Daily currency job => " + currencyJson); + JSONParser parser = new JSONParser(); + JSONArray currencyJsonArray = null; + try { + currencyJsonArray = (JSONArray) parser.parse(currencyJson); + } catch (ParseException e) { + e.printStackTrace(); + } List shopList = ShopDTO.findAll(); for (ShopDTO shop : shopList){ - if (shop.currencyShop.currency != null){ - getCurrencyList(shop); - } +// if (shop.currencyShop.currency != null) { + setCurrencyListToShop(shop, currencyJsonArray); +// } } } - private void getCurrencyList(ShopDTO shop) { + private void setCurrencyListToShop(ShopDTO shop, JSONArray currencyJsonArray) { + + System.out.println("setCurrencyListToShop => " + currencyJsonArray); +// CurrencyShopDTO currencyShop = CurrencyShopDTO.find("byShop", shop).first(); + for (int i = 0; i < currencyJsonArray.size(); i++) { + + } +// currencyShop.addCurrency(getCurrency()); + + +// JSONObject title = (JSONObject) jsonArray.get(0); +// JsonArray jsonArray = json.getAsJsonArray(); +// for (JsonElement element : jsonArray){ +// JsonObject jsonObject = element.getAsJsonObject(); +// createCurrency(jsonObject); +// System.out.println("currency json => " + (String) title.get("ccy")); } + private static void createCurrency(JsonObject element) { + String ccy, base_ccy; + double buy, sale; +// if (element.get("ccy") != null) { +// ccy = (String) element.get("ccy"); +// } + + } + } diff --git a/app/models/CurrencyDTO.java b/app/models/CurrencyDTO.java index 0293dca78..6b203bdf5 100644 --- a/app/models/CurrencyDTO.java +++ b/app/models/CurrencyDTO.java @@ -9,11 +9,18 @@ @Entity public class CurrencyDTO extends GenericModel { + @Id @GeneratedValue(generator = "system-uuid") @GenericGenerator(name = "system-uuid", strategy = "uuid") @Expose public String uuid; + @Expose + public String ccy; + + @Expose + public String base_ccy; + @Expose public double buy; diff --git a/app/models/CurrencyShopDTO.java b/app/models/CurrencyShopDTO.java index 6d0779ddd..4240c85da 100644 --- a/app/models/CurrencyShopDTO.java +++ b/app/models/CurrencyShopDTO.java @@ -21,12 +21,20 @@ public class CurrencyShopDTO extends GenericModel { @Expose public String currency; + @OneToOne(cascade=CascadeType.ALL) + public ShopDTO shop; + @Expose @OneToMany(cascade=CascadeType.ALL) List currencyList; - @OneToOne(cascade=CascadeType.ALL) - public ShopDTO shop; + public void addCurrency(CurrencyDTO currency){ + if (this.currencyList == null){ + this.currencyList = new ArrayList(); + } + this.currencyList.add(currency); + } + public CurrencyShopDTO() { if(currencyList == null) { @@ -37,4 +45,6 @@ public CurrencyShopDTO() { + + } From 431321d3a378453b33e91c8c951f3cb95aff0a95 Mon Sep 17 00:00:00 2001 From: Alexander Date: Thu, 17 Dec 2020 21:31:43 +0200 Subject: [PATCH 03/91] wip set currency list to shop --- app/jobs/GetDailyCurrency.java | 70 ++++++++++++++++----------------- app/models/CurrencyDTO.java | 7 ++++ app/models/CurrencyShopDTO.java | 5 ++- 3 files changed, 45 insertions(+), 37 deletions(-) diff --git a/app/jobs/GetDailyCurrency.java b/app/jobs/GetDailyCurrency.java index 938bc1d27..c4dd8319a 100644 --- a/app/jobs/GetDailyCurrency.java +++ b/app/jobs/GetDailyCurrency.java @@ -4,6 +4,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import models.CurrencyDTO; import models.CurrencyShopDTO; import models.ShopDTO; import org.json.simple.JSONArray; @@ -24,54 +25,53 @@ public class GetDailyCurrency extends Job { public void doJob() throws Exception { - WS.HttpResponse response = WS.url("https://api.privatbank.ua/p24api/pubinfo?exchange&json&coursid=11").get(); String currencyJson = response.getString(); - System.out.println(" Get Daily currency job => " + currencyJson); - JSONParser parser = new JSONParser(); - JSONArray currencyJsonArray = null; - try { - currencyJsonArray = (JSONArray) parser.parse(currencyJson); - } catch (ParseException e) { - e.printStackTrace(); - } - - List shopList = ShopDTO.findAll(); - for (ShopDTO shop : shopList){ -// if (shop.currencyShop.currency != null) { + if (!currencyJson.isEmpty()){ + JSONParser parser = new JSONParser(); + JSONArray currencyJsonArray = (JSONArray) parser.parse(currencyJson); + List shopList = ShopDTO.findAll(); + for (ShopDTO shop : shopList){ setCurrencyListToShop(shop, currencyJsonArray); -// } + } } } private void setCurrencyListToShop(ShopDTO shop, JSONArray currencyJsonArray) { - System.out.println("setCurrencyListToShop => " + currencyJsonArray); -// CurrencyShopDTO currencyShop = CurrencyShopDTO.find("byShop", shop).first(); - for (int i = 0; i < currencyJsonArray.size(); i++) { - + CurrencyShopDTO currencyShop = CurrencyShopDTO.find("byShop", shop).first(); + if (currencyShop == null){ + currencyShop = new CurrencyShopDTO(shop); + currencyShop.save(); } -// currencyShop.addCurrency(getCurrency()); - - -// JSONObject title = (JSONObject) jsonArray.get(0); -// JsonArray jsonArray = json.getAsJsonArray(); -// for (JsonElement element : jsonArray){ -// JsonObject jsonObject = element.getAsJsonObject(); -// createCurrency(jsonObject); -// System.out.println("currency json => " + (String) title.get("ccy")); + for (int i = 0; i < currencyJsonArray.size(); i++) { + JSONObject object = (JSONObject) currencyJsonArray.get(i); + CurrencyDTO currency = getCurrency(object, currencyShop); + currencyShop.addCurrency(currency); + } + currencyShop.save(); } - - private static void createCurrency(JsonObject element) { - String ccy, base_ccy; - double buy, sale; -// if (element.get("ccy") != null) { -// ccy = (String) element.get("ccy"); -// } - + private CurrencyDTO getCurrency(JSONObject object, CurrencyShopDTO currencyShop) { + + String ccy = (String) object.get("ccy"); + String baseCurrency = (String) object.get("base_ccy"); + double buy = Double.parseDouble((String) object.get("buy")); + double sale = Double.parseDouble((String) object.get("sale")); + + CurrencyDTO currency = CurrencyDTO.find("byCurrencyShop", currencyShop).first(); + if (currency == null) { + currency = new CurrencyDTO(ccy, baseCurrency, buy, sale); + } else { + currency.ccy = ccy; + currency.base_ccy = baseCurrency; + currency.buy = buy; + currency.sale = sale; + } + currency.save(); + return currency; } } diff --git a/app/models/CurrencyDTO.java b/app/models/CurrencyDTO.java index 6b203bdf5..c5d31beea 100644 --- a/app/models/CurrencyDTO.java +++ b/app/models/CurrencyDTO.java @@ -30,4 +30,11 @@ public class CurrencyDTO extends GenericModel { @ManyToOne(cascade = CascadeType.ALL) public CurrencyShopDTO currencyShop; + public CurrencyDTO(String ccy, String base_ccy, double buy, double sale){ + this.ccy = ccy; + this.base_ccy = base_ccy; + this.buy = buy; + this.sale = sale; + } + } diff --git a/app/models/CurrencyShopDTO.java b/app/models/CurrencyShopDTO.java index 4240c85da..5bd286b17 100644 --- a/app/models/CurrencyShopDTO.java +++ b/app/models/CurrencyShopDTO.java @@ -35,8 +35,9 @@ public void addCurrency(CurrencyDTO currency){ this.currencyList.add(currency); } - - public CurrencyShopDTO() { + public CurrencyShopDTO(ShopDTO shop) { + this.shop = shop; + currency = "USD"; if(currencyList == null) { currencyList = new ArrayList(); } From 6666802060fb294fc3a8a85995c0d9bed5416cb9 Mon Sep 17 00:00:00 2001 From: Alexander Date: Fri, 18 Dec 2020 14:23:13 +0200 Subject: [PATCH 04/91] A prepared place for select currency on the admin side --- app/jobs/GetDailyCurrency.java | 26 ++++++++--------------- wisehands/admin/css/admin.css | 7 ++++++ wisehands/admin/partials/userProfile.html | 12 ++++++----- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/app/jobs/GetDailyCurrency.java b/app/jobs/GetDailyCurrency.java index c4dd8319a..a76bbaaee 100644 --- a/app/jobs/GetDailyCurrency.java +++ b/app/jobs/GetDailyCurrency.java @@ -1,26 +1,19 @@ package jobs; -import com.google.gson.JsonElement; - -import com.google.gson.JsonObject; import models.CurrencyDTO; import models.CurrencyShopDTO; import models.ShopDTO; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; -import org.json.simple.parser.ParseException; import play.jobs.Every; import play.jobs.Job; -import play.jobs.On; import play.libs.WS; -import services.translaiton.Translation; import java.util.List; -//@On("0 0 12 * * ?") -@Every("1min") +@Every("6h") public class GetDailyCurrency extends Job { public void doJob() throws Exception { @@ -45,21 +38,20 @@ private void setCurrencyListToShop(ShopDTO shop, JSONArray currencyJsonArray) { currencyShop = new CurrencyShopDTO(shop); currencyShop.save(); } - - for (int i = 0; i < currencyJsonArray.size(); i++) { - JSONObject object = (JSONObject) currencyJsonArray.get(i); - CurrencyDTO currency = getCurrency(object, currencyShop); + for (Object object : currencyJsonArray) { + JSONObject jsonObject = (JSONObject) object; + CurrencyDTO currency = getCurrency(jsonObject, currencyShop); currencyShop.addCurrency(currency); } currencyShop.save(); } - private CurrencyDTO getCurrency(JSONObject object, CurrencyShopDTO currencyShop) { + private CurrencyDTO getCurrency(JSONObject jsonObject, CurrencyShopDTO currencyShop) { - String ccy = (String) object.get("ccy"); - String baseCurrency = (String) object.get("base_ccy"); - double buy = Double.parseDouble((String) object.get("buy")); - double sale = Double.parseDouble((String) object.get("sale")); + String ccy = (String) jsonObject.get("ccy"); + String baseCurrency = (String) jsonObject.get("base_ccy"); + double buy = Double.parseDouble((String) jsonObject.get("buy")); + double sale = Double.parseDouble((String) jsonObject.get("sale")); CurrencyDTO currency = CurrencyDTO.find("byCurrencyShop", currencyShop).first(); if (currency == null) { diff --git a/wisehands/admin/css/admin.css b/wisehands/admin/css/admin.css index b351c1674..254b7a00a 100644 --- a/wisehands/admin/css/admin.css +++ b/wisehands/admin/css/admin.css @@ -2405,6 +2405,13 @@ ul.admin-breadcrumb li a:hover { word-break: break-word; } +.user-profile-container { + display: flex; +} +.select-currency { + margin: 1rem 1rem 0 2rem; +} + @media screen and (min-width: 1500px) { .admin-container { max-width: 1300px; diff --git a/wisehands/admin/partials/userProfile.html b/wisehands/admin/partials/userProfile.html index 02690f4e2..8b6c2d2ab 100644 --- a/wisehands/admin/partials/userProfile.html +++ b/wisehands/admin/partials/userProfile.html @@ -18,22 +18,24 @@
{{'userprofile.myProfile' | translate}}

{{'editProduct.general' | translate}}

-
+

{{'userprofile.fullname' | translate}}

-
+

{{'singleOrder.Phone' | translate}}

-
+

E-mail

-
-
+ +
From c1ab5507ad1b801588fd69d046f00b7a0b29a60c Mon Sep 17 00:00:00 2001 From: Alexander Date: Sat, 19 Dec 2020 16:54:40 +0200 Subject: [PATCH 05/91] A prepared for checking array --- app/jobs/GetDailyCurrency.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/jobs/GetDailyCurrency.java b/app/jobs/GetDailyCurrency.java index a76bbaaee..d38a855f0 100644 --- a/app/jobs/GetDailyCurrency.java +++ b/app/jobs/GetDailyCurrency.java @@ -38,6 +38,9 @@ private void setCurrencyListToShop(ShopDTO shop, JSONArray currencyJsonArray) { currencyShop = new CurrencyShopDTO(shop); currencyShop.save(); } + + // TODO check array on currency if true - find anr rewrite + for (Object object : currencyJsonArray) { JSONObject jsonObject = (JSONObject) object; CurrencyDTO currency = getCurrency(jsonObject, currencyShop); From 96d516a6516996233adb73973c66f6bb096d1b2e Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 22 Dec 2020 00:22:18 +0200 Subject: [PATCH 06/91] wip currency: rewrite updating CurrencyDTO in job --- app/jobs/GetDailyCurrency.java | 62 +++++++++++++++++++++++---------- app/models/CurrencyDTO.java | 2 +- app/models/CurrencyShopDTO.java | 8 ++--- 3 files changed, 47 insertions(+), 25 deletions(-) diff --git a/app/jobs/GetDailyCurrency.java b/app/jobs/GetDailyCurrency.java index d38a855f0..8fa9e2498 100644 --- a/app/jobs/GetDailyCurrency.java +++ b/app/jobs/GetDailyCurrency.java @@ -11,9 +11,10 @@ import play.jobs.Job; import play.libs.WS; +import java.util.ArrayList; import java.util.List; -@Every("6h") +@Every("1min") public class GetDailyCurrency extends Job { public void doJob() throws Exception { @@ -38,34 +39,57 @@ private void setCurrencyListToShop(ShopDTO shop, JSONArray currencyJsonArray) { currencyShop = new CurrencyShopDTO(shop); currencyShop.save(); } - - // TODO check array on currency if true - find anr rewrite - - for (Object object : currencyJsonArray) { - JSONObject jsonObject = (JSONObject) object; - CurrencyDTO currency = getCurrency(jsonObject, currencyShop); - currencyShop.addCurrency(currency); + // TODO check array on currency if true - find and rewrite + if (currencyShop.currencyList.isEmpty()) { + for (Object object : currencyJsonArray) { + JSONObject jsonObject = (JSONObject) object; + CurrencyDTO currency = getCurrency(jsonObject); + currency.save(); + currencyShop.addCurrency(currency); + } + System.out.println("currencyList in job is empty => " + currencyShop.currencyList); + } else { + for (Object object : currencyJsonArray) { + JSONObject jsonObject = (JSONObject) object; + for (CurrencyDTO _currency : currencyShop.currencyList){ + _currency.ccy = (String) jsonObject.get("ccy"); + _currency.base_ccy = (String) jsonObject.get("base_ccy"); + _currency.buy = Double.parseDouble((String) jsonObject.get("buy")); + _currency.sale = Double.parseDouble((String) jsonObject.get("sale")); + _currency.save(); + } + } + System.out.println("currencyList in job is full => " + currencyShop.currencyList); } + currencyShop.save(); } - private CurrencyDTO getCurrency(JSONObject jsonObject, CurrencyShopDTO currencyShop) { + private CurrencyDTO updateCurrency(JSONObject jsonObject, CurrencyDTO currency) { String ccy = (String) jsonObject.get("ccy"); String baseCurrency = (String) jsonObject.get("base_ccy"); double buy = Double.parseDouble((String) jsonObject.get("buy")); double sale = Double.parseDouble((String) jsonObject.get("sale")); - CurrencyDTO currency = CurrencyDTO.find("byCurrencyShop", currencyShop).first(); - if (currency == null) { - currency = new CurrencyDTO(ccy, baseCurrency, buy, sale); - } else { - currency.ccy = ccy; - currency.base_ccy = baseCurrency; - currency.buy = buy; - currency.sale = sale; - } - currency.save(); + currency.ccy = ccy; + currency.base_ccy = baseCurrency; + currency.buy = buy; + currency.sale = sale; + + return currency; + + } + + private CurrencyDTO getCurrency(JSONObject jsonObject) { + + String ccy = (String) jsonObject.get("ccy"); + String baseCurrency = (String) jsonObject.get("base_ccy"); + double buy = Double.parseDouble((String) jsonObject.get("buy")); + double sale = Double.parseDouble((String) jsonObject.get("sale")); + + CurrencyDTO currency = new CurrencyDTO(ccy, baseCurrency, buy, sale); + return currency; } diff --git a/app/models/CurrencyDTO.java b/app/models/CurrencyDTO.java index c5d31beea..f7a432bdd 100644 --- a/app/models/CurrencyDTO.java +++ b/app/models/CurrencyDTO.java @@ -27,7 +27,7 @@ public class CurrencyDTO extends GenericModel { @Expose public double sale; - @ManyToOne(cascade = CascadeType.ALL) + @ManyToOne public CurrencyShopDTO currencyShop; public CurrencyDTO(String ccy, String base_ccy, double buy, double sale){ diff --git a/app/models/CurrencyShopDTO.java b/app/models/CurrencyShopDTO.java index 5bd286b17..db65f953c 100644 --- a/app/models/CurrencyShopDTO.java +++ b/app/models/CurrencyShopDTO.java @@ -26,7 +26,7 @@ public class CurrencyShopDTO extends GenericModel { @Expose @OneToMany(cascade=CascadeType.ALL) - List currencyList; + public List currencyList; public void addCurrency(CurrencyDTO currency){ if (this.currencyList == null){ @@ -37,10 +37,8 @@ public void addCurrency(CurrencyDTO currency){ public CurrencyShopDTO(ShopDTO shop) { this.shop = shop; - currency = "USD"; - if(currencyList == null) { - currencyList = new ArrayList(); - } + this.currency = "USD"; + this.currencyList = new ArrayList(); } From 93988f1040548a4691e0c85d70fd92282ede761f Mon Sep 17 00:00:00 2001 From: Aleksander Date: Tue, 22 Dec 2020 21:14:49 +0200 Subject: [PATCH 07/91] wip currency for shop: fixed updating currency --- app/jobs/GetDailyCurrency.java | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/app/jobs/GetDailyCurrency.java b/app/jobs/GetDailyCurrency.java index 8fa9e2498..e932b2af9 100644 --- a/app/jobs/GetDailyCurrency.java +++ b/app/jobs/GetDailyCurrency.java @@ -14,7 +14,7 @@ import java.util.ArrayList; import java.util.List; -@Every("1min") +@Every("6h") public class GetDailyCurrency extends Job { public void doJob() throws Exception { @@ -39,29 +39,18 @@ private void setCurrencyListToShop(ShopDTO shop, JSONArray currencyJsonArray) { currencyShop = new CurrencyShopDTO(shop); currencyShop.save(); } - // TODO check array on currency if true - find and rewrite if (currencyShop.currencyList.isEmpty()) { for (Object object : currencyJsonArray) { JSONObject jsonObject = (JSONObject) object; - CurrencyDTO currency = getCurrency(jsonObject); - currency.save(); - currencyShop.addCurrency(currency); + currencyShop.addCurrency(getCurrency(jsonObject)); } - System.out.println("currencyList in job is empty => " + currencyShop.currencyList); } else { - for (Object object : currencyJsonArray) { - JSONObject jsonObject = (JSONObject) object; - for (CurrencyDTO _currency : currencyShop.currencyList){ - _currency.ccy = (String) jsonObject.get("ccy"); - _currency.base_ccy = (String) jsonObject.get("base_ccy"); - _currency.buy = Double.parseDouble((String) jsonObject.get("buy")); - _currency.sale = Double.parseDouble((String) jsonObject.get("sale")); - _currency.save(); - } + for (int i = 0; i < currencyJsonArray.size(); i++) { + JSONObject jsonObject = (JSONObject) currencyJsonArray.get(i); + updateCurrency(jsonObject, currencyShop.currencyList.get(i)); } System.out.println("currencyList in job is full => " + currencyShop.currencyList); } - currencyShop.save(); } @@ -76,7 +65,7 @@ private CurrencyDTO updateCurrency(JSONObject jsonObject, CurrencyDTO currency) currency.base_ccy = baseCurrency; currency.buy = buy; currency.sale = sale; - + currency.save(); return currency; } @@ -89,7 +78,7 @@ private CurrencyDTO getCurrency(JSONObject jsonObject) { double sale = Double.parseDouble((String) jsonObject.get("sale")); CurrencyDTO currency = new CurrencyDTO(ccy, baseCurrency, buy, sale); - + currency.save(); return currency; } From 93adcf2cd3d7160bd8df90744e4245f6dd3ea0d6 Mon Sep 17 00:00:00 2001 From: Aleksander Date: Wed, 23 Dec 2020 16:54:07 +0200 Subject: [PATCH 08/91] added currency to admin in profile page --- app/jobs/GetDailyCurrency.java | 3 +- app/models/CurrencyShopDTO.java | 2 +- app/views/Application/admin.html | 1 + .../admin/js/directives/CurrencySelect.js | 51 +++++++++++++++++++ .../js/directives/LanguageSelectDirective.js | 2 +- 5 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 wisehands/admin/js/directives/CurrencySelect.js diff --git a/app/jobs/GetDailyCurrency.java b/app/jobs/GetDailyCurrency.java index e932b2af9..b5ca0f0d1 100644 --- a/app/jobs/GetDailyCurrency.java +++ b/app/jobs/GetDailyCurrency.java @@ -19,7 +19,7 @@ public class GetDailyCurrency extends Job { public void doJob() throws Exception { - WS.HttpResponse response = WS.url("https://api.privatbank.ua/p24api/pubinfo?exchange&json&coursid=11").get(); + WS.HttpResponse response = WS.url("https://api.privatbank.ua/p24api/pubinfo?exchange&json&coursid=12").get(); String currencyJson = response.getString(); if (!currencyJson.isEmpty()){ JSONParser parser = new JSONParser(); @@ -33,7 +33,6 @@ public void doJob() throws Exception { } private void setCurrencyListToShop(ShopDTO shop, JSONArray currencyJsonArray) { - CurrencyShopDTO currencyShop = CurrencyShopDTO.find("byShop", shop).first(); if (currencyShop == null){ currencyShop = new CurrencyShopDTO(shop); diff --git a/app/models/CurrencyShopDTO.java b/app/models/CurrencyShopDTO.java index db65f953c..ffbedfbef 100644 --- a/app/models/CurrencyShopDTO.java +++ b/app/models/CurrencyShopDTO.java @@ -37,7 +37,7 @@ public void addCurrency(CurrencyDTO currency){ public CurrencyShopDTO(ShopDTO shop) { this.shop = shop; - this.currency = "USD"; + this.currency = "UAH"; this.currencyList = new ArrayList(); } diff --git a/app/views/Application/admin.html b/app/views/Application/admin.html index 91d2c3721..665b23639 100644 --- a/app/views/Application/admin.html +++ b/app/views/Application/admin.html @@ -152,6 +152,7 @@
Wise + diff --git a/wisehands/admin/js/directives/CurrencySelect.js b/wisehands/admin/js/directives/CurrencySelect.js new file mode 100644 index 000000000..10b297d7d --- /dev/null +++ b/wisehands/admin/js/directives/CurrencySelect.js @@ -0,0 +1,51 @@ +angular.module('WiseHands') + .directive('ngTranslateLanguageSelect', ['LocaleService', function (LocaleService) { 'use strict'; + + return { + restrict: 'A', + replace: true, + template: ''+ + '
'+ + '

'+ + '{{"directives.language-select.Language" | translate}}:'+ + ''+ + '

'+ + '
'+ + '', + controller: ['$scope','$http', function ($scope, $http) { + $scope.currentLocaleDisplayName = LocaleService.getLocaleDisplayName(); + $scope.localesDisplayNames = LocaleService.getLocalesDisplayNames(); + $scope.visible = $scope.localesDisplayNames && + $scope.localesDisplayNames.length > 1; + + $scope.changeLanguage = function (locale) { + LocaleService.setLocaleByDisplayName(locale); + + }; + $scope.changeLocale = function (language) { + var currentLocale = ''; + if (language === 'Українська') { + currentLocale = 'uk_UA' + } else if (language === 'English') { + currentLocale = 'en_US' + } else if (language === 'Polski') { + currentLocale = 'pl_PL' + } + $http({ + method: 'PUT', + url: '/shop/' + currentLocale + }) + .success(function (response) { + localStorage.setItem('locale', currentLocale); + }). + error(function (response) { + $scope.loading = false; + console.log(response); + }); + }; + }] + }; + }]); \ No newline at end of file diff --git a/wisehands/admin/js/directives/LanguageSelectDirective.js b/wisehands/admin/js/directives/LanguageSelectDirective.js index 10b297d7d..c1c0cdfa0 100644 --- a/wisehands/admin/js/directives/LanguageSelectDirective.js +++ b/wisehands/admin/js/directives/LanguageSelectDirective.js @@ -1,5 +1,5 @@ angular.module('WiseHands') - .directive('ngTranslateLanguageSelect', ['LocaleService', function (LocaleService) { 'use strict'; + .directive('ngCurrencySelect', ['LocaleService', function (LocaleService) { 'use strict'; return { restrict: 'A', From 626f7efad3a7201854fd1c6216bb4cda4c082858 Mon Sep 17 00:00:00 2001 From: Aleksander Date: Wed, 23 Dec 2020 17:30:33 +0200 Subject: [PATCH 09/91] Changed label in currency container --- wisehands/admin/js/directives/LanguageSelectDirective.js | 2 +- wisehands/admin/resources/locale-en_US.json | 1 + wisehands/admin/resources/locale-uk_UA.json | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/wisehands/admin/js/directives/LanguageSelectDirective.js b/wisehands/admin/js/directives/LanguageSelectDirective.js index c1c0cdfa0..63333155c 100644 --- a/wisehands/admin/js/directives/LanguageSelectDirective.js +++ b/wisehands/admin/js/directives/LanguageSelectDirective.js @@ -7,7 +7,7 @@ angular.module('WiseHands') template: ''+ '
'+ '

'+ - '{{"directives.language-select.Language" | translate}}:'+ + '{{"directives.currency-select.Currency" | translate}}:'+ ''+ diff --git a/wisehands/admin/js/directives/LanguageSelectDirective.js b/wisehands/admin/js/directives/LanguageSelectDirective.js index 63333155c..10b297d7d 100644 --- a/wisehands/admin/js/directives/LanguageSelectDirective.js +++ b/wisehands/admin/js/directives/LanguageSelectDirective.js @@ -1,5 +1,5 @@ angular.module('WiseHands') - .directive('ngCurrencySelect', ['LocaleService', function (LocaleService) { 'use strict'; + .directive('ngTranslateLanguageSelect', ['LocaleService', function (LocaleService) { 'use strict'; return { restrict: 'A', @@ -7,7 +7,7 @@ angular.module('WiseHands') template: ''+ '

'+ '

'+ - '{{"directives.currency-select.Currency" | translate}}:'+ + '{{"directives.language-select.Language" | translate}}:'+ ' +
+ +
+ +
+

+
+

+
+
@@ -955,6 +976,12 @@

Створення магазину

const wizardPost = document.getElementById('wizardPost').checked; const wizardSelftake = document.getElementById('wizardSelftake').checked; + const uahCurrency = document.getElementById('wizardSelftake').checked; + const usdCurrency = document.getElementById('wizardSelftake').checked; + const eurCurrency = document.getElementById('wizardSelftake').checked; + + + const deliveryVariantsError = document.getElementById('handle-delivery-error'); const isSelectedDeliveryType = wizardСourier || wizardPost || wizardSelftake; From 8402b552e24aca4127d1d321c8eaa6f25a7f376a Mon Sep 17 00:00:00 2001 From: Aleksander Date: Thu, 14 Jan 2021 17:15:24 +0200 Subject: [PATCH 28/91] added currency in wizard page --- app/controllers/UserDashBoardAPI.java | 10 +++++-- app/controllers/WizardAPI.java | 16 ++++++++++ app/models/CurrencyShopDTO.java | 10 +++---- app/models/ProductDTO.java | 5 ++-- app/models/ShopDTO.java | 5 +++- app/models/WizardDTO.java | 3 ++ app/services/ShoppingCartService.java | 4 +++ app/services/querying/DataBaseQueries.java | 2 +- app/views/Application/product.html | 2 +- app/views/Application/uaNewWizard.html | 35 ++++++++++++++-------- app/views/WiseHands/index.html | 34 +++++++++++++-------- 11 files changed, 87 insertions(+), 39 deletions(-) diff --git a/app/controllers/UserDashBoardAPI.java b/app/controllers/UserDashBoardAPI.java index 98908614d..58f219528 100644 --- a/app/controllers/UserDashBoardAPI.java +++ b/app/controllers/UserDashBoardAPI.java @@ -70,13 +70,18 @@ public static void createShop() throws Exception{ BalanceDTO balance = new BalanceDTO(); VisualSettingsDTO visualSettings = new VisualSettingsDTO(); + CurrencyShopDTO currencyShop = new CurrencyShopDTO(); + currencyShop.currencyShop = user.wizard.shopCurrency; + ShopDTO shop = new ShopDTO(users, paymentSettings, delivery, contact, balance, visualSettings, user.wizard.shopName, - "public liqpay key here", "private liqpay key here", user.wizard.shopDomain, "uk_UA" - ); + "public liqpay key here", "private liqpay key here", user.wizard.shopDomain, + "uk_UA", currencyShop); shop.googleStaticMapsApiKey = "AIzaSyCcBhIqH-XMcNu99hnEKvWIZTrazd9XgXg"; shop.googleMapsApiKey = "AIzaSyAuKg9jszEEgoGfUlIqmd4n9czbQsgcYRM"; visualSettings.shop = shop; + currencyShop.shop = shop; + currencyShop.save(); _appendDomainToList(user.wizard.shopDomain); shop.save(); @@ -84,6 +89,7 @@ public static void createShop() throws Exception{ } + private static void setTranslationForCashPaymentLabel(PaymentSettingsDTO payment) { if (payment.manualPaymentTitleTranslationBucket == null){ System.out.println("delivery.selfTakeTranslationBucket is null and will be creating NEW"); diff --git a/app/controllers/WizardAPI.java b/app/controllers/WizardAPI.java index b08cf4ee0..81f9addd1 100644 --- a/app/controllers/WizardAPI.java +++ b/app/controllers/WizardAPI.java @@ -128,6 +128,11 @@ public static void setVariantsOfDeliveryAndPaymentTypes() throws Exception{ boolean courierDelivery = (boolean) jsonBody.get("courierDelivery"); boolean postDepartment = (boolean) jsonBody.get("postDepartment"); boolean selfTake = (boolean) jsonBody.get("selfTake"); + + boolean uah = (boolean) jsonBody.get("uahCurrency"); + boolean usd = (boolean) jsonBody.get("usdCurrency"); + boolean eur = (boolean) jsonBody.get("eurCurrency"); + boolean payCash = true; boolean payOnline = false; @@ -141,12 +146,23 @@ public static void setVariantsOfDeliveryAndPaymentTypes() throws Exception{ user.wizard.selfTake = selfTake; user.wizard.payCash = payCash; user.wizard.payOnline = payOnline; + user.wizard.shopCurrency = setCurrencyToShop(uah, usd, eur); user.wizard.save(); renderJSON(json(user.wizard)); } + private static String setCurrencyToShop(boolean uah, boolean usd, boolean eur) { + if (uah){ + return "UAH"; + } else if (usd) { + return "USD"; + } else { + return "EUR"; + } + } + public static void setSocialNetworkInfo() throws Exception{ String facebookLink = request.params.get("facebook"); diff --git a/app/models/CurrencyShopDTO.java b/app/models/CurrencyShopDTO.java index cdbc6bb91..3b9631c51 100644 --- a/app/models/CurrencyShopDTO.java +++ b/app/models/CurrencyShopDTO.java @@ -6,12 +6,8 @@ import util.CurrencySign; import javax.persistence.*; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; import static org.codehaus.groovy.runtime.DefaultGroovyMethods.round; @@ -44,13 +40,15 @@ public void addCurrency(CurrencyDTO currency){ this.currencyList.add(currency); } + public CurrencyShopDTO() { } + public CurrencyShopDTO(ShopDTO shop) { this.shop = shop; this.currencyShop = "UAH"; this.currencyList = new ArrayList(); } - public char currencyFormat(String currencyValue){ + public char currencyFormat(String currencyValue) { if (currencyValue.isEmpty()) { currencyValue = this.currencyShop; } @@ -71,7 +69,7 @@ public double formatPrice(ProductDTO product) { } else if (isSelectedCurrencyEqualShopCurrency){ return product.formatPrice(); } else { - return round(product.productPriceCurrency, 2); + return round(product.priceInCurrency, 2); } } diff --git a/app/models/ProductDTO.java b/app/models/ProductDTO.java index 1e373e2f1..d460bba7b 100644 --- a/app/models/ProductDTO.java +++ b/app/models/ProductDTO.java @@ -31,6 +31,8 @@ public class ProductDTO extends GenericModel { @Expose public Double oldPrice; + @Expose + public double priceInCurrency; @Expose public String fileName; @@ -87,9 +89,6 @@ public class ProductDTO extends GenericModel { @OneToOne(cascade=CascadeType.ALL) public TranslationBucketDTO productDescriptionTextTranslationBucket; - @Expose - public double productPriceCurrency; - public void addFeedback(FeedbackDTO orderFeedback) { if(this.feedbackList == null) { this.feedbackList = new ArrayList(); diff --git a/app/models/ShopDTO.java b/app/models/ShopDTO.java index d55ec4fcb..c470ab7b3 100644 --- a/app/models/ShopDTO.java +++ b/app/models/ShopDTO.java @@ -124,6 +124,7 @@ public class ShopDTO extends GenericModel { @Expose public String locale; + @Expose @OneToOne(cascade=CascadeType.ALL) public CurrencyShopDTO currencyShop; @@ -205,7 +206,8 @@ public ShopDTO(List users, String liqpayPublicKey, String liqpayPrivateKey, String customDomain, - String locale) { + String locale, + CurrencyShopDTO currencyShop) { this.userList = users; @@ -227,6 +229,7 @@ public ShopDTO(List users, this.locale = locale; this.alwaysOpen = true; this.isTemporaryClosed = false; + this.currencyShop = currencyShop; } diff --git a/app/models/WizardDTO.java b/app/models/WizardDTO.java index f939908d9..6c7feb4c2 100644 --- a/app/models/WizardDTO.java +++ b/app/models/WizardDTO.java @@ -50,6 +50,9 @@ public class WizardDTO extends GenericModel { @Expose public boolean payCash; + @Expose + public String shopCurrency; + @Expose public String facebookLink; diff --git a/app/services/ShoppingCartService.java b/app/services/ShoppingCartService.java index 8fc361136..75173421f 100644 --- a/app/services/ShoppingCartService.java +++ b/app/services/ShoppingCartService.java @@ -97,6 +97,10 @@ public static String addProduct(String client) throws ParseException { String quantityParam = request.params.get("quantity"); int quantity = _getProductQuantity(quantityParam); + if (product.priceInCurrency != 0){ + product.price = product.priceInCurrency; + } + LineItem lineItem = new LineItem( product.uuid, product.name, product.mainImage.filename, quantity, product.price, shop, additionOrderDTOList, diff --git a/app/services/querying/DataBaseQueries.java b/app/services/querying/DataBaseQueries.java index 539445927..3d08d2ec8 100644 --- a/app/services/querying/DataBaseQueries.java +++ b/app/services/querying/DataBaseQueries.java @@ -17,7 +17,7 @@ public static void changePriceAccordingToCurrency(ProductDTO product, ShopDTO sh boolean isSelectedCurrencyNotEqualShopCurrency = !currencyShop.selectedCurrency.equals(currencyShop.currencyShop); if (isSelectedCurrencyNotEqualShopCurrency) { CurrencyDTO currency = CurrencyDTO.find("select c from CurrencyDTO c where c.ccy = ?1", selectedCurrency).first(); - product.productPriceCurrency = product.price / currency.sale; + product.priceInCurrency = product.price / currency.sale; product.save(); } currencyShop.save(); diff --git a/app/views/Application/product.html b/app/views/Application/product.html index 9717ae3f0..0bc72f40c 100644 --- a/app/views/Application/product.html +++ b/app/views/Application/product.html @@ -439,7 +439,7 @@ } return; } - console.log("here uuid: ", uuid, additionList); + console.log("here product uuid => ", uuid, additionList); fetch('/api/cart?uuid=' + uuid + '&additionList=' + JSON.stringify(additionList), { method: 'POST' }).then(function (response) { diff --git a/app/views/Application/uaNewWizard.html b/app/views/Application/uaNewWizard.html index a5ffada9d..7576dbe58 100644 --- a/app/views/Application/uaNewWizard.html +++ b/app/views/Application/uaNewWizard.html @@ -225,7 +225,7 @@ right: 50%; } - #handle-delivery-error { + #handle-delivery-error, #handle-currency-error { color: red; margin-bottom: 0; margin-left: 60px; @@ -804,14 +804,14 @@

Створення магазину

-

Виберіть валюту для магазину

+

Виберіть одну валюту для магазину

- +
- +
- +
@@ -976,23 +976,32 @@

Створення магазину

const wizardPost = document.getElementById('wizardPost').checked; const wizardSelftake = document.getElementById('wizardSelftake').checked; - const uahCurrency = document.getElementById('wizardSelftake').checked; - const usdCurrency = document.getElementById('wizardSelftake').checked; - const eurCurrency = document.getElementById('wizardSelftake').checked; + const uah = document.getElementById('wizardUah').checked; + const usd = document.getElementById('wizardUsd').checked; + const eur = document.getElementById('wizardEur').checked; const deliveryVariantsError = document.getElementById('handle-delivery-error'); - const isSelectedDeliveryType = wizardСourier || wizardPost || wizardSelftake; + const isSelectedDeliveryType = wizardСourier || wizardPost || wizardSelftake; + + const errorMessage = 'Виберіть один із варіантів'; + deliveryVariantsError.innerText = isSelectedDeliveryType ? '' : errorMessage; + if (!isSelectedDeliveryType) return; + + const currencyVariantsError = document.getElementById('handle-currency-error'); + const isSelectedCurrencyType = uah || usd || eur; - const errorMessage = 'Виберіть один із варіантів'; - deliveryVariantsError.innerText = isSelectedDeliveryType ? '' : errorMessage; - if (!isSelectedDeliveryType) return; + currencyVariantsError.innerText = isSelectedCurrencyType ? '' : errorMessage; + if (!isSelectedCurrencyType) return; const toolInfo = { courierDelivery: wizardСourier, postDepartment: wizardPost, - selfTake: wizardSelftake + selfTake: wizardSelftake, + uahCurrency: uah, + usdCurrency: usd, + eurCurrency: eur }; console.log('toolInfo', toolInfo); const bodyParams = JSON.stringify(toolInfo); diff --git a/app/views/WiseHands/index.html b/app/views/WiseHands/index.html index a3510f9f2..ee1cbb675 100644 --- a/app/views/WiseHands/index.html +++ b/app/views/WiseHands/index.html @@ -238,7 +238,7 @@

Team

-
+

Bogdan

@@ -624,17 +624,27 @@
Contact Information
From 1dca68c989205876920ebedb6b4a237e876bec3c Mon Sep 17 00:00:00 2001 From: Aleksander Date: Thu, 28 Jan 2021 15:49:43 +0200 Subject: [PATCH 42/91] fixed link to product page --- app/controllers/Application.java | 57 ++++++++++++++++++-------------- app/models/ProductDTO.java | 12 +++---- app/views/Application/shop.html | 17 +++------- app/views/tags/shop-header.html | 28 ++++++++++------ 4 files changed, 60 insertions(+), 54 deletions(-) diff --git a/app/controllers/Application.java b/app/controllers/Application.java index c8cc1588e..d95e23f0e 100644 --- a/app/controllers/Application.java +++ b/app/controllers/Application.java @@ -103,6 +103,7 @@ public static void wisehands(String client) { } public static void languageChooser(String client) { + System.out.println(" --- executing languageChooser ---"); ShopDTO shop = ShopDTO.find("byDomain", client).first(); if (shop == null) { shop = ShopDTO.find("byDomain", "localhost").first(); @@ -194,6 +195,8 @@ private static CurrencyShopDTO setCurrencyToShop(ShopDTO shop) { public static void index(String client, String language) { System.out.println("client info " + client); + System.out.println(" --- executing index ---"); + ShopDTO shop = ShopDTO.find("byDomain", client).first(); if (shop == null) { shop = ShopDTO.find("byDomain", "localhost").first(); @@ -238,6 +241,8 @@ public static void index(String client, String language) { if (request.params.get("currency") != null){ selectedCurrency = request.params.get("currency"); } + + shop.currencyShop = setCurrencyToShop(shop); List productList = new ArrayList(); List products; @@ -272,6 +277,7 @@ public static void index(String client, String language) { public static void shop(String client, String language) { Date date = new Date(); + System.out.println(" --- executing shop ---"); ShopDTO shop = ShopDTO.find("byDomain", client).first(); if (shop == null) { @@ -357,6 +363,7 @@ public static void category(String client, String uuid, String language){ if (shop == null) { shop = ShopDTO.find("byDomain", "localhost").first(); } + System.out.println(" --- executing category ---"); Http.Header acceptLanguage = request.headers.get("accept-language"); String languageFromHeader = LanguageForShop.getLanguageFromAcceptHeaders(acceptLanguage); @@ -414,6 +421,7 @@ public static void productOld(String client, String uuid) { } public static void product(String client, String uuid, String language){ + System.out.println(" --- executing product ---"); ShopDTO shop = ShopDTO.find("byDomain", client).first(); if (shop == null){ shop = ShopDTO.find("byDomain", "localhost").first(); @@ -635,30 +643,6 @@ public static String generateTokenForCookie(String shoppingCartId, String userAg return token; } - public static void orderFeedback(String client, String uuid) { - ShopDTO shop = ShopDTO.find("byDomain", client).first(); - if (shop == null) { - shop = ShopDTO.find("byDomain", "localhost").first(); - } - OrderDTO order = OrderDTO.find("byUuid",uuid).first(); - boolean isSendRequest = order.feedbackRequestState.equals(FeedbackRequestState.REQUEST_SENT); - String shopName = shop.shopName; - - Http.Header acceptLanguage = request.headers.get("accept-language"); - String languageFromHeader = LanguageForShop.getLanguageFromAcceptHeaders(acceptLanguage); - String language = LanguageForShop.setLanguageForShop(null, languageFromHeader); - List orderItemList = order.items; - for(OrderItemDTO _orderItem: orderItemList){ - ProductDTO product = ProductDTO.findById(_orderItem.productUuid); - product = Translation.setTranslationForProduct(language, product); - _orderItem.name = product.name; - _orderItem.description = product.description; - } - - String currency = "UAH"; - renderTemplate("Application/orderFeedback.html", shop, order, isSendRequest, currency, language, shopName); - } - public static void shoppingCart(String client, String uuid, String language){ ShopDTO shop = ShopDTO.find("byDomain", client).first(); if (shop == null){ @@ -705,6 +689,31 @@ private static String setSelectedCurrency(ShopDTO shop) { } } + public static void orderFeedback(String client, String uuid) { + ShopDTO shop = ShopDTO.find("byDomain", client).first(); + if (shop == null) { + shop = ShopDTO.find("byDomain", "localhost").first(); + } + OrderDTO order = OrderDTO.find("byUuid",uuid).first(); + boolean isSendRequest = order.feedbackRequestState.equals(FeedbackRequestState.REQUEST_SENT); + String shopName = shop.shopName; + + Http.Header acceptLanguage = request.headers.get("accept-language"); + String languageFromHeader = LanguageForShop.getLanguageFromAcceptHeaders(acceptLanguage); + String language = LanguageForShop.setLanguageForShop(null, languageFromHeader); + List orderItemList = order.items; + for(OrderItemDTO _orderItem: orderItemList){ + ProductDTO product = ProductDTO.findById(_orderItem.productUuid); + product = Translation.setTranslationForProduct(language, product); + _orderItem.name = product.name; + _orderItem.description = product.description; + } + + String currency = "UAH"; + renderTemplate("Application/orderFeedback.html", shop, order, isSendRequest, currency, language, shopName); + } + + public static void done(String client) { ShopDTO shop = ShopDTO.find("byDomain", client).first(); if (shop == null) { diff --git a/app/models/ProductDTO.java b/app/models/ProductDTO.java index efe84360b..528972007 100644 --- a/app/models/ProductDTO.java +++ b/app/models/ProductDTO.java @@ -159,14 +159,14 @@ public String formatDecimalOldPrice() { public String getLinkToProductPage(ProductDTO product, String language, String qr_uuid, String selectedCurrency){ String link = "/" + language +"/product/" + product.uuid; - if (qr_uuid.isEmpty() && selectedCurrency.isEmpty()){ - return link; - } else if (!qr_uuid.isEmpty()) { + if (!qr_uuid.isEmpty() && !selectedCurrency.isEmpty()){ + return link + "?qr_uuid=" + qr_uuid + "¤cy=" + selectedCurrency; + } else if (!qr_uuid.isEmpty() && selectedCurrency.isEmpty()) { return link + "?qr_uuid=" + qr_uuid; - } else if (!selectedCurrency.isEmpty()) { - return link + "?selectedCurrency=" + selectedCurrency; + } else if (!selectedCurrency.isEmpty() && qr_uuid.isEmpty()) { + return link + "?currency=" + selectedCurrency; } else { - return link + "?qr_uuid=" + qr_uuid + "&selectedCurrency=" + selectedCurrency; + return link; } } diff --git a/app/views/Application/shop.html b/app/views/Application/shop.html index d848a578b..38b352da0 100644 --- a/app/views/Application/shop.html +++ b/app/views/Application/shop.html @@ -205,23 +205,14 @@
- #{if qr_uuid || selectedCurrency} - %{qrParam = "?qr_uuid="; currencyParam = "¤cy="}% - - ${_product.name} - - #{/if} - #{else} - + ${_product.name} - #{/else}

- + ${_product.name}

@@ -261,13 +252,13 @@

}%
- +

${_product.name}

${_product.description}

diff --git a/app/views/tags/shop-header.html b/app/views/tags/shop-header.html index b7ba6c38c..b412555c5 100644 --- a/app/views/tags/shop-header.html +++ b/app/views/tags/shop-header.html @@ -197,9 +197,9 @@

${shop.shopName}

#{/if} @@ -207,8 +207,8 @@

${shop.shopName}

@@ -273,16 +273,22 @@

${shop.shopName}

const newUrl = url.slice(3); console.log("changeLanguage newUrl => " + newUrl); - if (object.qrUuid){ - window.location = window.location.origin + '/' + object.language + newUrl + '?qr_uuid=' + object.qrUuid; + if (object.qrUuid && object.currency){ + window.location = window.location.origin + '/' + object.language + newUrl + + '?qr_uuid=' + object.qrUuid + '¤cy=' + object.currency; } else { window.location = window.location.origin + '/' + object.language + newUrl; } }; - changeCurrency = (currency) => { - const url = window.location.pathname; - console.log("changeCurrency => " + url); - window.location = window.location.origin + url + '?currency=' + currency; + changeCurrency = (object) => { + const pathname = window.location.pathname; + if (object.qrUuid){ + window.location = window.location.origin + pathname + + '?qr_uuid=' + object.qrUuid + '¤cy=' + object.currency; + } else { + window.location = window.location.origin + pathname + '?currency=' + object.currency; + } + } From 76dd49ee7228931d061e6cb096d617c527094e13 Mon Sep 17 00:00:00 2001 From: Aleksander Date: Thu, 28 Jan 2021 20:41:35 +0200 Subject: [PATCH 43/91] fixed price message --- app/models/CurrencyShopDTO.java | 15 +++++++++++---- app/views/Application/product.html | 9 +++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/app/models/CurrencyShopDTO.java b/app/models/CurrencyShopDTO.java index e9387687c..2340fdda2 100644 --- a/app/models/CurrencyShopDTO.java +++ b/app/models/CurrencyShopDTO.java @@ -73,10 +73,17 @@ public double formatPrice(ProductDTO product) { } } - public String getLinkToProductPage(ProductDTO product, String language, String qr_uuid, String selectedCurrency){ - String link = product.uuid + language + qr_uuid + selectedCurrency; - System.out.println("link => " + link); - return link; + public boolean isDefaultCurrencyNotEqualSelectedCurrency(String selectedCurrency){ + System.out.println("isDefaultCurrencyNotEqualSelectedCurrency selectedCurrency => " + selectedCurrency.isEmpty()); + + if (selectedCurrency.isEmpty()) { + System.out.println("isDefaultCurrencyNotEqualSelectedCurrency isEmpty()" + selectedCurrency.isEmpty()); + return false; + } else { + System.out.println("isDefaultCurrencyNotEqualSelectedCurrency " + !this.currency.equals(selectedCurrency)); + return !(this.currency.equals(selectedCurrency)); + } + } } diff --git a/app/views/Application/product.html b/app/views/Application/product.html index 9f0d6406b..5a96a8221 100644 --- a/app/views/Application/product.html +++ b/app/views/Application/product.html @@ -606,13 +606,14 @@

${product.name}

&{'page.product.price'} - #{if !(shop.currencyShop.currency.equals(selectedCurrency))} - ~ - #{/if} + + #{if shop.currencyShop.isDefaultCurrencyNotEqualSelectedCurrency(selectedCurrency)} + ~ + #{/if} ${shop.currencyShop.showCurrency()} - #{if !(shop.currencyShop.currency.equals(selectedCurrency))} + #{if shop.currencyShop.isDefaultCurrencyNotEqualSelectedCurrency(selectedCurrency)} (${product.formatPrice()} ${shop.currencyShop.currency})

~ &{'page.product.changes.price'}

#{/if} From 2bd3db893ef39f246ab084e87ac7bc9427bc8af3 Mon Sep 17 00:00:00 2001 From: Aleksander Date: Fri, 29 Jan 2021 16:55:06 +0200 Subject: [PATCH 44/91] fixed link into category page --- app/models/CategoryDTO.java | 13 ++++++++++ app/models/ProductDTO.java | 3 +++ app/views/Application/category.html | 39 ++++++++++++++++------------- app/views/Application/product.html | 13 ++++++---- 4 files changed, 45 insertions(+), 23 deletions(-) diff --git a/app/models/CategoryDTO.java b/app/models/CategoryDTO.java index eab57a554..b3f9b34d6 100644 --- a/app/models/CategoryDTO.java +++ b/app/models/CategoryDTO.java @@ -49,5 +49,18 @@ public CategoryDTO(ShopDTO shop, String name, String description) { this.description = description; } + public String getLinkToCategoryPage(String uuid, String language, String qr_uuid, String selectedCurrency){ + String link = "/" + language +"/category/" + uuid; + if (!qr_uuid.isEmpty() && !selectedCurrency.isEmpty()){ + return link + "?qr_uuid=" + qr_uuid + "¤cy=" + selectedCurrency; + } else if (!qr_uuid.isEmpty() && selectedCurrency.isEmpty()) { + return link + "?qr_uuid=" + qr_uuid; + } else if (!selectedCurrency.isEmpty() && qr_uuid.isEmpty()) { + return link + "?currency=" + selectedCurrency; + } else { + return link; + } + } + } diff --git a/app/models/ProductDTO.java b/app/models/ProductDTO.java index 528972007..8a6374d30 100644 --- a/app/models/ProductDTO.java +++ b/app/models/ProductDTO.java @@ -170,4 +170,7 @@ public String getLinkToProductPage(ProductDTO product, String language, String q } } + + + } diff --git a/app/views/Application/category.html b/app/views/Application/category.html index 680dc0ba5..442cc329a 100644 --- a/app/views/Application/category.html +++ b/app/views/Application/category.html @@ -182,7 +182,11 @@
@@ -197,16 +201,24 @@
-

${_product.name}

+

+ + ${_product.name} + +

-

${_product.formatDecimal()} uah

+
+

${shop.currencyShop.formatPrice(_product)} + ${shop.currencyShop.showCurrency()} +

${_product.formatDecimalOldPrice()}

+
@@ -214,18 +226,9 @@

${_product.description}

diff --git a/app/views/Application/product.html b/app/views/Application/product.html index 5a96a8221..1dda9da72 100644 --- a/app/views/Application/product.html +++ b/app/views/Application/product.html @@ -637,7 +637,10 @@

&{'page.product.additions.label'}

${defaultAddition.addition.title}

-

${defaultAddition.addition.formatDecimal()} UAH

+

+ ${defaultAddition.addition.formatDecimal()} + ${shop.currencyShop.showCurrency()} +

%{ } @@ -651,9 +654,6 @@

&{'page.product.additions.label'}

-

${_selectedAddition.addition.title}

@@ -673,7 +673,10 @@

&{'page.product.additions.label'}

-

${_selectedAddition.addition.formatDecimal()} UAH

+

+ ${_selectedAddition.addition.formatDecimal()} + ${shop.currencyShop.showCurrency()} +

%{ } From b3b7c2a39178c5d5d0f2b29028fbed81bfc81991 Mon Sep 17 00:00:00 2001 From: Aleksander Date: Tue, 2 Feb 2021 16:31:51 +0200 Subject: [PATCH 45/91] fixed exchanging for default addition in product page --- app/controllers/Application.java | 35 ++++--- app/models/ProductDTO.java | 2 +- app/services/querying/DataBaseQueries.java | 115 ++++++++++++++++++--- app/views/Application/product.html | 17 ++- 4 files changed, 132 insertions(+), 37 deletions(-) diff --git a/app/controllers/Application.java b/app/controllers/Application.java index d95e23f0e..c6cbebca0 100644 --- a/app/controllers/Application.java +++ b/app/controllers/Application.java @@ -156,7 +156,7 @@ public static void languageChooser(String client) { for (ProductDTO product : products) { product = Translation.setTranslationForProduct(language, product); - DataBaseQueries.changePriceAccordingToCurrency(product, shop, selectedCurrency); + DataBaseQueries.changePriceAccordingToCurrency(product, shop, selectedCurrency, new ArrayList()); productList.add(product); if(qr_uuid == null || qr_uuid.isEmpty()){ int totalPriceForDefaultAdditions = DataBaseQueries.getTotalPriceForDefaultAdditions(product.uuid); @@ -250,7 +250,7 @@ public static void index(String client, String language) { products = ProductDTO.find(query, shop, false, true).fetch(); for (ProductDTO product : products) { product = Translation.setTranslationForProduct(language, product); - DataBaseQueries.changePriceAccordingToCurrency(product, shop, selectedCurrency); + DataBaseQueries.changePriceAccordingToCurrency(product, shop, selectedCurrency, new ArrayList()); productList.add(product); if(qr_uuid == null || qr_uuid.isEmpty()){ int totalPriceForDefaultAdditions = DataBaseQueries.getTotalPriceForDefaultAdditions(product.uuid); @@ -332,7 +332,7 @@ public static void shop(String client, String language) { shop.currencyShop = setCurrencyToShop(shop); for (ProductDTO product : products) { product = Translation.setTranslationForProduct(language, product); - DataBaseQueries.changePriceAccordingToCurrency(product, shop, selectedCurrency); + DataBaseQueries.changePriceAccordingToCurrency(product, shop, selectedCurrency, new ArrayList()); productList.add(product); if(qr_uuid == null || qr_uuid.isEmpty()){ int totalPriceForDefaultAdditions = DataBaseQueries.getTotalPriceForDefaultAdditions(product.uuid); @@ -390,7 +390,7 @@ public static void category(String client, String uuid, String language){ List productList = new ArrayList(); for (ProductDTO product : products) { product = Translation.setTranslationForProduct(language, product); - DataBaseQueries.changePriceAccordingToCurrency(product, shop, selectedCurrency); + DataBaseQueries.changePriceAccordingToCurrency(product, shop, selectedCurrency, new ArrayList()); productList.add(product); if(qr_uuid == null || qr_uuid.isEmpty()){ int totalPriceForDefaultAdditions = DataBaseQueries.getTotalPriceForDefaultAdditions(product.uuid); @@ -447,27 +447,31 @@ public static void product(String client, String uuid, String language){ String additionsListQuery = "select s from SelectedAdditionDTO s where s.isSelected = 1 and s.isDefault = 0 and s.productUuid = ?1"; product.selectedAdditions = SelectedAdditionDTO.find(additionsListQuery, product.uuid).fetch(); - String qr_uuid = null; - int totalPriceForDefaultAdditions = 0; + String qr_uuid = null, selectedCurrency = ""; + double totalPriceForDefaultAdditions = 0; List defaultAdditions = new ArrayList<>(); + + if (request.params.get("currency") != null){ + selectedCurrency = request.params.get("currency"); + } + DataBaseQueries.changePriceAccordingToCurrency(product, shop, selectedCurrency, defaultAdditions); + shop.currencyShop = setCurrencyToShop(shop); + shop.save(); + if (request.params.get("qr_uuid") != null){ qr_uuid = request.params.get("qr_uuid"); DataBaseQueries.hideDefaultAddition(product); } - if(qr_uuid == null || qr_uuid.isEmpty()){ + + if(qr_uuid == null || qr_uuid.isEmpty()) { totalPriceForDefaultAdditions = DataBaseQueries.getTotalPriceForDefaultAdditions(product.uuid); - product.priceWithAdditions = Double.valueOf(totalPriceForDefaultAdditions); + product.priceWithAdditions = DataBaseQueries.exchangeTotalPriceForDefaultAddition(totalPriceForDefaultAdditions, shop, selectedCurrency); + totalPriceForDefaultAdditions = product.priceWithAdditions; defaultAdditions = DataBaseQueries.checkIsAdditionDefaultToProduct(product); product.defaultAdditions = defaultAdditions; + DataBaseQueries.changePriceAccordingToCurrency(product, shop, selectedCurrency, defaultAdditions); } - String selectedCurrency = ""; - if (request.params.get("currency") != null){ - selectedCurrency = request.params.get("currency"); - } - DataBaseQueries.changePriceAccordingToCurrency(product, shop, selectedCurrency); - shop.currencyShop = setCurrencyToShop(shop); - shop.save(); Translation.setTranslationForProduct(language, product); Translation.setTranslationForShop(language, shop); @@ -477,7 +481,6 @@ public static void product(String client, String uuid, String language){ mainShopUrl += "?qr_uuid=" + qr_uuid; urlToCategory += "?qr_uuid=" + qr_uuid; } - render(product, category, categories, shop, language, defaultAdditions, totalPriceForDefaultAdditions, qr_uuid, mainShopUrl, urlToCategory, selectedCurrency); } diff --git a/app/models/ProductDTO.java b/app/models/ProductDTO.java index 8a6374d30..6419324fe 100644 --- a/app/models/ProductDTO.java +++ b/app/models/ProductDTO.java @@ -82,7 +82,7 @@ public class ProductDTO extends GenericModel { public List selectedAdditions; @Expose - @OneToMany(cascade = CascadeType.ALL) + @OneToMany public List defaultAdditions; @Expose diff --git a/app/services/querying/DataBaseQueries.java b/app/services/querying/DataBaseQueries.java index 3b4cc6712..6bebbe54a 100644 --- a/app/services/querying/DataBaseQueries.java +++ b/app/services/querying/DataBaseQueries.java @@ -13,12 +13,13 @@ public class DataBaseQueries { - public static void changePriceAccordingToCurrency(ProductDTO product, ShopDTO shop, String selectedCurrency){ - + public static double exchangeTotalPriceForDefaultAddition(double additionsPrice, ShopDTO shop, String selectedCurrency) { CurrencyShopDTO currencyShop = CurrencyShopDTO.find("byShop", shop).first(); - if (selectedCurrency.isEmpty()){ - currencyShop.selectedCurrency = null; - currencyShop.save(); + if (currencyShop == null) { + return additionsPrice; + } + else if (selectedCurrency.isEmpty()){ + return additionsPrice; } else { currencyShop.selectedCurrency = selectedCurrency; boolean isSelectedCurrencyNotEqualShopCurrency = !currencyShop.currency.equals(currencyShop.selectedCurrency); @@ -26,41 +27,123 @@ public static void changePriceAccordingToCurrency(ProductDTO product, ShopDTO sh if (isSelectedCurrencyNotEqualShopCurrency) { String currencyQuery = "select c from CurrencyDTO c where c.base_ccy = ?1 and c.ccy = ?2"; CurrencyDTO currency = CurrencyDTO.find(currencyQuery, currencyShop.currency, selectedCurrency).first(); - product.priceInCurrency = product.price / currency.sale; - product.save(); + double price = additionsPrice / currency.sale; + return price; } } if (currencyShop.currency.equals("USD")){ if (isSelectedCurrencyNotEqualShopCurrency) { - calculateProductPriceToCurrency(currencyShop.currency, selectedCurrency, product); + if (selectedCurrency.equals("UAH")){ + String currencyQuery = "select c from CurrencyDTO c where c.base_ccy = ?1 and c.ccy = ?2"; + CurrencyDTO currency = CurrencyDTO.find(currencyQuery, selectedCurrency, currencyShop.currency).first(); + return additionsPrice * currency.buy; + } else { + CurrencyDTO currencyDTO = CurrencyDTO.find("select c from CurrencyDTO c where c.ccy = ?1", currencyShop.currency).first(); + CurrencyDTO currencyDTOSelected = CurrencyDTO.find("select c from CurrencyDTO c where c.ccy = ?1", selectedCurrency).first(); + return additionsPrice * (currencyDTO.buy / currencyDTOSelected.buy); + } } } if (currencyShop.currency.equals("EUR")){ if (isSelectedCurrencyNotEqualShopCurrency) { - calculateProductPriceToCurrency(currencyShop.currency, selectedCurrency, product); - + if (selectedCurrency.equals("UAH")){ + String currencyQuery = "select c from CurrencyDTO c where c.base_ccy = ?1 and c.ccy = ?2"; + CurrencyDTO currency = CurrencyDTO.find(currencyQuery, selectedCurrency, currencyShop.currency).first(); + return additionsPrice * currency.buy; + } else { + CurrencyDTO currencyDTO = CurrencyDTO.find("select c from CurrencyDTO c where c.ccy = ?1", currencyShop.currency).first(); + CurrencyDTO currencyDTOSelected = CurrencyDTO.find("select c from CurrencyDTO c where c.ccy = ?1", selectedCurrency).first(); + return additionsPrice * (currencyDTO.buy / currencyDTOSelected.buy); + } } } + return additionsPrice; + } + } + + public static void changePriceAccordingToCurrency(ProductDTO product, ShopDTO shop, String selectedCurrency, List defaultAdditions){ + + CurrencyShopDTO currencyShop = CurrencyShopDTO.find("byShop", shop).first(); + if (selectedCurrency.isEmpty()){ + currencyShop.selectedCurrency = null; + currencyShop.save(); + } else { + currencyShop.selectedCurrency = selectedCurrency; + boolean isSelectedCurrencyNotEqualShopCurrency = !currencyShop.currency.equals(currencyShop.selectedCurrency); + if (currencyShop.currency.equals("UAH") && isSelectedCurrencyNotEqualShopCurrency){ + String currencyQuery = "select c from CurrencyDTO c where c.base_ccy = ?1 and c.ccy = ?2"; + CurrencyDTO currency = CurrencyDTO.find(currencyQuery, currencyShop.currency, selectedCurrency).first(); + product.priceInCurrency = product.price / currency.sale; + exchangeCurrencyForAdditionsInUAHShop(product, currency, defaultAdditions); + product.save(); + } + if (currencyShop.currency.equals("USD") && isSelectedCurrencyNotEqualShopCurrency){ + exchangeCurrencyToProduct(currencyShop.currency, selectedCurrency, product, defaultAdditions); + } + if (currencyShop.currency.equals("EUR") && isSelectedCurrencyNotEqualShopCurrency){ + exchangeCurrencyToProduct(currencyShop.currency, selectedCurrency, product, defaultAdditions); + } currencyShop.save(); } shop.currencyShop = currencyShop; } - private static void calculateProductPriceToCurrency(String shopCurrency, String selectedCurrency, ProductDTO product) { + private static void exchangeCurrencyForAdditionsInUAHShop(ProductDTO product, CurrencyDTO currency, List defaultAdditions) { + if (!defaultAdditions.isEmpty()){ + for (int i = 0; i < defaultAdditions.size(); i++){ + defaultAdditions.get(i).addition.price = defaultAdditions.get(i).addition.price / currency.buy; + } + if (!product.selectedAdditions.isEmpty()){ + for (int i = 0; i < product.selectedAdditions.size(); i++){ + product.selectedAdditions.get(i).addition.price = product.selectedAdditions.get(i).addition.price / currency.sale; + } + } + } + } + + private static void exchangeCurrencyToProduct(String shopCurrency, String selectedCurrency, ProductDTO product, List defaultAdditions) { if (selectedCurrency.equals("UAH")){ String currencyQuery = "select c from CurrencyDTO c where c.base_ccy = ?1 and c.ccy = ?2"; CurrencyDTO currency = CurrencyDTO.find(currencyQuery, selectedCurrency, shopCurrency).first(); product.priceInCurrency = product.price * currency.buy; + exchangeCurrencyForAdditionsInUahSelected(product, currency, defaultAdditions); } else { - product.priceInCurrency = changePriceToUsdOrEurCurrency(shopCurrency, selectedCurrency, product); + product.priceInCurrency = changePriceToUsdOrEurCurrency(shopCurrency, selectedCurrency, product, defaultAdditions); } product.save(); } - private static double changePriceToUsdOrEurCurrency(String currency, String selectedCurrency, ProductDTO product) { - CurrencyDTO currencyToShop = CurrencyDTO.find("select c from CurrencyDTO c where c.ccy = ?1", currency).first(); - CurrencyDTO currencyToShopSelected = CurrencyDTO.find("select c from CurrencyDTO c where c.ccy = ?1", selectedCurrency).first(); - return product.price * (currencyToShop.buy / currencyToShopSelected.buy); + private static void exchangeCurrencyForAdditionsInUahSelected(ProductDTO product, CurrencyDTO currency, List defaultAdditions) { + if (!defaultAdditions.isEmpty()){ + for (int i = 0; i < defaultAdditions.size(); i++){ + defaultAdditions.get(i).addition.price = defaultAdditions.get(i).addition.price * currency.buy; + } + if (!product.selectedAdditions.isEmpty()){ + for (int i = 0; i < product.selectedAdditions.size(); i++){ + product.selectedAdditions.get(i).addition.price = product.selectedAdditions.get(i).addition.price * currency.buy; + } + } + } + } + + private static double changePriceToUsdOrEurCurrency(String currency, String selectedCurrency, ProductDTO product, List defaultAdditions) { + CurrencyDTO currencyDTO = CurrencyDTO.find("select c from CurrencyDTO c where c.ccy = ?1", currency).first(); + CurrencyDTO currencyDTOSelected = CurrencyDTO.find("select c from CurrencyDTO c where c.ccy = ?1", selectedCurrency).first(); + exchangeCurrencyForAdditions(product, currencyDTO, currencyDTOSelected, defaultAdditions); + return product.price * (currencyDTO.buy / currencyDTOSelected.buy); + } + + private static void exchangeCurrencyForAdditions(ProductDTO product, CurrencyDTO currencyDTO, CurrencyDTO currencyDTOSelected, List defaultAdditions) { + if (!defaultAdditions.isEmpty()){ + for (int i = 0; i < defaultAdditions.size(); i++){ + defaultAdditions.get(i).addition.price = defaultAdditions.get(i).addition.price * (currencyDTO.buy / currencyDTOSelected.buy); + } + if (!product.selectedAdditions.isEmpty()){ + for (int i = 0; i < product.selectedAdditions.size(); i++){ + product.selectedAdditions.get(i).addition.price = product.selectedAdditions.get(i).addition.price * (currencyDTO.buy / currencyDTOSelected.buy); + } + } + } } public static List getFeedbackList(ProductDTO product) { diff --git a/app/views/Application/product.html b/app/views/Application/product.html index 1dda9da72..f094a38ea 100644 --- a/app/views/Application/product.html +++ b/app/views/Application/product.html @@ -603,10 +603,8 @@

${product.name}

${product.description}

- &{'page.product.price'} - #{if shop.currencyShop.isDefaultCurrencyNotEqualSelectedCurrency(selectedCurrency)} ~ #{/if} @@ -617,7 +615,17 @@

${product.name}

(${product.formatPrice()} ${shop.currencyShop.currency})

~ &{'page.product.changes.price'}

#{/if} + #{if product.selectedAdditions || product.defaultAdditions} +
+ &{'page.product.additions.label'}: + + +
+ #{/if}
+ @@ -628,7 +636,7 @@

&{'page.product.additions.label'}

%{ - for(defaultAddition in defaultAdditions) { + for(defaultAddition in product.defaultAdditions) { }%
@@ -890,13 +898,14 @@

${shop.shopName}

function _setAdditionsTotalPrice() { if (!additionsTotalPriceContainer) return; let additionsTotalPrice = Number(additionsTotalPriceContainer.getAttribute('total')); + let currency = additionsTotalPriceContainer.getAttribute('currency'); const selectedAdditions = document.querySelectorAll('.add-item'); selectedAdditions.forEach(addition => { const counter = addition.getAttribute('counter'); const additionPrice = Number(addition.getAttribute('price')); additionsTotalPrice += counter * additionPrice; }); - additionsTotalPriceContainer.innerText = additionsTotalPrice + ' UAH'; + additionsTotalPriceContainer.innerText = additionsTotalPrice + ' ' +currency; } From fe30208d3ac61f0e3f993763ba0fcbcfe5653e75 Mon Sep 17 00:00:00 2001 From: Aleksander Date: Tue, 2 Feb 2021 17:01:36 +0200 Subject: [PATCH 46/91] fixed currency label on admin side --- .../admin/js/controllers/CourierDeliveryController.js | 1 + .../admin/js/controllers/EditProductController.js | 10 ++++++---- .../admin/js/controllers/ProductDetailsController.js | 10 ++++++---- .../admin/js/controllers/ProductListController.js | 3 +++ .../admin/js/controllers/SelectAdditionsController.js | 10 ++++++---- wisehands/admin/js/controllers/SideNavController.js | 3 ++- wisehands/admin/partials/courierDelivery.html | 4 ++-- wisehands/admin/partials/editProduct.html | 2 +- wisehands/admin/partials/productDetails.html | 4 ++-- wisehands/admin/partials/products.html | 2 +- wisehands/admin/partials/selectAdditions.html | 2 +- 11 files changed, 31 insertions(+), 20 deletions(-) diff --git a/wisehands/admin/js/controllers/CourierDeliveryController.js b/wisehands/admin/js/controllers/CourierDeliveryController.js index 40c90ba60..b0b208b0b 100644 --- a/wisehands/admin/js/controllers/CourierDeliveryController.js +++ b/wisehands/admin/js/controllers/CourierDeliveryController.js @@ -1,6 +1,7 @@ angular.module('WiseHands') .controller('CourierDeliveryController', ['$scope', '$http', '$location', 'sideNavInit', '$window', function ($scope, $http, $location, sideNavInit, $window) { $scope.loading = true; + $scope.currency = localStorage.getItem('currency'); $http({ method: 'GET', diff --git a/wisehands/admin/js/controllers/EditProductController.js b/wisehands/admin/js/controllers/EditProductController.js index 715455924..1fe2b267a 100644 --- a/wisehands/admin/js/controllers/EditProductController.js +++ b/wisehands/admin/js/controllers/EditProductController.js @@ -3,10 +3,12 @@ angular.module('WiseHands') '$http', '$scope', '$routeParams', '$location', 'signout', '$uibModal', function($http, $scope, $routeParams, $location, signout, $uibModal) { - $scope.uuid = $routeParams.uuid; - $scope.loading = true; - - // Edit image + $scope.uuid = $routeParams.uuid; + $scope.loading = true; + $scope.currency = localStorage.getItem('currency'); + + + // Edit image $scope.editImage = function(image){ if ( image && image.uuid ){ var modal = $uibModal.open({ diff --git a/wisehands/admin/js/controllers/ProductDetailsController.js b/wisehands/admin/js/controllers/ProductDetailsController.js index ba6a595b5..03a6e3b77 100644 --- a/wisehands/admin/js/controllers/ProductDetailsController.js +++ b/wisehands/admin/js/controllers/ProductDetailsController.js @@ -1,9 +1,11 @@ angular.module('WiseHands') .controller('ProductDetailsController', ['$http', '$scope', '$routeParams', '$window', 'signout', function($http, $scope, $routeParams, $window, signout) { - $scope.uuid = $routeParams.uuid; - $scope.loading = true; - - $http({ + $scope.uuid = $routeParams.uuid; + $scope.loading = true; + $scope.currency = localStorage.getItem('currency'); + + + $http({ method: 'GET', url: '/shop/details' }) diff --git a/wisehands/admin/js/controllers/ProductListController.js b/wisehands/admin/js/controllers/ProductListController.js index 578ce9192..228e1e969 100644 --- a/wisehands/admin/js/controllers/ProductListController.js +++ b/wisehands/admin/js/controllers/ProductListController.js @@ -1,6 +1,9 @@ angular.module('WiseHands') .controller('ProductListController', ['$scope', '$http', 'spinnerService', 'sideNavInit', 'signout', function ($scope, $http, spinnerService, sideNavInit, signout) { + + $scope.currency = localStorage.getItem('currency'); + $scope.loading = true; $scope.wrongMessage = false; $scope.getResource = function () { diff --git a/wisehands/admin/js/controllers/SelectAdditionsController.js b/wisehands/admin/js/controllers/SelectAdditionsController.js index cf8fd21f5..2c0a5731f 100644 --- a/wisehands/admin/js/controllers/SelectAdditionsController.js +++ b/wisehands/admin/js/controllers/SelectAdditionsController.js @@ -2,10 +2,12 @@ angular.module('WiseHands') .controller('SelectAdditionsController', ['$scope', '$http', 'sideNavInit', '$routeParams', function ($scope, $http, sideNavInit, $routeParams) { - $scope.addition = {}; - $scope.addition.isSelected = false; - $scope.addition.isDefault = false; - + $scope.addition = {}; + $scope.addition.isSelected = false; + $scope.addition.isDefault = false; + $scope.currency = localStorage.getItem('currency'); + + const productUuid = $routeParams.productUuid; $http({ diff --git a/wisehands/admin/js/controllers/SideNavController.js b/wisehands/admin/js/controllers/SideNavController.js index 0c01fbab4..9222bbe4e 100644 --- a/wisehands/admin/js/controllers/SideNavController.js +++ b/wisehands/admin/js/controllers/SideNavController.js @@ -12,7 +12,8 @@ angular.module('WiseHands') $scope.activeShop = response.data; localStorage.setItem('activeShop', $scope.activeShop.uuid); localStorage.setItem('activeShopName', $scope.activeShop.shopName); - console.log("/shop/details", response); + localStorage.setItem('currency', $scope.activeShop.currencyShop.currency); + console.log("shop in SideNavController", response); }, function errorCallback(response) { }); diff --git a/wisehands/admin/partials/courierDelivery.html b/wisehands/admin/partials/courierDelivery.html index 63d5a27a6..5670f403c 100644 --- a/wisehands/admin/partials/courierDelivery.html +++ b/wisehands/admin/partials/courierDelivery.html @@ -34,14 +34,14 @@

{{'editProduct.general' | translate}}

-

{{'delivery.deliveryPrice' | translate}} ({{'products.currency' | translate}})

+

{{'delivery.deliveryPrice' | translate}} ({{currency}})

Delivery price can't be less than zero

-

{{'delivery.freeDeliveryPrice' | translate}} ({{'products.currency' | translate}})

+

{{'delivery.freeDeliveryPrice' | translate}} ({{currency}})

Minimum order amount for free shipping can't be less than zero

diff --git a/wisehands/admin/partials/editProduct.html b/wisehands/admin/partials/editProduct.html index f4f523c95..66b210d17 100644 --- a/wisehands/admin/partials/editProduct.html +++ b/wisehands/admin/partials/editProduct.html @@ -38,7 +38,7 @@

{{'editProduct.general' | translate}}

- +
diff --git a/wisehands/admin/partials/productDetails.html b/wisehands/admin/partials/productDetails.html index fb1c9962e..83cd6c28d 100644 --- a/wisehands/admin/partials/productDetails.html +++ b/wisehands/admin/partials/productDetails.html @@ -42,7 +42,7 @@
{{product.name}}
- +
{{product.price}} {{product.priceWithAdditions > 0 ? ('+ ') + (product.priceWithAdditions) + (' ') + ('selectAdditions.additionsPrice' | translate) : ''}}
@@ -87,7 +87,7 @@

{{'productDetails.reviews' | translate}}

@@ -181,11 +147,15 @@

{{'editProduct.properties' | translate}}

- +
- - + +

diff --git a/wisehands/assets/angular-image-cropper/angular-image-cropper.js b/wisehands/assets/angular-image-cropper/angular-image-cropper.js index e8e8dc573..0c3d6dcbc 100644 --- a/wisehands/assets/angular-image-cropper/angular-image-cropper.js +++ b/wisehands/assets/angular-image-cropper/angular-image-cropper.js @@ -942,314 +942,314 @@ return /******/ (function(modules) { // webpackBootstrap /* 6 */ /***/ function(module, exports) { - /* - MIT License http://www.opensource.org/licenses/mit-license.php - Author Tobias Koppers @sokra - */ - // css base code, injected by the css-loader - module.exports = function() { - var list = []; - - // return the list of modules as css string - list.toString = function toString() { - var result = []; - for(var i = 0; i < this.length; i++) { - var item = this[i]; - if(item[2]) { - result.push("@media " + item[2] + "{" + item[1] + "}"); - } else { - result.push(item[1]); - } - } - return result.join(""); - }; - - // import a list of modules into the list - list.i = function(modules, mediaQuery) { - if(typeof modules === "string") - modules = [[null, modules, ""]]; - var alreadyImportedModules = {}; - for(var i = 0; i < this.length; i++) { - var id = this[i][0]; - if(typeof id === "number") - alreadyImportedModules[id] = true; - } - for(i = 0; i < modules.length; i++) { - var item = modules[i]; - // skip already imported module - // this implementation is not 100% perfect for weird media query combinations - // when a module is imported multiple times with different media queries. - // I hope this will never occur (Hey this way we have smaller bundles) - if(typeof item[0] !== "number" || !alreadyImportedModules[item[0]]) { - if(mediaQuery && !item[2]) { - item[2] = mediaQuery; - } else if(mediaQuery) { - item[2] = "(" + item[2] + ") and (" + mediaQuery + ")"; - } - list.push(item); - } - } - }; - return list; - }; + /* + MIT License http://www.opensource.org/licenses/mit-license.php + Author Tobias Koppers @sokra + */ + // css base code, injected by the css-loader + module.exports = function() { + var list = []; + + // return the list of modules as css string + list.toString = function toString() { + var result = []; + for(var i = 0; i < this.length; i++) { + var item = this[i]; + if(item[2]) { + result.push("@media " + item[2] + "{" + item[1] + "}"); + } else { + result.push(item[1]); + } + } + return result.join(""); + }; + + // import a list of modules into the list + list.i = function(modules, mediaQuery) { + if(typeof modules === "string") + modules = [[null, modules, ""]]; + var alreadyImportedModules = {}; + for(var i = 0; i < this.length; i++) { + var id = this[i][0]; + if(typeof id === "number") + alreadyImportedModules[id] = true; + } + for(i = 0; i < modules.length; i++) { + var item = modules[i]; + // skip already imported module + // this implementation is not 100% perfect for weird media query combinations + // when a module is imported multiple times with different media queries. + // I hope this will never occur (Hey this way we have smaller bundles) + if(typeof item[0] !== "number" || !alreadyImportedModules[item[0]]) { + if(mediaQuery && !item[2]) { + item[2] = mediaQuery; + } else if(mediaQuery) { + item[2] = "(" + item[2] + ") and (" + mediaQuery + ")"; + } + list.push(item); + } + } + }; + return list; + }; /***/ }, /* 7 */ /***/ function(module, exports, __webpack_require__) { - /* - MIT License http://www.opensource.org/licenses/mit-license.php - Author Tobias Koppers @sokra - */ - var stylesInDom = {}, - memoize = function(fn) { - var memo; - return function () { - if (typeof memo === "undefined") memo = fn.apply(this, arguments); - return memo; - }; - }, - isOldIE = memoize(function() { - return /msie [6-9]\b/.test(window.navigator.userAgent.toLowerCase()); - }), - getHeadElement = memoize(function () { - return document.head || document.getElementsByTagName("head")[0]; - }), - singletonElement = null, - singletonCounter = 0, - styleElementsInsertedAtTop = []; - - module.exports = function(list, options) { - if(false) { - if(typeof document !== "object") throw new Error("The style-loader cannot be used in a non-browser environment"); - } - - options = options || {}; - // Force single-tag solution on IE6-9, which has a hard limit on the # of -
+
Loading...
diff --git a/wisehands/admin/partials/addNewProduct.html b/wisehands/admin/partials/addNewProduct.html index 47a0a788f..e60ed5496 100644 --- a/wisehands/admin/partials/addNewProduct.html +++ b/wisehands/admin/partials/addNewProduct.html @@ -1,5 +1,28 @@ +
+ +
-
+ + + +
+ - diff --git a/wisehands/admin/resources/locale-en_US.json b/wisehands/admin/resources/locale-en_US.json index bfb8e7748..efaa18f5b 100644 --- a/wisehands/admin/resources/locale-en_US.json +++ b/wisehands/admin/resources/locale-en_US.json @@ -262,7 +262,7 @@ "addNewProduct.category": "Category", "addNewProduct.errorChooseCategory": "Category Required", "addNewProduct.createCategory": "Create category", - "addNewProduct.addPhoto": "Add image (size ratio 4:3, e.g. 640*480px)", + "addNewProduct.addPhoto": "Add image.", "addNewProduct.errorLoadPhoto": "Image Required", "addNewProduct.makeMain": "Make the main", "addNewProduct.deletePhoto": "Remove image", diff --git a/wisehands/admin/resources/locale-pl_PL.json b/wisehands/admin/resources/locale-pl_PL.json index 5b982aee1..2a75670d3 100644 --- a/wisehands/admin/resources/locale-pl_PL.json +++ b/wisehands/admin/resources/locale-pl_PL.json @@ -252,7 +252,7 @@ "addNewProduct.category": "Kategoria", "addNewProduct.errorChooseCategory": "Wymagana kategoria", "addNewProduct.createCategory": "Utwórz kategorię", - "addNewProduct.addPhoto": "Dodaj obraz (stosunek stron 4:3, stosunek stron 700 x 525 px)", + "addNewProduct.addPhoto": "Dodaj obraz", "addNewProduct.errorLoadPhoto": "Wymagany obraz", "addNewProduct.makeMain": "Zrób głównym", "addNewProduct.deletePhoto": "Usuń zdjęcie", diff --git a/wisehands/admin/resources/locale-uk_UA.json b/wisehands/admin/resources/locale-uk_UA.json index 693a3f8c2..f9e08cfe6 100644 --- a/wisehands/admin/resources/locale-uk_UA.json +++ b/wisehands/admin/resources/locale-uk_UA.json @@ -255,7 +255,7 @@ "addNewProduct.category": "Категорія", "addNewProduct.errorChooseCategory": "Категорія обов'язкова", "addNewProduct.createCategory": "Створити категорію", - "addNewProduct.addPhoto": "Додати зображення (співвідношення сторін 4:3, наприклад 640*480 пікс.)", + "addNewProduct.addPhoto": "Додати зображення", "addNewProduct.errorLoadPhoto": "Зображення обов'язкове", "addNewProduct.makeMain": "Зробити головною", "addNewProduct.deletePhoto": "Видалити", From 873640a1eb522821f60685e9cd4ca646d5c40a78 Mon Sep 17 00:00:00 2001 From: Reverie Date: Tue, 18 May 2021 02:00:38 +0300 Subject: [PATCH 74/91] add new product page - cropper WIP 0.0.4 --- .../js/controllers/ImageCropperController.js | 3 +- .../controllers/SubmitNewProductController.js | 18 +++---- wisehands/admin/partials/addNewProduct.html | 47 +++++++++---------- 3 files changed, 34 insertions(+), 34 deletions(-) diff --git a/wisehands/admin/js/controllers/ImageCropperController.js b/wisehands/admin/js/controllers/ImageCropperController.js index ce13f6002..3d5af70f5 100644 --- a/wisehands/admin/js/controllers/ImageCropperController.js +++ b/wisehands/admin/js/controllers/ImageCropperController.js @@ -68,8 +68,7 @@ function ImageCropperController( submitCrop: () => { const croppedImage = cropper.getCroppedCanvas().toDataURL(); - const event = new CustomEvent('crop-image', {detail: croppedImage}); - vm.dispatchEvent(event); + $scope.$emit('crop-image', croppedImage); } }); diff --git a/wisehands/admin/js/controllers/SubmitNewProductController.js b/wisehands/admin/js/controllers/SubmitNewProductController.js index dd5da75f4..cf061cfb2 100644 --- a/wisehands/admin/js/controllers/SubmitNewProductController.js +++ b/wisehands/admin/js/controllers/SubmitNewProductController.js @@ -1,10 +1,16 @@ angular.module('WiseHands') .controller('SubmitNewProductController', [ - '$scope', '$location', '$http', '$uibModal', - function ($scope, $location, $http, $uibModal) { + '$scope', '$location', '$http', + function ($scope, $location, $http) { $scope.product = {isActive: true}; $scope.productImages = []; + $scope.$on('crop-image', (event, data) => handleCroppedImage(event, data)); + + const handleCroppedImage = (event, data) => { + $scope.productImages.push(data); + }; + $http({ method: 'GET', url: '/api/category' @@ -32,7 +38,7 @@ angular.module('WiseHands') }; $scope.loadImage = () => { - $('#imageLoader').trigger('click') + $('#imageLoader').trigger('click'); }; const toBase64 = file => new Promise((resolve, reject) => { @@ -57,15 +63,11 @@ angular.module('WiseHands') const file = event.target.files[0]; const convertedFile = await toBase64(file); $scope.product.mainPhoto = 0; - $scope.productImages.push(convertedFile); + $scope.imageToCrop = convertedFile; $scope.loading = false; $scope.$apply(); }; - $scope.cropImage = event => { - console.log(event); - }; - $scope.setMainPhotoIndex = function (index) { if ($scope.product) { $scope.product.mainPhoto = index; diff --git a/wisehands/admin/partials/addNewProduct.html b/wisehands/admin/partials/addNewProduct.html index e60ed5496..6daada54a 100644 --- a/wisehands/admin/partials/addNewProduct.html +++ b/wisehands/admin/partials/addNewProduct.html @@ -52,38 +52,37 @@
{{'addNewProduct.add' | translate}}
-
- +
From 48176548f58f5b9a4edf765c87670937685bed3c Mon Sep 17 00:00:00 2001 From: Reverie Date: Tue, 18 May 2021 03:09:21 +0300 Subject: [PATCH 75/91] add new product page - cropper WIP 0.0.5 --- wisehands/admin/css/admin.css | 17 ------ .../controllers/SubmitNewProductController.js | 1 + wisehands/admin/partials/addNewProduct.html | 61 +++++++++++-------- 3 files changed, 36 insertions(+), 43 deletions(-) diff --git a/wisehands/admin/css/admin.css b/wisehands/admin/css/admin.css index baa6ae899..64c4653f4 100644 --- a/wisehands/admin/css/admin.css +++ b/wisehands/admin/css/admin.css @@ -787,10 +787,6 @@ label.whiteCheckBox::after { min-width: 150px; } -.imageFlex { - width: auto !important; -} - .correctImageDisplay { margin-bottom: 0 !important; } @@ -1157,15 +1153,6 @@ input { flex-basis: 50%; } -.load-product-image { - flex: 50%; - height: 525px; - margin: 1rem; - cursor: pointer; - padding: 0; - position: relative; -} - #price { padding-left: 0; } @@ -1174,10 +1161,6 @@ input { margin-left: 0.5rem; } -.load-product-image-border { - border: 2px dotted #666; -} - .load-product-image input { display: none; } diff --git a/wisehands/admin/js/controllers/SubmitNewProductController.js b/wisehands/admin/js/controllers/SubmitNewProductController.js index cf061cfb2..dda2d8aa4 100644 --- a/wisehands/admin/js/controllers/SubmitNewProductController.js +++ b/wisehands/admin/js/controllers/SubmitNewProductController.js @@ -9,6 +9,7 @@ angular.module('WiseHands') const handleCroppedImage = (event, data) => { $scope.productImages.push(data); + $scope.imageToCrop = ''; }; $http({ diff --git a/wisehands/admin/partials/addNewProduct.html b/wisehands/admin/partials/addNewProduct.html index 6daada54a..448aca8f9 100644 --- a/wisehands/admin/partials/addNewProduct.html +++ b/wisehands/admin/partials/addNewProduct.html @@ -1,9 +1,22 @@
diff --git a/wisehands/admin/partials/addNewProduct.html b/wisehands/admin/partials/addNewProduct.html index 448aca8f9..3bebd693d 100644 --- a/wisehands/admin/partials/addNewProduct.html +++ b/wisehands/admin/partials/addNewProduct.html @@ -31,9 +31,36 @@ display: none; } - .imageFlex { - height: 150px; - width: 150px; + ul.images-list { + margin-top: 1rem; + display: grid; + grid-template-columns: repeat(3, minmax(160px, 1fr)); + grid-template-rows: 1fr; + grid-gap: 1rem; + } + + li { + display: flex; + } + + li img { + max-height: 100%; + min-width: 100%; + object-fit: fill; + vertical-align: bottom; + } + + @media all and (max-width: 768px) { + .images-container { + display: flex; + flex-direction: column; + } + } + + @media all and (max-width: 550px) { + ul.images-list { + grid-template-columns: repeat(3, minmax(100px, 1fr)); + } }