2015-12-07 34 views
1

我已經成功地通過下面這個教程中添加自定義字段(source_code)到我的產品:http://www.php-dev-zone.com/2015/01/how-to-add-custom-product-field-in.htmlOpencart的自定義字段不允許連字符「 - 」

然而,這個領域將不允許「 - 」字符,即使我模仿了允許連字符的「模型」字段。

例如,如果我輸入「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> 

回答

1

它是一個在你的VQmod文件非常小的失誤。

變化
source_code = '" . (int)$data['source_code'] . "'


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

完蛋了。

編輯

由於(int)將字符串轉換爲整數。所以你的輸入408000-025將是408000

+0

非常感謝你! – Becca

相關問題