The error:

Uncaught TypeError: Argument 1 passed to Magento\Catalog\Model\ProductRepository::prepareSku()

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:

mysql> select * from catalog_product_entity where sku IS NULL;
+-----------+------------------+---------+------+-------------+------------------+---------------------+---------------------+
| entity_id | attribute_set_id | type_id | sku  | has_options | required_options | created_at          | updated_at          |
+-----------+------------------+---------+------+-------------+------------------+---------------------+---------------------+
|       946 |                4 | simple  | NULL |           1 |                0 | 2018-10-04 09:31:57 | 2018-10-04 09:31:57 |
|       970 |                4 | simple  | NULL |           1 |                0 | 2019-03-29 09:34:48 | 2019-03-29 09:34:48 |
+-----------+------------------+---------+------+-------------+------------------+---------------------+---------------------+
2 rows in set (0.00 sec)

Once you have found the products, you can just manually add the SKU:

update catalog_product_entity set sku = '0946' where entity_id = '946';
update catalog_product_entity set sku = '0970' where entity_id = '970';

You can now check that indexation works fine and you can also sort by SKU in your product grid.


0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.