Delta migration not removing categories in M2

When doing a delta migration it will not remove a category link in M2 when the category link has been removed in M1. Here’s the replacement function that does take that into account.
 

private function _migrateCatalogCategoryProduct($productId1, $productId2)
{
/**
* Table: catalog_category_product
*/
$models = Mage1CatalogCategoryProduct::model()->findAll("product_id = {$productId1}");
$categoryIds2 = [];
if ($models) {
foreach ($models as $model) {
$categoryId2 = UBMigrate::getM2EntityId(4, 'catalog_category_entity', $model->category_id);
$categoryIds2[] = $categoryId2;
if (!is_null($categoryId2)) {
$model2 = Mage2CatalogCategoryProduct::model()->find(
"product_id = {$productId2} AND category_id = {$categoryId2}"
);
if (!$model2) {
$model2 = new Mage2CatalogCategoryProduct();
$model2->category_id = $categoryId2;
$model2->product_id = $productId2;
}
$model2->position = $model->position;
if (!$model2->save()) {
$this->errors[] = get_class($model2) . ": " . UBMigrate::getStringErrors($model2->getErrors());
} else {
$this->_traceInfo();
}
}
}
}

$models = Mage2CatalogCategoryProduct::model()->findAll("product_id = {$productId2}");

if ($models) {
foreach ($models as $model) {
if (!in_array($model->category_id, $categoryIds2)) {
$model->delete();
}
}
}

return true;
}

1 answer

Profile photo of Mall Staff 155990.00 $tone October 31, 2020
Public

Hi Danny,

When doing a delta migration it will not remove a category link in M2 when the category link has been removed in M1. Here’s the replacement function that does take that into account.

Many thanks for sharing. We will consider handling that case in the next release of our migration tool.

Regards,
Mall.

#1

Please login or Register to Submit Answer

Written By

Comments