Solucionar data-vocabulary.org schema deprecated en PrestaShop

Muchos de nosotros nos hemos llevado un susto cuando hemos recibido este email:

¿CÓMO SOLUCIONAR EL PROBLEMA DEL BREADCrUMB en PS 1.6?

Muy sencillo si tienes cuidado. Tienes que tener muy claro que esta solución es para PrestaShop 1.6, unos conocimientos básicos y un poco de cabeza.

Haz copia de seguridad de todos los archivos que vamos a modificar. Los que están en la carpeta Override si ya existen tendrás que añadir las funciones que verás debajo de lo que haya si son otros funciones o sobreescribir si ya existieran.

Básicamente se modifican 3 archivos: Breadcrumb.tpl de tu tema, ProductController.php en override/controllers y Tools.php en override/clases. Vuelvo a repetir que hagas copias de seguridad de todos los archivos.

En el primero se modifican los primeros apartados del Breadcrumb con respecto al inicio y la categoría:

<!-- Breadcrumb -->
{if isset($smarty.capture.path)}{assign var='path' value=$smarty.capture.path}{/if}
<div class="breadcrumb" {if $page_name == 'product' or $page_name == 'category' or $page_name == 'cms'}itemscope itemtype="http://schema.org/BreadcrumbList"{/if}>
<!--    <div class="container"  > -->
        <!--<meta itemprop="name" content="{$meta_title|escape:'html':'UTF-8'}"/>-->
        <span {if $page_name == 'product' or $page_name == 'category' or $page_name == 'cms'}itemprop="itemListElement" itemscope="" itemtype="http://schema.org/ListItem"{/if}><meta itemprop="position" content="1"><a class="home" itemprop="item" href="{if isset($force_ssl) && $force_ssl}{$base_dir_ssl}{else}{$base_dir}{/if}" title="{l s='Return to Home'}"><meta itemprop="name" content="{l s='Home'}" /><i class="icon-home"></i></a></span>
    {if isset($path) AND $path}
        <span  class="navigation-pipe"  {if isset($category) && isset($category->id_category) && $category->id_category == (int)Configuration::get('PS_ROOT_CATEGORY')} style="display:none;"{/if}>{$navigationPipe|escape:'html':'UTF-8'}</span>
        {if $page_name == 'product' or $page_name == 'category' or $page_name == 'cms'}
            {if $path|strpos:'span' !== false}
                <span  class="navigation_page" >
                {$path|@replace:'<a ': '<span > <span >
                    <a itemprop="item" '|@replace:'data-gg="">': '>
                    <span >'|@replace:'</a>': '</a></span></span>'}</span>
            {else}
                <span itemprop="itemListElement" class="item-breadcrumb" itemscope="" itemtype="http://schema.org/ListItem"><meta itemprop="position" content="1"><meta itemprop="item" content="{if isset($force_ssl) && $force_ssl}https://{$smarty.server.HTTP_HOST}{$smarty.server.REQUEST_URI}{else}http://{$smarty.server.HTTP_HOST}{$smarty.server.REQUEST_URI}{/if}" /><meta itemprop="name" content="{$path}" /><span class="item-breadalone">{$path}</span></span>
            {/if}
        {else}
            {if $path|strpos:'span' !== false}
                <span  class="navigation_page" >
                {$path|@replace:'<a ': '<span > <span >
                    <a '|@replace:'data-gg="">': '>
                    <span >'|@replace:'</a>': '</a></span></span>'}</span>
            {else}
                <span class="item-breadalone">{$path}</span>
            {/if}
        {/if}
    {/if}
</div>

En override/controllers/ProductController.php que asigna la categoría del producto a nuestro tema para después usarla.

<?php

class ProductController extends ProductControllerCore
{

    protected function assignCategory()
    {
        // Assign category to the template
        if ($this->category !== false && Validate::isLoadedObject($this->category) && $this->category->inShop() && $this->category->isAssociatedToShop()) {
            $this->category = new Category((int)$this->product->id_category_default, (int)$this->context->language->id);
            $path = Tools::getPath($this->product->id_category_default, $this->product->name, true);
        } elseif (Category::inShopStatic($this->product->id_category_default, $this->context->shop)) {
            $this->category = new Category((int)$this->product->id_category_default, (int)$this->context->language->id);
            if (Validate::isLoadedObject($this->category) && $this->category->active && $this->category->isAssociatedToShop()) {
                $path = Tools::getPath((int)$this->product->id_category_default, $this->product->name);
            }
        }
        if (!isset($path) || !$path) {
            $this->category = new Category((int)$this->product->id_category_default, (int)$this->context->language->id);
            $path = Tools::getPath($this->product->id_category_default, $this->product->name, true);
        }

        $sub_categories = array();
        if (Validate::isLoadedObject($this->category)) {
            $sub_categories = $this->category->getSubCategories($this->context->language->id, true);

            // various assignements before Hook::exec
            $this->context->smarty->assign(array(
                'path' => $path,
                'category' => $this->category,
                'subCategories' => $sub_categories,
                'id_category_current' => (int)$this->category->id,
                'id_category_parent' => (int)$this->category->id_parent,
                'return_category_name' => Tools::safeOutput($this->category->getFieldByLang('name')),
                'categories' => Category::getHomeCategories($this->context->language->id, true, (int)$this->context->shop->id)
            ));
        }
        $this->context->smarty->assign(array('HOOK_PRODUCT_FOOTER' => Hook::exec('displayFooterProduct', array('product' => $this->product, 'category' => $this->category))));
    }

}

Y finalmente override/classes/Tools.php que genera lo que nos falta para que esté correcto y Google nos dé el visto bueno.

<?php

class Tools extends ToolsCore
{
    public static function getPath($id_category, $path = '', $link_on_the_item = false, $category_type = 'products', Context $context = null)
    {
        if (!$context)
            $context = Context::getContext();
        $id_category = (int)$id_category;
        if ($id_category == 1)
            return '<span class="navigation_end">'.$path.'</span>';
        $pipe = Configuration::get('PS_NAVIGATION_PIPE');
        if (empty($pipe))
            $pipe = '>';
        $full_path = '';
        if ($category_type === 'products')
        {
            $interval = Category::getInterval($id_category);
            $id_root_category = $context->shop->getCategory();
            $interval_root = Category::getInterval($id_root_category);
            if ($interval)
            {
                $sql = 'SELECT c.id_category, cl.name, cl.link_rewrite, cl.meta_title
                        FROM '._DB_PREFIX_.'category c
                        LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_category = c.id_category'.Shop::addSqlRestrictionOnLang('cl').')
                        '.Shop::addSqlAssociation('category', 'c').'
                        WHERE c.nleft <= '.$interval['nleft'].'
                            AND c.nright >= '.$interval['nright'].'
                            AND c.nleft >= '.$interval_root['nleft'].'
                            AND c.nright <= '.$interval_root['nright'].'
                            AND cl.id_lang = '.(int)$context->language->id.'
                            AND c.active = 1
                            AND c.level_depth > '.(int)$interval_root['level_depth'].'
                        ORDER BY c.level_depth ASC';
                $categories = Db::getInstance()->executeS($sql);
                $n = 1;
                $n_categories = count($categories);
                foreach ($categories as $key => $category)
                {
                    $key = $key+2;
                    $full_path .='<span itemprop="itemListElement" class="item-breadcrumb" itemscope="" itemtype="http://schema.org/ListItem" ><meta itemprop="position" content="'.$key.'">'. (($n < $n_categories || $link_on_the_item) ? '<a itemprop="url" href="'.Tools::safeOutput($context->link->getCategoryLink((int)$category['id_category'], $category['link_rewrite'])).'" title="'.htmlentities($category['name'], ENT_NOQUOTES, 'UTF-8').'">' : '<meta itemprop="url" content="'.Tools::safeOutput($context->link->getCategoryLink((int)$category['id_category'], $category['link_rewrite'])).'" title="'.htmlentities($category['name'], ENT_NOQUOTES, 'UTF-8').'" />').'<meta itemprop="name" content="'.htmlentities($category['name'], ENT_NOQUOTES, 'UTF-8').'" />'.
                    htmlentities($category['name'], ENT_NOQUOTES, 'UTF-8').
                    (($n < $n_categories || $link_on_the_item) ? '</a>' : '').
                    (($n++ != $n_categories || !empty($path)) ? '<span class="navigation-pipe">'.$pipe.'</span>' : '').'</span>';
                }
                return $full_path.$path;
            }
        }
        else if ($category_type === 'CMS')
        {
            $category = new CMSCategory($id_category, $context->language->id);
            if (!Validate::isLoadedObject($category))
                die(Tools::displayError());
            $category_link = $context->link->getCMSCategoryLink($category);
            if ($path != $category->name)
                $full_path .= '<a href="'.Tools::safeOutput($category_link).'">'.htmlentities($category->name, ENT_NOQUOTES, 'UTF-8').'</a><span class="navigation-pipe">'.$pipe.'</span>'.$path;
            else
                $full_path = ($link_on_the_item ? '<a href="'.Tools::safeOutput($category_link).'">' : '').htmlentities($path, ENT_NOQUOTES, 'UTF-8').($link_on_the_item ? '</a>' : '');
            return Tools::getPath($category->id_parent, $full_path, $link_on_the_item, $category_type);
        }
    }
}

Después de estas modificaciones recuerda borrar class_index.php del directorio caché para que coja estás modificaciones.

Esto no es mérito mío sino que una persona lo ha compartido en el foro oficial de PrestaShop. Gracias a Trace por su aporte.

Os puedo asegurar que funciona perfectamente.

2 comentarios en «Solucionar data-vocabulary.org schema deprecated en PrestaShop»

  1. Buenos dias! En mi caso no tenia archivos ni en

    ProductController.php en override/controllers y Tools.php en override/clases.

    He creado sendos y los he subido a las rutas indicadas, además he realizado la edición del 1º que indicas. La web corre bien, no se si estaré o no en lo correcto. Veremos que dice Google.

    ¿Es posible lo que digo de que no existiesen?

    Responder

Deja un comentario