dtpa98038 2015-07-01 22:18
浏览 31
已采纳

获取Prestashop中产品功能的URL

Prestashop allows to create CMS pages for product features. At least, they offer a field in the CMS creation that says URL. I would like to retrieve that URL in my product page and insert it there with a different controller extended from CMS. This should be an easy task if the actualURL of the product feature could be retrieved at all, but it seems like it is an impossible task. When you use:

$this->product->getFrontFeatures($this->context->language->id);

in your product controller, you get an array of features that looks like this:

Array
(
    [name] => Material
    [value] => Polartec Classic 200.
    [id_feature] => 68
)

The URL value is not listed anywhere and of course it makes the task really hard. Unless I am doing something wrong and I should use a different function to get the features values. Can someone tell me which modifications should I do to Prestashop in order to be able to capture the value I require? I would like my array to look like this:

Array
(
    [name] => Material
    [value] => Polartec Classic 200.
    [id_feature] => 68
    [URL] => polartec-classic-200
)
  • 写回答

1条回答 默认 最新

  • doukengzi3517 2015-07-02 12:43
    关注

    The function does not return the layered navigation url for the features. In order to have this in that array, you need to do an override:

    Create a file Product.php in override/classes/ with the following content:

    <?php
    class Product extends ProductCore
    {
        public static function getFrontFeaturesStatic($id_lang, $id_product)
        {
            if (!Feature::isFeatureActive())
                return array();
            if (!array_key_exists($id_product.'-'.$id_lang, self::$_frontFeaturesCache))
            {
                self::$_frontFeaturesCache[$id_product.'-'.$id_lang] = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
                    SELECT name, value, pf.id_feature, liflv.url_name AS url
                    FROM '._DB_PREFIX_.'feature_product pf
                    LEFT JOIN '._DB_PREFIX_.'feature_lang fl ON (fl.id_feature = pf.id_feature AND fl.id_lang = '.(int)$id_lang.')
                    LEFT JOIN '._DB_PREFIX_.'feature_value_lang fvl ON (fvl.id_feature_value = pf.id_feature_value AND fvl.id_lang = '.(int)$id_lang.')
                    LEFT JOIN '._DB_PREFIX_.'feature f ON (f.id_feature = pf.id_feature AND fl.id_lang = '.(int)$id_lang.')
                    LEFT JOIN '._DB_PREFIX_.'layered_indexable_feature_lang_value liflv ON (f.id_feature = liflv.id_feature AND liflv.id_lang = '.(int)$id_lang.')
                    '.Shop::addSqlAssociation('feature', 'f').'
                    WHERE pf.id_product = '.(int)$id_product.'
                    ORDER BY f.position ASC'
                );
            }
            return self::$_frontFeaturesCache[$id_product.'-'.$id_lang];
        }
    }
    

    and do not forget to delete cache/class_index.php in order to clear the overrides cache.

    Note #1: The solution is based on the getFrontFeaturesStatic() method from PrestaShop 1.6.0.14 Note #2: The array index is 'url' in lower case (not URL in upper case) - best practice

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?