¨4.0.1¨

This commit is contained in:
¨NW¨
2023-12-03 14:07:47 +00:00
parent c08b36d1b6
commit f35052522d
1112 changed files with 43019 additions and 24987 deletions

View File

@@ -1,20 +1,24 @@
<?php
use Modules\Product\Entities\Product;
use Modules\FlashSale\Entities\FlashSale;
use Modules\Product\Entities\ProductVariant;
if (! function_exists('product_price_formatted')) {
if (!function_exists('product_price_formatted')) {
/**
* Get the selling price of the given product.
*
* @param \Modules\Product\Entities\Product $product
* @param \Closure $callback
* @param Product $productOrProductVariant
* @param Closure|null $callback
*
* @return string
*/
function product_price_formatted($product, $callback = null)
function product_price_formatted(Product|ProductVariant $productOrProductVariant, Closure $callback = null): string
{
if (FlashSale::contains($product)) {
$previousPrice = $product->getSellingPrice()->convertToCurrentCurrency()->format();
$flashSalePrice = FlashSale::pivot($product)->price->convertToCurrentCurrency()->format();
if ($productOrProductVariant instanceof Product && FlashSale::contains($productOrProductVariant)) {
$sellingPrice = $productOrProductVariant->hasSpecialPrice() ? $productOrProductVariant->getSpecialPrice() : $productOrProductVariant->price;
$previousPrice = $sellingPrice->convertToCurrentCurrency()->format();
$flashSalePrice = FlashSale::pivot($productOrProductVariant)->price->convertToCurrentCurrency()->format();
if (is_callable($callback)) {
return $callback($flashSalePrice, $previousPrice);
@@ -23,14 +27,14 @@ if (! function_exists('product_price_formatted')) {
return "{$flashSalePrice} <span class='previous-price'>{$previousPrice}</span>";
}
$price = $product->price->convertToCurrentCurrency()->format();
$specialPrice = $product->getSpecialPrice()->convertToCurrentCurrency()->format();
$price = $productOrProductVariant->price->convertToCurrentCurrency()->format();
$specialPrice = $productOrProductVariant->getSpecialPrice()->convertToCurrentCurrency()->format();
if (is_callable($callback)) {
return $callback($price, $specialPrice);
}
if (! $product->hasSpecialPrice()) {
if (!$productOrProductVariant->hasSpecialPrice()) {
return $price;
}