private function bindToProducts($feature, $values) { if (is_array($feature)) { $feature_id = $feature['id']; } else { $feature_id = (int) $feature; $feature = $this->feature_model->getById($feature_id); } $is_multidimensional = $this->isMultidimensional($feature); // bind products with values of new feature foreach ($values as $v) { if ($feature['type'] !== 'boolean') { if (isset($v['original_id'])) { $new_id = $v['original_id']; } else { $new_id = $v['id']; } if (isset($v['original_id'])) { $old_id = -$v['id']; } else { $old_id = -$v['insert_id']; } } else { $old_id = -$v['id']; $new_id = $v['value']; } if (!$is_multidimensional) { $key = array('feature_id' => $feature_id, 'feature_value_id' => $old_id); $value = array('feature_value_id' => $new_id); } else { $key = array('feature_id' => $v['feature_id'], 'feature_value_id' => $old_id); $value = array('feature_value_id' => $new_id); } $this->product_features_model->updateByField($key, $value); $key['value_id'] = $key['feature_value_id']; unset($key['feature_value_id']); $value['value_id'] = $value['feature_value_id']; unset($value['feature_value_id']); $this->product_features_selectable_model->updateByField($key, $value); } }