Catalog URL Indexing Issues in Magento 2

If you develop for Magento 2, you might have run into Catalog URL indexing issues like duplicated urls and constraints. There are many posts and answers about it on the net. After trying many free modules, this was the good one: https://github.com/karliuka/m2.IndexerUrlRewrite It adds Product, Category and Catalog reindex to indexes When reindexing from terminal you’ll see that it reindex these three models You can also reindex separately: This just saved my day 🙂

[Magento 2] Move billing address to shipping step (Magento >= 2.3)

I’ve been looking for a solution that works fine in Magento 2.3 to move billing address to shipping step in Magento 2.3. There aren’t many available solution online but I’ve found one that works fine with a couple of modifications. Pull request haven’t been accepted in the original repo, but I’ve created a fork with the modifications to: Make this module work with Magento > 2.3 Remove completely the billing address from the payment step Read more…

[Magento 2] Error: Uncaught TypeError: Argument 1 passed to Magento\Catalog\Model\ProductRepository::prepareSku()

The error: Is related to a product which doesn’t have a SKU. This might cause different issues: Indexation problems » URL Rewrites not created Product Grid sorting issues: can’t sort by sku The solution should be easy. Go to your database and check which products don’t have an SKU: Once you have found the products, you can just manually add the SKU: You can now check that indexation works fine and you can also sort Read more…

[Magento 2] Migration errors: unserialize

One of the trickiest errors I’ve found when Migrating Magento 1 to Magento 2 (2.3) has been an issue related to unserialization. There are 2 types of messages I received: Reason: in both cases, the reason is that some data that was stored serialized in the Magento 1 database, had been serialized incorrectly. In this particular case, the issue was related to the item product_options value (there is where custom options selected by the customer Read more…

[Magento 2] Migration errors: Data Integrity Step

Noting down the errors and possible solutions I get while migrating data from Magento 1 to Magento 2. In the data integrity step we can find many type of errors. Here you have some of them, explanation and solution: Error Foreign key (FK_CATALOG_EAV_ATTRIBUTE_ATTRIBUTE_ID_EAV_ATTRIBUTE_ATTRIBUTE_ID) constraint fails on source database. Orphan records id: 121,182 from catalog_eav_attribute.attribute_id has no referenced records in `eav_attribute Explanation A catalog eav attribute (product attribute or category attribute) was created in the past Read more…

[Magento 2] Add require fields dynamically in a form

Recently I had to modify the customer registration form from one of the websites I manage. VAT ID had to be included but only for professional customers. This meant that when a customer clicked on the «I’m a professional» field, new fields should show up and, the most important, the TAXVAT field had to become required (when in Magento is not required). This solution is not perfect because it uses just the javascript validation. But Read more…

[Apache] How to correctly protect your Magento backoffice with htpasswd

One of the good security practices in Magento (either 1 or 2) is to protect your backoffice url with password using htpasswd (directly in the Apache conf or in the htaccess file). It is not the perfect solution, but it adds an extra layer of security which: Will prevent anyone trying to log from anywhere Will prevent brute force attacks. This particular case is what we’ve experienced in our Magento stores. Apache configuration This is Read more…

[Magento 2] How to clean the cache by TAG

Cleaning the cache by TAG is quite easy in Magento 2. You will need to: Inject the classes in your construct function Know the exact tags you want to cache Flush the actual Cache Start creating your class injecting the classes we need: Create a function to retrieve the tags you want to flush. For example, for a CMS page with an ID 2: And, in a custom function you can just execute the cache Read more…

[Magento 2] Adding custom category attribute (with scopes)

Creating a new category attribute should be easy in Magento 2. It is, more or less. Follow these steps and you will get to it: Files you will need to create A quick screenshot of how your module will look once you create it: YourCompany/YourModule/registration.php YourCompany/YourModule/etc/module.xml YourCompany/YourModule/Setup/InstallData.php YourCompany/YourModule/view/adminhtml/ui_component/category_form.xml This code should be enough to create the category attribute. However, even though we have created the attribute passing the parameter ‘global’ = \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE, you’ll see that Read more…