feedSettings = $feedSettings; } public function getCombinationId($productId, $combinationId) { $langId = (int)Configuration::get('PS_LANG_DEFAULT'); $langId = !empty($langId) ? $langId : 1; $combinationIdNew = $combinationId; $mergeGroupId = $this->getAttributeMergeGroupId(); $productColorAttributeId = 0; $allCombinationsWithTheSameColor = []; if (empty($mergeGroupId)) { return $combinationId; } $product_class = new Product($productId, false, $langId); $combinations = $product_class->getAttributesResume($langId, ' ', ', '); $productAttributes = $product_class->getAttributesGroups($langId); if (empty($combinations)) { return $combinationId; } foreach ($productAttributes as $p) { if ($p['id_product_attribute'] == $combinationId && $p['id_attribute_group'] == $mergeGroupId) { $productColorAttributeId = $p['id_attribute']; break; } } foreach ($productAttributes as $p) { if ($productColorAttributeId == $p['id_attribute']) { $allCombinationsWithTheSameColor[] = $p['id_product_attribute']; } } if (!empty($allCombinationsWithTheSameColor)) { foreach ($combinations as $c) { if ($c['quantity'] < 1 && $this->feedSettings['only_in_stock']) { continue; } if (in_array($c['id_product_attribute'], $allCombinationsWithTheSameColor)) { return $c['id_product_attribute']; } } } return $combinationIdNew; } protected function getAttributeMergeGroupId() { if (empty($this->feedSettings['merge_attributes_parent'])) { return 0; } return $this->feedSettings['merge_attributes_parent']; } }