Categories Importer

Verze:

15. 02. 2024

Zodpovědná osoba:

Dominik Šlechta

DISCLAIMER: This importer was originally created for VNT B2B catalog and may need some little changes before working properly somewhere else. It can be easily recreated to MenuitemImporter.php by doing few changes.

You can find this component in vnt-b2b project in Utils/CategoriesImporter folder. Quick summary how main parts of this component works:

Feed retrieval:

This is happening in the sub-component FeedUtil.php, function retrieveFeed takes id of the supplier as an argument and then gets URL of the feed, which is stored in the supplement of the supplier. Then the feed is retrieved using curl and returned.

Category import:

This is happening in the main sub-component CategoriesImporter.php in the function importCategories, where we're looping through supplier's feed. Firstly we gotta find out if the category already exists in our database. This is done using $categoryId, which is the ID from the feed. This ID is stored in our database as id_original. We gotta take supplier_id into the account as well, because different categories from different suppliers can have same original ids. If the category exists in our database, then we update its name. Its parent is updated only if the category has originally some parent (isn't main category at supplier's). If the category doesn't exist, then we create one. We set its supplier's ID and if the category is the main category at supplier's we set its parent to supplier's category in our database - it also can be null and their parents don't have to be set.

Parents update:

After every category from the feed is either created or updated we gotta update their parents and loop through the whole feed again, because now we can be sure that every category from supplier's exists. Again, don't update parents of the categories which are main categories at supplier's (might be specific only for vnt b2b catalog).

Supplement import:

You can send all supplements from supplier, but you have to specify which supplements you want to be imported. You can specify these supplements for each supplier separately in the file SupplementsToImport.php. Names of supplements in this file have to match supplements' names in supplier's feed.

Image import:

Images are imported only on production. Currently there are two functions importCategoryImage and importCategoryImagePreview which differentiate only in image settings ID sent to the main function function importImage, which was taken from SupplierFeedPresenter.php.

MenuitemConstants.php:

There is a default menuitem defined in this component, which values are overwritten if they come in the supplier's feed. There also defined an array which overwrites values from the feed. This should be deleted if you want to recreate this component into MenuitemImporter. This array specifically in b2b catalog contains menu_id which is always set for menu id of the category (since this is a categories importer).

MainCategoriesSupplierMap.php:

The ID of the supplier is mapped here to the category (menuitem) ID. This ID is then set as the parent_id of the categories which has no parent's in supplier's feed.

ImageSettingsConstants.php:

These constants are used to retrieve specific settings for images, so we know where and how to store them.