我对上面的代码改了一下可以出来,其他流程还测试看会不会影响
public function getAllItems()
{
$custom_option_attr_info = Yii::$service->product->getCustomOptionAttrInfo($this->attr_group);
//#########
$my_arr = [];
$arr = [];
//#在custom_option里面第一个属性
$img_attr = '';
if (is_array($custom_option_attr_info) && !empty($custom_option_attr_info)) {
foreach ($custom_option_attr_info as $attr => $info) {
if (isset($info['showAsImg']) && $info['showAsImg']) {
$img_attr = $attr;
break;
}
}
}
$img_arr = [];
if (is_array($this->custom_option) && (!empty($this->custom_option))) {
foreach ($this->custom_option as $option) {
$qty = $option['qty'];
if ($qty > 0) {
$this->_custom_option_arr[] = $option;
if (isset($option[$img_attr])) {
$val = $option[$img_attr];
$img_arr[$val] = $option['image'];
}
foreach ($option as $k=>$v) {
$my_arr[$k][] = $v;
}
}
}
}
if (is_array($custom_option_attr_info) && !empty($custom_option_attr_info)) {
foreach ($custom_option_attr_info as $attr => $info) {
if (isset($info['display']['type']) && ($info['display']['type'] == 'select')) {
if (isset($info['display']['data']) && is_array($info['display']['data'])) {
foreach ($info['display']['data'] as $key=>$val) {
if (is_array($my_arr[$attr]) && in_array(htmlspecialchars($key), $my_arr[$attr])) {
$t_arr = [
'key' => $key,
'val' => $val,
];
$require = isset($info['require']) ? $info['require'] : 0;
if (isset($info['showAsImg']) && $info['showAsImg']) {
if (isset($img_arr[htmlspecialchars($key)])) {
$t_arr['image'] = $img_arr[htmlspecialchars($key)];
}
}
$arr[$attr]['info'][] = $t_arr;
$arr[$attr]['require'] = $require;
}
}
}
}
}
}
return $arr;
}
增加了对$key的html转义