akeneo / magento2-connector-community

Akeneo Connector for Magento 2
Open Software License 3.0
80 stars 87 forks source link

Akeneo Connector cannot handle excluded category trees #659

Closed robinero closed 7 months ago

robinero commented 10 months ago

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 https://github.com/akeneo/magento2-connector-community/issues/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 commented 9 months ago

@robinero We have the same issue.

robinero commented 7 months ago

Closing issue, this is fixed in: v104.0.5