This article provides a fix for when product status is Disabled and products are not displayed on the store front, or are assigned to the wrong store views, when created/updated programmatically.
Affected products and versions
- Magento Commerce Cloud, Magento Commerce
When the catalog products get created or updated programmatically from a script with Magento application bootstrapped, products might have Disabled status and/or assigned to the wrong store views.
The issue might appear because of ACL restrictions set for the Magento instance admin roles. In case of bootstrapped application, there will be no initialized admin sessions with appropriate ACL settings. That would cause validations to fail in the Magento_AdminGws module, which is responsible for permissions check on such actions.
Solution for incorrect product status
Set a dynamic DI preference for the
Magento\Framework\Authorization\PolicyInterface , as described in the ObjectManager>Programmatic product updates topic.