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 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊