Answer the question
In order to leave comments, you need to log in
How to display your array in opencart product?
Good afternoon! You need to display the field in the opencart admin panel (in the product), with the ability to add an infinite number. such fields (that is, make an array). The question is how to do it in terms of php?
I render the fields like this:
<file path="catalog/controller/product/product.php">
<operation error="log">
<search>
<![CDATA[
$data['points'] = $product_info['points'];
]]>
</search>
<add position="after"><![CDATA[
$data['features'] = html_entity_decode($product_info['features'], ENT_QUOTES, 'UTF-8');
$data['specifications'] = html_entity_decode($product_info['specifications'], ENT_QUOTES, 'UTF-8');
$data['documentations'] = html_entity_decode($product_info['documentations'], ENT_QUOTES, 'UTF-8');
$data['href_product'] = $product_info['href_product'];
$data['instructions'] = html_entity_decode($product_info['instructions'], ENT_QUOTES, 'UTF-8');
]]>
</add>
</operation>
</file>
<file path="catalog/model/catalog/product.php">
<operation error="log">
<search>
<![CDATA[
'name' => $query->row['name'],
]]>
</search>
<add position="after"><![CDATA[
'features' => $query->row['features'],
'specifications' => $query->row['specifications'],
'documentations' => $query->row['documentations'],
'href_product' => $query->row['href_product'],
'instructions' => $query->row['instructions'],
]]>
</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']) . "', specifications = '" . $this->db->escape($data['specifications']) . "', features = '" . $this->db->escape($data['features']) . "', documentations = '" . $this->db->escape($data['documentations']) . "', href_product = '" . $this->db->escape($data['href_product']) . "', instructions = '" . $this->db->escape($data['instructions']) . "',
]]>
</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 = 'features'");
if (count($exist->row) == 0) {
$this->db->query("ALTER TABLE `" . DB_PREFIX . "product`
ADD COLUMN `features` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
ADD COLUMN `specifications` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
ADD COLUMN `documentations` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
ADD COLUMN `href_product` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
ADD COLUMN `instructions` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL
");
}
]]></add>
</operation>
</file>
<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['features'])) {
$data['features'] = $this->request->post['features'];
} elseif (!empty($product_info)) {
$data['features'] = $product_info['features'];
} else {
$data['features'] = '';
}
if (isset($this->request->post['specifications'])) {
$data['specifications'] = $this->request->post['specifications'];
} elseif (!empty($product_info)) {
$data['specifications'] = $product_info['specifications'];
} else {
$data['specifications'] = '';
}
if (isset($this->request->post['documentations'])) {
$data['documentations'] = $this->request->post['documentations'];
} elseif (!empty($product_info)) {
$data['documentations'] = $product_info['documentations'];
} else {
$data['documentations'] = '';
}
if (isset($this->request->post['instructions'])) {
$data['instructions'] = $this->request->post['instructions'];
} elseif (!empty($product_info)) {
$data['instructions'] = $product_info['instructions'];
} else {
$data['instructions'] = '';
}
if (isset($this->request->post['href_product'])) {
$data['href_product'] = $this->request->post['href_product'];
} elseif (!empty($product_info)) {
$data['href_product'] = $product_info['href_product'];
} else {
$data['href_product'] = '';
}
]]>
</add>
</operation>
</file>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question