_priceObj = new App_ECommerce_ShippingPrice_Admin_Obj(); return $this; } protected function _initElements() { parent::_initElements(); $this->addElement( 'text', 'startQuantity', [ 'label' => 'Start Quantity', 'validators' => [['Int', false]], 'required' => true, ] ); $this->addElement( 'text', 'endQuantity', [ 'label' => 'End Quantity', 'validators' => [['Int', false]], 'required' => true, ] ); $this->addElement( 'numeric', 'price', [ 'label' => 'Price', 'required' => true, ] ); /** @var $numeric Qs_Form_Decorator_Numeric */ $numeric = $this->getElement('price')->getDecorator('Numeric'); $numeric->setHtmlBeforeElement('$'); $this->addFormRule([$this, 'validateForm']); return $this; } public function validateForm(array $data) { $errors = []; $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; } }