Skip to content

Commit

Permalink
[ADD] Prices fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
Seiger committed Nov 19, 2024
1 parent 94f30c4 commit 0d1a140
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 28 deletions.
1 change: 1 addition & 0 deletions lang/en/global.php
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions lang/ru/global.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"price_opt" => "Оптовая цена",
"price_opt_special" => "Специальная оптовая цена",
"price_special" => "Специальная цена",
"price_special_help" => "Специальная цена товара в валюте магазина.",
"price_symbol" => "Показать символ",
"price_symbol_help" => "Отображение символа валюты при выводе цены",
"price_thousands_separator" => "Разделитель тысяч",
Expand Down
1 change: 1 addition & 0 deletions lang/uk/global.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"price_opt" => "Оптова ціна",
"price_opt_special" => "Спеціальна оптова ціна",
"price_special" => "Спеціальна ціна",
"price_special_help" => "Спеціальна ціна товару в валюті магазину.",
"price_symbol" => "Показати символ",
"price_symbol_help" => "Відображати символ валюти при виведенні ціни",
"price_thousands_separator" => "Розділювач тисяч",
Expand Down
42 changes: 41 additions & 1 deletion src/Models/sProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion views/contentTab.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
</div>
</div>
<div class="row-col col-12">
@php($mainAttributes = sCommerce::config('constructor.main_product'))
@php($mainAttributes = sCommerce::config('constructor.main_product', []))
@foreach($mainAttributes as $attribute)
<input type="hidden" name="constructor[{{$attribute['key']}}]" value="{{$product->{'constructor_'.$attribute['key']}??''}}">
@endforeach
Expand Down
71 changes: 58 additions & 13 deletions views/productTab.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,22 @@
<i class="fa fa-question-circle" data-tooltip="@lang('sCommerce::global.published_help')"></i>
</div>
<div class="col">
<input type="checkbox" id="publishedcheck" class="form-checkbox form-control"
name="publishedcheck" value="" onchange="documentDirty=true;"
onclick="changestate(document.form.published);"
@if(isset($item->published) && $item->published) checked @endif>
<input type="checkbox" id="publishedcheck" class="form-checkbox form-control" name="publishedcheck" value="" onchange="documentDirty=true;" onclick="changestate(document.form.published);" @if(isset($item->published) && $item->published) checked @endif>
<input type="hidden" id="published" name="published" value="{{$item->published ?? 0}}" onchange="documentDirty=true;">
@if(sCommerce::config('product.views_on', 1) == 1)&emsp;
<i class="fa fa-eye" data-tooltip="@lang('sCommerce::global.views')">
<b>{{$item->views ?? 0}}</b>
</i>
<i class="fa fa-eye" data-tooltip="@lang('sCommerce::global.views')">
<b>{{$item->views ?? 0}}</b>
</i>
@endif
@if(sCommerce::config('product.rating_on', 1) == 1)&emsp;
<i class="fa fa-star" data-tooltip="@lang('sCommerce::global.rating')">
<b>{{$item->rating ?? 5}}</b>
</i>
<i class="fa fa-star" data-tooltip="@lang('sCommerce::global.rating')">
<b>{{$item->rating ?? 5}}</b>
</i>
@endif
@if(sCommerce::config('product.quantity_on', 1) == 1)&emsp;
<i class="fas fa-warehouse" data-tooltip="@lang('sCommerce::global.quantity')">
<b>{{$item->quantity ?? 0}}</b>
</i>
<i class="fas fa-warehouse" data-tooltip="@lang('sCommerce::global.quantity')">
<b>{{$item->quantity ?? 0}}</b>
</i>
@endif
</div>
</div>
Expand Down Expand Up @@ -106,6 +103,54 @@
</div>
</div>
@endif
@if(sCommerce::config('product.show_field_price_special', 1) == 1)
<div class="row-col col-lg-3 col-md-6 col-12">
<div class="row form-row">
<div class="col-auto col-title">
<label for="price_special">@lang('sCommerce::global.price_special')</label>
<i class="fa fa-question-circle" data-tooltip="@lang('sCommerce::global.price_special_help')"></i>
</div>
<div class="input-group col">
<div class="input-group-prepend">
<span class="input-group-text"><small>{{sCommerce::getCurrencies([$item->currency ?? sCommerce::config('basic.main_currency', 'USD')])->first()['symbol']}}</small></span>
</div>
<input id="price_special" class="form-control" name="price_special" value="{{$item->price_special ?? ''}}" onblur="documentDirty=true;">
</div>
</div>
</div>
@endif
@if(sCommerce::config('product.show_field_price_opt', 1) == 1)
<div class="row-col col-lg-3 col-md-6 col-12">
<div class="row form-row">
<div class="col-auto col-title">
<label for="price_opt_regular">@lang('sCommerce::global.price_opt')</label>
<i class="fa fa-question-circle" data-tooltip="@lang('sCommerce::global.price_opt_help')"></i>
</div>
<div class="input-group col">
<div class="input-group-prepend">
<span class="input-group-text"><small>{{sCommerce::getCurrencies([$item->currency ?? sCommerce::config('basic.main_currency', 'USD')])->first()['symbol']}}</small></span>
</div>
<input id="price_opt_regular" class="form-control" name="price_opt_regular" value="{{$item->price_opt_regular ?? ''}}" onblur="documentDirty=true;">
</div>
</div>
</div>
@endif
@if(sCommerce::config('product.show_field_price_opt_special', 1) == 1)
<div class="row-col col-lg-3 col-md-6 col-12">
<div class="row form-row">
<div class="col-auto col-title">
<label for="price_opt_special">@lang('sCommerce::global.price_opt_special')</label>
<i class="fa fa-question-circle" data-tooltip="@lang('sCommerce::global.price_opt_special_help')"></i>
</div>
<div class="input-group col">
<div class="input-group-prepend">
<span class="input-group-text"><small>{{sCommerce::getCurrencies([$item->currency ?? sCommerce::config('basic.main_currency', 'USD')])->first()['symbol']}}</small></span>
</div>
<input id="price_opt_special" class="form-control" name="price_opt_special" value="{{$item->price_opt_special ?? ''}}" onblur="documentDirty=true;">
</div>
</div>
</div>
@endif
@if (evo()->getConfig('check_sMultisite', false))
<span id="parentName" class="hidden"></span>
<input type="hidden" name="parent" value="0"/>
Expand Down
24 changes: 12 additions & 12 deletions views/productsTab.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,35 +45,35 @@ class="form-control rounded-left scom-input seiger__search"
<button class="seiger-sort-btn" style="padding:0;displai: inline;border: none;background: transparent;">ID <i class="fas fa-sort" style="color: #036efe;"></i></button>
</th>
@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))
<th class="sorting @if($order == 'sku') sorted @endif" data-order="sku">
<button class="seiger-sort-btn" style="padding:0;displai: inline;border: none;background: transparent;">@lang('sCommerce::global.sku') <i class="fas fa-sort" style="color: #036efe;"></i></button>
</th>
@endif
<th class="sorting @if($order == 'pagetitle') sorted @endif" data-order="pagetitle">
<button class="seiger-sort-btn" style="padding:0;displai: inline;border: none;background: transparent;">@lang('sCommerce::global.product_name') <i class="fas fa-sort" style="color: #036efe;"></i></button>
</th>
@if (sCommerce::config('products.show_field_price', 1) == 1)
@if (sCommerce::config('products.show_field_price', 1) && sCommerce::config('product.show_field_price', 1))
<th class="sorting @if($order == 'price_regular') sorted @endif" data-order="price_regular">
<button class="seiger-sort-btn" style="padding:0;displai: inline;border: none;background: transparent;">@lang('sCommerce::global.price') <i class="fas fa-sort" style="color: #036efe;"></i></button>
</th>
@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))
<th class="sorting @if($order == 'price_special') sorted @endif" data-order="price_special">
<button class="seiger-sort-btn" style="padding:0;displai: inline;border: none;background: transparent;">@lang('sCommerce::global.price_special') <i class="fas fa-sort" style="color: #036efe;"></i></button>
</th>
@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))
<th class="sorting @if($order == 'price_opt_regular') sorted @endif" data-order="price_opt_regular">
<button class="seiger-sort-btn" style="padding:0;displai: inline;border: none;background: transparent;">@lang('sCommerce::global.price_opt') <i class="fas fa-sort" style="color: #036efe;"></i></button>
</th>
@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))
<th class="sorting @if($order == 'price_opt_special') sorted @endif" data-order="price_opt_special">
<button class="seiger-sort-btn" style="padding:0;displai: inline;border: none;background: transparent;">@lang('sCommerce::global.price_opt_special') <i class="fas fa-sort" style="color: #036efe;"></i></button>
</th>
@endif
@if (sCommerce::config('products.show_field_quantity', 1) == 1)
@if (sCommerce::config('products.show_field_quantity', 1) && sCommerce::config('product.quantity_on', 1))
<th class="sorting @if($order == 'quantity') sorted @endif" data-order="quantity">
<button class="seiger-sort-btn" style="padding:0;displai: inline;border: none;background: transparent;">@lang('sCommerce::global.quantity') <i class="fas fa-sort" style="color: #036efe;"></i></button>
</th>
Expand Down Expand Up @@ -124,14 +124,14 @@ class="form-control rounded-left scom-input seiger__search"
@if (sCommerce::config('products.show_field_id', 1) == 1)
<td>{{$item->id}}</td>
@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))
<td>{{$item->sku}}</td>
@endif
<td>
<img src="{{$item->coverSrc}}" alt="{{$item->coverSrc}}" class="product-thumbnail">
<a href="{{$item->link}}" target="_blank"><b>{{$item->pagetitle ?? __('sCommerce::global.no_text')}}</b></a>
</td>
@if (sCommerce::config('products.show_field_price', 1) == 1)
@if (sCommerce::config('products.show_field_price', 1) && sCommerce::config('product.show_field_price', 1))
<td>
@if(sCommerce::config('basic.price_symbol', 1))
{{$item->priceTo($item->currency)}}
Expand All @@ -140,16 +140,16 @@ class="form-control rounded-left scom-input seiger__search"
@endif
</td>
@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))
<td>{{$item->price_special}}</td>
@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))
<td>{{$item->price_opt_regular}}</td>
@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))
<td>{{$item->price_opt_special}}</td>
@endif
@if (sCommerce::config('products.show_field_quantity', 1) == 1)
@if (sCommerce::config('products.show_field_quantity', 1) && sCommerce::config('product.quantity_on', 1))
<td>{{$item->quantity}}</td>
@endif
@if (sCommerce::config('products.show_field_availability', 1) == 1)
Expand Down
12 changes: 11 additions & 1 deletion views/settingsTab.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@
<div class="row form-row">
<div class="col-auto">
<label for="product__quantity_on" class="warning">@lang('sCommerce::global.quantity')</label>
<i class="fa fa-question-circle" data-tooltip="@lang('sCommerce::global.rating_on_help')"></i>
<i class="fa fa-question-circle" data-tooltip="@lang('sCommerce::global.quantity_on_help')"></i>
</div>
<div class="col">
<input type="checkbox" class="form-checkbox form-control" onchange="documentDirty=true;" onclick="changestate(document.form.product__quantity_on);" @if(sCommerce::config('product.quantity_on', 1) == 1) checked @endif>
Expand Down Expand Up @@ -331,6 +331,16 @@
<input type="hidden" id="product__show_field_price" name="product__show_field_price" value="{{sCommerce::config('product.show_field_price', 1)}}" onchange="documentDirty=true;">
</div>
</div>
<div class="row form-row">
<div class="col-auto">
<label for="product__show_field_price_special" class="warning">@lang('sCommerce::global.price_special')</label>
<i class="fa fa-question-circle" data-tooltip="@lang('sCommerce::global.show_field') @lang('sCommerce::global.price_special')"></i>
</div>
<div class="col">
<input type="checkbox" class="form-checkbox form-control" onchange="documentDirty=true;" onclick="changestate(document.form.product__show_field_price_special);" @if(sCommerce::config('product.show_field_price_special', 1) == 1) checked @endif>
<input type="hidden" id="product__show_field_price_special" name="product__show_field_price_special" value="{{sCommerce::config('product.show_field_price_special', 1)}}" onchange="documentDirty=true;">
</div>
</div>
<div class="row form-row">
<div class="col-auto">
<label for="product__show_field_categories" class="warning">@lang('sCommerce::global.categories')</label>
Expand Down

0 comments on commit 0d1a140

Please sign in to comment.