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?