Get product applied price rule by product id in magento 2Catalog Price Rules applied to special_priceWidget of products with catalog ruleHow to get the toDate of a catalog rule programatically?Get Applied shopping cart price rule/Catalog price Rule name in product details pageShopping card price rule NOT overriding catalog price ruleMagento 2 check which catalog rule is applied to cart productMagento 2.3 - event when catalog price rules are appliedHow to calculate product price based on custom action in Catalog Price RulesCatalog Price Rule Magento 2Get Conditions from Catalog price rule

3D Statue Park: U shapes

Scaling of single component (tlinestub) indepent of "bipole/length" scaling of other components?

Can two figures have the same area, perimeter, and same number of segments have different shape?

Why isn't there a serious attempt at creating a third mass-appeal party in the US?

Drillers for petroleum strike gusher of blood

A planet illuminated by a black hole?

What to do when you reach a conclusion and find out later on that someone else already did?

Spin vs orbital angular momenta in QFT

What self-defense weapons are legal in London?

How to judge a Ph.D. applicant that arrives "out of thin air"

How do I stop my characters falling in love?

Why can't my huge trees be chopped down?

This message is flooding my syslog, how to find where it comes from?

(1 of 11: Numberlink) What is Pyramid Cult's Favorite Activity?

Is dd if=/dev/urandom of=/dev/mem safe?

How can I prevent corporations from growing their own workforce?

Basic Questions on Wiener Filtering

Binomial analogue of Riemann sum for definite integral

What is the meaning of "you has the wind of me"?

Where to place an artificial gland in the human body?

Does the Intel 8086 CPU have user mode and kernel mode?

Send a single HTML email from Thunderbird, overriding the default "plain text" setting

TSA asking to see cell phone

Why was Sauron preparing for war instead of trying to find the ring?



Get product applied price rule by product id in magento 2


Catalog Price Rules applied to special_priceWidget of products with catalog ruleHow to get the toDate of a catalog rule programatically?Get Applied shopping cart price rule/Catalog price Rule name in product details pageShopping card price rule NOT overriding catalog price ruleMagento 2 check which catalog rule is applied to cart productMagento 2.3 - event when catalog price rules are appliedHow to calculate product price based on custom action in Catalog Price RulesCatalog Price Rule Magento 2Get Conditions from Catalog price rule






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















Simply I want to get the rule_id or catalog rule details that is applied to a product in product details page and product listing page.



I have checked with this function _getRulesFromProduct() from magento-catalog-rule/Model/Rule.php but it return all catalog rule applicable for that product.



I want only one rule which is currently applied to that product.










share|improve this question
























  • Did you pass all the arguments to the getRulesFromProduct function ?

    – aravind
    Jul 17 at 9:58











  • Yes, $this->_getRulesFromProduct($dateTs, $websiteId, $customerGroupId, $product->getId());

    – Akhil Anand
    Jul 17 at 10:09











  • could you share the full code you have implemented for this proces

    – aravind
    Jul 17 at 10:24











  • public function get($product) $priceRules = null; $price = $product->getPriceInfo()->getPrice('regular_price')->getAmount()->getValue(); $storeId = $product->getStoreId(); $dateTs = $this->_localeDate->scopeTimeStamp($storeId); $websiteId = $this->_storeManager->getStore($storeId)->getWebsiteId(); if ($product->hasCustomerGroupId()) $customerGroupId = $product->getCustomerGroupId(); else $customerGroupId = $this->_customerSession->getCustomerGroupId(); $rules = $this->_getRulesFromProduct($dateTs, $websiteId, $customerGroupId, $product->getId()); return $rules;

    – Akhil Anand
    Jul 17 at 10:49











  • This is the code i have written. and return all rules which is applicable to the same product in product details page.

    – Akhil Anand
    Jul 17 at 12:00

















1















Simply I want to get the rule_id or catalog rule details that is applied to a product in product details page and product listing page.



I have checked with this function _getRulesFromProduct() from magento-catalog-rule/Model/Rule.php but it return all catalog rule applicable for that product.



I want only one rule which is currently applied to that product.










share|improve this question
























  • Did you pass all the arguments to the getRulesFromProduct function ?

    – aravind
    Jul 17 at 9:58











  • Yes, $this->_getRulesFromProduct($dateTs, $websiteId, $customerGroupId, $product->getId());

    – Akhil Anand
    Jul 17 at 10:09











  • could you share the full code you have implemented for this proces

    – aravind
    Jul 17 at 10:24











  • public function get($product) $priceRules = null; $price = $product->getPriceInfo()->getPrice('regular_price')->getAmount()->getValue(); $storeId = $product->getStoreId(); $dateTs = $this->_localeDate->scopeTimeStamp($storeId); $websiteId = $this->_storeManager->getStore($storeId)->getWebsiteId(); if ($product->hasCustomerGroupId()) $customerGroupId = $product->getCustomerGroupId(); else $customerGroupId = $this->_customerSession->getCustomerGroupId(); $rules = $this->_getRulesFromProduct($dateTs, $websiteId, $customerGroupId, $product->getId()); return $rules;

    – Akhil Anand
    Jul 17 at 10:49











  • This is the code i have written. and return all rules which is applicable to the same product in product details page.

    – Akhil Anand
    Jul 17 at 12:00













1












1








1


1






Simply I want to get the rule_id or catalog rule details that is applied to a product in product details page and product listing page.



I have checked with this function _getRulesFromProduct() from magento-catalog-rule/Model/Rule.php but it return all catalog rule applicable for that product.



I want only one rule which is currently applied to that product.










share|improve this question
















Simply I want to get the rule_id or catalog rule details that is applied to a product in product details page and product listing page.



I have checked with this function _getRulesFromProduct() from magento-catalog-rule/Model/Rule.php but it return all catalog rule applicable for that product.



I want only one rule which is currently applied to that product.







magento2 magento2.2.3 catalog-price-rules catalog-rules






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 17 at 10:12









Anas Mansuri

1,1251 silver badge16 bronze badges




1,1251 silver badge16 bronze badges










asked Jul 17 at 9:46









Akhil AnandAkhil Anand

64 bronze badges




64 bronze badges












  • Did you pass all the arguments to the getRulesFromProduct function ?

    – aravind
    Jul 17 at 9:58











  • Yes, $this->_getRulesFromProduct($dateTs, $websiteId, $customerGroupId, $product->getId());

    – Akhil Anand
    Jul 17 at 10:09











  • could you share the full code you have implemented for this proces

    – aravind
    Jul 17 at 10:24











  • public function get($product) $priceRules = null; $price = $product->getPriceInfo()->getPrice('regular_price')->getAmount()->getValue(); $storeId = $product->getStoreId(); $dateTs = $this->_localeDate->scopeTimeStamp($storeId); $websiteId = $this->_storeManager->getStore($storeId)->getWebsiteId(); if ($product->hasCustomerGroupId()) $customerGroupId = $product->getCustomerGroupId(); else $customerGroupId = $this->_customerSession->getCustomerGroupId(); $rules = $this->_getRulesFromProduct($dateTs, $websiteId, $customerGroupId, $product->getId()); return $rules;

    – Akhil Anand
    Jul 17 at 10:49











  • This is the code i have written. and return all rules which is applicable to the same product in product details page.

    – Akhil Anand
    Jul 17 at 12:00

















  • Did you pass all the arguments to the getRulesFromProduct function ?

    – aravind
    Jul 17 at 9:58











  • Yes, $this->_getRulesFromProduct($dateTs, $websiteId, $customerGroupId, $product->getId());

    – Akhil Anand
    Jul 17 at 10:09











  • could you share the full code you have implemented for this proces

    – aravind
    Jul 17 at 10:24











  • public function get($product) $priceRules = null; $price = $product->getPriceInfo()->getPrice('regular_price')->getAmount()->getValue(); $storeId = $product->getStoreId(); $dateTs = $this->_localeDate->scopeTimeStamp($storeId); $websiteId = $this->_storeManager->getStore($storeId)->getWebsiteId(); if ($product->hasCustomerGroupId()) $customerGroupId = $product->getCustomerGroupId(); else $customerGroupId = $this->_customerSession->getCustomerGroupId(); $rules = $this->_getRulesFromProduct($dateTs, $websiteId, $customerGroupId, $product->getId()); return $rules;

    – Akhil Anand
    Jul 17 at 10:49











  • This is the code i have written. and return all rules which is applicable to the same product in product details page.

    – Akhil Anand
    Jul 17 at 12:00
















Did you pass all the arguments to the getRulesFromProduct function ?

– aravind
Jul 17 at 9:58





Did you pass all the arguments to the getRulesFromProduct function ?

– aravind
Jul 17 at 9:58













Yes, $this->_getRulesFromProduct($dateTs, $websiteId, $customerGroupId, $product->getId());

– Akhil Anand
Jul 17 at 10:09





Yes, $this->_getRulesFromProduct($dateTs, $websiteId, $customerGroupId, $product->getId());

– Akhil Anand
Jul 17 at 10:09













could you share the full code you have implemented for this proces

– aravind
Jul 17 at 10:24





could you share the full code you have implemented for this proces

– aravind
Jul 17 at 10:24













public function get($product) $priceRules = null; $price = $product->getPriceInfo()->getPrice('regular_price')->getAmount()->getValue(); $storeId = $product->getStoreId(); $dateTs = $this->_localeDate->scopeTimeStamp($storeId); $websiteId = $this->_storeManager->getStore($storeId)->getWebsiteId(); if ($product->hasCustomerGroupId()) $customerGroupId = $product->getCustomerGroupId(); else $customerGroupId = $this->_customerSession->getCustomerGroupId(); $rules = $this->_getRulesFromProduct($dateTs, $websiteId, $customerGroupId, $product->getId()); return $rules;

– Akhil Anand
Jul 17 at 10:49





public function get($product) $priceRules = null; $price = $product->getPriceInfo()->getPrice('regular_price')->getAmount()->getValue(); $storeId = $product->getStoreId(); $dateTs = $this->_localeDate->scopeTimeStamp($storeId); $websiteId = $this->_storeManager->getStore($storeId)->getWebsiteId(); if ($product->hasCustomerGroupId()) $customerGroupId = $product->getCustomerGroupId(); else $customerGroupId = $this->_customerSession->getCustomerGroupId(); $rules = $this->_getRulesFromProduct($dateTs, $websiteId, $customerGroupId, $product->getId()); return $rules;

– Akhil Anand
Jul 17 at 10:49













This is the code i have written. and return all rules which is applicable to the same product in product details page.

– Akhil Anand
Jul 17 at 12:00





This is the code i have written. and return all rules which is applicable to the same product in product details page.

– Akhil Anand
Jul 17 at 12:00










2 Answers
2






active

oldest

votes


















0














Try with below way!



public function getCatalogPriceRuleProductIds()

$storeManager = MagentoFrameworkAppObjectManager::getInstance()->create(
'MagentoStoreModelStoreManagerInterface'
);
$catalogRule = MagentoFrameworkAppObjectManager::getInstance()->create(
'MagentoCatalogRuleModelRuleFactory'
);

$websiteId = $storeManager->getStore()->getWebsiteId();//current Website Id

$resultProductIds = [];
$catalogRuleCollection = $catalogRule->create()->getCollection();
$catalogRuleCollection->addIsActiveFilter(1);//filter for active rules only
foreach ($catalogRuleCollection as $catalogRule)
$productIdsAccToRule = $catalogRule->getMatchingProductIds();
if (in_array("Your currrent productId", $affectedProductIds))
//product has a price rule set for it


return $resultProductIds;



Please don't use objectmanager. it's bad practice! I hope it helps!






share|improve this answer























  • This function will return all product Ids applicable for the product right? i want the rule id

    – Akhil Anand
    Jul 17 at 11:02












  • Yes! and using condition if (in_array("Your currrent productId", $affectedProductIds)) you can match your current product id

    – Chirag Patel
    Jul 17 at 11:03











  • The function i have written in the comment will return all rule ids which is applicable for the product. i want only single rule which is applied currently.

    – Akhil Anand
    Jul 17 at 11:06











  • It is not necessary every product have a singe rule there will be multiple rules will be applied on a single product.

    – Chirag Patel
    Jul 17 at 11:10











  • I have enabled "Discard subsequent rules" to yes in Catalog Price Rule from admin side. So i think only one rule is applied a product at same time right?

    – Akhil Anand
    Jul 17 at 11:14


















0














Try getting rules from the resourceModel instead, I have used objectmanager try to use it as dependency,



public function get($product) 
$priceRules = null;
$price = $product->getPriceInfo()->getPrice('regular_price')->getAmount()->getValue();
$storeId = $product->getStoreId();
$dateTs = $this->_localeDate->scopeTimeStamp($storeId);
$websiteId = $this->_storeManager->getStore($storeId)->getWebsiteId();

if ($product->hasCustomerGroupId())
$customerGroupId = $product->getCustomerGroupId();
else
$customerGroupId = $this->_customerSession->getCustomerGroupId();


$resource = $this->_objectManager->create('MagentoCatalogRuleModelResourceModelRule');

$rules = $resource->getRulesFromProduct($dateTs, $websiteId, $customerGroupId, $product->getId());

print_r( $rules);



Let me know if you have any queries






share|improve this answer

























  • In this function it will return array of rules. Not a single one.

    – Akhil Anand
    Jul 17 at 12:40











  • share the result ..

    – aravind
    Jul 17 at 12:43













Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f282356%2fget-product-applied-price-rule-by-product-id-in-magento-2%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Try with below way!



public function getCatalogPriceRuleProductIds()

$storeManager = MagentoFrameworkAppObjectManager::getInstance()->create(
'MagentoStoreModelStoreManagerInterface'
);
$catalogRule = MagentoFrameworkAppObjectManager::getInstance()->create(
'MagentoCatalogRuleModelRuleFactory'
);

$websiteId = $storeManager->getStore()->getWebsiteId();//current Website Id

$resultProductIds = [];
$catalogRuleCollection = $catalogRule->create()->getCollection();
$catalogRuleCollection->addIsActiveFilter(1);//filter for active rules only
foreach ($catalogRuleCollection as $catalogRule)
$productIdsAccToRule = $catalogRule->getMatchingProductIds();
if (in_array("Your currrent productId", $affectedProductIds))
//product has a price rule set for it


return $resultProductIds;



Please don't use objectmanager. it's bad practice! I hope it helps!






share|improve this answer























  • This function will return all product Ids applicable for the product right? i want the rule id

    – Akhil Anand
    Jul 17 at 11:02












  • Yes! and using condition if (in_array("Your currrent productId", $affectedProductIds)) you can match your current product id

    – Chirag Patel
    Jul 17 at 11:03











  • The function i have written in the comment will return all rule ids which is applicable for the product. i want only single rule which is applied currently.

    – Akhil Anand
    Jul 17 at 11:06











  • It is not necessary every product have a singe rule there will be multiple rules will be applied on a single product.

    – Chirag Patel
    Jul 17 at 11:10











  • I have enabled "Discard subsequent rules" to yes in Catalog Price Rule from admin side. So i think only one rule is applied a product at same time right?

    – Akhil Anand
    Jul 17 at 11:14















0














Try with below way!



public function getCatalogPriceRuleProductIds()

$storeManager = MagentoFrameworkAppObjectManager::getInstance()->create(
'MagentoStoreModelStoreManagerInterface'
);
$catalogRule = MagentoFrameworkAppObjectManager::getInstance()->create(
'MagentoCatalogRuleModelRuleFactory'
);

$websiteId = $storeManager->getStore()->getWebsiteId();//current Website Id

$resultProductIds = [];
$catalogRuleCollection = $catalogRule->create()->getCollection();
$catalogRuleCollection->addIsActiveFilter(1);//filter for active rules only
foreach ($catalogRuleCollection as $catalogRule)
$productIdsAccToRule = $catalogRule->getMatchingProductIds();
if (in_array("Your currrent productId", $affectedProductIds))
//product has a price rule set for it


return $resultProductIds;



Please don't use objectmanager. it's bad practice! I hope it helps!






share|improve this answer























  • This function will return all product Ids applicable for the product right? i want the rule id

    – Akhil Anand
    Jul 17 at 11:02












  • Yes! and using condition if (in_array("Your currrent productId", $affectedProductIds)) you can match your current product id

    – Chirag Patel
    Jul 17 at 11:03











  • The function i have written in the comment will return all rule ids which is applicable for the product. i want only single rule which is applied currently.

    – Akhil Anand
    Jul 17 at 11:06











  • It is not necessary every product have a singe rule there will be multiple rules will be applied on a single product.

    – Chirag Patel
    Jul 17 at 11:10











  • I have enabled "Discard subsequent rules" to yes in Catalog Price Rule from admin side. So i think only one rule is applied a product at same time right?

    – Akhil Anand
    Jul 17 at 11:14













0












0








0







Try with below way!



public function getCatalogPriceRuleProductIds()

$storeManager = MagentoFrameworkAppObjectManager::getInstance()->create(
'MagentoStoreModelStoreManagerInterface'
);
$catalogRule = MagentoFrameworkAppObjectManager::getInstance()->create(
'MagentoCatalogRuleModelRuleFactory'
);

$websiteId = $storeManager->getStore()->getWebsiteId();//current Website Id

$resultProductIds = [];
$catalogRuleCollection = $catalogRule->create()->getCollection();
$catalogRuleCollection->addIsActiveFilter(1);//filter for active rules only
foreach ($catalogRuleCollection as $catalogRule)
$productIdsAccToRule = $catalogRule->getMatchingProductIds();
if (in_array("Your currrent productId", $affectedProductIds))
//product has a price rule set for it


return $resultProductIds;



Please don't use objectmanager. it's bad practice! I hope it helps!






share|improve this answer













Try with below way!



public function getCatalogPriceRuleProductIds()

$storeManager = MagentoFrameworkAppObjectManager::getInstance()->create(
'MagentoStoreModelStoreManagerInterface'
);
$catalogRule = MagentoFrameworkAppObjectManager::getInstance()->create(
'MagentoCatalogRuleModelRuleFactory'
);

$websiteId = $storeManager->getStore()->getWebsiteId();//current Website Id

$resultProductIds = [];
$catalogRuleCollection = $catalogRule->create()->getCollection();
$catalogRuleCollection->addIsActiveFilter(1);//filter for active rules only
foreach ($catalogRuleCollection as $catalogRule)
$productIdsAccToRule = $catalogRule->getMatchingProductIds();
if (in_array("Your currrent productId", $affectedProductIds))
//product has a price rule set for it


return $resultProductIds;



Please don't use objectmanager. it's bad practice! I hope it helps!







share|improve this answer












share|improve this answer



share|improve this answer










answered Jul 17 at 10:53









Chirag PatelChirag Patel

3,7527 silver badges28 bronze badges




3,7527 silver badges28 bronze badges












  • This function will return all product Ids applicable for the product right? i want the rule id

    – Akhil Anand
    Jul 17 at 11:02












  • Yes! and using condition if (in_array("Your currrent productId", $affectedProductIds)) you can match your current product id

    – Chirag Patel
    Jul 17 at 11:03











  • The function i have written in the comment will return all rule ids which is applicable for the product. i want only single rule which is applied currently.

    – Akhil Anand
    Jul 17 at 11:06











  • It is not necessary every product have a singe rule there will be multiple rules will be applied on a single product.

    – Chirag Patel
    Jul 17 at 11:10











  • I have enabled "Discard subsequent rules" to yes in Catalog Price Rule from admin side. So i think only one rule is applied a product at same time right?

    – Akhil Anand
    Jul 17 at 11:14

















  • This function will return all product Ids applicable for the product right? i want the rule id

    – Akhil Anand
    Jul 17 at 11:02












  • Yes! and using condition if (in_array("Your currrent productId", $affectedProductIds)) you can match your current product id

    – Chirag Patel
    Jul 17 at 11:03











  • The function i have written in the comment will return all rule ids which is applicable for the product. i want only single rule which is applied currently.

    – Akhil Anand
    Jul 17 at 11:06











  • It is not necessary every product have a singe rule there will be multiple rules will be applied on a single product.

    – Chirag Patel
    Jul 17 at 11:10











  • I have enabled "Discard subsequent rules" to yes in Catalog Price Rule from admin side. So i think only one rule is applied a product at same time right?

    – Akhil Anand
    Jul 17 at 11:14
















This function will return all product Ids applicable for the product right? i want the rule id

– Akhil Anand
Jul 17 at 11:02






This function will return all product Ids applicable for the product right? i want the rule id

– Akhil Anand
Jul 17 at 11:02














Yes! and using condition if (in_array("Your currrent productId", $affectedProductIds)) you can match your current product id

– Chirag Patel
Jul 17 at 11:03





Yes! and using condition if (in_array("Your currrent productId", $affectedProductIds)) you can match your current product id

– Chirag Patel
Jul 17 at 11:03













The function i have written in the comment will return all rule ids which is applicable for the product. i want only single rule which is applied currently.

– Akhil Anand
Jul 17 at 11:06





The function i have written in the comment will return all rule ids which is applicable for the product. i want only single rule which is applied currently.

– Akhil Anand
Jul 17 at 11:06













It is not necessary every product have a singe rule there will be multiple rules will be applied on a single product.

– Chirag Patel
Jul 17 at 11:10





It is not necessary every product have a singe rule there will be multiple rules will be applied on a single product.

– Chirag Patel
Jul 17 at 11:10













I have enabled "Discard subsequent rules" to yes in Catalog Price Rule from admin side. So i think only one rule is applied a product at same time right?

– Akhil Anand
Jul 17 at 11:14





I have enabled "Discard subsequent rules" to yes in Catalog Price Rule from admin side. So i think only one rule is applied a product at same time right?

– Akhil Anand
Jul 17 at 11:14













0














Try getting rules from the resourceModel instead, I have used objectmanager try to use it as dependency,



public function get($product) 
$priceRules = null;
$price = $product->getPriceInfo()->getPrice('regular_price')->getAmount()->getValue();
$storeId = $product->getStoreId();
$dateTs = $this->_localeDate->scopeTimeStamp($storeId);
$websiteId = $this->_storeManager->getStore($storeId)->getWebsiteId();

if ($product->hasCustomerGroupId())
$customerGroupId = $product->getCustomerGroupId();
else
$customerGroupId = $this->_customerSession->getCustomerGroupId();


$resource = $this->_objectManager->create('MagentoCatalogRuleModelResourceModelRule');

$rules = $resource->getRulesFromProduct($dateTs, $websiteId, $customerGroupId, $product->getId());

print_r( $rules);



Let me know if you have any queries






share|improve this answer

























  • In this function it will return array of rules. Not a single one.

    – Akhil Anand
    Jul 17 at 12:40











  • share the result ..

    – aravind
    Jul 17 at 12:43















0














Try getting rules from the resourceModel instead, I have used objectmanager try to use it as dependency,



public function get($product) 
$priceRules = null;
$price = $product->getPriceInfo()->getPrice('regular_price')->getAmount()->getValue();
$storeId = $product->getStoreId();
$dateTs = $this->_localeDate->scopeTimeStamp($storeId);
$websiteId = $this->_storeManager->getStore($storeId)->getWebsiteId();

if ($product->hasCustomerGroupId())
$customerGroupId = $product->getCustomerGroupId();
else
$customerGroupId = $this->_customerSession->getCustomerGroupId();


$resource = $this->_objectManager->create('MagentoCatalogRuleModelResourceModelRule');

$rules = $resource->getRulesFromProduct($dateTs, $websiteId, $customerGroupId, $product->getId());

print_r( $rules);



Let me know if you have any queries






share|improve this answer

























  • In this function it will return array of rules. Not a single one.

    – Akhil Anand
    Jul 17 at 12:40











  • share the result ..

    – aravind
    Jul 17 at 12:43













0












0








0







Try getting rules from the resourceModel instead, I have used objectmanager try to use it as dependency,



public function get($product) 
$priceRules = null;
$price = $product->getPriceInfo()->getPrice('regular_price')->getAmount()->getValue();
$storeId = $product->getStoreId();
$dateTs = $this->_localeDate->scopeTimeStamp($storeId);
$websiteId = $this->_storeManager->getStore($storeId)->getWebsiteId();

if ($product->hasCustomerGroupId())
$customerGroupId = $product->getCustomerGroupId();
else
$customerGroupId = $this->_customerSession->getCustomerGroupId();


$resource = $this->_objectManager->create('MagentoCatalogRuleModelResourceModelRule');

$rules = $resource->getRulesFromProduct($dateTs, $websiteId, $customerGroupId, $product->getId());

print_r( $rules);



Let me know if you have any queries






share|improve this answer















Try getting rules from the resourceModel instead, I have used objectmanager try to use it as dependency,



public function get($product) 
$priceRules = null;
$price = $product->getPriceInfo()->getPrice('regular_price')->getAmount()->getValue();
$storeId = $product->getStoreId();
$dateTs = $this->_localeDate->scopeTimeStamp($storeId);
$websiteId = $this->_storeManager->getStore($storeId)->getWebsiteId();

if ($product->hasCustomerGroupId())
$customerGroupId = $product->getCustomerGroupId();
else
$customerGroupId = $this->_customerSession->getCustomerGroupId();


$resource = $this->_objectManager->create('MagentoCatalogRuleModelResourceModelRule');

$rules = $resource->getRulesFromProduct($dateTs, $websiteId, $customerGroupId, $product->getId());

print_r( $rules);



Let me know if you have any queries







share|improve this answer














share|improve this answer



share|improve this answer








edited Jul 17 at 12:18

























answered Jul 17 at 12:13









aravindaravind

6121 silver badge14 bronze badges




6121 silver badge14 bronze badges












  • In this function it will return array of rules. Not a single one.

    – Akhil Anand
    Jul 17 at 12:40











  • share the result ..

    – aravind
    Jul 17 at 12:43

















  • In this function it will return array of rules. Not a single one.

    – Akhil Anand
    Jul 17 at 12:40











  • share the result ..

    – aravind
    Jul 17 at 12:43
















In this function it will return array of rules. Not a single one.

– Akhil Anand
Jul 17 at 12:40





In this function it will return array of rules. Not a single one.

– Akhil Anand
Jul 17 at 12:40













share the result ..

– aravind
Jul 17 at 12:43





share the result ..

– aravind
Jul 17 at 12:43

















draft saved

draft discarded
















































Thanks for contributing an answer to Magento Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f282356%2fget-product-applied-price-rule-by-product-id-in-magento-2%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Grendel Contents Story Scholarship Depictions Notes References Navigation menu10.1093/notesj/gjn112Berserkeree

Area configuration aggregation error after install Porto themeMagento 2.1 CE Installed but front/backend not loading/workingCSS not loading on page within Magento 2 pageCannot install module in Magento 2no commands defined in the “setup” namespace. in Magento2Magento 2: Static files are present but shows 404Why do i have to always run the commands to clean cache in Magento 2.1.8?Failure reason: 'Unable to unserialize value.'Error 500 after magento migrationIn production mode the site does not loadMagento 2 : Error 500 after installing

Middle Expansion Olielle Resaix Definition: Uttering songs of triumph shouting with joy triumphant exulting Sejunction Journal 붙다 달 고급 품목 외출 The stretch trades the screeching tin. Definition: The act of speaking with a drawl a drawl Cough Sand Definition: An uproar a quarrel a noisy outbreak Shake Iron Publicize Horse House Baby 사과 Resaix Flaggy Jelly Temporary Unequaled Puppet A drop in the bucket Shrew 성격 회원 성질 미팅 The burn frames the tacky quality. Materialistic The smoke reduces the way. Yammoe Nondescript Cheek 얼굴 배 약하다 날리다 타다 The illegal country shows the iron. Help Rule Drearien Smoke Teaching Meaty Wasp Abraham Lincoln Jaws 진심 수리하다 Size Cork Idea Convert Think Lark John Lennon 거울 청소 군 추천하다 아이스크림