I want to retrieve all salesrule ids applied to the quote, by using my quote id

for example:

$quote = $this->quote->create()->loadActive($quoteId);
$salesruleIds = $quote->getSalesRuleIds(); // how ??
$discounts = array();
foreach($salesruleIds as $salesruleId){
  $rule = $this->salesRule->load($salesruleId);
  $discount['name'] = $rule->getName();
  $discount['description'] = $rule->getDescription();
  $discount['discount_amount'] = $rule->getDiscountAmount();
  $discounts[] = $discount;
return $discounts;


$salesruleIds = explode(',', $quote->getAppliedRuleIds());

If you want the only salesrule, you can try the following way.

$salesruleIds[] = $coupon->getRuleId();

Where coupon is the instance of Magento\SalesRule\Model\Coupon

  • it gives me empty result, but the sales rule is applied to the order – Hunter Jan 30 '19 at 9:15
  • Check your quote object. This is working code. Also, check to quote table coupon_code column. – Sohel Rana Jan 30 '19 at 11:54
  • turns out i need to $quote->collectTotals() first after load my quote – Hunter Jan 30 '19 at 13:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.