Reputation: 20163
This .xml file and vqmod created my new custom post field in the products post type of my openchart.
<modification>
<id>Custom Field - unit_price</id>
<version>1</version>
<vqmver>1.0.8</vqmver>
<author>Jonathan de Jong - tigerton.se</author>
<file name="admin/language/english/catalog/product.php">
<operation>
<search position="after"><![CDATA[
$_['entry_model'] = 'Model:';
]]></search>
<add><![CDATA[
$_['entry_unit_price'] = 'unit_price:';
]]></add>
</operation>
</file>
<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']) . "', 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 = '" . $this->db->escape($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']) . "', 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'] . "', unit_price = '" . $this->db->escape($data['unit_price']) . "', status = '" . (int)$data['status'] . "', tax_class_id = '" . $this->db->escape($data['tax_class_id']) . "', sort_order = '" . (int)$data['sort_order'] . "', 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']) . "', 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 = '" . $this->db->escape($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']) . "', 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'] . "', unit_price = '" . $this->db->escape($data['unit_price']) . "', status = '" . (int)$data['status'] . "', tax_class_id = '" . $this->db->escape($data['tax_class_id']) . "', sort_order = '" . (int)$data['sort_order'] . "', date_modified = NOW() WHERE product_id = '" . (int)$product_id . "'");
]]></add>
</operation>
</file>
<file name="admin/controller/catalog/product.php">
<operation>
<search position="after"><![CDATA[
$this->data['entry_model'] = $this->language->get('entry_model');
]]></search>
<add><![CDATA[
$this->data['entry_unit_price'] = $this->language->get('entry_unit_price');
]]></add>
</operation>
<operation>
<search position="before"><![CDATA[
if (isset($this->request->post['sku'])) {
]]></search>
<add><![CDATA[
if (isset($this->request->post['unit_price'])) {
$this->data['unit_price'] = $this->request->post['unit_price'];
} elseif (!empty($product_info)) {
$this->data['unit_price'] = $product_info['unit_price'];
} else {
$this->data['unit_price'] = '';
}
]]></add>
</operation>
</file>
<file name="admin/view/template/catalog/product_form.tpl">
<operation>
<search position="after" offset="10"><![CDATA[
<td><?php echo $entry_weight_class; ?></td>
]]></search>
<add><![CDATA[
<tr>
<td><?php echo $entry_unit_price; ?></td>
<td><input type="text" name="unit_price" value="<?php echo $unit_price; ?>" /></td>
</td>
</tr>
]]></add>
</operation>
</file>
<file name="catalog/controller/product/product.php">
<operation error="skip">
<search position="after"><![CDATA[
$this->data['text_model'] = $this->language->get('text_model');
]]></search>
<add><![CDATA[
$this->data['text_unit_price'] = $this->language->get('text_unit_price');
]]></add>
</operation>
</file>
<file name="catalog/language/english/product/product.php">
<operation error="skip">
<search position="after"><![CDATA[
$_['tab_related'] = 'Related Products';
]]></search>
<add><![CDATA[
$_['text_unit_price'] = 'unit_price:';
]]></add>
</operation>
</file>
<file name="catalog/language/english/product/product.php">
<operation error="skip">
<search position="after"><![CDATA[
$_['tab_related'] = 'Relaterade produkter';
]]></search>
<add><![CDATA[
$_['text_unit_price'] = 'unit_price:';
]]></add>
</operation>
</file>
<file name="catalog/controller/product/product.php">
<operation error="skip">
<search position="after"><![CDATA[
$this->data['manufacturer'] = $product_info['manufacturer'];
]]></search>
<add><![CDATA[
$this->data['unit_price'] = $product_info['unit_price'];
]]></add>
</operation>
</file>
</modification>
which works great!
the thing is that it's one of the last ones now
Is there a way I can make it the next field to 'price' field?
if so, how?
Upvotes: 2
Views: 635
Reputation: 16055
Within this section:
<file name="admin/view/template/catalog/product_form.tpl">
<operation>
<search position="after" offset="10"><![CDATA[
<td><?php echo $entry_weight_class; ?></td>
]]></search>
<add><![CDATA[
<tr>
<td><?php echo $entry_unit_price; ?></td>
<td><input type="text" name="unit_price" value="<?php echo $unit_price; ?>" /></td>
</td> <!-- <- ALSO REMOVE THAT LINE FROM YOUR XML FILE... -->
</tr>
]]></add>
</operation>
</file>
change the <search>
part to:
<search position="after" offset="3"><![CDATA[<td><?php echo $entry_price; ?></td>]]></search>
Play with the offset - it means how many lines after the one that is found the add
part will be added. I guess it should be 3, but maybe You would have to adjust it a little (maybe only to 2).
Upvotes: 0