Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Akeneo Connector cannot handle excluded category trees #659

Closed
robinero opened this issue Sep 5, 2023 · 2 comments
Closed

Akeneo Connector cannot handle excluded category trees #659

robinero opened this issue Sep 5, 2023 · 2 comments

Comments

@robinero
Copy link

robinero commented Sep 5, 2023

Environment and configuration

  1. Magento 2.4.6-p2
  2. Akeneo connector 104.0.0
  3. Akeneo 6.x

Steps to reproduce in Akeneo

  1. Add two category trees, each with a "sub category".
  2. Create a product and add the product to both category trees.

Steps to reproduce in Magento

  1. Setup the Akeneo Connector, but only select one of the Category trees to import.
  2. Run bin/magento akeneo_connector:import --code=category,product (or schedule the jobs)

Expected result

  1. Akeneo Connector imports the products.

Actual result

  1. Akeneo Connector crashes, because it tries to match categories that are not imported:
Warning: Undefined array key "CATEGORY_THAT_IS_NOT_IMPORTED" in vendor/akeneo/module-magento2-connector-community/Job/Product.php on line 2972

This issue is related to #653.

The approach however is different: no categories vs multiple category trees.
But the following fix will work by simply checking if the category is set:

$notInWhere = [];
foreach ($categoriesByProduct as $row) {
    $categoryList = explode(',', $row['categories']);
    foreach ($categoryList as $category) {
        // imported product category does not exist in Magento
        if (!isset($categoryAkeneo[$category])) {
            continue;
        }

        $data = [
            $row['_entity_id'],
            $categoryAkeneo[$category]['entity_id'],
        ];
        $productCategoryInsertData[] = $data;
        $notInWhere[] = '(' . $row['_entity_id'] . ',' . $categoryAkeneo[$category]['entity_id'] . ')';
    }
}

reference

Although the related issue can be fixed with the above, it's probably better to skip the setCategories step altogether,
by checking if the akeneo_connector_entities table contains imported categories, as to not waste resources.

@oefterdal
Copy link

@robinero We have the same issue.

@robinero
Copy link
Author

robinero commented Dec 8, 2023

Closing issue, this is fixed in: v104.0.5

@robinero robinero closed this as completed Dec 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants