From 0d1a1403833622c6679313514c39acce1bd4a668 Mon Sep 17 00:00:00 2001 From: Serhii Korneliuk Date: Tue, 19 Nov 2024 22:13:50 +0200 Subject: [PATCH] [ADD] Prices fields. --- lang/en/global.php | 1 + lang/ru/global.php | 1 + lang/uk/global.php | 1 + src/Models/sProduct.php | 42 +++++++++++++++++++++- views/contentTab.blade.php | 2 +- views/productTab.blade.php | 71 ++++++++++++++++++++++++++++++------- views/productsTab.blade.php | 24 ++++++------- views/settingsTab.blade.php | 12 ++++++- 8 files changed, 126 insertions(+), 28 deletions(-) diff --git a/lang/en/global.php b/lang/en/global.php index 1fc0de7..8e18145 100644 --- a/lang/en/global.php +++ b/lang/en/global.php @@ -97,6 +97,7 @@ "price_opt" => "Wholesale price", "price_opt_special" => "Special wholesale price", "price_special" => "Special Price", + "price_special_help" => "Special Price of the product is in the currency of the store.", "price_symbol" => "Show symbol", "price_symbol_help" => "Display the currency symbol when displaying the price", "price_thousands_separator" => "Thousands separator", diff --git a/lang/ru/global.php b/lang/ru/global.php index 6011388..8cf58be 100644 --- a/lang/ru/global.php +++ b/lang/ru/global.php @@ -97,6 +97,7 @@ "price_opt" => "Оптовая цена", "price_opt_special" => "Специальная оптовая цена", "price_special" => "Специальная цена", + "price_special_help" => "Специальная цена товара в валюте магазина.", "price_symbol" => "Показать символ", "price_symbol_help" => "Отображение символа валюты при выводе цены", "price_thousands_separator" => "Разделитель тысяч", diff --git a/lang/uk/global.php b/lang/uk/global.php index 5764824..9e80791 100644 --- a/lang/uk/global.php +++ b/lang/uk/global.php @@ -97,6 +97,7 @@ "price_opt" => "Оптова ціна", "price_opt_special" => "Спеціальна оптова ціна", "price_special" => "Спеціальна ціна", + "price_special_help" => "Спеціальна ціна товару в валюті магазину.", "price_symbol" => "Показати символ", "price_symbol_help" => "Відображати символ валюти при виведенні ціни", "price_thousands_separator" => "Розділювач тисяч", diff --git a/src/Models/sProduct.php b/src/Models/sProduct.php index ec97c8b..b11846e 100644 --- a/src/Models/sProduct.php +++ b/src/Models/sProduct.php @@ -383,7 +383,7 @@ public function getCoverSrcAttribute(): string public function getPriceAttribute(): string { if (!isset($_SESSION['currency'])) { - $_SESSION['currency'] = sCommerce::config('basic.main_currency', 'EUR'); + $_SESSION['currency'] = sCommerce::config('basic.main_currency', 'USD'); } return $this->priceTo($_SESSION['currency']); @@ -411,4 +411,44 @@ public function priceToNumber($currency): float { return sCommerce::convertPiceNumber($this->price_regular, $this->currency, $currency); } + + /** + * Gets the price special attribute of the sProduct. + * Formats the price based on configuration values. + * + * @return string The formatted price of the product. + * + * @throws ErrorException if configuration values are not set. + */ + public function getspecialPriceAttribute(): string + { + if (!isset($_SESSION['currency'])) { + $_SESSION['currency'] = sCommerce::config('basic.main_currency', 'USD'); + } + + return $this->specialPriceTo($_SESSION['currency']); + } + + /** + * Convert the price special to the specified currency and format it as a string. + * + * @param string $currency The target currency. + * @return string The formatted price. + */ + public function specialPriceTo($currency): string + { + return sCommerce::convertPice($this->price_special, $this->currency, $currency); + } + + /** + * Convert the product special price to a number in a specified currency. + * + * @param string $currency The desired currency to convert to. + * + * @return float The converted price in the specified currency. + */ + public function priceSpecialToNumber($currency): float + { + return sCommerce::convertPiceNumber($this->price_special, $this->currency, $currency); + } } \ No newline at end of file diff --git a/views/contentTab.blade.php b/views/contentTab.blade.php index 30947fa..826e29c 100644 --- a/views/contentTab.blade.php +++ b/views/contentTab.blade.php @@ -72,7 +72,7 @@
- @php($mainAttributes = sCommerce::config('constructor.main_product')) + @php($mainAttributes = sCommerce::config('constructor.main_product', [])) @foreach($mainAttributes as $attribute) @endforeach diff --git a/views/productTab.blade.php b/views/productTab.blade.php index ec334b0..177ad9f 100644 --- a/views/productTab.blade.php +++ b/views/productTab.blade.php @@ -18,25 +18,22 @@
- published) && $item->published) checked @endif> + published) && $item->published) checked @endif> @if(sCommerce::config('product.views_on', 1) == 1)  - - {{$item->views ?? 0}} - + + {{$item->views ?? 0}} + @endif @if(sCommerce::config('product.rating_on', 1) == 1)  - - {{$item->rating ?? 5}} - + + {{$item->rating ?? 5}} + @endif @if(sCommerce::config('product.quantity_on', 1) == 1)  - - {{$item->quantity ?? 0}} - + + {{$item->quantity ?? 0}} + @endif
@@ -106,6 +103,54 @@ @endif + @if(sCommerce::config('product.show_field_price_special', 1) == 1) +
+
+
+ + +
+
+
+ {{sCommerce::getCurrencies([$item->currency ?? sCommerce::config('basic.main_currency', 'USD')])->first()['symbol']}} +
+ +
+
+
+ @endif + @if(sCommerce::config('product.show_field_price_opt', 1) == 1) +
+
+
+ + +
+
+
+ {{sCommerce::getCurrencies([$item->currency ?? sCommerce::config('basic.main_currency', 'USD')])->first()['symbol']}} +
+ +
+
+
+ @endif + @if(sCommerce::config('product.show_field_price_opt_special', 1) == 1) +
+
+
+ + +
+
+
+ {{sCommerce::getCurrencies([$item->currency ?? sCommerce::config('basic.main_currency', 'USD')])->first()['symbol']}} +
+ +
+
+
+ @endif @if (evo()->getConfig('check_sMultisite', false)) diff --git a/views/productsTab.blade.php b/views/productsTab.blade.php index 79e64f0..f8825ee 100644 --- a/views/productsTab.blade.php +++ b/views/productsTab.blade.php @@ -45,7 +45,7 @@ class="form-control rounded-left scom-input seiger__search" @endif - @if (sCommerce::config('products.show_field_sku', 1) == 1) + @if (sCommerce::config('products.show_field_sku', 1) && sCommerce::config('product.show_field_sku', 1)) @@ -53,27 +53,27 @@ class="form-control rounded-left scom-input seiger__search" - @if (sCommerce::config('products.show_field_price', 1) == 1) + @if (sCommerce::config('products.show_field_price', 1) && sCommerce::config('product.show_field_price', 1)) @endif - @if (sCommerce::config('products.show_field_price_special', 1) == 1) + @if (sCommerce::config('products.show_field_price_special', 1) && sCommerce::config('product.show_field_price_special', 1)) @endif - @if (sCommerce::config('products.show_field_price_opt', 1) == 1) + @if (sCommerce::config('products.show_field_price_opt', 1) && sCommerce::config('product.show_field_price_opt', 1)) @endif - @if (sCommerce::config('products.show_field_price_opt_special', 1) == 1) + @if (sCommerce::config('products.show_field_price_opt_special', 1) && sCommerce::config('product.show_field_price_opt_special', 1)) @endif - @if (sCommerce::config('products.show_field_quantity', 1) == 1) + @if (sCommerce::config('products.show_field_quantity', 1) && sCommerce::config('product.quantity_on', 1)) @@ -124,14 +124,14 @@ class="form-control rounded-left scom-input seiger__search" @if (sCommerce::config('products.show_field_id', 1) == 1) {{$item->id}} @endif - @if (sCommerce::config('products.show_field_sku', 1) == 1) + @if (sCommerce::config('products.show_field_sku', 1) && sCommerce::config('product.show_field_sku', 1)) {{$item->sku}} @endif {{$item->coverSrc}} {{$item->pagetitle ?? __('sCommerce::global.no_text')}} - @if (sCommerce::config('products.show_field_price', 1) == 1) + @if (sCommerce::config('products.show_field_price', 1) && sCommerce::config('product.show_field_price', 1)) @if(sCommerce::config('basic.price_symbol', 1)) {{$item->priceTo($item->currency)}} @@ -140,16 +140,16 @@ class="form-control rounded-left scom-input seiger__search" @endif @endif - @if (sCommerce::config('products.show_field_price_special', 1) == 1) + @if (sCommerce::config('products.show_field_price_special', 1) && sCommerce::config('product.show_field_price_special', 1)) {{$item->price_special}} @endif - @if (sCommerce::config('products.show_field_price_opt', 1) == 1) + @if (sCommerce::config('products.show_field_price_opt', 1) && sCommerce::config('product.show_field_price_opt', 1)) {{$item->price_opt_regular}} @endif - @if (sCommerce::config('products.show_field_price_opt_special', 1) == 1) + @if (sCommerce::config('products.show_field_price_opt_special', 1) && sCommerce::config('product.show_field_price_opt_special', 1)) {{$item->price_opt_special}} @endif - @if (sCommerce::config('products.show_field_quantity', 1) == 1) + @if (sCommerce::config('products.show_field_quantity', 1) && sCommerce::config('product.quantity_on', 1)) {{$item->quantity}} @endif @if (sCommerce::config('products.show_field_availability', 1) == 1) diff --git a/views/settingsTab.blade.php b/views/settingsTab.blade.php index 493f945..d35160c 100644 --- a/views/settingsTab.blade.php +++ b/views/settingsTab.blade.php @@ -294,7 +294,7 @@
- +
@@ -331,6 +331,16 @@
+
+
+ + +
+
+ + +
+