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 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器