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/topswtwmobile.komma.pro/app/KommaApp/Shop/Shop.php
<?php

namespace KommaApp\Shop;

use KommaApp\Shop\Checkout\CheckoutSession\CheckoutSession;
use KommaApp\Shop\Countries\Models\Country;
use KommaApp\Shop\Pages\PageService;


class Shop
{
    protected $id;
    protected $shop;

    protected $shopRepository;
    protected $languageService;
    protected $cart;
    protected $shopResolver;
    protected $routeData;
    protected $pageService;

    function __construct(ShopRepository $shopRepository,
                         ShopResolver $shopResolver,
                         LanguageService $languageService,
                         PageService $pageService,
                         CheckoutSession $checkoutSession)
    {
        $this->shopRepository = $shopRepository;
        $this->shopResolver = $shopResolver;
        $this->languageService = $languageService;
        $this->pageService = $pageService;
        $this->cart = $checkoutSession->cart();

        $this->id = $this->shopResolver->getShopId();
        $this->shop = $this->shopRepository->getShop($this->id);;

        \View::share('shop', $this);
    }

    public function get()
    {
        return $this;
    }

    /*
     * @return Int id
     */
    public function getId()
    {
        return $this->id;
    }

    public function getShop()
    {
        return $this->shop;
    }

    public function setShop($shop_id)
    {
        $this->shop = $this->shopRepository->getShop($shop_id);;
    }

    public function getCountryId()
    {
        return $this->getShop()->country_id;
    }

    public function getCountry()
    {
        return $this->shopRepository->getShopCountry($this->id);
    }

    /**
     * @param $currentLanguageId
     */
    public function setLanguageService($currentLanguageId)
    {
        // Set the available languages for the Language object
        $shops = $this->shopRepository->getShopsWithLanguageById($this->id);
        $this->languageService->setAvailableLanguages($shops);

        // Set current language id
        $this->languageService->setCurrentLanguage($currentLanguageId);

        // Update Cart when switching Language
        if (\Input::has('switch')) {
            if (\Input::get('switch') == 'language')
                /**
                 * The products in the cart are already translated,
                 * When changing the languages, the products should be removed
                 * and added again in the correct language.
                 */
                $this->cart->reloadProducts();
        }
    }

    /*
     * @return Object Languages
     */
    public function getLanguageService()
    {
        return $this->languageService;
    }

    /*
     * @return Object Cart
     */
    public function getCart()
    {
        return $this->cart;
    }

    /**
     * @param $routeData
     */
    public function setRouteData($routeData)
    {
        $this->routeData = $routeData;
    }

    /**
     * @return Route
     */
    public function getRouteData()
    {
        return $this->routeData;
    }

    /**
     * @return PageService
     */
    public function getPageService()
    {
        return $this->pageService;
    }

    public function shopRepository()
    {
        return $this->shopRepository;
    }

    public function getDomainCountry($field = 'iso_2')
    {
        return $this->shopResolver->getDomainCountry($field);
    }

    public function getLinkedDomains()
    {
        return $this->shopResolver->getLinkedDomains();

    }

    public function getDomain()
    {
        return $this->shopResolver->getDomain();
    }


    public function getCountriesList($countryIso2s = [])
    {

        if (!empty($countryIso2s)) $countries = Country::whereIn('iso_2', $countryIso2s)->get();
        else         $countries = Country::all();


        $countriesList = [];
        foreach ($countries as $country) {
            if (\Lang::has('countries.' . $country->iso_2)) {
                $countriesList [$country->iso_2] = \Lang::get('countries.' . $country->iso_2);
            }
        }
        asort($countriesList);

        return $countriesList;
    }


    public function getOtherShopRedirect($type)
    {
        $route = (\Config::get('komma/tops.www') == true ? 'www.' : '');
        if ($this->shop->id != 1) {
            $route .= 'topswtwfilters.nl';
        } elseif ($this->shop->id != 2) {
            $route .= 'topskwlfilter.de';
        }
        if ($type == 'location') $route = (\Config::get('komma/tops.https') == true ? 'https://' : 'http://') . $route;
        return $route;
    }

    /**
     * This method checks if the languageSwitch should be enabled
     *
     * @return bool|string False, or the locale used to get the correct translation
     */
    public function enableLanguageSwitcher()
    {

        //Check if the cookie already exists
        if (\Cookie::get('disableLanguageSwitch') == 'disable') return false;

        //Check if the HTTP_ACCEPT_LANGUAGE exist
        if (!isset($_SERVER["HTTP_ACCEPT_LANGUAGE"])) return false;

        //Check if the first part is de or nl, else return false
        if (!preg_match('/^(de|nl)(-[a-z]{2})?/', $_SERVER["HTTP_ACCEPT_LANGUAGE"], $match)) return false;

        //If shop is 1 and language is de, return de
        if ($this->shop->id == 1 && $match[1] == 'de') {
            return 'de';
        } //If shop is 2 and lang is nl , return nl
        if ($this->shop->id == 2 && $match[1] == 'nl') {
            return 'nl';
        }
        //If shop is 3 and the lang is de or nl, return the lang (match[1])
        if ($this->shop->id == 3 && ($match[1] == 'de' || $match[1] == 'nl')) {
            return $match[1];
        }

        //Default return false
        return false;
    }

    /**
     * Check if maintenance is available
     * based on the shopId and the domainCountry
     *
     * @return mixed
     *
     */
    public function isMaintenanceAvailable()
    {
        return \Config::get('komma/tops.maintenance_availability.' . $this->getShop()->id . '_' . $this->getDomainCountry(), false);
    }


    /**
     * Check if the ParcelShop is active for the given shop
     * This is based on the settings in the komma/tops config file
     *
     * @return boolean
     */
    public function isParcelShopActive()
    {
        return \Config::get('komma/tops.parcelShop.' . $this->shop->id, false);
    }
}