Deepak Shinde
Deepak Shinde

Reputation: 111

In magento2, How to get applicable catalog rule details for particular product

I want to get all applicable catalog product rules for particular product. How can I achieve this?

Upvotes: 0

Views: 934

Answers (1)

johncarlson21
johncarlson21

Reputation: 19

I know this probably isn't the best answer as to people not wanting you to use the objectmanager, but here is a dirty way:

<?php 
//Get Object Manager Instance
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

//Load product by product id
$rules = $objectManager->create('Magento\CatalogRule\Model\ResourceModel\Rule')->getRulesFromProduct($date, $websiteId, $customerGroupId, $productId);

You will need to get the variables from where ever your code is ( template file, or class etc )

Upvotes: 1

Related Questions