I’m running a custom import.
At some point the error: The stock item was unable to be saved. Please try again.
Is triggered by : $this->_productRepository->save($prod);
Now I’m trying to figure out why.
MariaDB [magento]> select * from cataloginventory_stock;
+----------+------------+------------+
| stock_id | website_id | stock_name |
+----------+------------+------------+
| 1 | 0 | Default |
+----------+------------+------------+
Is the fact I only have one stock there might be related? This script is launched by an URL from one of the front stores
MariaDB [magento]> select * from inventory_stock;
+----------+---------------+
| stock_id | name |
+----------+---------------+
| 1 | Default Stock |
| 2 | Stock RE |
| 3 | Stock YT |
| 4 | Stock GF |
| 5 | Stock MQ |
| 6 | Stock BL |
| 7 | Stock GP |
| 8 | Stock SX |
+----------+---------------+
I indeed have 8 websites (0 being an admin and 1 being base) website and stocks
EDIT : So I’ve been investigating a little bit more
It appears that my real error comes from vendor/magento/module-catalog/Model/CategoryRepository.php
on the get method
He can’t find the category
/** @var Category $category */
$category = $this->categoryFactory->create();
if (null !== $storeId) {
$category->setStoreId($storeId);
}
$category->load($categoryId);
if (!$category->getId()) {
var_dump($storeId);
var_dump($categoryId);
var_dump($category->getCollection()->getSelect()->__toString());
throw NoSuchEntityException::singleField('id', $categoryId);
}
Store id : 10
Category Id : 50
Error : No such entity with id = 50
Problem is, the category actually exist; she is even found when I log the collection matching the request
SELECT `main_table`.`entity_id`, `main_table`.`level`, `main_table`.`path`, `main_table`.`position`, `main_table`.`is_active`, `main_table`.`is_anchor` FROM `catalog_category_flat_store_10` AS `main_table`
Among other results I have this one :
+-----------+-------+---------------+----------+-----------+-----------+
| entity_id | level | path | position | is_active | is_anchor |
+-----------+-------+---------------+----------+-----------+-----------+
| 50 | 2 | 1/2/50 | 2 | 1 | 1 |