Retrieve all product IDs associated with directory price rules in Magento

I need a way to retrieve the product ID associated with a catalog price rule promotion (for example, 50% of the price of all items in the BICYCLES category). I want to do this without having to traverse The entire product database.

I know that there is a function called getRuleProductIds($ruleID), which should return an array of product IDs by rule ID, but I don’t know where to use it and which collection Related to it and so on.

I have the following code in the products_in_promotion.phtml template:

 $rules = Mage ::getModel('catalogrule/rule');
$collection = $rules->getCollection();
$sale_items = $collection->getRuleProductIds(1); # ??????? this throws an error
?>

$collection correctly stores an array of all Catalog Price rules, but this rule is as close as possible. There is no product list.

I am here Any thoughts on what I did wrong?

You don’t have to use it as a collection. Just load the rules you want and use Mage_CatalogRule_Model_Rule( (Aka catalogrule/rule) getMatchingProductIds.

$catalog_rule = Mage::getModel('catalogrule/rule')->load(1); // Rule ID
$skus = $catalog_rule->getMatchingProductIds();

var_dump($skus);

Heart to Heart

< /p>

I need a way to retrieve product IDs associated with catalog price rule promotions (for example, 50% of the price of all items in the BICYCLES category). I want to do this without having to traverse the entire product database. < p>

I know there is a function called getRuleProductIds($ruleID), which should return an array of product IDs by rule ID, but I don’t know where to use it, which collection is associated with it, etc. Etc.

I have the following code in the products_in_promotion.phtml template:

 $rules = Mage::getModel(' catalogrule/rule');
$collection = $rules->getCollection();
$sale_items = $collection->getRuleProductIds(1); # ??????? this throws an error< br />?>

$collection correctly stores an array of all Catalog Price rules, but this rule is as close as possible. There is no product list.

What thoughts am I doing wrong here? ?

You don’t have to use it as a collection. Just load the rules you want and use getMatchingProductIds 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);

Heart to Heart

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 2760 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.