I need a way to retrieve product IDs associated with a Catalog Price Rule promotion (ex. 50% the price of all items in the BICYCLES category). I'd like to do this without having to iterate through the entire product database.
I know there is a function called getRuleProductIds($ruleID)
, which should return an array of product IDs by rule ID, but I have no idea where to use it, which collection to associate it with, etc.
I have the following code in a products_in_promotion.phtml
template:
<?php
$rules = Mage::getModel('catalogrule/rule');
$collection = $rules->getCollection();
$sale_items = $collection->getRuleProductIds(1); # ??????? this throws an error
?>
$collection
properly stores an array of all the Catalog Price rules, but that's as close as I can get. No product list is in sight.
Any ideas what I'm doing wrong here?
You don't have to get it as a collection. Just load the rule that you want and use getMatchingProductIds
as found in Mage_CatalogRule_Model_Rule
(aka catalogrule/rule
).
$catalog_rule = Mage::getModel('catalogrule/rule')->load(1); // Rule ID
$skus = $catalog_rule->getMatchingProductIds();
var_dump($skus);
hth
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With