['asBilling' => 'y']]; protected $_states4Select; protected $_hasSeoFields = false; protected function _initElements() { $this->_initPersonalInfoFields(); $this->_initCheckoutFields(); return $this; } /** * @return AdminObj */ protected function _getDataObj() { if (null === $this->_dataObj) { $this->_dataObj = new AdminObj(); } return $this->_dataObj; } /** * @return CartObj */ protected function _getCart() { return CartObj::getInstance(); } /** * "Personal" fields for "simple" mode * @return $this */ protected function _initPersonalInfoFields() { $this->addElement('text', 'firstName', ['label' => 'First Name', 'required' => true]); $this->addElement('text', 'lastName', ['label' => 'Last Name', 'required' => true]); $this->addElement('internationalTel', 'directPhone', ['label' => 'Phone Number', 'required' => true]); $this->addElement( 'email', 'email', ['label' => 'Email Address', 'required' => true, 'attribs' => ['autocomplete' => 'off']] ); $uniqueValidator = new Qs_Validate_Unique(new Qs_Db_Table('User'), 'email', $this->_getData('id')); $this->getElement('email')->addValidator($uniqueValidator); $this->_initPasswordFields(); $this->addDisplayGroup( ['firstName', 'lastName', 'directPhone', 'email', 'password', 'confirmPassword'], 'personalInfo', ['legend' => 'Personal Information'] ); return $this; } protected function _initPasswordFields() { $this->addElement( 'password', 'password', [ 'label' => 'Password', 'required' => true, 'attribs' => ['autocomplete' => 'off'], ] ); $this->getElement('password')->addValidator('Callback', true, [[$this, 'validatePassword']]); $this->addElement( 'password', 'confirmPassword', [ 'label' => 'Confirm Password', 'required' => true, 'attribs' => ['autocomplete' => 'off'], ] ); $this->getElement('confirmPassword')->addValidator('ConfirmPassword', true, ['password']); return $this; } protected function _initCheckoutFields($isRequired = true) { $this->_initAddressFields(Entity::ADDRESS_BILLING, $isRequired); $this->_initAddressFields(Entity::ADDRESS_SHIPPING, $isRequired); return $this; } /** * "Address" fields for "simple" mode * @param string $type * @param bool $isRequired * @return $this */ protected function _initAddressFields($type, $isRequired = true) { $form = new Qs_Form_SubForm(['legend' => ucfirst($type) . ' Address']); if ($type != Entity::ADDRESS_BILLING) { $form->addElement( 'checkbox', 'asBilling', ['label' => 'My shipping address is the same as my billing address', 'decoration' => 'simple'] ); } $form->addElement('text', 'firstName', ['label' => 'First Name']); $form->addElement('text', 'lastName', ['label' => 'Last Name']); $form->addElement('text', 'address', ['label' => 'Address']); $form->addElement('text', 'address2', ['label' => 'Address 2']); $form->addElement('text', 'city', ['label' => 'City', 'class' => 'city']); $form->addElement( 'select', 'state', [ 'label' => 'State', 'class' => 'state', 'multiOptions' => ['' => 'Select One'] + $this->_getStates4Select(), ] ); $form->addElement('zip', 'zip', ['label' => 'Zip', 'class' => 'zip']); if ($isRequired) { /** @var $element \Zend_Form_Element */ $element = null; if ($type == Entity::ADDRESS_BILLING) { foreach ($form as $element) { if ($element->getName() != 'address2') { $element->setRequired(); } } } else { $asBilling = $this->_getData($type . '[asBilling]'); foreach ($form as $element) { if (in_array($element->getName(), ['asBilling', 'address2'])) { continue; } if ($asBilling && 'n' == $asBilling) { $element->setRequired(); } else { $element->getDecorator('Label')->setOption('class', 'required'); } } } } $this->addSubForm($form, $type); return $this; } protected function _getScriptOptions() { $options['formId'] = $this->getId(); $options['addressTypes'] = [Entity::ADDRESS_SHIPPING]; if ($this->getSubForm(Entity::ADDRESS_BILLING)) { $options['addressFields'] = array_keys($this->getSubForm(Entity::ADDRESS_BILLING)->getElements()); } $options['inheritedAddress'] = Entity::ADDRESS_BILLING; return $options; } public function render(Zend_View_Interface $view = null) { /** @var $doc \App_Doc_Admin */ $doc = Zend_Registry::get('doc'); $doc->addScript('js/app/user/form.js'); $doc->addInitObject('app.user.Form', [$this->_getScriptOptions()], 'appUserForm'); return parent::render($view); } public function validatePassword($value, $context = null) { if (!empty($value) && empty($context['confirmPassword'])) { $this->getElement('confirmPassword')->setRequired()->isValid(''); $this->getElement('confirmPassword')->setErrors(['Password confirmation does not match']); } return true; } protected function _getStates4Select() { if (null === $this->_states4Select) { $this->_states4Select = $this->_getDataObj()->getDState4Select(); } return $this->_states4Select; } }