Update url-key

A Magento 2 store may undergo changes from time to time. There may be changes in product or catalogue pages or changed the location entirely! In such cases, if the URL rewriting is not taken care of, then the store might lose potential customers due to landing on a page that does not exist anymore. Also, the admin would want to rewrite the URL with higher-value keywords to make it more search friendly and improve the SEO of the store. If you’re going to do the same for your store, learn how to manage the Magento 2 URL rewrite! Remember, a misconfigured URL rewrite can cause Magento 2 404 error.

  • The Pacemaker always required an url key, which sometimes led to problems with missing CSV files.

  • With this configuration, it is possible to set the URL key based on the name of a category/product.

Example

That can get performed by setting the update-url-key-from-name flag to true:
{
  "operation": {
    "catalog_product" : {
      "add-update": {
        "plugins": {
          "subject": {
            "id": "import.plugin.subject",
            "subjects": [
              {
                "id": "import_product.subject.bunch",
                "file-resolver": {
                  "prefix": "product-import"
                },
                "params": {
                  "copy-images": false,
                  "media-directory" : "pub/media/catalog/product",
                  "images-file-directory" : "var/importexport/media/catalog/product",
                  "update-url-key-from-name": true,(1)
                  "clean-up-variants": false,
                  "clean-up-links": false,
                  "clean-up-media-gallery": true,
                  "clean-up-empty-image-columns": true,
                  "clean-up-website-product-relations": true,
                  "clean-up-category-product-relations": true,
                  "clean-up-empty-columns": [
                    "special_price",
                    "special_price_from_date",
                    "special_price_to_date"
                  ]
                },
                "observers": [
                  {
                    "import": [
                      "import_product.observer.composite.base.add_update"
                    ]
                  }
                ]
              }
            ]
          }
        }
      }
    },
    "catalog_category": {
      "add-update": {
        "plugins": {
          "subject": {
            "id": "import.plugin.subject",
            "subjects": [
              {
                "id": "import_category.subject.bunch",
                "file-resolver": {
                  "prefix": "category-create"
                },
                "params": {
                  "copy-images": false,
                  "media-directory" : "pub/media/catalog/category",
                  "images-file-directory" : "var/importexport/media/catalog/category",
                  "clean-up-empty-columns": [],(2)
                  "update-url-key-from-name": true
                },
                "observers": [
                  {
                    "import": [
                      "import_category.observer.composite.add_update"
                    ]
                  }
                ]
              }
            ]
          }
        }
      }
    }
  }
}
1 To set the update-url-key-from-name for product operation flag to true or false.
2 To set the update-url-key-from-name for category operation flag to true or false.
  • true is set by default

During product-import, the observer import_product.store.in.website.validator.observer checks for each store view row whether the product is also assigned to the website of the respective store view. If not, the validation will issue a corresponding error message.

<service id="import_product.observer.composite.base.add_update" class="TechDivision\Import\Observers\GenericCompositeObserver">
    <call method="addObserver">
        <argument id="import_product.observer.normalize.categories" type="service"/>
    </call>
    ...
    <call method="addObserver">
        <argument id="import_product_custom_option.observer.product.custom.option" type="service"/>
    </call>
    <call method="addObserver">
        <argument id="import_product_smile.observer.smile.create" type="service"/>
    </call>
    <call method="addObserver">(1)
        <argument id="import_product.store.in.website.validator.observer" type="service"/>
    </call>
    <call method="addObserver">
        <argument id="import_product.observer.clean.up" type="service"/>
    </call>
</service>
1 The observer who checks whether the store belongs to the specified websites.