コード例 #1
0
ファイル: Address.php プロジェクト: rguedes/axiscommerce
 public function init()
 {
     $configOptions = Axis::config('account/address_form')->toArray();
     $this->_fieldConfig = array_merge(array('firstname_sort_order' => -20, 'firstname_status' => 'required', 'lastname_sort_order' => -19, 'lastname_status' => 'required'), $configOptions);
     $form = $this;
     if ($subform = $this->getAttrib('subform')) {
         $form = new Axis_Form();
         // makes possible to use brackets in field names
         $form->setIsArray(true);
         $form->removeDecorator('Form');
         $this->addSubForm($form, $subform);
     }
     $countries = Axis_Collect_Country::collect();
     if (isset($countries['0']) && 'ALL WORLD COUNTRY' === $countries['0']) {
         unset($countries['0']);
     }
     $allowedCountries = $configOptions['country_id_allow'];
     if (!in_array(0, $allowedCountries)) {
         // ALL WORLD COUNTRIES is not selected
         $countries = array_intersect_key($countries, array_flip($allowedCountries));
     }
     $countryIds = array_keys($countries);
     $defaultCountry = current($countryIds);
     $zones = Axis_Collect_Zone::collect();
     $this->_zones = $zones;
     if ('billing_address' == $subform && !($customerId = Axis::getCustomerId())) {
         $form->addElement('text', 'email', array('required' => true, 'label' => 'Email', 'class' => 'input-text required email', 'validators' => array('EmailAddress')));
     }
     foreach ($this->_fields as $name => $values) {
         $status = $this->_fieldConfig[$name . '_status'];
         if ('disabled' == $status) {
             continue;
         }
         $fieldOptions = array('required' => 'required' === $status, 'label' => $values['label'], 'class' => $values['class'] . ('required' === $status ? ' required' : ''));
         if (isset($this->_fieldConfig[$name . '_sort_order'])) {
             $fieldOptions['order'] = $this->_fieldConfig[$name . '_sort_order'];
         }
         if ('country_id' == $name) {
             $fieldOptions['validators'] = array(new Zend_Validate_InArray(array_keys($countries)));
             $values['type'] = new Zend_Form_Element_Select($name, $fieldOptions);
             $values['type']->removeDecorator('HtmlTag')->addDecorator('HtmlTag', array('tag' => 'li', 'id' => "{$subform}-{$name}-row", 'class' => 'element-row'));
             $values['type']->options = $countries;
         } else {
             if ('zone_id' == $name) {
                 $values['type'] = new Zend_Form_Element_Select($name, $fieldOptions);
                 $values['type']->removeDecorator('HtmlTag')->addDecorator('HtmlTag', array('tag' => 'li', 'id' => "{$subform}-{$name}-row", 'class' => 'element-row'));
                 if (isset($zones[$defaultCountry]) && count($countries)) {
                     $values['type']->options = $zones[$defaultCountry];
                 }
                 // zone name field
                 $zoneNameOptions = $fieldOptions;
                 $zoneNameOptions['order']++;
                 $zoneNameOptions['class'] .= ' input-text';
                 $form->addElement('text', 'state', $zoneNameOptions);
             }
         }
         $form->addElement($values['type'], $name, $fieldOptions);
     }
     $form->addDisplayGroup($form->getElements(), $subform);
 }