|
<?xml version="1.0" encoding="UTF-8"?> |
|
<modification> |
|
<name>coder_product_related_order</name> |
|
<code>coder_product_related_order</code> |
|
<author>google.com</author> |
|
<link>https://google.com</link> |
|
|
|
<file path="catalog/model/catalog/product.php|admin/model/catalog/product.php"> |
|
<operation> |
|
<search><![CDATA[class ModelCatalogProduct extends Model {]]></search> |
|
<add position="after"><![CDATA[ |
|
private function checkAndCreateColumn() { |
|
$table_name = 'product_related'; |
|
$column_name = 'order_n'; |
|
|
|
$query = $this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . $table_name . "` LIKE '" . $column_name . "'"); |
|
|
|
if ($query->num_rows == 0) { |
|
$this->db->query("ALTER TABLE `" . DB_PREFIX . $table_name . "` ADD COLUMN `" . $column_name . "` INT"); |
|
//$this->log->write("Column '" . $column_name . "' has been added to table '" . $table_name . "'"); |
|
return "created"; |
|
} else { |
|
return "already exists"; |
|
} |
|
} |
|
]]></add> |
|
</operation> |
|
</file> |
|
|
|
<file path="admin/model/catalog/product.php"> |
|
<operation> |
|
<search><![CDATA[if (isset($data['product_related'])) {]]></search> |
|
<add position="after"><![CDATA[ |
|
$this->checkAndCreateColumn(); |
|
$order_n = 0; |
|
]]></add> |
|
</operation> |
|
<operation> |
|
<search><![CDATA["product_related SET product_id]]></search> |
|
<add position="replace"><![CDATA["product_related SET order_n = '" . (int) $order_n++ . "', product_id]]></add> |
|
</operation> |
|
<operation> |
|
<search><![CDATA[$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$product_id . "'"); ]]></search> |
|
<add><![CDATA[ |
|
$this->checkAndCreateColumn(); |
|
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$product_id . "' ORDER BY order_n ASC"); |
|
]]></add> |
|
</operation> |
|
</file> |
|
|
|
<file path="catalog/model/catalog/product.php"> |
|
<operation> |
|
<search><![CDATA[public function getProductRelated($product_id) {]]></search> |
|
<add position="after"><![CDATA[$this->checkAndCreateColumn();]]></add> |
|
</operation> |
|
<operation> |
|
<search index="1"><![CDATA[AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "'");]]></search> |
|
<add position="replace"><![CDATA[AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' ORDER BY order_n ASC");]]></add> |
|
</operation> |
|
</file> |
|
|
|
|
|
</modification> |