Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: add currency setting for admin panel #1612

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,84 @@
'tr' => 'Türkçe',
],

/*
|--------------------------------------------------------------------------
| Available Currencies Configuration
|--------------------------------------------------------------------------
|
| The application available currencies determines the supported currencies
| by application and their respective flags. The key of the array is the
| currency code and the value is the currency flag.
|
*/

'available_currencies' => [
'AED' => 'united-arab-emirates-dirham',
'ARS' => 'argentine-peso',
'AUD' => 'australian-dollar',
'BDT' => 'bangladeshi-taka',
'BRL' => 'brazilian-real',
'CAD' => 'canadian-dollar',
'CHF' => 'swiss-franc',
'CLP' => 'chilean-peso',
'CNY' => 'chinese-yuan',
'COP' => 'colombian-peso',
'CZK' => 'czech-koruna',
'DKK' => 'danish-krone',
'DZD' => 'algerian-dinar',
'EGP' => 'egyptian-pound',
'EUR' => 'euro',
'FJD' => 'fijian-dollar',
'GBP' => 'british-pound-sterling',
'HKD' => 'hong-kong-dollar',
'HUF' => 'hungarian-forint',
'IDR' => 'indonesian-rupiah',
'ILS' => 'israeli-new-shekel',
'INR' => 'indian-rupee',
'JOD' => 'jordanian-dinar',
'JPY' => 'japanese-yen',
'KRW' => 'south-korean-won',
'KWD' => 'kuwaiti-dinar',
'KZT' => 'kazakhstani-tenge',
'LBP' => 'lebanese-pound',
'LKR' => 'sri-lankan-rupee',
'LYD' => 'libyan-dinar',
'MAD' => 'moroccan-dirham',
'MUR' => 'mauritian-rupee',
'MXN' => 'mexican-peso',
'MYR' => 'malaysian-ringgit',
'NGN' => 'nigerian-naira',
'NOK' => 'norwegian-krone',
'NPR' => 'nepalese-rupee',
'NZD' => 'new-zealand-dollar',
'OMR' => 'omani-rial',
'PAB' => 'panamanian-balboa',
'PEN' => 'peruvian-nuevo-sol',
'PHP' => 'philippine-peso',
'PKR' => 'pakistani-rupee',
'PLN' => 'polish-zloty',
'PYG' => 'paraguayan-guarani',
'QAR' => 'qatari-rial',
'RON' => 'romanian-leu',
'RUB' => 'russian-ruble',
'SAR' => 'saudi-riyal',
'SEK' => 'swedish-krona',
'SGD' => 'singapore-dollar',
'THB' => 'thai-baht',
'TND' => 'tunisian-dinar',
'TRY' => 'turkish-lira',
'TWD' => 'new-taiwan-dollar',
'UAH' => 'ukrainian-hryvnia',
'USD' => 'united-states-dollar',
'UZS' => 'uzbekistani-som',
'VEF' => 'venezuelan-bolívar',
'VND' => 'vietnamese-dong',
'XAF' => 'cfa-franc-beac',
'XOF' => 'cfa-franc-bceao',
'ZAR' => 'south-african-rand',
'ZMW' => 'zambian-kwacha',
],

/*
|--------------------------------------------------------------------------
| Application Fallback Locale
Expand Down
15 changes: 15 additions & 0 deletions packages/Webkul/Admin/src/Config/core_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,19 @@
],
],
],
[
'key' => 'general.general.currency-settings',
'name' => 'admin::app.configuration.index.general.general.currency-settings.title',
'info' => 'admin::app.configuration.index.general.general.currency-settings.title-info',
'sort' => 1,
'fields' => [
[
'name' => 'currency',
'title' => 'admin::app.configuration.index.general.general.currency-settings.title',
'type' => 'select',
'default' => 'USD',
'options' => 'Webkul\Core\Core@retrieveCurrencies',
],
],
],
];
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function prepareColumns(): void
'sortable' => true,
'searchable' => true,
'filterable' => true,
'closure' => fn ($row) => round($row->price, 2),
'closure' => fn ($row) => core()->formatBasePrice(round($row->price, 2)),
]);

$this->addColumn([
Expand Down
4 changes: 4 additions & 0 deletions packages/Webkul/Admin/src/Resources/lang/en/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -1841,6 +1841,10 @@
'title' => 'Locale Settings',
'title-info' => 'Defines the language used in the user interface, such as English (en), French (fr), or Japanese (ja).',
],
'currency-settings' => [
'title' => 'Currency Settings',
'title-info' => 'Defines the currency used in the user interface, such as US Dollar ($), Euro (€), or Japanese Yen (¥).',
],
],
],
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
<div class="relative flex w-[525px] max-w-[525px] items-center max-lg:w-[400px] ltr:ml-2.5 rtl:mr-2.5">
<i class="icon-search absolute top-1.5 flex items-center text-2xl ltr:left-3 rtl:right-3"></i>

<input
type="text"
<input
type="text"
class="block w-full rounded-lg border bg-white px-10 py-1.5 leading-6 text-gray-600 transition-all hover:border-gray-400 dark:border-gray-800 dark:bg-gray-900 dark:text-gray-300"
placeholder="@lang('admin::app.configuration.index.search')"
placeholder="@lang('admin::app.configuration.index.search')"
>
</div>
</v-configuration-search>
Expand All @@ -37,6 +37,7 @@ class="block w-full rounded-lg border bg-white px-10 py-1.5 leading-6 text-gray-
<!-- Page Content -->
<div class="grid gap-y-8">
@foreach (system_config()->getItems() as $item)

<div>
<div class="grid gap-1">
<!-- Title of the Main Card -->
Expand All @@ -53,7 +54,7 @@ class="block w-full rounded-lg border bg-white px-10 py-1.5 leading-6 text-gray-
<div class="box-shadow max-1580:grid-cols-3 mt-2 grid grid-cols-4 flex-wrap justify-between gap-12 rounded bg-white p-4 dark:bg-gray-900 max-xl:grid-cols-2 max-sm:grid-cols-1">
<!-- Menus cards -->
@foreach ($item->getChildren() as $key => $child)
<a
<a
class="flex max-w-[360px] items-center gap-2 rounded-lg p-2 transition-all hover:bg-gray-100 dark:hover:bg-gray-950"
href="{{ route('admin.configuration.index', ($item->getKey() . '/' . $key)) }}"
>
Expand All @@ -67,7 +68,7 @@ class="flex max-w-[360px] items-center gap-2 rounded-lg p-2 transition-all hover
<p class="mb-1.5 text-base font-semibold text-gray-800 dark:text-white">
{{ $child->getName() }}
</p>

<p class="text-xs text-gray-600 dark:text-gray-300">
{{ $child->getInfo() }}
</p>
Expand All @@ -86,7 +87,7 @@ class="flex max-w-[360px] items-center gap-2 rounded-lg p-2 transition-all hover
<div class="relative flex w-[525px] max-w-[525px] items-center max-lg:w-[400px] ltr:ml-2.5 rtl:mr-2.5">
<i class="icon-search absolute top-1.5 flex items-center text-2xl ltr:left-3 rtl:right-3"></i>

<input
<input
type="text"
class="peer block w-full rounded-lg border bg-white px-10 py-1.5 leading-6 text-gray-600 transition-all hover:border-gray-400 focus:border-gray-400 dark:border-gray-800 dark:bg-gray-900 dark:text-gray-300 dark:hover:border-gray-400 dark:focus:border-gray-400"
:class="{'border-gray-400': isDropdownOpen}"
Expand Down Expand Up @@ -129,7 +130,7 @@ class="p-4 text-sm font-semibold text-gray-600 dark:text-gray-300"
<script type="module">
app.component('v-configuration-search', {
template: '#v-configuration-search-template',

data() {
return {
isDropdownOpen: false,
Expand Down Expand Up @@ -169,7 +170,7 @@ class="p-4 text-sm font-semibold text-gray-600 dark:text-gray-300"
this.isDropdownOpen = true;

this.isLoading = true;

this.$axios.get("{{ route('admin.configuration.search') }}", {
params: {query: this.searchTerm}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<div class="flex items-center gap-x-2.5">
<div class="flex items-center gap-x-2.5">
{!! view_render_event('admin.products.edit.create_button.before', ['product' => $product]) !!}

<!-- Edit button for Product -->
<button
type="submit"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
['code', 'IN', ['SKU', 'price', 'quantity', 'status']]
])->sortBy('sort_order')"
:entity="$product"
:url="route('admin.products.update', $product->id)"
:url="route('admin.products.update', $product->id)"
:allow-edit="true"
/>

{!! view_render_event('admin.products.view.attributes.view.after', ['product' => $product]) !!}
</div>

{!! view_render_event('admin.products.view.attributes.before', ['product' => $product]) !!}
{!! view_render_event('admin.products.view.attributes.before', ['product' => $product]) !!}
17 changes: 16 additions & 1 deletion packages/Webkul/Attribute/src/Traits/CustomAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ public function getAttribute($key)
}
}

// check key === 'price' and return the price attribute value
if (isset($this->id) && $key === 'price') {
$attribute = app(AttributeRepository::class)->getAttributeByCode($key);

return $this->getCustomAttributeValue($attribute);
}

return parent::getAttribute($key);
}

Expand Down Expand Up @@ -112,7 +119,15 @@ public function getCustomAttributeValue($attribute)

$attributeValue = $this->attribute_values->where('attribute_id', $attribute->id)->first();

return $attributeValue[self::$attributeTypeFields[$attribute->type]] ?? null;
$value = $attributeValue[self::$attributeTypeFields[$attribute->type]] ?? null;

// Custom handling for price attribute
if ($attribute->code === 'price') {
// Format price, e.g., add currency symbol and format decimal places
$value = round($value, 2);
}

return $value;
}

/**
Expand Down
26 changes: 26 additions & 0 deletions packages/Webkul/Category/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "mix",
"watch": "mix watch",
"watch-poll": "mix watch -- --watch-options-poll=1000",
"hot": "mix watch --hot",
"prod": "npm run production",
"production": "mix --production"
},
"devDependencies": {
"cross-env": "^7.0.3",
"laravel-mix": "^6.0.6",
"laravel-mix-merge-manifest": "^2.0.0",
"lodash": "^4.17.19",
"postcss": "^8.1.14",
"sass": "^1.32.8",
"sass-loader": "^11.0.1",
"vue": "^2.6.12",
"vue-loader": "^15.9.6",
"vue-template-compiler": "^2.6.12"
},
"dependencies": {
}
}
1 change: 1 addition & 0 deletions packages/Webkul/Category/publishable/assets/css/admin.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions packages/Webkul/Category/publishable/assets/images/Icon-Temp.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/Webkul/Category/publishable/assets/js/app.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions packages/Webkul/Category/src/Config/acl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

return [
[
'key' => 'category',
'name' => 'Category',
'route' => 'admin.category.index',
'sort' => 2
]
];
11 changes: 11 additions & 0 deletions packages/Webkul/Category/src/Config/menu.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

return [
[
'key' => 'category',
'name' => 'Category',
'route' => 'admin.category.index',
'sort' => 2,
'icon-class' => 'temp-icon',
]
];
Loading