magento2-vsbridge-indexer
magento2-vsbridge-indexer copied to clipboard
Products not assigned for Anchor categories
Hi
products are not being indexed for parent category which has anchoring categories to it. is it necessary to have products assigned to each category and anchoring product collection does not work?
Please explain.
I have applied fix as below:
extend with plugin: product/ConfigurableData.php >> afterAddData $result[$key] = $this->getCategoryIdsData($result[$key]);
` /** * @param $configProduct * @return mixed */ private function getCategoryIdsData($configProduct) { //get category ids $categoryIds = $configProduct['category_ids'] ?? '';
if (!empty($categoryIds)) {
$categorIds = implode(',', $categoryIds);
$ids = $this->helper->getCategoryIdsData($categorIds);
if (!empty($ids)) {
$configProduct['category_ids'] = [];
foreach ($ids as $cat) {
$configProduct['category_ids'][] = (int)$cat;
}
}
}
return $configProduct;
}`
Helper File: `/** * @param $ids * @return false|string|string[] */ public function getCategoryIdsData($ids) { $catalogCategoryEntity = $this->connection->getTableName('catalog_category_entity'); $conditions = "entity_id in ($ids)"; $select = $this->connection->select() ->from( ['category' => $catalogCategoryEntity], ["group_concat(category.path SEPARATOR '/')"] ) ->where($conditions) ->order('category.entity_id asc'); $categoryIds = $this->connection->fetchOne($select);
if (!empty($categoryIds)) {
$categoryIds = $this->processCategoryIds($categoryIds);
if (!empty($categoryIds)) {
return $categoryIds;
}
}
return '';
}`
`/** * @param $categoryIds * @return false|string[] */ private function processCategoryIds($categoryIds) { //remove root and default category $baseCategoryIds = [1,2];
$ids = array_unique(explode('/', $categoryIds));
$categoryIds = array_diff($ids, $baseCategoryIds);
return $categoryIds;
}`