¨4.0.1¨
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user