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;
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
add a comment |
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
magento.stackexchange.com/questions/111153/…
– ProxiBlue
Nov 23 '16 at 6:17
add a comment |
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
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
magento-1 shopping-cart-price-rules discount
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
add a comment |
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
add a comment |
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
);
);
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%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
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%2f147041%2fmagento-validate-product-against-shopping-cart-rule%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
magento.stackexchange.com/questions/111153/…
– ProxiBlue
Nov 23 '16 at 6:17