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 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办