Prestahsop:在制造商列表中获取制造商Meta关键字

时间:2017-05-16 07:50:44

标签: prestashop prestashop-1.6 templating

我正在维护一个网上商店,其中制造商Meta关键字用于在列表页面上订购制造商:制造商显示在页面的不同部分,具体取决于他们的元关键字。

最近,页面破了,所有制造商都显示在页面的同一部分。

研究这一点,似乎Prestashop在加载制造商(客户端最近更新到1.6.11)时不再加载meta_keywords。这是有道理的,因为meta_keywords几乎已经过时且很少使用 - 但无论如何我都需要它们才能正确显示这个页面。

我还有加载并使用ManufacturerList.tpl上的meta_keywords吗?

1 个答案:

答案 0 :(得分:0)

如果您确实需要获取meta_keywords,则不会在函数getManufacturers中选择它们。仅从manufacturer_lang中选择了description和short_description。

您可以更改该文件(不建议使用,因为将来的更新可以覆盖它),或者在覆盖/ classes / Manufacturer.php中创建覆盖文件 用:

class Manufacturer extends ManufacturerCore
{
    public static function getManufacturers($get_nb_products = false, $id_lang = 0, $active = true, $p = false, $n = false, $all_group = false, $group_by = false)
    {
        if (!$id_lang) {
            $id_lang = (int)Configuration::get('PS_LANG_DEFAULT');
        }
        if (!Group::isFeatureActive()) {
            $all_group = true;
        }

        $manufacturers = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
        SELECT m.*, ml.`description`, ml.`short_description`, ml.`meta_keywords`, ml.`meta_description`
        FROM `'._DB_PREFIX_.'manufacturer` m
        '.Shop::addSqlAssociation('manufacturer', 'm').'
        INNER JOIN `'._DB_PREFIX_.'manufacturer_lang` ml ON (m.`id_manufacturer` = ml.`id_manufacturer` AND ml.`id_lang` = '.(int)$id_lang.')
        '.($active ? 'WHERE m.`active` = 1' : '')
        .($group_by ? ' GROUP BY m.`id_manufacturer`' : '').'
        ORDER BY m.`name` ASC
        '.($p ? ' LIMIT '.(((int)$p - 1) * (int)$n).','.(int)$n : ''));
        if ($manufacturers === false) {
            return false;
        }

        if ($get_nb_products) {
            $sql_groups = '';
            if (!$all_group) {
                $groups = FrontController::getCurrentCustomerGroups();
                $sql_groups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1');
            }

            $results = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
                    SELECT  p.`id_manufacturer`, COUNT(DISTINCT p.`id_product`) as nb_products
                    FROM `'._DB_PREFIX_.'product` p USE INDEX (product_manufacturer)
                    '.Shop::addSqlAssociation('product', 'p').'
                    LEFT JOIN `'._DB_PREFIX_.'manufacturer` as m ON (m.`id_manufacturer`= p.`id_manufacturer`)
                    WHERE p.`id_manufacturer` != 0 AND product_shop.`visibility` NOT IN ("none")
                    '.($active ? ' AND product_shop.`active` = 1 ' : '').'
                    '.(Group::isFeatureActive() && $all_group ? '' : ' AND EXISTS (
                        SELECT 1
                        FROM `'._DB_PREFIX_.'category_group` cg
                        LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`)
                        WHERE p.`id_product` = cp.`id_product` AND cg.`id_group` '.$sql_groups.'
                    )').'
                    GROUP BY p.`id_manufacturer`'
                );

            $counts = array();
            foreach ($results as $result) {
                $counts[(int)$result['id_manufacturer']] = (int)$result['nb_products'];
            }

            if (count($counts)) {
                foreach ($manufacturers as $key => $manufacturer) {
                    if (array_key_exists((int)$manufacturer['id_manufacturer'], $counts)) {
                        $manufacturers[$key]['nb_products'] = $counts[(int)$manufacturer['id_manufacturer']];
                    } else {
                        $manufacturers[$key]['nb_products'] = 0;
                    }
                }
            }
        }

        $total_manufacturers = count($manufacturers);
        $rewrite_settings = (int)Configuration::get('PS_REWRITING_SETTINGS');
        for ($i = 0; $i < $total_manufacturers; $i++) {
            $manufacturers[$i]['link_rewrite'] = ($rewrite_settings ? Tools::link_rewrite($manufacturers[$i]['name']) : 0);
        }
        return $manufacturers;
    }
}

然后删除要使用该文件中的覆盖再次重新创建的文件cache / class_index.php,它应该包含您需要的数据。