dongmimeng5500 2015-11-12 19:46
浏览 77
已采纳

在OpenCart 2.x.x.x admin(OCmod)中使必需的模型字段可选

I tried to make the required model field in OpenCart optional by writing the following OCmod in OpenCart version 2.0.1.1.

<modification>
    <name>Remove required model (OC 2.0+)</name>
    <version>v1.0</version>
    <link>http://www.example.com</link> 
    <author>John Doe</author>
    <code>fv16343000</code>

    <!-- Remove required "Model" from Product controller -->
    <file path="admin/model/catalog/product.php">
    <operation>
        <search><![CDATA[if ((utf8_strlen($this->request->post['model']) < 1) || (utf8_strlen($this->request->post['model']) > 64)) {]]></search>
        <add position="replace"><![CDATA[if (utf8_strlen($this->request->post['model']) > 64) {]]></add>
    </operation>
    </file>
</modification>

As you can see, I aimed to replace the condition, to make it ignore the minimum length.

I also modified the product_form.tpl (removed the "required" class that it had next to form-group):

      <div class="form-group">
        <label class="col-sm-2 control-label" for="input-model"><?php echo $entry_model; ?></label>
        <div class="col-sm-10">
          <input type="text" name="model" value="<?php echo $model; ?>" placeholder="<?php echo $entry_model; ?>" id="input-model" class="form-control" />
          <?php if ($error_model) { ?>
          <div class="text-danger"><?php echo $error_model; ?></div>
          <?php } ?>
        </div>
      </div>

Then I tried adding the product without the model, the asterisk was gone but the error still popped (saying that I need to complete the field with a minimum of 1 char to max 64 chars).

I thought my OCmod might not be good enough so I tried editing the controller product.php directly as shown in the OCmod. Error still there so I completely deleted the condition and the following code from the .tpl:

  <?php if ($error_model) { ?>
  <div class="text-danger"><?php echo $error_model; ?></div>
  <?php } ?>  

Removing the bootstrap class worked (not showing the asterisk so it works) but for some reason the field is still required, even with the condition in the controller gone.

What am I doing wrong? How can I make the model field optional?

  • 写回答

3条回答 默认 最新

  • dongzhimeng2464 2016-03-01 17:39
    关注

    I managed to fix my problem by using a OCmod. The correct way to remove the model is this:

    <!-- Remove required class from register.tpl-->
    <file path="admin/view/template/catalog/product_form.tpl">
    <operation>
        <search offset="1" index="2"><![CDATA[<div class="form-group required">]]></search>
        <add position="replace"><![CDATA[<div class="form-group">]]></add>
    </operation>
    </file>
    <!-- Comment the error line from the controller-->
    <file path="admin/controller/catalog/product.php">
    <operation>
        <search><![CDATA[$this->error['model'] = $this->language->get('error_model');]]></search>
        <add position="replace"><![CDATA[//$this->error['model'] = $this->language->get('error_model');]]></add>
    </operation>
    </file>
    

    This code also works as a VQmod (if you use the proper tags before this).

    For those that don't understand how OCmods work and still want to hardcode the removal of the mandatory model here's what you need to do:

    • open admin/view/template/catalog/product_form.tpl
    • search for the <div class="form-group required"> that is relevant for the model field and remove the required class
    • open the admin/controller/catalog/product.php file
    • look for this line: $this->error['model'] = $this->language->get('error_model');
    • comment it

    You're done.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 【急】在线问答CNC雕刻机的电子电路与编程
  • ¥60 在mc68335芯片上移植ucos ii 的成功工程文件
  • ¥15 笔记本外接显示器正常,但是笔记本屏幕黑屏
  • ¥15 Python pandas
  • ¥15 蓝牙硬件,可以用哪几种方法控制手机点击和滑动
  • ¥15 生物医学数据分析。基础课程就v经常唱课程舅成牛逼
  • ¥15 云环境云开发云函数对接微信商户中的分账功能
  • ¥15 空间转录组CRAD遇到问题
  • ¥20 materialstudio计算氢键脚本问题
  • ¥15 有没有代做有偿主要做数据可视化部分即可(2023全国高考更省一本线理科类)