_priceObj = new App_ECommerce_ShippingPrice_Admin_Obj(); return $this; } protected function _initElements() { parent::_initElements(); $this->addElement( 'text', 'startQuantity', array( 'label' => 'Start Quantity', 'validators' => array(array('Int', false)), 'required' => true ) ); $this->addElement( 'text', 'endQuantity', array( 'label' => 'End Quantity', 'validators' => array(array('Int', false)), 'required' => true ) ); $this->addElement( 'numeric', 'price', array( 'label' => 'Price', 'required' => true ) ); /** @var $numeric Qs_Form_Decorator_Numeric */ $numeric = $this->getElement('price')->getDecorator('Numeric'); $numeric->setHtmlBeforeElement('$'); $this->addFormRule(array($this, 'validateForm')); return $this; } public function validateForm(array $data) { $errors = array(); $previousPrice = $this->_priceObj->getNeighborPrice($this->_getData('id')); if ($data['startQuantity'] != '') { if ($data['startQuantity'] < static::MIN_QUANTITY) { $errors['startQuantity'] = str_replace('%value%', static::MIN_QUANTITY, $this->_wrongQuantity); } else if ($previousPrice && $data['startQuantity'] < $previousPrice['startQuantity'] + 1) { $errors['startQuantity'] = str_replace( '%value%', $previousPrice['startQuantity'], $this->_notRecommendedStartQuantity ); } } if ($data['endQuantity'] != '') { if ($data['endQuantity'] < static::MIN_QUANTITY) { $errors['endQuantity'] = str_replace('%value%', static::MIN_QUANTITY, $this->_wrongQuantity); } else if ($data['startQuantity'] > $data['endQuantity']) { $errors['endQuantity'] = $this->_endQuantityGrater; } } return (empty($errors)) ? true : $errors; } }