Opencart 自定义字段不允许连字符“-”

Opencart Custom Field not allowing Hyphen character "-"

我已按照本教程成功向我的产品添加了自定义字段 (source_code):http://www.php-dev-zone.com/2015/01/how-to-add-custom-product-field-in.html

但是,我的字段不允许使用“-”字符,即使我模仿了允许连字符的 "model" 字段。

例如,如果我输入“408000-025”,该字段会在数据库中输入“408000”。如果我输入“408000025”,我会在数据库中收到“408000025”。如果我在模型字段中输入“408000-025”,我会收到“408000-025”。

模型和 source_code(我的自定义字段)都是 varchar(64),我数据库中的 utf8_general_ci 字段。

下面是我的 vqmod:

<file name="admin/model/catalog/product.php">
    <operation>
        <search position="replace"><![CDATA[
        $this->db->query("INSERT INTO " . DB_PREFIX . "product SET model = '" . $this->db->escape($data['model']) . "', sku = '" . $this->db->escape($data['sku']) . "', upc = '" . $this->db->escape($data['upc']) . "', ean = '" . $this->db->escape($data['ean']) . "', jan = '" . $this->db->escape($data['jan']) . "', isbn = '" . $this->db->escape($data['isbn']) . "', mpn = '" . $this->db->escape($data['mpn']) . "', location = '" . $this->db->escape($data['location']) . "', quantity = '" . (int)$data['quantity'] . "', minimum = '" . (int)$data['minimum'] . "', subtract = '" . (int)$data['subtract'] . "', stock_status_id = '" . (int)$data['stock_status_id'] . "', date_available = '" . $this->db->escape($data['date_available']) . "', manufacturer_id = '" . (int)$data['manufacturer_id'] . "', shipping = '" . (int)$data['shipping'] . "', price = '" . (float)$data['price'] . "', points = '" . (int)$data['points'] . "', weight = '" . (float)$data['weight'] . "', weight_class_id = '" . (int)$data['weight_class_id'] . "', length = '" . (float)$data['length'] . "', width = '" . (float)$data['width'] . "', height = '" . (float)$data['height'] . "', length_class_id = '" . (int)$data['length_class_id'] . "', status = '" . (int)$data['status'] . "', tax_class_id = '" . (int)$data['tax_class_id'] . "', sort_order = '" . (int)$data['sort_order'] . "', date_added = NOW()");
        ]]></search>
        <add><![CDATA[
        $this->db->query("INSERT INTO " . DB_PREFIX . "product SET model = '" . $this->db->escape($data['model']) . "', sku = '" . $this->db->escape($data['sku']) . "', upc = '" . $this->db->escape($data['upc']) . "', ean = '" . $this->db->escape($data['ean']) . "', jan = '" . $this->db->escape($data['jan']) . "', isbn = '" . $this->db->escape($data['isbn']) . "', mpn = '" . $this->db->escape($data['mpn']) . "', location = '" . $this->db->escape($data['location']) . "', quantity = '" . (int)$data['quantity'] . "', minimum = '" . (int)$data['minimum'] . "', subtract = '" . (int)$data['subtract'] . "', stock_status_id = '" . (int)$data['stock_status_id'] . "', date_available = '" . $this->db->escape($data['date_available']) . "', manufacturer_id = '" . (int)$data['manufacturer_id'] . "', shipping = '" . (int)$data['shipping'] . "', price = '" . (float)$data['price'] . "', points = '" . (int)$data['points'] . "', weight = '" . (float)$data['weight'] . "', weight_class_id = '" . (int)$data['weight_class_id'] . "', length = '" . (float)$data['length'] . "', width = '" . (float)$data['width'] . "', height = '" . (float)$data['height'] . "', length_class_id = '" . (int)$data['length_class_id'] . "', status = '" . (int)$data['status'] . "', tax_class_id = '" . (int)$data['tax_class_id'] . "', sort_order = '" . (int)$data['sort_order'] . "', source_code = '" . (int)$data['source_code'] . "', date_added = NOW()");
        ]]></add>
    </operation>
    <operation>
        <search position="replace"><![CDATA[
        $this->db->query("UPDATE " . DB_PREFIX . "product SET model = '" . $this->db->escape($data['model']) . "', sku = '" . $this->db->escape($data['sku']) . "', upc = '" . $this->db->escape($data['upc']) . "', ean = '" . $this->db->escape($data['ean']) . "', jan = '" . $this->db->escape($data['jan']) . "', isbn = '" . $this->db->escape($data['isbn']) . "', mpn = '" . $this->db->escape($data['mpn']) . "', location = '" . $this->db->escape($data['location']) . "', quantity = '" . (int)$data['quantity'] . "', minimum = '" . (int)$data['minimum'] . "', subtract = '" . (int)$data['subtract'] . "', stock_status_id = '" . (int)$data['stock_status_id'] . "', date_available = '" . $this->db->escape($data['date_available']) . "', manufacturer_id = '" . (int)$data['manufacturer_id'] . "', shipping = '" . (int)$data['shipping'] . "', price = '" . (float)$data['price'] . "', points = '" . (int)$data['points'] . "', weight = '" . (float)$data['weight'] . "', weight_class_id = '" . (int)$data['weight_class_id'] . "', length = '" . (float)$data['length'] . "', width = '" . (float)$data['width'] . "', height = '" . (float)$data['height'] . "', length_class_id = '" . (int)$data['length_class_id'] . "', status = '" . (int)$data['status'] . "', tax_class_id = '" . (int)$data['tax_class_id'] . "', sort_order = '" . (int)$data['sort_order'] . "', date_modified = NOW() WHERE product_id = '" . (int)$product_id . "'");
        ]]></search>
        <add><![CDATA[
        $this->db->query("UPDATE " . DB_PREFIX . "product SET model = '" . $this->db->escape($data['model']) . "', sku = '" . $this->db->escape($data['sku']) . "', upc = '" . $this->db->escape($data['upc']) . "', ean = '" . $this->db->escape($data['ean']) . "', jan = '" . $this->db->escape($data['jan']) . "', isbn = '" . $this->db->escape($data['isbn']) . "', mpn = '" . $this->db->escape($data['mpn']) . "', location = '" . $this->db->escape($data['location']) . "', quantity = '" . (int)$data['quantity'] . "', minimum = '" . (int)$data['minimum'] . "', subtract = '" . (int)$data['subtract'] . "', stock_status_id = '" . (int)$data['stock_status_id'] . "', date_available = '" . $this->db->escape($data['date_available']) . "', manufacturer_id = '" . (int)$data['manufacturer_id'] . "', shipping = '" . (int)$data['shipping'] . "', price = '" . (float)$data['price'] . "', points = '" . (int)$data['points'] . "', weight = '" . (float)$data['weight'] . "', weight_class_id = '" . (int)$data['weight_class_id'] . "', length = '" . (float)$data['length'] . "', width = '" . (float)$data['width'] . "', height = '" . (float)$data['height'] . "', length_class_id = '" . (int)$data['length_class_id'] . "', status = '" . (int)$data['status'] . "', tax_class_id = '" . (int)$data['tax_class_id'] . "', sort_order = '" . (int)$data['sort_order'] . "', source_code = '" . (int)$data['source_code'] . "', date_modified = NOW() WHERE product_id = '" . (int)$product_id . "'");
        ]]></add>
    </operation>
</file>
<file name="admin/controller/catalog/product.php">
    <operation>
        <search position="after"><![CDATA[
        $data['entry_sort_order'] = $this->language->get('entry_sort_order');
        ]]></search>
        <add><![CDATA[
        $data['entry_source_code'] = $this->language->get('entry_source_code');
        ]]></add>
    </operation>
    <operation>
        <search position="after"><![CDATA[
        $data['help_isbn'] = $this->language->get('help_isbn');
        ]]></search>
        <add><![CDATA[
        $data['help_source_code'] = $this->language->get('help_source_code');
        ]]></add>
    </operation>
    <operation>
        <search position="before"><![CDATA[
        if (isset($this->request->post['mpn'])) {
        ]]></search>
        <add><![CDATA[
        if (isset($this->request->post['source_code'])) {
             $data['source_code'] = $this->request->post['source_code'];
            } elseif (!empty($product_info)) {
             $data['source_code'] = $product_info['source_code'];
            } else {
             $data['source_code'] = '';
        }
        ]]></add>
    </operation>
</file>
<file name="admin/view/template/catalog/product_form.tpl">
    <operation>
        <search position="after"><![CDATA[
        <div class="tab-pane" id="tab-data">
        ]]></search>
        <add><![CDATA[
        <div class="form-group required">
            <label class="col-sm-2 control-label" for="input-source_code">
                 <span data-toggle="tooltip" title="<?php echo $help_source_code; ?>"><?php echo $entry_source_code; ?></span>
             </label>
             <div class="col-sm-10">
                <input type="text" name="source_code" value="<?php echo $source_code; ?>" id="input-source_code" placeholder="<?php echo $entry_source_code; ?>" class="form-control" />
             </div>
        </div>
        ]]></add>
    </operation>
</file>
<file name="admin/language/english/catalog/product.php">
    <operation>
        <search position="after"><![CDATA[
        $_['entry_recurring']        = 'Recurring Profile';
        ]]></search>
        <add><![CDATA[
        $_['entry_source_code']        = 'Source Code';
        ]]></add>
    </operation>
    <operation>
        <search position="after"><![CDATA[
        $_['help_tag']               = 'comma separated';
        ]]></search>
        <add><![CDATA[
        $_['help_source_code']        = 'ACS Billing Code';
        ]]></add>
    </operation>
</file>

这是您的 VQmod 文件中的一个非常小的错误。

改变
source_code = '" . (int)$data['source_code'] . "'


source_code = '" . $this->db->escape($data['source_code']) . "'

就是这样。

编辑

As (int) 会将字符串转换为整数。所以你的输入 408000-025 将是 408000