Jump to content

Edit History

StrefaBiznesu

StrefaBiznesu

<?php
class Link extends LinkCore
{
    /*
    * module: sturls
    * date: 2022-03-23 07:48:58
    * version: 1.1.11
    */
    public function getCategoryLink(
        $category,
        $alias = null,
        $idLang = null,
        $selectedFilters = null,
        $idShop = null,
        $relativeProtocol = false
    ) {
        $dispatcher = Dispatcher::getInstance();
        if (!$idLang) {
            $idLang = Context::getContext()->language->id;
        }
        $url = $this->getBaseLink($idShop, null, $relativeProtocol).$this->getLangLink($idLang, null, $idShop);
        $params = array();
        if (!is_object($category)) {
            $params['id'] = $category;
        } else {
            $params['id'] = $category->id;
        }
        $selectedFilters = is_null($selectedFilters) ? '' : $selectedFilters;
        if (empty($selectedFilters)) {
            $rule = 'category_rule';
        } else {
            $rule = 'layered_rule';
            $params['selected_filters'] = $selectedFilters;
        }
        if (!is_object($category)) {
            $category = new Category($category, $idLang);
        }
        $params['rewrite'] = (!$alias) ? $category->link_rewrite : $alias;
        if ($dispatcher->hasKeyword($rule, $idLang, 'meta_keywords', $idShop)) {
            $params['meta_keywords'] = Tools::str2url($category->getFieldByLang('meta_keywords'));
        }
        if ($dispatcher->hasKeyword($rule, $idLang, 'meta_title', $idShop)) {
            $params['meta_title'] = Tools::str2url($category->getFieldByLang('meta_title'));
        }
        if (Dispatcher::getInstance()->hasKeyword('category_rule', $idLang, 'categories', $idShop))
        {
            $p = array();
            foreach ($category->getParentsCategories($idLang) as $c)
            {
                if (!$c['is_root_category'] && $c['id_category'] != $category->id)
                    $p[$c['level_depth']] = $c['link_rewrite'];
            }
            $params['categories'] = implode('/', array_reverse($p));
        }
        return $url.Dispatcher::getInstance()->createUrl($rule, $idLang, $params, $this->allow, '', $idShop);
    }
    /*
    * module: sturls
    * date: 2022-03-23 07:48:58
    * version: 1.1.11
    */
    public function getModuleLink(
        $module,
        $controller = 'default',
        array $params = array(),
        $ssl = null,
        $idLang = null,
        $idShop = null,
        $relativeProtocol = false
    ) {
        if ($module == 'stblog' && $idLang && $idLang != Context::getContext()->language->id) {
            if ($controller == 'article') {
                $id = Tools::version_compare(_PS_VERSION_, '1.7') ? 'id_blog' : 'id_st_blog';
                $blog = new StBlogClass($params[$id], $idLang);
                $params['rewrite'] = $blog->link_rewrite;
            } elseif ($controller == 'category') {
                $id = Tools::version_compare(_PS_VERSION_, '1.7') ? 'blog_id_category' : 'id_st_blog_category';
                $category = new StBlogCategory($params[$id], $idLang);
                $params['rewrite'] = $category->link_rewrite;
            }
        }
        return parent::getModuleLink($module, $controller, $params, $ssl, $idLang, $idShop, $relativeProtocol);
    }
    /*
    * module: ultimateimagetool
    * date: 2022-10-14 14:40:48
    * version: 1.5.98
    */
    protected $webpSupported = false;
    /*
    * module: ultimateimagetool
    * date: 2022-10-14 14:40:48
    * version: 1.5.98
    */
    public function __construct($protocolLink = null, $protocolContent = null)
    {
        parent::__construct($protocolLink, $protocolContent);
        if(
            Module::isEnabled('ultimateimagetool') &&  
            (int)Configuration::get('uit_use_webp') >= 1 &&  
            (int)Configuration::get('uit_use_picture_webp') == 0 &&
            (int)Configuration::get('uit_use_webp_termination') >= 1
            && (isset($_SERVER['HTTP_ACCEPT']) === true) &&  (false !== strpos($_SERVER['HTTP_ACCEPT'], 'image/webp'))   )
        {
            $this->webpSupported = true;
        }
    }
   /*
    * module: ultimateimagetool
    * date: 2022-10-14 14:40:48
    * version: 1.5.98
    */
    public function getImageLink($name, $ids, $type = null)
    {
        $parent = parent::getImageLink($name, $ids, $type);
   
        if ($this->webpSupported)
        {
            $split_ids = explode('-', $ids);
            $id_image = (isset($split_ids[1]) ? $split_ids[1] : $split_ids[0]);
            $uri_path = _PS_ROOT_DIR_._THEME_PROD_DIR_.Image::getImgFolderStatic( $id_image ). $id_image .($type ? '-'.$type : '').'.webp';
             if(file_exists(  $uri_path ) && strpos($uri_path , '/p/default-') === false)
                return str_replace('.jpg', '.webp', $parent);
         
             return $parent;
        }
       
        return $parent;
    }
    /*
    * module: ultimateimagetool
    * date: 2022-10-14 14:40:48
    * version: 1.5.98
    */
    public function getCatImageLink($name, $idCategory, $type = null)
    {
        $parent = parent::getCatImageLink($name, $idCategory, $type);
        if ($this->webpSupported)
        {
            $uri_path = _PS_ROOT_DIR_._THEME_CAT_DIR_.Image::getImgFolderStatic($idCategory).$idCategory.($type ? '-'.$type : '').'.webp';
       
            if(file_exists(  $uri_path )&& strpos($uri_path , '/c/default-') === false)
                 return str_replace('.jpg', '.webp', $parent);
           
            $allow = (int) Configuration::get('PS_REWRITING_SETTINGS');
            if ($allow == 1 && $type) {
                $uri_path = _PS_ROOT_DIR_ . '/img/c/' . $idCategory . '-' . $type  . '.webp';
            } else {
                $uri_path = _THEME_CAT_DIR_ . $idCategory . ($type ? '-' . $type : '') . '.webp';
            }
 
            if(file_exists(  $uri_path )&& strpos($uri_path , '/c/default-') === false)
                 return str_replace('.jpg', '.webp', $parent);
        }
       
        return $parent;
    }
    /*
    * module: ultimateimagetool
    * date: 2022-10-14 14:40:48
    * version: 1.5.98
    */
    public function getSupplierImageLink($idSupplier, $type = null)
    {
        $parent = parent::getSupplierImageLink($idSupplier, $type);
        if ($this->webpSupported)
        {          
            $uri_path = _PS_ROOT_DIR_._PS_SUPP_IMG_DIR_.Image::getImgFolderStatic($idSupplier).$idSupplier.($type ? '-'.$type : '').'.webp';
            if(file_exists(  $uri_path )&& strpos($uri_path , '/s/default-') === false)
                return str_replace('.jpg', '.webp', $parent);
        }
        return $parent;
    }
    /*
    * module: ultimateimagetool
    * date: 2022-10-14 14:40:48
    * version: 1.5.98
    */
    public function getStoreImageLink($name, $idStore, $type = null)
    {
        $parent = parent::getStoreImageLink($name, $idStore, $type);
        if ($this->webpSupported)
        {          
            $uri_path = _PS_ROOT_DIR_._PS_STORE_IMG_DIR_.Image::getImgFolderStatic($idStore).$idStore.($type ? '-'.$type : '').'.webp';
            if(file_exists(  $uri_path )&& strpos($uri_path , '/st/default-') === false)
                return str_replace('.jpg', '.webp', $parent);
        }
        return $parent;
    }
    /*
    * module: ultimateimagetool
    * date: 2022-10-14 14:40:48
    * version: 1.5.98
    */
    public function getManufacturerImageLink($idManufacturer, $type = null)
    {
        $parent = parent::getManufacturerImageLink($idManufacturer, $type);
        if ($this->webpSupported)
        {          
            $uri_path = _PS_ROOT_DIR_._PS_MANU_IMG_DIR_.Image::getImgFolderStatic($idManufacturer).$idManufacturer.($type ? '-'.$type : '').'.webp';
            if(file_exists(  $uri_path )&& strpos($uri_path , '/m/default-') === false)
                return str_replace('.jpg', '.webp', $parent);
           
        }
        return $parent;
    }
use PrestaShop\PrestaShop\Adapter\SymfonyContainer;
use PrestaShop\PrestaShop\Core\Addon\Module\ModuleManagerBuilder;
use PrestaShop\PrestaShop\Core\Exception\CoreException;
use PrestaShop\PrestaShop\Core\Feature\TokenInUrls;
use PrestaShopBundle\Routing\Converter\LegacyUrlConverter;
use PrestaShopBundle\Service\TransitionalBehavior\AdminPagePreferenceInterface;
use Symfony\Component\Routing\Exception\InvalidParameterException;
use Symfony\Component\Routing\Exception\MissingMandatoryParametersException;
use Symfony\Component\Routing\Exception\RouteNotFoundException;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
class Link extends LinkCore
{
    /** @var bool Rewriting activation */
    protected $allow;
    protected $url;
    public static $cache = ['page' => []];

    public $protocol_link;
    public $protocol_content;

    protected $ssl_enable;
    protected $urlShopId = null;

    protected static $category_disable_rewrite = null;

    public function getProductLink(
        $product,
        $alias = null,
        $category = null,
        $ean13 = null,
        $idLang = null,
        $idShop = null,
        $idProductAttribute = null,
        $force_routes = false,
        $relativeProtocol = false,
        $withIdInAnchor = false,
        $extraParams = [],
        bool $addAnchor = true
    ) {
        $dispatcher = Dispatcher::getInstance();

        if (!$idLang) {
            $idLang = Context::getContext()->language->id;
        }

        $url = $this->getBaseLink($idShop, null, $relativeProtocol) . $this->getLangLink($idLang, null, $idShop);

        // Set available keywords
        $params = [];

        if (!is_object($product)) {
            if (is_array($product) && isset($product['id_product'])) {
                $params['id'] = $product['id_product'];
            } elseif ((int) $product) {
                $params['id'] = $product;
            } else {
                throw new PrestaShopException('Invalid product vars');
            }
        } else {
            $params['id'] = $product->id;
        }

        //Attribute equal to 0 or empty is useless, so we force it to null so that it won't be inserted in query parameters
        if (empty($idProductAttribute)) {
            $idProductAttribute = null;
        } else {

            // find if attributer is 0 quantity
            $log = '';
            $findNewAttributeByQuantity = 0;
            $isQuantityNull = Db::getInstance()->getValue('SELECT quantity FROM '._DB_PREFIX_.'stock_available WHERE id_product = '.$params['id'].' AND id_product_attribute = '. $idProductAttribute);
            $log .= $isQuantityNull."\n";

            if ($isQuantityNull == '0'){
                $findNewAttributeByQuantity = Db::getInstance()->getValue('SELECT id_product_attribute FROM '._DB_PREFIX_.'stock_available WHERE id_product = '.$params['id'].' AND id_product_attribute > 0 AND quantity > 0');
            }

            $log .= $findNewAttributeByQuantity."\n";

            if ($findNewAttributeByQuantity){
                $idProductAttribute = $findNewAttributeByQuantity;
            }

            file_put_contents(_PS_ROOT_DIR_.'/override/classes/Link.txt', $log);
        }

        $params['id_product_attribute'] = $idProductAttribute;
        if (!$alias) {
            $product = $this->getProductObject($product, $idLang, $idShop);
        }
        $params['rewrite'] = (!$alias) ? $product->getFieldByLang('link_rewrite') : $alias;
        if (!$ean13) {
            $product = $this->getProductObject($product, $idLang, $idShop);
        }
        $params['ean13'] = (!$ean13) ? $product->ean13 : $ean13;
        if ($dispatcher->hasKeyword('product_rule', $idLang, 'meta_keywords', $idShop)) {
            $product = $this->getProductObject($product, $idLang, $idShop);
            $params['meta_keywords'] = Tools::str2url($product->getFieldByLang('meta_keywords'));
        }
        if ($dispatcher->hasKeyword('product_rule', $idLang, 'meta_title', $idShop)) {
            $product = $this->getProductObject($product, $idLang, $idShop);
            $params['meta_title'] = Tools::str2url($product->getFieldByLang('meta_title'));
        }

        if ($dispatcher->hasKeyword('product_rule', $idLang, 'manufacturer', $idShop)) {
            $product = $this->getProductObject($product, $idLang, $idShop);
            $params['manufacturer'] = Tools::str2url($product->isFullyLoaded ? $product->manufacturer_name : Manufacturer::getNameById($product->id_manufacturer));
        }

        if ($dispatcher->hasKeyword('product_rule', $idLang, 'supplier', $idShop)) {
            $product = $this->getProductObject($product, $idLang, $idShop);
            $params['supplier'] = Tools::str2url($product->isFullyLoaded ? $product->supplier_name : Supplier::getNameById($product->id_supplier));
        }

        if ($dispatcher->hasKeyword('product_rule', $idLang, 'price', $idShop)) {
            $product = $this->getProductObject($product, $idLang, $idShop);
            $params['price'] = $product->isFullyLoaded ? $product->price : Product::getPriceStatic($product->id, false, null, 6, null, false, true, 1, false, null, null, null, $product->specificPrice);
        }

        if ($dispatcher->hasKeyword('product_rule', $idLang, 'tags', $idShop)) {
            $product = $this->getProductObject($product, $idLang, $idShop);
            $params['tags'] = Tools::str2url($product->getTags($idLang));
        }

        if ($dispatcher->hasKeyword('product_rule', $idLang, 'category', $idShop)) {
            if (!$category) {
                $product = $this->getProductObject($product, $idLang, $idShop);
            }
            $params['category'] = (!$category) ? $product->category : $category;
        }

        if ($dispatcher->hasKeyword('product_rule', $idLang, 'reference', $idShop)) {
            $product = $this->getProductObject($product, $idLang, $idShop);
            $params['reference'] = Tools::str2url($product->reference);
        }

        if ($dispatcher->hasKeyword('product_rule', $idLang, 'categories', $idShop)) {
            $product = $this->getProductObject($product, $idLang, $idShop);
            $params['category'] = (!$category) ? $product->category : $category;
            $cats = [];
            foreach ($product->getParentCategories($idLang) as $cat) {
                if (!in_array($cat['id_category'], Link::$category_disable_rewrite)) {
                    //remove root and home category from the URL
                    $cats[] = $cat['link_rewrite'];
                }
            }
            $params['categories'] = implode('/', $cats);
        }
        if ($idProductAttribute) {
            $product = $this->getProductObject($product, $idLang, $idShop);
        }

        $anchor = $addAnchor && $idProductAttribute ? $product->getAnchor((int) $idProductAttribute, (bool) $withIdInAnchor) : '';

        return $url . $dispatcher->createUrl('product_rule', $idLang, array_merge($params, $extraParams), $force_routes, $anchor, $idShop);

    }
}

>

×
×
  • Create New...