I have cart rule collection created at admin side and displaying rule names in the system configuration of the custom module. Actually, I wanted to get coupon code of a cart rule that has been selected by admin in system configuration and display it on success page for customer to use it in next order
I am guessing you are storing the rule id. so here is code to get coupon from rule id.
class CouponCode extends \Magento\Framework\View\Element\Template
public function __construct(
$this->rule = $rule;
public function getCouponCode()
$ruleId = 7;
$couponCodeData = $this->rule->create()->load($ruleId);