即使我有点尴尬地问这个问题,但现在是这样。我试图在我的控制器文件中定义$ stock_status_id变量,我将在后面的tpl中回显。我在控制器文件中设置为'stock_status_id' => $result['status_stock_id'],
,但它给了我
未定义的索引' stock_status_id'错误
。通常,这就足够了,就像我定义的其他变量一样。我在这做错了什么? stock_status_id字段存在于oc_product表中。我的整个控制器文件如下:
<?php
class ControllerModuleDobavljivi extends Controller {
public function index($setting) {
$this->load->language('module/dobavljivi');
$data['logged'] = $this->customer->isLogged();
$data['heading_title'] = $this->language->get('heading_title');
$data['customer_group_id'] = $this->customer->getGroupId();
$data['text_tax'] = $this->language->get('text_tax');
$data['button_cart'] = $this->language->get('button_cart');
$data['button_wishlist'] = $this->language->get('button_wishlist');
$data['button_compare'] = $this->language->get('button_compare');
$this->load->model('catalog/product');
$this->load->model('tool/image');
$data['products'] = array();
$filter_data = array(
'sort' => 'p.stock_status_id',
'order' => 'DESC',
'start' => 0,
'limit' => $setting['limit']
);
$results = $this->model_catalog_product->getProducts($filter_data);
if ($results) {
foreach ($results as $result) {
if ($result['image']) {
$image = $this->model_tool_image->resize($result['image'], $setting['width'], $setting['height']);
} else {
$image = $this->model_tool_image->resize('placeholder.png', $setting['width'], $setting['height']);
}
if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
$price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
$wholesale = $this->currency->format($this->tax->calculate($result['wholesale'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
} else {
$price = false;
$wholesale = false;
}
if ((float)$result['special']) {
$special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
} else {
$special = false;
}
if ($this->config->get('config_tax')) {
$tax = $this->currency->format((float)$result['special'] ? $result['special'] : $result['price'], $this->session->data['currency']);
} else {
$tax = false;
}
if ($this->config->get('config_review_status')) {
$rating = $result['rating'];
} else {
$rating = false;
}
$data['products'][] = array(
'product_id' => $result['product_id'],
'thumb' => $image,
'name' => $result['name'],
'stock_status_id' => $result['status_stock_id'],
'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get($this->config->get('config_theme') . '_product_description_length')) . '..',
'price' => $price,
'wholesale' => $wholesale,
'special' => $special,
'tax' => $tax,
'upc' => $result['upc'],
'rating' => $rating,
'href' => $this->url->link('product/product', 'product_id=' . $result['product_id'])
);
}
return $this->load->view('module/dobavljivi', $data);
}
}
}
感谢。
答案 0 :(得分:1)
产品数据将以$products
数组的形式提供。尝试通过循环遍历$products
数组来访问stock_status_id。要更清晰地查看数组,请使用var_dump($products)
。这将完全解释你的阵列。
答案 1 :(得分:1)
在您的产品型号中,请确保您在stock_status_id
中提取getProducts($data = array())
,然后它将返回预期结果。