I am trying to find the discount amount which match the shopping cart rule based on product. I want to get discount amount that matches my product price rule based on product details(product id, sku). here is the code i am using but its not working.

$products_id = $_helper->productAttribute($_product, $_product->getId(), 'id');
$_p = $objectManager->get('Magento\Catalog\Model\Product')->load($products_id);
$price_rules = array();
$rules = $objectManager->create('Magento\SalesRule\Model\Rule\Action\Collection')
foreach($rules as $rule){

$quoteId = $objectManager->getSingleton('checkout/session')->getQuoteId(); 
$real_quote = $objectManager->getSingleton('sales/quote')->load($quoteId);                
$product = $objectManager->get('sales/quote_item')->setQuote($real_quote)->setProduct($_p);  
foreach($rules as $rule) 
    if ($rule->getConditions()->validate($product))  
        echo ':)';
        echo $rule->getData('discount_amount');


You should init an quote item like this:

$real_quote = $objectManager->get('Magento\Checkout\Model\Session')->getQuote();
$item = $objectManager->get('Magento\Quote\Model\Quote\Item')->setQuote($real_quote)->setProduct($product);

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.