Magento : Validate Product against shopping cart rulehow to get shopping cart price rule items in catalog pageShopping cart price ruleShopping Cart Price rule - tieredcart to show coupon or shopping cart rule with taxShopping cart rule: first product 50% off (only first product) - How do I?Shopping Cart Rule to discount N 'paired' itemsShopping Cart Rule and Catalog Price Rule — Stop further Rule Processing not workingShopping Cart Price Rule where the discount given changes according to the shopping cart totalMagento How to add configurable product while placing order programatically?Shopping cart price rule : product price percent discountShopping cart price rule percent discount

QR codes, do people use them?

Why do people prefer metropolitan areas, considering monsters and villains?

Passwordless authentication - how and when to invalidate a login code

What is the meaning of "prairie-dog" in this sentence?

What are the effects of abstaining from eating a certain flavor?

Why do airports remove/realign runways?

Why did RFK loathe LBJ?

Users forgotting to regenerate PDF before sending it

Interpretation of non-significant results as "trends"

Examples of fluid (including air) being used to transmit digital data?

Quotients of a ring of integers

In layman's terms, does the Luckstone just give a passive +1 to all d20 rolls and saves except for death saves?

What do you call a situation where you have choices but no good choice?

Taking my Ph.D. advisor out for dinner after graduation

How many Jimmys can fit?

Are host configurations in the SSH config merged?

Was the 45.9°C temperature in France in June 2019 the highest ever recorded in France?

Can one block with a protection from color creature?

Possibility to correct pitch from digital versions of records with the hole not centered

Chilling juice in copper vessel

What are some bad ways to subvert tropes?

Why is there paternal, for fatherly, fraternal, for brotherly, but no similar word for sons?

How do I talk to my wife about unrealistic expectations?

What was the nature of the known bugs in the Space Shuttle software?



Magento : Validate Product against shopping cart rule


how to get shopping cart price rule items in catalog pageShopping cart price ruleShopping Cart Price rule - tieredcart to show coupon or shopping cart rule with taxShopping cart rule: first product 50% off (only first product) - How do I?Shopping Cart Rule to discount N 'paired' itemsShopping Cart Rule and Catalog Price Rule — Stop further Rule Processing not workingShopping Cart Price Rule where the discount given changes according to the shopping cart totalMagento How to add configurable product while placing order programatically?Shopping cart price rule : product price percent discountShopping cart price rule percent discount






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








6















I have a Shopping cart rule which applies to a particular category with some discount.



I have a situation wherein I want to validate product against this rule whether this rule can be applied to that product or not.



I have tried following code, but it gives me Boolean true all the time.



protected function validate($product) {

$coupon_code = Mage::getSingleton('checkout/session')->getQuote()->getCouponCode();
$oCoupon = Mage::getModel('salesrule/coupon')->load($coupon_code, 'code');
$oRule = Mage::getModel('salesrule/rule')->load($oCoupon->getRuleId());

// Sales Rule Id of the coupon we want to validate
$ruleId = $oCoupon->getRuleId();
//echo "<br />";
// Id of Product we want to validate
$productId = $product->getId();

/** @var Mage_SalesRule_Model_Rule $salesRule */
$salesRule = Mage::getModel('salesrule/rule')->load($ruleId);

/** @var Mage_Catalog_Model_Product $product */
$product = Mage::getModel('catalog/product')->load($productId);


UPDATE 1: Tried with the following code also. But thats returning nothing.



<?php

set_time_limit(3000);
ini_set('memory_limit', '-1');
include_once 'app/Mage.php';
umask(0);
Mage::app();

$product_ids = array(1199, 1200, 1202);
foreach ($product_ids as $productId)

Mage::getSingleton('core/session', array('name' => 'frontend'));

// Get customer session
$session = Mage::getSingleton('customer/session');

// Get cart instance
$cart = Mage::getSingleton('checkout/cart');
$cart->init();
<?php

set_time_limit(3000);
ini_set('memory_limit', '-1');
include_once 'app/Mage.php';
umask(0);
Mage::app();

$product_ids = array(1199, 1200, 1202);
foreach ($product_ids as $productId)

Mage::getSingleton('core/session', array('name' => 'frontend'));

// Get customer session
$session = Mage::getSingleton('customer/session');

// Get cart instance
$cart = Mage::getSingleton('checkout/cart');
$cart->init();

echo $coupon_code = Mage::getSingleton('checkout/session')->getQuote()->getCouponCode();
$oCoupon = Mage::getModel('salesrule/coupon')->load($coupon_code, 'code');
$oRule = Mage::getModel('salesrule/rule')->load($oCoupon->getRuleId());

// Sales Rule Id of the coupon we want to validate
$ruleId = $oCoupon->getRuleId();

/** @var Mage_SalesRule_Model_Rule $salesRule */
$salesRule = Mage::getModel('salesrule/rule')->load($ruleId);

/** @var Mage_Catalog_Model_Product $product */
$product = Mage::getModel('catalog/product')->load($productId);

$item = new Varien_Object();
$item->setProduct($product);
echo $isValid = $salesRule->getConditions()->validate($product);

?>
$item = new Varien_Object();
$item->setProduct($product);

$isValid = $salesRule->getActions()->validate($item);

return $isValid; //Returning true always










share|improve this question
























  • magento.stackexchange.com/questions/111153/…

    – ProxiBlue
    Nov 23 '16 at 6:17

















6















I have a Shopping cart rule which applies to a particular category with some discount.



I have a situation wherein I want to validate product against this rule whether this rule can be applied to that product or not.



I have tried following code, but it gives me Boolean true all the time.



protected function validate($product) {

$coupon_code = Mage::getSingleton('checkout/session')->getQuote()->getCouponCode();
$oCoupon = Mage::getModel('salesrule/coupon')->load($coupon_code, 'code');
$oRule = Mage::getModel('salesrule/rule')->load($oCoupon->getRuleId());

// Sales Rule Id of the coupon we want to validate
$ruleId = $oCoupon->getRuleId();
//echo "<br />";
// Id of Product we want to validate
$productId = $product->getId();

/** @var Mage_SalesRule_Model_Rule $salesRule */
$salesRule = Mage::getModel('salesrule/rule')->load($ruleId);

/** @var Mage_Catalog_Model_Product $product */
$product = Mage::getModel('catalog/product')->load($productId);


UPDATE 1: Tried with the following code also. But thats returning nothing.



<?php

set_time_limit(3000);
ini_set('memory_limit', '-1');
include_once 'app/Mage.php';
umask(0);
Mage::app();

$product_ids = array(1199, 1200, 1202);
foreach ($product_ids as $productId)

Mage::getSingleton('core/session', array('name' => 'frontend'));

// Get customer session
$session = Mage::getSingleton('customer/session');

// Get cart instance
$cart = Mage::getSingleton('checkout/cart');
$cart->init();
<?php

set_time_limit(3000);
ini_set('memory_limit', '-1');
include_once 'app/Mage.php';
umask(0);
Mage::app();

$product_ids = array(1199, 1200, 1202);
foreach ($product_ids as $productId)

Mage::getSingleton('core/session', array('name' => 'frontend'));

// Get customer session
$session = Mage::getSingleton('customer/session');

// Get cart instance
$cart = Mage::getSingleton('checkout/cart');
$cart->init();

echo $coupon_code = Mage::getSingleton('checkout/session')->getQuote()->getCouponCode();
$oCoupon = Mage::getModel('salesrule/coupon')->load($coupon_code, 'code');
$oRule = Mage::getModel('salesrule/rule')->load($oCoupon->getRuleId());

// Sales Rule Id of the coupon we want to validate
$ruleId = $oCoupon->getRuleId();

/** @var Mage_SalesRule_Model_Rule $salesRule */
$salesRule = Mage::getModel('salesrule/rule')->load($ruleId);

/** @var Mage_Catalog_Model_Product $product */
$product = Mage::getModel('catalog/product')->load($productId);

$item = new Varien_Object();
$item->setProduct($product);
echo $isValid = $salesRule->getConditions()->validate($product);

?>
$item = new Varien_Object();
$item->setProduct($product);

$isValid = $salesRule->getActions()->validate($item);

return $isValid; //Returning true always










share|improve this question
























  • magento.stackexchange.com/questions/111153/…

    – ProxiBlue
    Nov 23 '16 at 6:17













6












6








6








I have a Shopping cart rule which applies to a particular category with some discount.



I have a situation wherein I want to validate product against this rule whether this rule can be applied to that product or not.



I have tried following code, but it gives me Boolean true all the time.



protected function validate($product) {

$coupon_code = Mage::getSingleton('checkout/session')->getQuote()->getCouponCode();
$oCoupon = Mage::getModel('salesrule/coupon')->load($coupon_code, 'code');
$oRule = Mage::getModel('salesrule/rule')->load($oCoupon->getRuleId());

// Sales Rule Id of the coupon we want to validate
$ruleId = $oCoupon->getRuleId();
//echo "<br />";
// Id of Product we want to validate
$productId = $product->getId();

/** @var Mage_SalesRule_Model_Rule $salesRule */
$salesRule = Mage::getModel('salesrule/rule')->load($ruleId);

/** @var Mage_Catalog_Model_Product $product */
$product = Mage::getModel('catalog/product')->load($productId);


UPDATE 1: Tried with the following code also. But thats returning nothing.



<?php

set_time_limit(3000);
ini_set('memory_limit', '-1');
include_once 'app/Mage.php';
umask(0);
Mage::app();

$product_ids = array(1199, 1200, 1202);
foreach ($product_ids as $productId)

Mage::getSingleton('core/session', array('name' => 'frontend'));

// Get customer session
$session = Mage::getSingleton('customer/session');

// Get cart instance
$cart = Mage::getSingleton('checkout/cart');
$cart->init();
<?php

set_time_limit(3000);
ini_set('memory_limit', '-1');
include_once 'app/Mage.php';
umask(0);
Mage::app();

$product_ids = array(1199, 1200, 1202);
foreach ($product_ids as $productId)

Mage::getSingleton('core/session', array('name' => 'frontend'));

// Get customer session
$session = Mage::getSingleton('customer/session');

// Get cart instance
$cart = Mage::getSingleton('checkout/cart');
$cart->init();

echo $coupon_code = Mage::getSingleton('checkout/session')->getQuote()->getCouponCode();
$oCoupon = Mage::getModel('salesrule/coupon')->load($coupon_code, 'code');
$oRule = Mage::getModel('salesrule/rule')->load($oCoupon->getRuleId());

// Sales Rule Id of the coupon we want to validate
$ruleId = $oCoupon->getRuleId();

/** @var Mage_SalesRule_Model_Rule $salesRule */
$salesRule = Mage::getModel('salesrule/rule')->load($ruleId);

/** @var Mage_Catalog_Model_Product $product */
$product = Mage::getModel('catalog/product')->load($productId);

$item = new Varien_Object();
$item->setProduct($product);
echo $isValid = $salesRule->getConditions()->validate($product);

?>
$item = new Varien_Object();
$item->setProduct($product);

$isValid = $salesRule->getActions()->validate($item);

return $isValid; //Returning true always










share|improve this question
















I have a Shopping cart rule which applies to a particular category with some discount.



I have a situation wherein I want to validate product against this rule whether this rule can be applied to that product or not.



I have tried following code, but it gives me Boolean true all the time.



protected function validate($product) {

$coupon_code = Mage::getSingleton('checkout/session')->getQuote()->getCouponCode();
$oCoupon = Mage::getModel('salesrule/coupon')->load($coupon_code, 'code');
$oRule = Mage::getModel('salesrule/rule')->load($oCoupon->getRuleId());

// Sales Rule Id of the coupon we want to validate
$ruleId = $oCoupon->getRuleId();
//echo "<br />";
// Id of Product we want to validate
$productId = $product->getId();

/** @var Mage_SalesRule_Model_Rule $salesRule */
$salesRule = Mage::getModel('salesrule/rule')->load($ruleId);

/** @var Mage_Catalog_Model_Product $product */
$product = Mage::getModel('catalog/product')->load($productId);


UPDATE 1: Tried with the following code also. But thats returning nothing.



<?php

set_time_limit(3000);
ini_set('memory_limit', '-1');
include_once 'app/Mage.php';
umask(0);
Mage::app();

$product_ids = array(1199, 1200, 1202);
foreach ($product_ids as $productId)

Mage::getSingleton('core/session', array('name' => 'frontend'));

// Get customer session
$session = Mage::getSingleton('customer/session');

// Get cart instance
$cart = Mage::getSingleton('checkout/cart');
$cart->init();
<?php

set_time_limit(3000);
ini_set('memory_limit', '-1');
include_once 'app/Mage.php';
umask(0);
Mage::app();

$product_ids = array(1199, 1200, 1202);
foreach ($product_ids as $productId)

Mage::getSingleton('core/session', array('name' => 'frontend'));

// Get customer session
$session = Mage::getSingleton('customer/session');

// Get cart instance
$cart = Mage::getSingleton('checkout/cart');
$cart->init();

echo $coupon_code = Mage::getSingleton('checkout/session')->getQuote()->getCouponCode();
$oCoupon = Mage::getModel('salesrule/coupon')->load($coupon_code, 'code');
$oRule = Mage::getModel('salesrule/rule')->load($oCoupon->getRuleId());

// Sales Rule Id of the coupon we want to validate
$ruleId = $oCoupon->getRuleId();

/** @var Mage_SalesRule_Model_Rule $salesRule */
$salesRule = Mage::getModel('salesrule/rule')->load($ruleId);

/** @var Mage_Catalog_Model_Product $product */
$product = Mage::getModel('catalog/product')->load($productId);

$item = new Varien_Object();
$item->setProduct($product);
echo $isValid = $salesRule->getConditions()->validate($product);

?>
$item = new Varien_Object();
$item->setProduct($product);

$isValid = $salesRule->getActions()->validate($item);

return $isValid; //Returning true always







magento-1 shopping-cart-price-rules discount






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jun 28 at 6:31









Sarfaraj Sipai

5211 gold badge7 silver badges20 bronze badges




5211 gold badge7 silver badges20 bronze badges










asked Nov 23 '16 at 5:46









Magento LearnerMagento Learner

4497 silver badges32 bronze badges




4497 silver badges32 bronze badges












  • magento.stackexchange.com/questions/111153/…

    – ProxiBlue
    Nov 23 '16 at 6:17

















  • magento.stackexchange.com/questions/111153/…

    – ProxiBlue
    Nov 23 '16 at 6:17
















magento.stackexchange.com/questions/111153/…

– ProxiBlue
Nov 23 '16 at 6:17





magento.stackexchange.com/questions/111153/…

– ProxiBlue
Nov 23 '16 at 6:17










0






active

oldest

votes














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%2f147041%2fmagento-validate-product-against-shopping-cart-rule%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















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%2f147041%2fmagento-validate-product-against-shopping-cart-rule%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 거울 청소 군 추천하다 아이스크림