public function validate(Varien_Object $object)
 {
     // for optimization if we no conditions
     if (!$this->getConditions()) {
         return true;
     }
     $origProduct = null;
     if ($object->getHasChildren() && $object->getProductType() == 'configurable') {
         //remember original product
         $origProduct = $object->getProduct();
         $origSku = $object->getSku();
         foreach ($object->getChildren() as $child) {
             // only one itereation.
             $categoryIds = array_merge($child->getProduct()->getCategoryIds(), $origProduct->getCategoryIds());
             $categoryIds = array_unique($categoryIds);
             $object->setProduct($child->getProduct());
             $object->setSku($child->getSku());
             $object->getProduct()->setCategoryIds($categoryIds);
         }
     }
     $result = @Mage_Rule_Model_Condition_Combine::validate($object);
     if ($origProduct) {
         // restore original product
         $object->setProduct($origProduct);
         $object->setSku($origSku);
     }
     return $result;
 }
 /**
  * calculate earning for quote/order item
  * 
  * @param Varien_Object $item
  * @param int $customerGroupId
  * @param int $websiteId
  * @param string $date
  * @return int
  */
 public function getCatalogItemEarningPoints($item, $customerGroupId = null, $websiteId = null, $date = null)
 {
     $product = Mage::getModel('catalog/product')->load($item->getProductId());
     //webpos
     $customerId = Mage::getSingleton('checkout/session')->getData('webpos_customerid');
     if ($customerId) {
         $customerGroupId = Mage::getModel('customer/customer')->load($customerId)->getGroupId();
     } else {
         $customerGroupId = Mage_Customer_Model_Group::NOT_LOGGED_IN_ID;
     }
     if (is_null($websiteId)) {
         $websiteId = Mage::app()->getStore($item->getStoreId())->getWebsiteId();
     }
     if (is_null($date)) {
         $date = date('Y-m-d', strtotime($item->getCreatedAt()));
     }
     $cacheKey = "catalog_item_earning:{$item->getId()}:{$customerGroupId}:{$websiteId}";
     if ($this->hasCache($cacheKey)) {
         return $this->getCache($cacheKey);
     }
     $points = 0;
     $collectionKey = "catalog_earning_collection:{$customerGroupId}:{$websiteId}";
     if (!$this->hasCache($collectionKey)) {
         $rules = Mage::getResourceModel('rewardpointsrule/earning_catalog_collection')->setAvailableFilter($customerGroupId, $websiteId, $date);
         foreach ($rules as $rule) {
             $rule->afterLoad();
         }
         $this->saveCache($collectionKey, $rules);
     } else {
         $rules = $this->getCache($collectionKey);
     }
     if ($item->getHasChildren() && $item->isChildrenCalculated()) {
         $price = 0;
         $profit = 0;
         foreach ($item->getChildren() as $child) {
             $price += $child->getQty() * $child->getBasePrice();
             $profit += $child->getQty() * ($child->getBasePrice() - $child->getBaseCost());
         }
     } else {
         $price = $item->getBasePrice();
         if (!$price && $item->getPrice()) {
             $price = $item->getPrice() / Mage::app()->getStore($item->getStoreId())->convertPrice(1);
         }
         $profit = $price - $item->getBaseCost();
     }
     foreach ($rules as $rule) {
         if ($rule->validate($product)) {
             $points += $this->calcCatalogPoint($rule->getSimpleAction(), $rule->getPointsEarned(), $price, $profit, $rule->getMoneyStep(), $rule->getMaxPointsEarned());
             if ($rule->getStopRulesProcessing()) {
                 break;
             }
         }
     }
     $this->saveCache($cacheKey, $points * $item->getQty());
     return $this->getCache($cacheKey);
 }