而不是在产品上有基本价格并显示我想将基本价格设置为0.00并显示最低成本价格选项价格,即
Polo衫价格= 0
小= 10英镑
中= 15英镑
大= 20英镑
它应显示从10英镑开始
目前在产品页面上,它显示价格为0,直到选择了选项
<?php echo $price; ?>
我希望它能做到这样的事情,但我不确定语法
<?php $min_value [] = $options['option_value']; ?>
<?php $min_value_price [] = $min_value['price']; ?>
<?php $min = min($min_value_price); ?>
<?php echo $min; ?>
这是在正确的位置吗?目前它没有显示任何上述代码
模型
public function getProductOptions($product_id) {
$product_option_data = array();
$product_option_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option po LEFT JOIN `" . DB_PREFIX . "option` o ON (po.option_id = o.option_id) LEFT JOIN " . DB_PREFIX . "option_description od ON (o.option_id = od.option_id) WHERE po.product_id = '" . (int)$product_id . "' AND od.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY o.sort_order");
foreach ($product_option_query->rows as $product_option) {
if ($product_option['type'] == 'select' || $product_option['type'] == 'radio' || $product_option['type'] == 'checkbox' || $product_option['type'] == 'image') {
$product_option_value_data = array();
$product_option_value_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option_value pov LEFT JOIN " . DB_PREFIX . "option_value ov ON (pov.option_value_id = ov.option_value_id) LEFT JOIN " . DB_PREFIX . "option_value_description ovd ON (ov.option_value_id = ovd.option_value_id) WHERE pov.product_id = '" . (int)$product_id . "' AND pov.product_option_id = '" . (int)$product_option['product_option_id'] . "' AND ovd.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY ov.sort_order");
foreach ($product_option_value_query->rows as $product_option_value) {
$product_option_value_data[] = array(
'product_option_value_id' => $product_option_value['product_option_value_id'],
'option_value_id' => $product_option_value['option_value_id'],
'name' => $product_option_value['name'],
'image' => $product_option_value['image'],
'quantity' => $product_option_value['quantity'],
'subtract' => $product_option_value['subtract'],
'price' => $product_option_value['price'],
'price_prefix' => $product_option_value['price_prefix'],
'weight' => $product_option_value['weight'],
'weight_prefix' => $product_option_value['weight_prefix']
);
}
$product_option_data[] = array(
'product_option_id' => $product_option['product_option_id'],
'option_id' => $product_option['option_id'],
'name' => $product_option['name'],
'type' => $product_option['type'],
'option_value' => $product_option_value_data,
'required' => $product_option['required']
);
} else {
$product_option_data[] = array(
'product_option_id' => $product_option['product_option_id'],
'option_id' => $product_option['option_id'],
'name' => $product_option['name'],
'type' => $product_option['type'],
'option_value' => $product_option['option_value'],
'required' => $product_option['required']
);
}
}
return $product_option_data;
}
控制器
$this->data['options'] = array();
foreach ($this->model_catalog_product->getProductOptions($this- >request->get['product_id']) as $option) {
if ($option['type'] == 'select' || $option['type'] == 'radio' || $option['type'] == 'checkbox' || $option['type'] == 'image') {
$option_value_data = array();
foreach ($option['option_value'] as $option_value) {
if (!$option_value['subtract'] || ($option_value['quantity'] > 0)) {
if ((($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) && (float)$option_value['price']) {
$price = $this->currency->format($this->tax->calculate($option_value['price'], $product_info['tax_class_id'], $this->config->get('config_tax')));
} else {
$price = false;
}
$option_value_data[] = array(
'product_option_value_id' => $option_value['product_option_value_id'],
'option_value_id' => $option_value['option_value_id'],
'name' => $option_value['name'],
'image' => $this->model_tool_image->resize($option_value['image'], 50, 50),
'price' => $price,
'price_prefix' => $option_value['price_prefix']
);
}
}
$this->data['options'][] = array(
'product_option_id' => $option['product_option_id'],
'option_id' => $option['option_id'],
'name' => $option['name'],
'type' => $option['type'],
'option_value' => $option_value_data,
'required' => $option['required']
);
} elseif ($option['type'] == 'text' || $option['type'] == 'textarea' || $option['type'] == 'file' || $option['type'] == 'date' || $option['type'] == 'datetime' || $option['type'] == 'time') {
$this->data['options'][] = array(
'product_option_id' => $option['product_option_id'],
'option_id' => $option['option_id'],
'name' => $option['name'],
'type' => $option['type'],
'option_value' => $option['option_value'],
'required' => $option['required']
);
}
}
答案 0 :(得分:1)
如果条件在
之后,只需在第一个循环内的控制器中添加以下代码 第349行 $option_value_data = array();
。
if($option['option_id'] == your_option_id){
function cmp($a, $b)
{
return $b['price'] + $a['price'];
}
usort($option['option_value'], "cmp");
$this->data['min_price'] = $option['option_value'][0]['price'];
}
将your_option_id
替换为您想要的所需选项ID。
现在在模板文件中检查是否设置了$min_price
,然后回显$min_price
否则回显默认价格。
if(isset($min_price)){
echo $min_price;
......
}else{
echo $price
......
}
答案 1 :(得分:0)
这里的问题是设置......产品不应该有 $ 0.0 的价格,而选项设置产品的价格。而不是这个产品应该有一些价格(你可以使用产品的最低价格)和选项然后只修改这个基价:
如果您的商店销售的产品的选项总是会修改价格,那么您只能检查(在模板中)产品是否有选项,在这种情况下您可以显示价格:从10.0美元起,如果产品没有选项,请像往常一样显示,例如价格:10.0美元。
或者将基本价格设置为 0.0 有什么重要原因吗?
仅仅是我自己的观点:人们不喜欢(一般情况下)T恤(或任何其他衣服)在需要的尺寸上有不同的价格,而且当他们的尺寸更大时他们可能会气馁昂贵。计算一件T恤(或任何其他衣服)的平均价格并使用所有尺码的平均价格是一个好习惯。如果我必须这样做,我会期望出售,例如20%的S,30%的M和L,15%的XL和5%的XXL - 然后我可以计算出平均价格为0.2 x 10 + 0.3 x 11 + 0.3 x 12 + 0.15 x 13 + 0.05 x 14 = 2 + 3.3 + 3.6 + 1.95 + 0.7 = 11.55。然后,我将使用这个平均价格的所有尺码的这件衬衫......
答案 2 :(得分:0)
也许在mysql查询(模型文件)中替换顺序
$product_option_value_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option_value pov LEFT JOIN " . DB_PREFIX . "option_value ov ON (pov.option_value_id = ov.option_value_id) LEFT JOIN " . DB_PREFIX . "option_value_description ovd ON (ov.option_value_id = ovd.option_value_id) WHERE pov.product_id = '" . (int)$product_id . "' AND pov.product_option_id = '" . (int)$product_option['product_option_id'] . "' AND ovd.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY ov.sort_order");
到
$product_option_value_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option_value pov LEFT JOIN " . DB_PREFIX . "option_value ov ON (pov.option_value_id = ov.option_value_id) LEFT JOIN " . DB_PREFIX . "option_value_description ovd ON (ov.option_value_id = ovd.option_value_id) WHERE pov.product_id = '" . (int)$product_id . "' AND pov.product_option_id = '" . (int)$product_option['product_option_id'] . "' AND ovd.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY pov.price ASC");
ov.sort_order &gt;&gt; pov.price ASC
或
ov.sort_order &gt;&gt; pov.price DESC