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

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

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度