Mage_CatalogRule_Model_Rule Class Reference

Inheritance diagram for Mage_CatalogRule_Model_Rule:

Mage_Rule_Model_Rule Mage_Core_Model_Abstract Varien_Object

List of all members.

Public Member Functions

 getConditionsInstance ()
 getActionsInstance ()
 getNow ()
 setNow ($now)
 toString ($format='')
 toArray (array $arrAttributes=array())
 getResourceCollection ()
 getMatchingProductIds ()
 callbackValidateProduct ($args)
 applyToProduct ($product, $websiteIds=null)
 getCustomerGroupIds ()

Protected Member Functions

 _construct ()
 _afterSave ()

Protected Attributes

 $_productIds = array()
 $_now


Detailed Description

Definition at line 28 of file Rule.php.


Member Function Documentation

_afterSave (  )  [protected]

Processing object after save data

Returns:
Mage_Core_Model_Abstract

Reimplemented from Mage_Core_Model_Abstract.

Definition at line 131 of file Rule.php.

00132     {
00133         $this->_getResource()->updateRuleProductData($this);
00134         parent::_afterSave();
00135     }

_construct (  )  [protected]

Enter description here...

Reimplemented from Mage_Rule_Model_Rule.

Definition at line 34 of file Rule.php.

00035     {
00036         parent::_construct();
00037         $this->_init('catalogrule/rule');
00038         $this->setIdFieldName('rule_id');
00039     }

applyToProduct ( product,
websiteIds = null 
)

Definition at line 178 of file Rule.php.

00179     {
00180         if (is_numeric($product)) {
00181             $product = Mage::getModel('catalog/product')->load($product);
00182         }
00183         if (is_null($websiteIds)) {
00184             $websiteIds = explode(',', $this->getWebsiteIds());
00185         }
00186         $this->getResource()->applyToProduct($this, $product, $websiteIds);
00187     }

callbackValidateProduct ( args  ) 

Definition at line 162 of file Rule.php.

00163     {
00164         $product = $args['product']->setData($args['row']);
00165         if (!empty($args['attributes']['category_ids'])) {
00166             $categoryCollection = $product->getCategoryCollection()->load();
00167             $categories = array();
00168             foreach ($categoryCollection as $category) {
00169                 $categories[] = $category->getId();
00170             }
00171             $product->setCategoryIds($categories);
00172         }
00173         if ($this->getConditions()->validate($product)) {
00174             $this->_productIds[] = $product->getId();
00175         }
00176     }

getActionsInstance (  ) 

Reimplemented from Mage_Rule_Model_Rule.

Definition at line 46 of file Rule.php.

00047     {
00048         return Mage::getModel('catalogrule/rule_action_collection');
00049     }

getConditionsInstance (  ) 

Reimplemented from Mage_Rule_Model_Rule.

Definition at line 41 of file Rule.php.

00042     {
00043         return Mage::getModel('catalogrule/rule_condition_combine');
00044     }

getCustomerGroupIds (  ) 

Definition at line 189 of file Rule.php.

00190     {
00191         $ids = $this->getData('customer_group_ids');
00192         if (($ids && !$this->getCustomerGroupChecked()) || is_string($ids)) {
00193             if (is_string($ids)) {
00194                 $ids = explode(',', $ids);
00195             }
00196 
00197             $groupIds = Mage::getModel('customer/group')->getCollection()->getAllIds();
00198             $ids = array_intersect($ids, $groupIds);
00199             $this->setData('customer_group_ids', $ids);
00200             $this->setCustomerGroupChecked(true);
00201         }
00202         return $ids;
00203     }

getMatchingProductIds (  ) 

Definition at line 137 of file Rule.php.

00138     {
00139         if (empty($this->_productIds)) {
00140             $productCollection = Mage::getResourceModel('catalog/product_collection');
00141             $websiteIds = explode(',', $this->getWebsiteIds());
00142             if (!empty($websiteIds)) {
00143                 $productCollection->addWebsiteFilter($websiteIds);
00144             }
00145 
00146             $this->setCollectedAttributes(array());
00147             $this->getConditions()->collectValidatedAttributes($productCollection);
00148 
00149             $this->_productIds = array();
00150             Mage::getSingleton('core/resource_iterator')->walk(
00151                 $productCollection->getSelect(),
00152                 array(array($this, 'callbackValidateProduct')),
00153                 array(
00154                     'attributes'=>$this->getCollectedAttributes(),
00155                     'product'=>Mage::getModel('catalog/product'),
00156                 )
00157             );
00158         }
00159         return $this->_productIds;
00160     }

getNow (  ) 

Definition at line 51 of file Rule.php.

00052     {
00053         if (!$this->_now) {
00054             return now();
00055         }
00056         return $this->_now;
00057     }

getResourceCollection (  ) 

Get collection instance

Returns:
object

Reimplemented from Mage_Core_Model_Abstract.

Definition at line 126 of file Rule.php.

00127     {
00128         return Mage::getResourceModel('catalogrule/rule_collection');
00129     }

setNow ( now  ) 

Definition at line 59 of file Rule.php.

00060     {
00061         $this->_now = $now;
00062     }

toArray ( array arrAttributes = array()  ) 

Returns rule as an array for admin interface

Output example: array( 'name'=>'Example rule', 'conditions'=>{condition_combine.toArray} 'actions'=>{action_collection.toArray} )

Returns:
array

Reimplemented from Varien_Object.

Definition at line 89 of file Rule.php.

00090     {
00091         $out = parent::toArray($arrAttributes);
00092         $out['customer_registered'] = $this->getCustomerRegistered();
00093         $out['customer_new_buyer'] = $this->getCustomerNewBuyer();
00094 
00095         return $out;
00096     }

toString ( format = ''  ) 

Public wrapper for __toString

Will use $format as an template and substitute {{key}} for attributes

Parameters:
string $format
Returns:
string

Reimplemented from Varien_Object.

Definition at line 64 of file Rule.php.

00065     {
00066         $str = Mage::helper('catalogrule')->__("Name: %s", $this->getName()) ."\n"
00067              . Mage::helper('catalogrule')->__("Start at: %s", $this->getStartAt()) ."\n"
00068              . Mage::helper('catalogrule')->__("Expire at: %s", $this->getExpireAt()) ."\n"
00069              . Mage::helper('catalogrule')->__("Customer registered: %s", $this->getCustomerRegistered()) ."\n"
00070              . Mage::helper('catalogrule')->__("Customer is new buyer: %s", $this->getCustomerNewBuyer()) ."\n"
00071              . Mage::helper('catalogrule')->__("Description: %s", $this->getDescription()) ."\n\n"
00072              . $this->getConditions()->toStringRecursive() ."\n\n"
00073              . $this->getActions()->toStringRecursive() ."\n\n";
00074         return $str;
00075     }


Member Data Documentation

$_now [protected]

Definition at line 32 of file Rule.php.

$_productIds = array() [protected]

Definition at line 30 of file Rule.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:23:48 2009 for Magento by  doxygen 1.5.8