使用开放式购物车在网站上工作我希望以调整后的价格显示每个选项。
在控制器中,我将获取所有选项,循环遍历它们,并对最终结果进行简单的添加/格式化。然而它只是不工作,我完全不知道为什么。渲染到模板时的价格不会显示结果价格+ 123。
我的代码如下。
$options = $this->model_catalog_product->getProductOptions($result['product_id']);
foreach ($options as $option) {
foreach($option['option_value'] as $option_value) {
$option_value['price'] = $result['price'] = $option_value['price'];
}
}
$this->data['products'][] = array(
'options' => $options,
'product_id' => $result['product_id'],
'thumb' => $image,
'name' => $result['name'],
'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, 100) . '..',
'price' => $price,
'special' => $special,
'tax' => $tax,
'rating' => $result['rating'],
'reviews' => sprintf($this->language->get('text_reviews'), (int)$result['reviews']),
'href' => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id'] . $url)
);
答案 0 :(得分:1)
$option_value['price'] = $result['price'] = $option_value['price'];
实际应该是
$option_value['price'] = $result['price'] + $option_value['price'];
虽然如果您想确保包含特价,也可以使用
$option_value['price'] = $option_value['price'] + (empty($result['special']) ? $result['price'] : $result['special']);