setType('rule/condition_combine')
->setAggregator('all')
->setValue(true)
->setConditions(array())
->setActions(array());
$this->loadAggregatorOptions();
if ($options = $this->getAggregatorOptions()) {
foreach ($options as $aggregator=>$dummy) { $this->setAggregator($aggregator); break; }
}
}
/* start aggregator methods */
public function loadAggregatorOptions()
{
$this->setAggregatorOption(array(
'all' => Mage::helper('rule')->__('ALL'),
'any' => Mage::helper('rule')->__('ANY'),
));
return $this;
}
public function getAggregatorSelectOptions()
{
$opt = array();
foreach ($this->getAggregatorOption() as $k=>$v) {
$opt[] = array('value'=>$k, 'label'=>$v);
}
return $opt;
}
public function getAggregatorName()
{
return $this->getAggregatorOption($this->getAggregator());
}
public function getAggregatorElement()
{
if (is_null($this->getAggregator())) {
foreach ($this->getAggregatorOption() as $k=>$v) {
$this->setAggregator($k);
break;
}
}
return $this->getForm()->addField($this->getPrefix().'__'.$this->getId().'__aggregator', 'select', array(
'name'=>'rule['.$this->getPrefix().']['.$this->getId().'][aggregator]',
'values'=>$this->getAggregatorSelectOptions(),
'value'=>$this->getAggregator(),
'value_name'=>$this->getAggregatorName(),
))->setRenderer(Mage::getBlockSingleton('rule/editable'));
}
/* end aggregator methods */
public function loadValueOptions()
{
$this->setValueOption(array(
1 => Mage::helper('rule')->__('TRUE'),
0 => Mage::helper('rule')->__('FALSE'),
));
return $this;
}
public function addCondition($condition)
{
$condition->setRule($this->getRule());
$condition->setObject($this->getObject());
$condition->setPrefix($this->getPrefix());
$conditions = $this->getConditions();
$conditions[] = $condition;
if (!$condition->getId()) {
$condition->setId($this->getId().'--'.sizeof($conditions));
}
$this->setData($this->getPrefix(), $conditions);
return $this;
}
public function getValueElementType()
{
return 'select';
}
/**
* Returns array containing conditions in the collection
*
* Output example:
* array(
* 'type'=>'combine',
* 'operator'=>'ALL',
* 'value'=>'TRUE',
* 'conditions'=>array(
* {condition::asArray},
* {combine::asArray},
* {quote_item_combine::asArray}
* )
* )
*
* @return array
*/
public function asArray(array $arrAttributes = array())
{
$out = parent::asArray();
$out['aggregator'] = $this->getAggregator();
foreach ($this->getConditions() as $condition) {
$out['conditions'][] = $condition->asArray();
}
return $out;
}
public function asXml($containerKey='conditions', $itemKey='condition')
{
$xml = "