Manual integration of earning points prediction in Catalog listing and Product page (v1.12.0)

Starting from MageRewards version 1.12.0 Earning Prediction are based on Rewards Shopping Cart Earning Rules.

Here is the code snippet you can use to perform manual integration of earning points prediction in Catalog listing page and Product page.

/**
 * !!! Rewards Points Earnings Predictions requires a valid `product` instance of Mage_Catalog_Model_Product with valid id
 */
/* Example 1 */
$product = Mage::getModel('catalog/product')->load(10);

/* Example 2 */
$product = Mage::registry('current_product'); /* this implementation is only available in frontend catalog product view pages. all other areas will fail */

/* Example 3 */
$product = $this->getProduct(); /* this implementation available in template files were such method is available and returns a valid product instance (example of template file `app/design/frontend/base/default/template/catalog/product/view.phtml`) */
 
==========================

/**
 * Manual Integration for Rewards Points Earnings Predictions inside template file
 * @note !! requires a valid `$product` instance of Mage_Catalog_Model_Product with valid id
 */
$predictionsBlock = $this->getLayout()->createBlock('rewards/catalog_predictPoints', 'rewards_catalog_predictions');

if ($predictionsBlock) {
    $predictionsBlock->setProduct($product);
    
    echo $predictionsBlock->toHtml();
}

Still need help? Get Help Get Help