Skip to content

Commit

Permalink
Revert "try to fix all products"
Browse files Browse the repository at this point in the history
This reverts commit f281218.
  • Loading branch information
mcifra committed Jul 11, 2024
1 parent f281218 commit ed3db2b
Showing 1 changed file with 5 additions and 21 deletions.
26 changes: 5 additions & 21 deletions Fitmo_backend/app/Http/Controllers/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,32 +129,16 @@ public function getSearchedItems($query)

public function getAllProducts()
{
$products = Product::select('colors.*', 'prices.*', 'product_states.*', 'products.*')->with(['categories', 'children' => function ($query) {
$query->select(
'prices.*',
'product_states.*',
'categories.name as category_name',
'colors.*',
'products.*',
'product_categories.category_id as category_id'
)
->leftJoin('prices', 'products.id', '=', 'prices.product_id')
->join('product_states', 'products.id', '=', 'product_states.product_id')
->join('product_categories', 'products.id', '=', 'product_categories.product_id')
->join('categories', 'categories.id', '=', 'product_categories.category_id')
->leftJoin('colors', 'products.color_id', '=', 'colors.id')
->selectRaw('(SELECT GROUP_CONCAT(image_path) FROM images WHERE images.product_id = products.id AND images.is_main = 1) AS image_urls')
->where('products.parent_id', '!=', 0);
}])
$products = Product::select('colors.*', 'prices.*', 'product_states.*', 'products.*')
->selectRaw('(SELECT GROUP_CONCAT(image_path) FROM images WHERE images.product_id = products.id AND images.is_main = 1) AS image_urls')
->leftJoin('prices', 'products.id', '=', 'prices.product_id')
->leftJoin('colors', 'products.color_id', '=', 'colors.id')
->join('product_states', 'products.id', '=', 'product_states.product_id')
->where('products.parent_id', 0)
->get();


return $this->formatProducts($products, true);
foreach ($products as $product) {
$product->image_urls = explode(',', $product->image_urls);
}
return $products;
}

public function setUrlNames()
Expand Down

0 comments on commit ed3db2b

Please sign in to comment.