get product list according to a catalog price rule
suppose i have created a price rule that all product which have price more than Rs.1000 they will get 30% off. Now what i should do to make a list of those product which are under that catalog price开发者_如何转开发 rule
Quite odd that there is no simple functionality for that indeed. What I can think of is the following to get a list of all ids of the selected products:
This works only when the rules have been applied already.
- Find out the id of the rule. You can read this from the url bar when you're in the rule edit screen.
- Run the following query against the database:
SELECT DISTINCT product_id FROM catalogrule_product WHERE rule_id=<id>;
where you replace <id> by the id found in step 1.
There might be something easier though..
I have been looking for the same thing, found the following piece of code you can paste in your list.phtml and it shows you the products under a particular catalog price rule:
$rule = Mage::getModel('catalogrule/rule')->load(12); /* catalog price rule id */
$rule->setWebsiteIds("1");
$productIdsArray = $rule->getMatchingProductIds();
$productsCollection = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect("*")
->addAttributeToFilter('visibility', 4)
->addAttributeToFilter("entity_id", array("in", $productIdsArray));
Be sure to change the price rule id and $productsCollection in the rest of the code in list.phtml
Should you be able to pull all the rules please let me know, been looking for a solution for a couple of days now.
精彩评论