我已按照本教程成功向我的产品添加了自定义字段(source_code):http://www.php-dev-zone.com/2015/01/how-to-add-custom-product-field-in.html
然而,我的领域不会允许" - "即使我模仿了#34;模型"允许连字符的字段。
例如,如果我输入" 408000-025"该字段进入" 408000"进入数据库。如果我输入" 408000025"我收到" 408000025"在数据库中。如果我进入" 408000-025"进入模型领域,我收到" 408000-025"。
我的数据库中的model和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>
答案 0 :(得分:1)
你的VQmod文件中的一个非常小的错误。
更改
$client->setAccessToken([
'access_token' => $accessToken,
'expires_in' => $expiresIn,
]);
要
source_code = '" . (int)$data['source_code'] . "'
多数民众赞成。
修改强>
由于source_code = '" . $this->db->escape($data['source_code']) . "'
会将字符串转换为整数。因此,您的输入(int)
将为408000-025