feat(texts): add options to redefine text for zero product prices
This commit is contained in:
@@ -47,6 +47,7 @@ export const useSettingsStore = defineStore('settings', {
|
||||
text_no_more_products: '',
|
||||
text_empty_cart: '',
|
||||
text_order_created_success: '',
|
||||
zero_price_text: '',
|
||||
},
|
||||
|
||||
sliders: {
|
||||
|
||||
@@ -11,6 +11,11 @@
|
||||
<ItemInput label="Текст для успешного заказа" v-model="settings.items.texts.text_order_created_success">
|
||||
Текст, отображаемый при успешном создании заказа.
|
||||
</ItemInput>
|
||||
|
||||
<ItemInput label="Текст вместо нулевой цены" v-model="settings.items.texts.zero_price_text" placeholder="0.00р.">
|
||||
Текст, который будет выводиться вместо цены, в случае если цена = 0.
|
||||
Если текст отсутствует, то будет выводиться нулевая цена по умолчанию.
|
||||
</ItemInput>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Openguru\OpenCartFramework\OpenCart;
|
||||
|
||||
use App\Services\SettingsService;
|
||||
use Cart\Currency as OpenCartCurrency;
|
||||
use Cart\Tax;
|
||||
|
||||
class PriceCalculator
|
||||
{
|
||||
private OpenCartCurrency $currency;
|
||||
private Tax $tax;
|
||||
private SettingsService $settings;
|
||||
|
||||
public function __construct(OpenCartCurrency $currency, Tax $tax, SettingsService $settings)
|
||||
{
|
||||
$this->currency = $currency;
|
||||
$this->tax = $tax;
|
||||
$this->settings = $settings;
|
||||
}
|
||||
|
||||
public function getPriceNumeric($price, $taxClassId): float
|
||||
{
|
||||
return $this->tax->calculate(
|
||||
$price,
|
||||
$taxClassId,
|
||||
$this->settings->config()->getStore()->isOcConfigTax(),
|
||||
);
|
||||
}
|
||||
|
||||
public function format($price, $taxClassId): string
|
||||
{
|
||||
$priceNumeric = $this->getPriceNumeric($price, $taxClassId);
|
||||
|
||||
$zeroPriceText = $this->settings->get('texts.zero_price_text');
|
||||
|
||||
if ($zeroPriceText && $priceNumeric === 0.0) {
|
||||
$price = $zeroPriceText;
|
||||
} else {
|
||||
$currency = $this->settings->config()->getStore()->getOcDefaultCurrency();
|
||||
$price = $this->currency->format($priceNumeric, $currency);
|
||||
}
|
||||
|
||||
return $price;
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ use Openguru\OpenCartFramework\Exceptions\EntityNotFoundException;
|
||||
use Openguru\OpenCartFramework\ImageTool\ImageFactory;
|
||||
use Openguru\OpenCartFramework\ImageTool\ImageNotFoundException;
|
||||
use Openguru\OpenCartFramework\OpenCart\Decorators\OcRegistryDecorator;
|
||||
use Openguru\OpenCartFramework\OpenCart\PriceCalculator;
|
||||
use Openguru\OpenCartFramework\QueryBuilder\Builder;
|
||||
use Openguru\OpenCartFramework\QueryBuilder\JoinClause;
|
||||
use Openguru\OpenCartFramework\QueryBuilder\RawExpression;
|
||||
@@ -29,6 +30,7 @@ class ProductsService
|
||||
private OcRegistryDecorator $oc;
|
||||
private LoggerInterface $logger;
|
||||
private CriteriaBuilder $criteriaBuilder;
|
||||
private PriceCalculator $priceCalculator;
|
||||
|
||||
public function __construct(
|
||||
Builder $queryBuilder,
|
||||
@@ -38,7 +40,8 @@ class ProductsService
|
||||
ImageFactory $image,
|
||||
OcRegistryDecorator $registry,
|
||||
LoggerInterface $logger,
|
||||
CriteriaBuilder $criteriaBuilder
|
||||
CriteriaBuilder $criteriaBuilder,
|
||||
PriceCalculator $priceCalculator
|
||||
) {
|
||||
$this->queryBuilder = $queryBuilder;
|
||||
$this->currency = $currency;
|
||||
@@ -48,6 +51,7 @@ class ProductsService
|
||||
$this->oc = $registry;
|
||||
$this->logger = $logger;
|
||||
$this->criteriaBuilder = $criteriaBuilder;
|
||||
$this->priceCalculator = $priceCalculator;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -175,12 +179,8 @@ class ProductsService
|
||||
'alt' => Str::htmlEntityEncode($product['product_name']),
|
||||
];
|
||||
|
||||
$priceNumeric = $this->tax->calculate(
|
||||
$product['price'],
|
||||
$product['tax_class_id'],
|
||||
$this->settings->config()->getStore()->isOcConfigTax(),
|
||||
);
|
||||
$price = $this->currency->format($priceNumeric, $currency);
|
||||
$price = $this->priceCalculator->format($product['price'], $product['tax_class_id']);
|
||||
$priceNumeric = $this->priceCalculator->getPriceNumeric($product['price'], $product['tax_class_id']);
|
||||
|
||||
$special = false;
|
||||
$specialPriceNumeric = null;
|
||||
@@ -305,14 +305,12 @@ class ProductsService
|
||||
|
||||
$data['images'] = $images;
|
||||
|
||||
$productPrice = $this->tax->calculate(
|
||||
$product_info['price'],
|
||||
$product_info['tax_class_id'],
|
||||
$configTax,
|
||||
);
|
||||
$data['price'] = $this->currency->format($productPrice, $currency);
|
||||
$price = $this->priceCalculator->format($product_info['price'], $product_info['tax_class_id']);
|
||||
$priceNumeric = $this->priceCalculator->getPriceNumeric($product_info['price'], $product_info['tax_class_id']);
|
||||
|
||||
$data['price'] = $price;
|
||||
$data['currency'] = $currency;
|
||||
$data['final_price_numeric'] = $productPrice;
|
||||
$data['final_price_numeric'] = $priceNumeric;
|
||||
|
||||
if (! is_null($product_info['special']) && (float) $product_info['special'] >= 0) {
|
||||
$productSpecialPrice = $this->tax->calculate(
|
||||
|
||||
Reference in New Issue
Block a user