$product */ $variants = $product['preview_variants'] ?? []; $activeVariant = $variants[0] ?? [ 'name' => $product['variant_name'] ?? '', 'unit' => $product['unit'] ?? '', 'price_per_unit' => $product['price_per_unit'] ?? null, 'package_price' => $product['package_price'] ?? null, 'package_quantity' => $product['package_quantity'] ?? 0, 'old_package_price' => $product['old_package_price'] ?? null, ]; $showUnitPriceForVariant = static function (array $variant) use ($product): bool { if (function_exists('product_should_show_unit_price')) { return product_should_show_unit_price($product, $variant); } $unit = (string) ($variant['unit'] ?? $product['base_unit'] ?? ''); if (!in_array($unit, ['kg', 'кг'], true)) { return false; } if (($variant['price_per_unit'] ?? null) === null || (float) $variant['price_per_unit'] <= 0) { return false; } $packageQuantity = (float) ($variant['package_quantity'] ?? 0); if ($packageQuantity < 1) { return false; } $lower = static function (string $value): string { return function_exists('mb_strtolower') ? mb_strtolower($value, 'UTF-8') : strtolower($value); }; return preg_match('/(^|[\s,.;])\d+(?:[.,]\d+)?\s*(мл|шт)\.?($|[\s,.;])/u', $lower((string) ($variant['name'] ?? ''))) !== 1; }; $cardId = 'product-card-' . (int) ($product['id'] ?? 0); $activePackagePrice = (float) ($activeVariant['package_price'] ?? 0); $activeUnitPrice = $activeVariant['price_per_unit'] === null ? null : (float) $activeVariant['price_per_unit']; $activePackageQuantity = (float) ($activeVariant['package_quantity'] ?? 0); $activeVariantOldPackagePrice = $activeVariant['old_package_price'] ?? null; $activeOldPackagePrice = ( $activeVariantOldPackagePrice !== null && (float) $activeVariantOldPackagePrice > $activePackagePrice ) ? (float) $activeVariantOldPackagePrice : null; $activeOldUnitPrice = ($activeOldPackagePrice !== null && $activePackageQuantity > 0 && $activeUnitPrice !== null) ? $activeOldPackagePrice / $activePackageQuantity : null; if ($activeOldUnitPrice !== null && $activeOldUnitPrice <= $activeUnitPrice) { $activeOldUnitPrice = null; } $activeShowsUnitPrice = $showUnitPriceForVariant($activeVariant); $activeTierBase = $activeShowsUnitPrice ? ($activeUnitPrice ?? $activePackagePrice) : $activePackagePrice; $activeTierUnit = $activeShowsUnitPrice ? unit_label((string) ($activeVariant['unit'] ?? '')) : 'фасовку'; $isPublished = (int) ($product['is_published'] ?? 1) === 1; $isAvailable = (int) ($product['is_available'] ?? 1) === 1; $isPurchasable = $isPublished && $isAvailable && $activePackagePrice > 0; $sourceImagePath = (string) ($product['main_image_path'] ?? ''); $previewImagePath = function_exists('optimized_image_path') ? optimized_image_path($sourceImagePath, 'preview') : $sourceImagePath; ?>
<?= e((string) $product['name']) ?>
<?= e((string) $product['name']) ?>
Рыбсток
Рыбсток

Доступные фасовки:
$variant): ?> $variantPackagePrice ) ? (float) $variant['old_package_price'] : null; $variantOldUnitPrice = ($variantOldPackagePrice !== null && $variantPackageQuantity > 0 && $variantUnitPrice !== null) ? $variantOldPackagePrice / $variantPackageQuantity : null; if ($variantOldUnitPrice !== null && $variantOldUnitPrice <= $variantUnitPrice) { $variantOldUnitPrice = null; } $variantShowsUnitPrice = $showUnitPriceForVariant($variant); ?>
Цена за : > За фасовку : > Цена за ×
Цену уточним после поступления товара.