While using the ObjectManager directly is considered bad practice in Magento, I understand that you're currently using it to load a sales rule with ID 123. Instead, I'll provide you with an alternative method that follows Magento's best practices by using dependency injection.
To load a sales rule with ID 123 using dependency injection, you can follow these steps:
1)Inject the \Magento\SalesRule\Model\RuleFactory class into your constructor or method:
protected $ruleFactory;
public function __construct(
\Magento\SalesRule\Model\RuleFactory $ruleFactory
) {
$this->ruleFactory = $ruleFactory;
}
2)Use the $ruleFactory instance to load the sales rule:
$rule = $this->ruleFactory->create()->load(123);
By utilizing dependency injection and the RuleFactory, you can properly instantiate the Rule model without directly using the ObjectManager.
It's important to follow Magento's best practices and rely on dependency injection to ensure modularity and maintainability in your code.