How to get Shopping cart Coupon data by id Magento 2?

Magento 2, Get Shopping cart rule data by the coupon id to retrieve information of coupon code, the coupon used details, rule id and usage limit of the coupon.

Coupon details are saved in the salesrule_coupon table of the database.

Coupon code is the actual code which user will add from the Cart or Checkout page to get a discount.

rule_id is the parent id of the sales rule table. You can retrieve the details of coupons using Coupon Repository Interface.

Use the getById() method of the Magento\SalesRule\Api\CouponRepositoryInterface interface to retrieve the details of Coupon code.

You need to pass Coupon id to fetch data of the specific coupon.

Output: if coupon id is correct,

Coupon id is not found, the result will be null.

 

One Reply to “How to get Shopping cart Coupon data by id Magento 2?”

Leave a Reply