I want to filter cart rules list in my account page. I've list cart rules in My Account page "Dashboard". But I want to filter cart rules list by condition.

Cart Rules List

I've configure the conditions in cart rules by date of birth. I just want to show the rules if the customer date of birth is same with my conditions.

I got the Data from \Magento\Customer\Block\Account\Dashboard\Info. but I dont know how to filter cart rules list.

$datax = $helper->getSalesRule();
echo '<pre>';
echo '</pre>';

and the result


1 Answer 1


First, you have to get the collection of all rules, then validate those by using validate() function

$rules = $this->ruleFactory->create()->getCollection()

foreach ($rules as $rule) {
            if ($quote->isVirtual()) {
                $address = $quote->getBillingAddress();
            } else {
                $address = $quote->getShippingAddress();
            foreach ($address->getAllItems() as $item) {// total_qty - allowed only in total collection process
                $address->setTotalQty($address->getTotalQty() + $item->getQty());
            if ($rule->validate($address)) {
                $subtotal = 0;
                foreach ($quote->getItemsCollection() as $item) {
                    if ($item->getParentItemId()) {
                    if ($rule->getConditions()->validate($item)) {
                        $subtotal += $item->getBasePrice() * $item->getQty();
                if ($subtotal > 0) {
                    return $rule;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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