feat(product): add show_in_list toggle and TV price formula
- New `show_in_list` column to control product visibility in customer list - New `tv_price_formula_enabled` + `tv_price_formula` columns for separate TV pricing - FormulaPriceService: isTvEnabled() and calculateTvForProduct() - listTvProducts applies TV formula overrides before returning - filterProductData handles both new field sets Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -21,6 +21,41 @@ class FormulaPriceService
|
||||
return (bool) ($product?->price_formula_enabled);
|
||||
}
|
||||
|
||||
public static function isTvEnabled(?Product $product): bool
|
||||
{
|
||||
if (! Product::hasTvPriceFormulaColumns()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (bool) ($product?->show_on_tv) && (bool) ($product?->tv_price_formula_enabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed>|null $mazanehRow
|
||||
*/
|
||||
public static function calculateTvForProduct(Product $product, ?array $mazanehRow): ?int
|
||||
{
|
||||
if (! self::isTvEnabled($product) || $mazanehRow === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (array_key_exists('active', $mazanehRow) && $mazanehRow['active'] == false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$p = (float) ($mazanehRow['price'] ?? 0);
|
||||
if ($p <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$formula = trim((string) ($product->tv_price_formula ?? ''));
|
||||
if ($formula === '') {
|
||||
$formula = self::DEFAULT_FORMULA;
|
||||
}
|
||||
|
||||
return self::evaluate($formula, $p, self::resolveWeight($product->amount ?? 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* P = قیمت وسط مرجع (بدون تفاوت ارائهدهنده / بدون price_offset_percent)
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user