доставка в плавающем
This commit is contained in:
@@ -30,7 +30,15 @@ final class ProductRepository extends BaseRepository
|
||||
*/
|
||||
public function promoPreview(int $limit = 10): array
|
||||
{
|
||||
$limit = max(1, min($limit, 10));
|
||||
return array_slice($this->promoProducts(max(1, min($limit, 10))), 0, max(1, min($limit, 10)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, array<string, mixed>>
|
||||
*/
|
||||
private function promoProducts(int $limit = 50): array
|
||||
{
|
||||
$limit = max(1, min($limit, 50));
|
||||
$products = $this->manualPromoPreview($limit);
|
||||
$usedIds = array_flip(array_map(static fn (array $product): int => (int) ($product['id'] ?? 0), $products));
|
||||
|
||||
@@ -63,6 +71,20 @@ final class ProductRepository extends BaseRepository
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{products: array<int, array<string, mixed>>, total: int}
|
||||
*/
|
||||
public function promoListing(int $limit = 48, int $offset = 0): array
|
||||
{
|
||||
$products = $this->promoProducts(50);
|
||||
$total = count($products);
|
||||
|
||||
return [
|
||||
'products' => array_slice($products, max(0, $offset), max(1, min($limit, 48))),
|
||||
'total' => $total,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, array<string, mixed>>
|
||||
*/
|
||||
@@ -88,6 +110,20 @@ final class ProductRepository extends BaseRepository
|
||||
return $products;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{products: array<int, array<string, mixed>>, total: int}
|
||||
*/
|
||||
public function newListing(int $limit = 48, int $offset = 0): array
|
||||
{
|
||||
$products = $this->newPreview(50);
|
||||
$total = count($products);
|
||||
|
||||
return [
|
||||
'products' => array_slice($products, max(0, $offset), max(1, min($limit, 48))),
|
||||
'total' => $total,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, array<string, mixed>>
|
||||
*/
|
||||
@@ -151,6 +187,23 @@ final class ProductRepository extends BaseRepository
|
||||
return (int) $statement->fetchColumn();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, array{slug: string, updated_at: string|null, published_at: string|null, created_at: string|null}>
|
||||
*/
|
||||
public function sitemapProducts(int $limit = 10000): array
|
||||
{
|
||||
$statement = $this->pdo()->query(
|
||||
'SELECT slug, updated_at, published_at, created_at
|
||||
FROM products
|
||||
WHERE is_published = 1
|
||||
AND is_available = 1
|
||||
ORDER BY updated_at DESC, published_at DESC, created_at DESC, id DESC
|
||||
LIMIT ' . max(1, min($limit, 10000))
|
||||
);
|
||||
|
||||
return $statement->fetchAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{products: array<int, array<string, mixed>>, total: int}
|
||||
*/
|
||||
@@ -291,7 +344,17 @@ final class ProductRepository extends BaseRepository
|
||||
);
|
||||
$statement->execute(['product_id' => $productId]);
|
||||
|
||||
return $statement->fetchAll();
|
||||
return array_map(
|
||||
static function (array $image): array {
|
||||
$path = (string) ($image['path'] ?? '');
|
||||
$image['preview_path'] = \function_exists('optimized_image_path')
|
||||
? \optimized_image_path($path, 'preview')
|
||||
: $path;
|
||||
|
||||
return $image;
|
||||
},
|
||||
$statement->fetchAll()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -435,7 +498,9 @@ final class ProductRepository extends BaseRepository
|
||||
'variantId' => !empty($row['variant_id']) ? (int) $row['variant_id'] : $variantId,
|
||||
'name' => (string) ($row['name'] ?? ''),
|
||||
'slug' => (string) ($row['slug'] ?? ''),
|
||||
'image' => (string) ($row['main_image_path'] ?? ''),
|
||||
'image' => \function_exists('optimized_image_path')
|
||||
? \optimized_image_path((string) ($row['main_image_path'] ?? ''), 'preview')
|
||||
: (string) ($row['main_image_path'] ?? ''),
|
||||
'variantName' => (string) ($row['variant_name'] ?? 'Фасовка'),
|
||||
'unit' => (string) ($row['unit'] ?? ''),
|
||||
'packageQuantity' => (float) ($row['package_quantity'] ?? 0),
|
||||
|
||||
Reference in New Issue
Block a user