HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/topswtw.komma.pro/app/KommaApp/Shop/Routes/RouteService.php
<?php

/**
 * Short description for the file.
 *
 * @author      Tim Van Samang <timvansamang@komma.pro>
 * @copyright   (c) 2012-2015, Komma Mediadesign
 */

namespace KommaApp\Shop\Routes;

use KommaApp\Shop\Routes;
use KommaApp\Shop\Language;

class RouteService
{
    public function getSitemapRoutes($groups = ['pages', 'categories', 'products'], $weight_from = 0.1)
    {

        $available_langs =


        $routes = \DB::table('routes')
            ->select('routes.*', 'category_translations.category_id as cat_id', 'product_translations.products_shop_id as prod_id', 'page_translations.page_id as page_id'
                , 'category_translations.language_id as cat_lang', 'product_translations.language_id as prod_lang', 'page_translations.language_id as page_lang'
                , 'category_translations.name as cat_name', 'product_translations.name as prod_name', 'page_translations.name as page_name'
            )
            ->where('routes.shop_id', '=', \Shop::getShop()->id)
            ->leftJoin('shop_language as sl', 'sl.shop_id', '=', 'routes.shop_id')
            //Join to the coupling id
            //Catgories
            ->leftJoin('category_translations', 'category_translations.id', '=', 'routes.routable_id')
            ->leftJoin('categories', 'category_translations.category_id', '=', 'categories.id')
            ->where(function ($query) {
                $query->where('categories.active', '=', 1)
                    ->orWhereNull('categories.id');
            })
            //Products
            ->leftJoin('product_translations', 'product_translations.id', '=', 'routes.routable_id')
            //Pages
            ->leftJoin('page_translations', 'page_translations.id', '=', 'routes.routable_id')
            ->where('sitemap_weight', '>=', $weight_from)
            ->orderBy('route', 'asc')
            ->groupBy('route')
            ->get();


        $cleaned_routes = [];
        foreach ($routes as $route) {
            if (in_array('products', $groups) && $route->routable_type == 'Komma\Kms\Products\Models\ShopProductTranslation') {

                $cleaned_routes[$route->routable_type][$route->prod_id][$route->prod_lang] = [
                    'route' => $route->route,
                    'weight' => $route->sitemap_weight,
                    'name' => $route->prod_name
                ];
            } elseif (in_array('pages', $groups) && $route->routable_type == 'Komma\Kms\Pages\Models\PageTranslation') {
                $cleaned_routes[$route->routable_type][$route->page_id][$route->page_lang] = [
                    'route' => $route->route,
                    'weight' => $route->sitemap_weight,
                    'name' => $route->page_name
                ];
            } elseif (in_array('categories', $groups) && $route->routable_type == 'Komma\Kms\Categories\Models\CategoryTranslation') {

                $cleaned_routes[$route->routable_type][$route->cat_id][$route->cat_lang] = [
                    'route' => $route->route,
                    'weight' => $route->sitemap_weight,
                    'name' => $route->cat_name
                ];
            }

        }
        return $cleaned_routes;
    }
}