_formType = $options['formType']; if ($this->_formType === 'cart') { $this->_controllerAction = 'updateNumbers'; } else if ($this->_formType === 'simple') { $this->_controllerAction = 'getAddToCartForm'; } } if (isset($options['showAdditionalFields']) && $options['showAdditionalFields']) { $this->_showAdditionalFields = true; } return parent::setOptions($options); } protected function _initElements() { $this->addElement('hidden', 'productId'); if ($this->_formType !== 'simple') { if ($this->_formType === 'full') { $this->addElement( 'text', 'quantity', array('label' => 'Quantity', 'required' => true, 'precision' => 0) ); $this->getElement('quantity')->addValidator('Int', true); $greaterThan = new Zend_Validate_GreaterThan(0); $greaterThan->setMessage( 'Quantity must be greater than zero', Zend_Validate_GreaterThan::NOT_GREATER ); $this->getElement('quantity')->addValidator($greaterThan, false); } if ($this->_showAdditionalFields) { $this->addElement('text', 'numbersText', array( 'label' => 'Numbers', 'description' => 'Enter a list of numbers separated by comma', )); $this->getElement('numbersText')->getDecorator('Label')->setOption('class', 'required'); $acceptExtensions = array('xls', 'xlsx', 'pdf', 'csv'); $this->addElement('extendedFile', 'numbersFile', array( 'label' => 'Numbers', 'description' => 'Permitted file extensions: ".' . implode('", ".', $acceptExtensions) . '"', )); $this->getElement('numbersFile')->addValidator( new Zend_Validate_File_Extension($acceptExtensions), true ); $this->getElement('numbersFile')->getDecorator('Label')->setOption('class', 'required'); if (!$this->_getData('numbersText') && !isset($_FILES['numbersFile'])) { $this->getElement('numbersText')->setRequired(true); } } } return $this; } protected function _initButtons() { $this->addElement( 'submit', 'btnSubmit', array( 'label' => $this->_formType !== 'cart' ? 'Add To Cart' : 'Update', 'attribs' => array('class' => 'btn btn-primary') ) ); return $this; } }