我需要在Module Featured产品
上显示此自定义字段
目前它只在产品页面上显示此字段, 需要在模块特色产品中显示此字段
我已将此代码放入Controller中 目录/控制器/扩展/模块/ featured.php $ data [' extra_field'] = html_entity_decode($ product_info [' extra_field'],ENT_QUOTES,' UTF-8');
但没有工作...... 有人能帮助我吗?
这是自定义字段
<modification>
<name><![CDATA[<font color="#000000"><b>sale</font>]]></name>
<code>product_extra_field</code>
<version>1.0</version>
<link></link>
<file path="admin/controller/catalog/product.php">
<operation>
<search><![CDATA[if (isset($this->request->post['points'])) {]]></search>
<add position="before"><![CDATA[if ($this->db->query("SHOW TABLES LIKE '". DB_PREFIX ."product_extra_field'")->num_rows == 0) {
$sql = "CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "product_extra_field` (
`product_id` int(11) NOT NULL,
`language_id` int(11) NOT NULL,
`extra_field`VARCHAR(125) NOT NULL
) ENGINE=MyISAM COLLATE=utf8_general_ci";
$this->db->query($sql);
}
if (isset($this->request->post['product_extra_field'])) {
$data['product_extra_field'] = $this->request->post['product_extra_field'];
} elseif (isset($this->request->get['product_id'])) {
$data['product_extra_field'] = $this->model_catalog_product->getProductExtraField($this->request->get['product_id']);
} else {
$data['product_extra_field'] = array();
}]]></add>
</operation>
</file>
<file path="admin/model/catalog/product.php">
<operation>
<search><![CDATA[foreach ($data['product_description'] as $language_id => $value) {]]></search>
<add position="before"><![CDATA[$this->db->query("DELETE FROM " . DB_PREFIX . "product_extra_field WHERE product_id = '" . (int)$product_id . "'");
foreach ($data['product_extra_field'] as $language_id => $value) {
$this->db->query("INSERT INTO " . DB_PREFIX . "product_extra_field SET product_id = '" . (int)$product_id . "', language_id = '" . (int)$language_id . "', extra_field = '" . $this->db->escape($value['extra_field']) . "'");
}]]></add>
</operation>
<operation>
<search><![CDATA[public function getProductOptions($product_id) {]]></search>
<add position="before"><![CDATA[public function getProductExtraField($product_id) {
$product_extra_field_data = array();
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_extra_field WHERE product_id = '" . (int)$product_id . "'");
foreach ($query->rows as $result) {
$product_extra_field_data[$result['language_id']] = array(
'extra_field' => $result['extra_field']
);
}
return $product_extra_field_data;
}]]></add>
</operation>
</file>
<file path="admin/view/template/catalog/product_form.tpl">
<operation>
<search index="0"><![CDATA[<div class="form-group">]]></search>
<add position="before"><![CDATA[<div class="form-group">
<label class="col-sm-2 control-label" for="input-extra_field<?php echo $language['language_id']; ?>">Texto personalizado</label>
<div class="col-sm-10">
<textarea class="form-control" name="product_extra_field[<?php echo $language['language_id']; ?>][extra_field]" placeholder="Digite aqui" id="input-extra_field<?php echo $language['language_id']; ?>"><?php echo isset($product_extra_field[$language['language_id']]) ? $product_extra_field[$language['language_id']]['extra_field'] : ''; ?></textarea>
</div>
</div>]]></add>
</operation>
</file>
<file path="catalog/controller/product/product.php">
<operation>
<search><![CDATA[$data['points'] = $product_info['points'];]]></search>
<add position="before"><![CDATA[$data['extra_field'] = html_entity_decode($product_info['extra_field'], ENT_QUOTES, 'UTF-8');]]></add>
</operation>
</file>
<file path="catalog/model/catalog/product.php">
<operation>
<search><![CDATA[return array(]]></search>
<add position="before"><![CDATA[
$extra_field_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_extra_field WHERE product_id = '" . (int)$product_id . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'");
if($extra_field_query->num_rows) {
$extra_field = $extra_field_query->row['extra_field'];
} else {
$extra_field = "";
}]]></add>
</operation>
<operation>
<search><![CDATA[return array(]]></search>
<add position="after">
<![CDATA[
'extra_field' => $extra_field,]]></add>
</operation>
</file>
<file path="catalog/view/theme/*/template/product/product.tpl">
<operation>
<search><![CDATA[<?php echo $heading_title; ?></h1>]]></search>
<add position="after"><![CDATA[<?php if(isset($extra_field) && $extra_field) { ?>
<?php echo $extra_field; ?>
<?php } ?>]]></add>
</operation>
</file>
答案 0 :(得分:0)
您还需要让您的代码在特色产品中运行;它使用与product.php不同的代码库:
控制器: /your_dir/catalog/controller/extension/module/featured.php:
周边:
'name' => $product_info['name'],
'extra_field' => $product_info['extra_field'],
查看: /your_dir/catalog/view/theme/your_theme/template/extension/module/featured.tpl: 将其添加到您希望显示的位置,例如:
<?php if ($product['extra_field']) { ?>
//your extra field stuff goes here
<?php } ?>