Сегодня этот мой сайт достиг совершеннолетия. 16 лет назад в этот день я запустил его на домене goodluck.org.ua. С той поры пришлось поменять домен, сменился хостинг. Я так до конца и не решил каким этот ресурс должен быть. Но он дожил до этого дня такой как есть.

Но раз я его изначально задумывал как помощь в программировании и написании кодо выложу кусок кода который искал несколько дней и он должен помочь в работе над другим проектом.

Extra Fields in Product

<?xml version="1.0" encoding="UTF-8"?>
<modification>
<name>Extra Fields in Product</name>
<code>Extra-Fields-Product</code>
<version>2.0</version>
<link>https://opencart2x.ru</link>
<author>opencart2x.ru</author>

<file path="admin/controller/catalog/product.php">
<operation error="log">
<search>
<![CDATA[
if (isset($this->request->post['model'])) {
]]>
</search>
<add position="before"><![CDATA[
if (isset($this->request->post['entry_1'])) {
$data['entry_1'] = $this->request->post['entry_1'];
} elseif (!empty($product_info)) {
$data['entry_1'] = $product_info['entry_1'];
} else {
$data['entry_1'] = '';
}
if (isset($this->request->post['entry_2'])) {
$data['entry_2'] = $this->request->post['entry_2'];
} elseif (!empty($product_info)) {
$data['entry_2'] = $product_info['entry_2'];
} else {
$data['entry_2'] = '';
}
if (isset($this->request->post['entry_3'])) {
$data['entry_3'] = $this->request->post['entry_3'];
} elseif (!empty($product_info)) {
$data['entry_3'] = $product_info['entry_3'];
} else {
$data['entry_3'] = '';
}
if (isset($this->request->post['entry_text_1'])) {
$data['entry_text_1'] = $this->request->post['entry_text_1'];
} elseif (!empty($product_info)) {
$data['entry_text_1'] = $product_info['entry_text_1'];
} else {
$data['entry_text_1'] = '';
}
if (isset($this->request->post['entry_text_2'])) {
$data['entry_text_2'] = $this->request->post['entry_text_2'];
} elseif (!empty($product_info)) {
$data['entry_text_2'] = $product_info['entry_text_2'];
} else {
$data['entry_text_2'] = '';
}
if (isset($this->request->post['entry_text_3'])) {
$data['entry_text_3'] = $this->request->post['entry_text_3'];
} elseif (!empty($product_info)) {
$data['entry_text_3'] = $product_info['entry_text_3'];
} else {
$data['entry_text_3'] = '';
}

]]>
</add>
</operation>
</file>
<file path="admin/model/catalog/product.php">
<operation error="log">
<search>
<![CDATA[
model = '" . $this->db->escape($data['model']) . "',
]]>
</search>
<add position="replace"><![CDATA[
model = '" . $this->db->escape($data['model']) . "', entry_text_1 = '" . $this->db->escape($data['entry_text_1']) . "', entry_text_2 = '" . $this->db->escape($data['entry_text_2']) . "', entry_text_3 = '" . $this->db->escape($data['entry_text_3']) . "', entry_1 = '" . $this->db->escape($data['entry_1']) . "', entry_2 = '" . $this->db->escape($data['entry_2']) . "', entry_3 = '" . $this->db->escape($data['entry_3']) . "',
]]>
</add>
</operation>
<operation>
<search index="0" error="skip"><![CDATA[
public function getProducts($data = array()) {
]]></search>
<add position="after" ><![CDATA[
$exist = $this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "product` WHERE Field = 'entry_1'");
if (count($exist->row) == 0) {
$this->db->query("ALTER TABLE `" . DB_PREFIX . "product`
ADD COLUMN `entry_1` VARCHAR(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
ADD COLUMN `entry_text_1` VARCHAR(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
ADD COLUMN `entry_2` VARCHAR(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
ADD COLUMN `entry_text_2` VARCHAR(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
ADD COLUMN `entry_3` VARCHAR(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
ADD COLUMN `entry_text_3` VARCHAR(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
");
}
]]></add>
</operation>
</file>
<file path="admin/view/template/catalog/product_form.tpl">
<operation error="log">
<search>
<![CDATA[
<label class="col-sm-2 control-label" for="input-model"><?php echo $entry_model; ?></label>
]]>
</search>
<add position="before" offset="1"><![CDATA[
<div class="form-group">
<label class="col-sm-2 control-label" for="input-entry_1">Поле 1</label>
<div class="col-sm-10">
<input style="width: 20%; display:inline" type="text" name="entry_1" value="<?php echo $entry_1; ?>" placeholder="Заголовок 1" id="input-entry_1" class="form-control" />
<input style="width: 20%; display:inline" type="text" name="entry_text_1" value="<?php echo $entry_text_1; ?>" placeholder="Значение 1" id="input-entry_text_1" class="form-control" />
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="input-entry_2">Поле 2</label>
<div class="col-sm-10">
<input style="width: 20%; display:inline" type="text" name="entry_2" value="<?php echo $entry_2; ?>" placeholder="Заголовок 2" id="input-entry_2" class="form-control" />
<input style="width: 20%; display:inline" type="text" name="entry_text_2" value="<?php echo $entry_text_2; ?>" placeholder="Значение 2" id="input-entry_text_2" class="form-control" />
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="input-entry_3">Поле 3</label>
<div class="col-sm-10">
<input style="width: 20%; display:inline" type="text" name="entry_3" value="<?php echo $entry_3; ?>" placeholder="Заголовок 3" id="input-entry_3" class="form-control" />
<input style="width: 20%; display:inline" type="text" name="entry_text_3" value="<?php echo $entry_text_3; ?>" placeholder="Значение 3" id="input-entry_text_3" class="form-control" />
</div>
</div>
]]>
</add>
</operation>
</file>
<file path="catalog/model/catalog/product.php">
<operation error="log">
<search>
<![CDATA[
'name' => $query->row['name'],
]]>
</search>
<add position="after"><![CDATA[
'entry_1' => $query->row['entry_1'],
'entry_2' => $query->row['entry_2'],
'entry_3' => $query->row['entry_3'],
'entry_text_1' => $query->row['entry_text_1'],
'entry_text_2' => $query->row['entry_text_2'],
'entry_text_3' => $query->row['entry_text_3'],
]]>
</add>
</operation>
</file>
<file path="catalog/controller/product/product.php">
<operation error="log">
<search>
<![CDATA[
$data['points'] = $product_info['points'];
]]>
</search>
<add position="after"><![CDATA[
$data['entry_1'] = $product_info['entry_1'];
$data['entry_2'] = $product_info['entry_2'];
$data['entry_3'] = $product_info['entry_3'];
$data['entry_text_1'] = $product_info['entry_text_1'];
$data['entry_text_2'] = $product_info['entry_text_2'];
$data['entry_text_3'] = $product_info['entry_text_3'];
]]>
</add>
</operation>
</file>
<file path="catalog/view/theme/*/template/product/product.tpl">
<operation error="log">
<search>
<![CDATA[
<li><?php echo $text_model; ?> <?php echo $model; ?></li>
]]>
</search>
<add position="after"><![CDATA[
<?php if($entry_1 && $entry_text_1) { ?>
<li><?php echo $entry_1; ?>: <?php echo $entry_text_1; ?></li>
<?php } ?>
<?php if($entry_2 && $entry_text_2) { ?>
<li><?php echo $entry_2; ?>: <?php echo $entry_text_2; ?></li>
<?php } ?>
<?php if($entry_3 && $entry_text_3) { ?>
<li><?php echo $entry_3; ?>: <?php echo $entry_text_3; ?></li>
<?php } ?>
]]>
</add>
</operation>
</file>
<file path="system/library/db.php">
<operation>
<search><![CDATA[
function query($sql) {
]]></search>
<add trim="true" position="before"><![CDATA[
public function checkTable($table, $column) {
//check if column exists. If not, then make it exist.
$sql = "DESC " . DB_PREFIX . "{$table} {$column}";
$query = $this->query($sql);
if (!$query->num_rows) {
$sql = "ALTER TABLE " . DB_PREFIX . "{$table} ADD {$column} VARCHAR(255) NOT NULL DEFAULT ''";
$this->query($sql);
}
}
]]></add>
</operation>
</file>
</modification>

 

От dmitry

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *