From 9134c33f6e94078f1ad587f7809117890f79b5b8 Mon Sep 17 00:00:00 2001 From: Devansh Bawari Date: Thu, 22 Jun 2023 17:47:47 +0530 Subject: [PATCH] formatting plugins added and some improvisation done --- packages/Webkul/Core/src/Core.php | 22 --- .../Shop/src/Resources/assets/js/app.js | 23 ++- .../src/Resources/assets/js/plugins/axios.js | 16 +++ .../src/Resources/assets/js/plugins/shop.js | 27 ++++ .../views/categories/filters.blade.php | 1 + .../views/components/layouts/index.blade.php | 1 + .../components/range-slider/index.blade.php | 92 +++++++++++- .../products/view/types/bundle.blade.php | 135 +++++++----------- .../default/build/assets/app-8644b3b6.js | 21 --- .../default/build/assets/app-f800a541.js | 21 +++ public/themes/default/build/manifest.json | 2 +- 11 files changed, 213 insertions(+), 148 deletions(-) create mode 100644 packages/Webkul/Shop/src/Resources/assets/js/plugins/axios.js create mode 100644 packages/Webkul/Shop/src/Resources/assets/js/plugins/shop.js delete mode 100644 public/themes/default/build/assets/app-8644b3b6.js create mode 100644 public/themes/default/build/assets/app-f800a541.js diff --git a/packages/Webkul/Core/src/Core.php b/packages/Webkul/Core/src/Core.php index b2a175632dc..ca969c72e8b 100755 --- a/packages/Webkul/Core/src/Core.php +++ b/packages/Webkul/Core/src/Core.php @@ -629,28 +629,6 @@ public function currencySymbol($currency) return $formatter->getSymbol(\NumberFormatter::CURRENCY_SYMBOL); } - /** - * Format and convert price with currency symbol. - * - * @return array - */ - public function getAccountJsSymbols() - { - $formatter = new \NumberFormatter(app()->getLocale(), \NumberFormatter::CURRENCY); - - $pattern = $formatter->getPattern(); - - $pattern = str_replace('¤', '%s', $pattern); - - $pattern = str_replace('#,##0.00', '%v', $pattern); - - return [ - 'symbol' => $this->currencySymbol($this->getCurrentCurrencyCode()), - 'decimal' => $formatter->getSymbol(\NumberFormatter::DECIMAL_SEPARATOR_SYMBOL), - 'format' => $pattern, - ]; - } - /** * Format and convert price with currency symbol. * diff --git a/packages/Webkul/Shop/src/Resources/assets/js/app.js b/packages/Webkul/Shop/src/Resources/assets/js/app.js index c6e7741e160..ec2270f08af 100755 --- a/packages/Webkul/Shop/src/Resources/assets/js/app.js +++ b/packages/Webkul/Shop/src/Resources/assets/js/app.js @@ -3,15 +3,6 @@ */ import.meta.glob(["../images/**", "../fonts/**"]); -/** - * We'll load the axios HTTP library which allows us to easily issue requests - * to our Laravel back-end. This library automatically handles sending the - * CSRF token as a header based on the value of the "XSRF" token cookie. - */ -import axios from "axios"; -window.axios = axios; -window.axios.defaults.headers.common["X-Requested-With"] = "XMLHttpRequest"; - /** * Main vue bundler. */ @@ -89,16 +80,18 @@ window.app = createApp({ }); /** - * Global components registration; + * Global plugins registration. */ -app.component('VForm', Form); -app.component('VField', Field); -app.component('VErrorMessage', ErrorMessage); +import Shop from "./plugins/shop"; +import Axios from "./plugins/axios"; +[Shop, Axios].forEach((plugin) => app.use(plugin)); /** - * Global properties registration. + * Global components registration; */ -app.config.globalProperties.$axios = axios; +app.component("VForm", Form); +app.component("VField", Field); +app.component("VErrorMessage", ErrorMessage); /** * Load event, the purpose of using the event is to mount the application diff --git a/packages/Webkul/Shop/src/Resources/assets/js/plugins/axios.js b/packages/Webkul/Shop/src/Resources/assets/js/plugins/axios.js new file mode 100644 index 00000000000..662292f0663 --- /dev/null +++ b/packages/Webkul/Shop/src/Resources/assets/js/plugins/axios.js @@ -0,0 +1,16 @@ +/** + * We'll load the axios HTTP library which allows us to easily issue requests + * to our Laravel back-end. This library automatically handles sending the + * CSRF token as a header based on the value of the "XSRF" token cookie. + */ +import axios from "axios"; +window.axios = axios; +window.axios.defaults.headers.common["X-Requested-With"] = "XMLHttpRequest"; + +const Axios = { + install(app) { + app.config.globalProperties.$axios = axios; + }, +}; + +export default Axios; diff --git a/packages/Webkul/Shop/src/Resources/assets/js/plugins/shop.js b/packages/Webkul/Shop/src/Resources/assets/js/plugins/shop.js new file mode 100644 index 00000000000..5f89353d726 --- /dev/null +++ b/packages/Webkul/Shop/src/Resources/assets/js/plugins/shop.js @@ -0,0 +1,27 @@ +const Shop = { + install(app) { + app.config.globalProperties.$shop = { + /** + * Generates a formatted price string using the provided price, localeCode, and currencyCode. + * + * @param {number} price - The price value to be formatted. + * @param {string} localeCode - The locale code specifying the desired formatting rules. + * @param {string} currencyCode - The currency code specifying the desired currency symbol. + * @returns {string} - The formatted price string. + */ + formatPrice: (price, localeCode = null, currencyCode = null) => { + if (! localeCode) { + localeCode = document.querySelector('meta[http-equiv="content-language"]').content ?? 'en'; + } + + if (! currencyCode) { + currencyCode = document.querySelector('meta[name="currency-code"]').content ?? 'USD'; + } + + return new Intl.NumberFormat(localeCode, { style: 'currency', currency: currencyCode }).format(price); + }, + }; + }, +}; + +export default Shop; diff --git a/packages/Webkul/Shop/src/Resources/views/categories/filters.blade.php b/packages/Webkul/Shop/src/Resources/views/categories/filters.blade.php index 1e32dd5ba2c..35ac85c9e71 100755 --- a/packages/Webkul/Shop/src/Resources/views/categories/filters.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/categories/filters.blade.php @@ -102,6 +102,7 @@ class="w-full text-[16px] text-gray-900 p-2 pl-0 cursor-pointer"