Вопрос такого плана
Есть код который собирает массив свойств
if ($product_values = $this->features_values->get_features_values(array('product_id'=>$product->id))) {
foreach ($product_values as $pv) {
if (!isset($product->features[$pv->feature_id])) {
$product->features[$pv->feature_id] = $pv;
}
$product->features[$pv->feature_id]->values[] = $pv;
}
}
В связи с обновлением CMS он стал таким, добавилась групировка этих самых свойств
Теперь он стал таким.
$product_features = $this->featuresgroups->get_product_features_groups_options(array('product_id'=>$product->id));
$unique_product_features_keys = array();
$unique_product_features = array();
foreach($product_features as $f) {
if (!in_array($f->name, $unique_product_features_keys)) {
$unique_product_features_keys[] = $f->name;
$unique_product_features[] = $f;
}
}
foreach($unique_product_features as $f) {
foreach($product_features as $fv) {
if ($f->name === $fv->name) {
$f->values[] = $fv;
}
}
}
$product->features = $unique_product_features;
По нему вопросов нет, но возникает вопрос дальше.
Есть такой код который собирает вариации.
if($variation_id = $this->variations->get_variation_id($product->id)) {
$filter = array();
$variation_products_ids = $filter['id'] = $this->variations->get_variation_products_ids($variation_id);
$variation_features = $this->variations->get_variation_features($variation_id);
$filter_all_features = array();
foreach($variation_features as $f) {
$filter_all_features[$f->id] = array(0=>$product->features[$f->id]->values[0]->translit);
}
$product->variation_features = array();
foreach($variation_features as $f) {
$product->variation_features[$f->id] = $f;
$filter['features'] = array_diff_key($filter_all_features, array($f->id=>''));
$products = array();
foreach ($this->products->get_products($filter) as $p) {
$products[$p->id] = $p;
}
foreach($variation_products_ids as $p_id) {
if(isset($products[$p_id])) {
$product->variation_features[$f->id]->values[$p_id] = new stdClass();
$product->variation_features[$f->id]->values[$p_id]->product_url = $products[$p_id]->url;
$f_values = $this->features_values->get_features_values(array('product_id'=>$p_id, 'feature_id'=>$f->id));
$product->variation_features[$f->id]->values[$p_id]->value = $f_values[0]->value;
$product->variation_features[$f->id]->values[$p_id]->translit = $f_values[0]->translit;
$product->variation_features[$f->id]->values[$p_id]->color = $f_values[0]->color;
}
}
}
}
А проблема после обновления именно фильтре
$filter_all_features = array();
foreach($variation_features as $f) {
$filter_all_features[$f->id] = array(0=>$product->features[$f->id]->values[0]->translit);
}
Со старым кодом до обновления если смотреть на $filter_all_features
Array ( [38] => Array ( [0] => chernyj ) [75] => Array ( [0] => 64spgb ) )
А после обновления
Array ( [38] => Array ( [0] => ) [75] => Array ( [0] => ) )