最近我买了一个扩展程序来为我的产品创建自定义字段。 此扩展程序在我的产品页面中运行良好,显示我放在管理员上的所有信息。但是我也需要在类别页面中显示这些自定义字段,所以我可以列出一些信息。
我尝试复制代码并添加类别(控制器和查看),但它返回空 - 没有显示任何内容:没有错误,没有警告..而且没有资讯
扩展程序附带一个vqmod文件,主要包含目录文件夹中的操作:
目录中的更改 产品/控制器:
$this->data['text_download'] = $this->language->get('text_download');
if ($this->config->get('cpf_fields')) {
$fields = $this->config->get('cpf_fields');
} else {
$fields = array();
}
$field_data = array();
if (!empty($product_info['cpf'])) {
$cpf = unserialize($product_info['cpf']);
} else {
$cpf = array();
}
$this->load->model('catalog/option');
foreach ($fields as $field) {
$option = $this->model_catalog_option->getOption($field['option_id']);
if ($option) {
if ($option['type'] == 'select' || $option['type'] == 'radio') {
$values = array();
$option_values = $this->model_catalog_option->getOptionValues($field['option_id']);
foreach ($option_values as $option_value) {
$selected = (!empty($cpf[$field['option_id']])) ? $cpf[$field['option_id']] : 0;
$values[] = array(
'option_value_id' => $option_value['option_value_id'],
'name' => $option_value['name'],
'selected' => $selected
);
}
$field_data[] = array(
'name' => $option['name'],
'type' => $option['type'],
'status' => $field['status'],
'sort_order' => $field['sort_order'],
'values' => $values
);
} elseif ($option['type'] == 'checkbox') {
$values = array();
$option_values = $this->model_catalog_option->getOptionValues($field['option_id']);
foreach ($option_values as $option_value) {
$selected = (!empty($cpf[$field['option_id']]) && is_array($cpf[$field['option_id']]) && in_array($option_value['option_value_id'], $cpf[$field['option_id']])) ? $option_value['option_value_id'] : 0;
$values[] = array(
'option_value_id' => $option_value['option_value_id'],
'name' => $option_value['name'],
'selected' => $selected
);
}
$field_data[] = array(
'name' => $option['name'],
'type' => $option['type'],
'status' => $field['status'],
'sort_order' => $field['sort_order'],
'values' => $values
);
} else {
$value = (!empty($cpf[$field['option_id']])) ? $cpf[$field['option_id']] : '';;
$field_data[] = array(
'name' => $option['name'],
'type' => $option['type'],
'status' => $field['status'],
'sort_order' => $field['sort_order'],
'value' => $value
);
}
}
}
$sort_order = array();
foreach ($field_data as $key => $value) {
$sort_order[$key] = $value['sort_order'];
}
array_multisort($sort_order, SORT_ASC, $field_data);
$this->data['fields'] = array();
foreach ($field_data as $field) {
$this->data['fields'][] = $field;
}
产品视图:
<?php foreach ($fields as $field) { ?>
<?php if ($field['status'] && (!empty($field['value']) || !empty($field['values']))) { ?>
<?php $selected = false; ?>
<?php if ($field['type'] == 'select' || $field['type'] == 'radio') { ?>
<?php foreach ($field['values'] as $value) { ?>
<?php if ($value['selected'] && !$selected) { ?>
<?php $selected = true; ?>
<span><?php echo $field['name']; ?></span>
<?php } ?>
<?php if ($value['selected'] == $value['option_value_id']) { ?>
<?php echo $value['name']; ?>
<?php } ?>
<?php } ?><?php if ($selected) { ?><br /><?php } ?>
<?php } elseif ($field['type'] == 'checkbox') { ?>
<?php $checkbox_value = ''; ?>
<?php foreach ($field['values'] as $value) { ?>
<?php if ($value['selected'] && !$selected) { ?>
<?php $selected = true; ?>
<span><?php echo $field['name']; ?></span>
<?php } ?>
<?php if ($value['selected'] == $value['option_value_id']) { ?>
<?php $checkbox_value .= $value['name'] . ', '; ?>
<?php } ?>
<?php } ?>
<?php echo substr($checkbox_value, 0, -2); ?><?php if ($selected) { ?><br /><?php } ?>
<?php } elseif ($field['type'] == 'file') { ?>
<span><?php echo $field['name']; ?></span>
<a href="index.php?route=product/product/download&file=<?php echo $field['value']; ?>"><?php echo $text_download; ?></a><br />
<?php } else { ?>
<span><?php echo $field['name']; ?></span>
<?php echo $field['value']; ?><br />
<?php } ?>
<?php } ?>
<?php } ?>
产品型号仅限:
'cpf' => $query->row['cpf']
但是,在 ADMIN 产品型号中,会注入以下代码:
if (isset($data['cpf'])) {
foreach ($data['cpf'] as $language_id => $cpf) {
$cpf = serialize($cpf);
$this->db->query("UPDATE " . DB_PREFIX . "product_description SET cpf = '" . $this->db->escape($cpf) . "' WHERE product_id = '" . (int)$product_id . "' AND language_id = '" . (int)$language_id . "'");
}
} else {
$this->db->query("UPDATE " . DB_PREFIX . "product_description SET cpf = '' WHERE product_id = '" . (int)$product_id . "'");
}
我的问题是如何获取这些相同的信息并将其显示在另一个视图中,例如类别或搜索,或制造商?
非常感谢提前。
答案 0 :(得分:0)
这可能是因为扩展程序将这些自定义字段值存储到单独的数据库表中,该表在加载类别,制造商,搜索,最新,相关,畅销书等列表的产品时未填充。
您的赌注是探索该扩展程序的模型类,并确保在检索产品列表时加入相关的表并加载必需的列... < / p>
填充正确的数据后您的控制器和视图应该像您为...准备它们一样。