Prestashop:我可以在主题中添加模块吗?

时间:2018-09-10 12:49:17

标签: php prestashop prestashop-1.6

我正在重建Prestashop应用程序,我想知道,是否有可能将我购买的模块(Home Categories Pro https://addons.prestashop.com/en/products-homepage/26563-home-products-pro.html)添加到页面上当前使用的主题(SP Hurama)。 更清楚地说,该模块注册了多个挂钩,但是它们仅由PS默认引导主题使用。有没有办法将这些挂钩与当前主题一起使用?谢谢。

1 个答案:

答案 0 :(得分:0)

有两种方法可以实现您的要求。

第一个也是推荐的一个,是在主题.tpl文件中的正确位置添加一个模块正在使用的钩子(例如在default-bootstrap中)。应该是类似于

的行
 API Response

     "listValidators": [
            {
                "inputType": 1,
                "lableName": "Smart Card Number",
                "message": "Smart Card Number starts with 4 or 1 and have only 11 digits",
                "productId": 1218,
                "regex": "^[4|1]{1}[0-9]{10}$"
            },
            {
                "inputType": 1,
                "lableName": "Amount",
                "message": "Amount must be between Rs.10 and Rs.10000",
                "productId": 1218,
                "regex": "^([0-9]{2,4})$|^10000$"
            },
            {
                "inputType": 1,
                "lableName": "Customer Relation Number",
                "message": "Customer Relation Number starts with 4 or 1 and have only 11 digits",
                "productId": 1218,
                "regex": "^[4|1]{1}[0-9]{10}$"
            },
            {
                "inputType": 10,
                "lableName": "Recharge Now",
                "message": "",
                "productId": 1218,
                "regex": ""
            }
        ]

    Java Code

    for(final Validators v : validators){
                    if(v.type == 1){ //inputType
                        // 1 editable text


                        if(vendorId==220){
                            EditText tv = new EditText(this);
                            //tv.setId(viewOffest++);

                            LinearLayout.LayoutParams tvLayoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
                            tvLayoutParams.setMargins(0,10,0,0);
                            tv.setLayoutParams(tvLayoutParams);

                            tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.dynamic_text_size_medium));
                            //tv.setHint("Enter " + v.text);
                            tv.setTextAppearance(this, R.style.parent_filled);
                            tv.setInputType(InputType.TYPE_CLASS_NUMBER);
                            if(v.regex.contains("a-z"))
                                tv.setInputType(InputType.TYPE_CLASS_TEXT);
                            d(LS, "adding inputype "+ v.type + " to view");
                            tv.setTag(R.string.tag_hint_validator, validators);
                            tv.setOnFocusChangeListener(hintListener);

    //flexisection is Linear layout here is confusion

                            if(flexiSection.getTag.equals("Smart Card Number")  
     ||flexiSection.getTag().equals("Customer Relation Number")){ 
                                break;
                            }
                            flexiSection.addView(tv);


                        }

                        else{

                            EditText tv = new EditText(this);
                            //tv.setId(viewOffest++);

                            LinearLayout.LayoutParams tvLayoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
                            tvLayoutParams.setMargins(0,10,0,0);
                            tv.setLayoutParams(tvLayoutParams);

                            tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.dynamic_text_size_medium));
                            tv.setHint("Enter " + v.text);
                            tv.setTextAppearance(this, R.style.parent_filled);
                            tv.setInputType(InputType.TYPE_CLASS_NUMBER);
                            if(v.regex.contains("a-z"))
                                tv.setInputType(InputType.TYPE_CLASS_TEXT);
                            d(LS, "adding inputype "+ v.type + " to view");
                            flexiSection.addView(tv);
                            tv.setTag(R.string.tag_hint_validator, validators);
                            tv.setOnFocusChangeListener(hintListener);
                        }

    Any responses will be appreciated. 

{hook h='displayYourHookName'}

如果有任何参数。

第二种方法是修改模块并在其中添加所需的钩子,该钩子已存在于主题中。在主模块文件yourmodulename.php中,将以下内容添加到安装方法

{hook h='displayYourHookName' parameter=$parameter parameter_1=$parameter_1}

并实现钩子实例化

public function install()
{
    return parent::install() &&
        $this->registerHook('displayYourHookName')
        // continue your module's code here
}

然后将模块移植到挂钩上,或者只是在管理面板中将其重置。