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;
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
|
show 2 more comments
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
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
|
show 2 more comments
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
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
magento2 magento2.2.3 catalog-price-rules catalog-rules
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
|
show 2 more comments
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
|
show 2 more comments
2 Answers
2
active
oldest
votes
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!
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 conditionif (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
|
show 3 more comments
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
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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!
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 conditionif (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
|
show 3 more comments
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!
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 conditionif (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
|
show 3 more comments
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!
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!
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 conditionif (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
|
show 3 more comments
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 conditionif (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
|
show 3 more comments
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
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
add a comment |
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
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
add a comment |
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
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
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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