我的opencart product.php控件文件中包含以下代码。
$product_option_value_data = array();
foreach ($product_option['product_option_value'] 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'],
'quantity' => isset ($product_option_value['quantity']) ? $product_option_value['quantity'] : '1',
'subtract' => $product_option_value['subtract'],
'price' => isset ($product_option_value['price'])? $product_option_value['price'] : '27.99',
'price_prefix' => $product_option_value['price_prefix'],
'points' => $product_option_value['points'],
'points_prefix' => $product_option_value['points_prefix'],
'weight' => $product_option_value['weight'],
'weight_prefix' => $product_option_value['weight_prefix']
);
}
我需要为数量,价格,减去添加默认值。 任何帮助将受到高度赞赏。
答案 0 :(得分:1)
你快到了。你已经为你的两个元素做了这个。只需为subtract
一个添加相同的检查。
$product_option_value_data = array();
foreach ($product_option['product_option_value'] 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'],
'quantity' =>
isset ($product_option_value['quantity']) ?
$product_option_value['quantity'] :
'1', // THE DEFAULT FOR QUANTITY
'subtract' =>
isset ($product_option_value['subtract']) ?
$product_option_value['subtract'] :
'22', // THE DEFAULT FOR SUBTRACK
'price' =>
isset ($product_option_value['price']) ?
$product_option_value['price'] :
'27.99', //THE DEFAULT FOR PRICE
'price_prefix' => $product_option_value['price_prefix'],
'points' => $product_option_value['points'],
'points_prefix' => $product_option_value['points_prefix'],
'weight' => $product_option_value['weight'],
'weight_prefix' => $product_option_value['weight_prefix']
);
}
希望这有帮助