예제 #1
0
 /**
  * Edit an address record. Based on the PersonalData core module
  * @param integer
  * @return void
  */
 protected function edit($intAddressId = 0)
 {
     $table = Address::getTable();
     \System::loadLanguageFile(\MemberModel::getTable());
     $this->Template = new \Isotope\Template($this->memberTpl);
     $this->Template->hasError = false;
     $this->Template->slabel = specialchars($GLOBALS['TL_LANG']['MSC']['saveData']);
     if ($intAddressId === 0) {
         $objAddress = Address::createForMember(\FrontendUser::getInstance()->id);
     } else {
         $objAddress = Address::findOneForMember($intAddressId, \FrontendUser::getInstance()->id);
     }
     if (null === $objAddress) {
         global $objPage;
         \Controller::redirect(\Controller::generateFrontendUrl($objPage->row()));
     }
     $objForm = new Form($table . '_' . $this->id, 'POST', function ($objForm) {
         return \Input::post('FORM_SUBMIT') === $objForm->getFormId();
     }, (bool) $this->tableless);
     $objForm->bindModel($objAddress);
     // Add form fields and modify for the address book
     $arrFields = $this->arrFields;
     $objForm->addFieldsFromDca($table, function ($strName, &$arrDca) use($arrFields) {
         if (!in_array($strName, $arrFields) || !$arrDca['eval']['feEditable']) {
             return false;
         }
         // Map checkboxWizard to regular checkbox widget
         if ($arrDca['inputType'] == 'checkboxWizard') {
             $arrDca['inputType'] = 'checkbox';
         }
         // Special field "country"
         if ($strName == 'country') {
             $arrCountries = array_merge(Isotope::getConfig()->getBillingCountries(), Isotope::getConfig()->getShippingCountries());
             $arrDca['reference'] = $arrDca['options'];
             $arrDca['options'] = array_values(array_intersect(array_keys($arrDca['options']), $arrCountries));
             $arrDca['default'] = Isotope::getConfig()->billing_country;
         }
         return true;
     });
     if ($objForm->isSubmitted()) {
         if ($objForm->validate()) {
             $objAddress->save();
             // Call onsubmit_callback
             if (is_array($GLOBALS['TL_DCA'][$table]['config']['onsubmit_callback'])) {
                 foreach ($GLOBALS['TL_DCA'][$table]['config']['onsubmit_callback'] as $callback) {
                     $objCallback = \System::importStatic($callback[0]);
                     $objCallback->{$callback}[1]($objAddress);
                 }
             }
             global $objPage;
             \Controller::redirect(\Controller::generateFrontendUrl($objPage->row()));
         } else {
             $this->Template->hasError = true;
         }
     }
     $objForm->addToTemplate($this->Template);
     // Add groups
     $arrGroups = array();
     foreach ($objForm->getFormFields() as $strName => $arrConfig) {
         if ($arrConfig['feGroup'] != '') {
             $arrGroups[$arrConfig['feGroup']][$strName] = $objForm->getWidget($strName)->parse();
         }
     }
     foreach ($arrGroups as $k => $v) {
         $this->Template->{$k} = $v;
     }
     $this->Template->addressDetails = $GLOBALS['TL_LANG'][$table]['addressDetails'];
     $this->Template->contactDetails = $GLOBALS['TL_LANG'][$table]['contactDetails'];
     $this->Template->personalData = $GLOBALS['TL_LANG'][$table]['personalData'];
     $this->Template->loginDetails = $GLOBALS['TL_LANG'][$table]['loginDetails'];
 }
예제 #2
0
 /**
  * Generate the module
  */
 protected function compile()
 {
     $this->Template->hasError = false;
     $this->Template->slabel = specialchars($GLOBALS['TL_LANG']['MSC']['saveAddressButton']);
     $table = Address::getTable();
     \System::loadLanguageFile($table);
     \Controller::loadDataContainer($table);
     // Call onload_callback (e.g. to check permissions)
     if (is_array($GLOBALS['TL_DCA'][$table]['config']['onload_callback'])) {
         foreach ($GLOBALS['TL_DCA'][$table]['config']['onload_callback'] as $callback) {
             $objCallback = \System::importStatic($callback[0]);
             $objCallback->{$callback}[1]();
         }
     }
     $arrFields = $this->iso_addressFields;
     $useBilling = in_array('billing', $this->iso_address);
     $objAddress = $this->getDefaultAddress($useBilling);
     $objForm = new Form('iso_cart_address_' . $this->id, 'POST', function ($objHaste) {
         /** @type Form $objHaste */
         return \Input::post('FORM_SUBMIT') === $objHaste->getFormId();
     }, (bool) $this->tableless);
     $objForm->bindModel($objAddress);
     // Add form fields
     $objForm->addFieldsFromDca($table, function ($strName, &$arrDca) use($arrFields, $useBilling) {
         if (!in_array($strName, $arrFields) || !$arrDca['eval']['feEditable'] || $arrDca['eval']['membersOnly'] && FE_USER_LOGGED_IN !== true) {
             return false;
         }
         // Special field "country"
         if ($strName == 'country') {
             if ($useBilling) {
                 $arrCountries = Isotope::getConfig()->getBillingCountries();
                 $arrDca['default'] = Isotope::getConfig()->billing_country;
             } else {
                 $arrCountries = Isotope::getConfig()->getShippingCountries();
                 $arrDca['default'] = Isotope::getConfig()->shipping_country;
             }
             $arrDca['reference'] = $arrDca['options'];
             $arrDca['options'] = array_values(array_intersect(array_keys($arrDca['options']), $arrCountries));
         }
         return true;
     });
     $objCart = Isotope::getCart();
     // Save the data
     if ($objForm->validate()) {
         if (!$objCart->id) {
             $objCart->save();
         }
         $objAddress->tstamp = time();
         $objAddress->pid = $objCart->id;
         $objAddress->save();
         // Call onsubmit_callback
         if (is_array($GLOBALS['TL_DCA'][$table]['config']['onsubmit_callback'])) {
             foreach ($GLOBALS['TL_DCA'][$table]['config']['onsubmit_callback'] as $callback) {
                 $objCallback = \System::importStatic($callback[0]);
                 $objCallback->{$callback}[1]($objAddress);
             }
         }
         // Set the billing address
         if ($useBilling) {
             $objCart->setBillingAddress($objAddress);
         }
         // Set the shipping address
         if (in_array('shipping', $this->iso_address)) {
             $objCart->setShippingAddress($objAddress);
         }
         $this->jumpToOrReload($this->jumpTo);
     }
     $objForm->addToTemplate($this->Template);
     // Predefine the group order (other groups will be appended automatically)
     $arrGroups = array();
     $categories = array('personal' => array(), 'address' => array(), 'contact' => array(), 'login' => array(), 'profile' => array());
     foreach ($objForm->getFormFields() as $strName => $arrConfig) {
         if ($arrConfig['feGroup'] != '') {
             $arrGroups[$arrConfig['feGroup']][$strName] = $objForm->getWidget($strName)->parse();
         }
     }
     foreach ($arrGroups as $k => $v) {
         $this->Template->{$k} = $v;
         // backwards compatibility
         $key = $k . ($k == 'personal' ? 'Data' : 'Details');
         $categories[$GLOBALS['TL_LANG']['tl_member'][$key]] = $v;
     }
     $this->Template->categories = $categories;
     $this->Template->addressDetails = $GLOBALS['TL_LANG'][$table]['addressDetails'];
     $this->Template->contactDetails = $GLOBALS['TL_LANG'][$table]['contactDetails'];
     $this->Template->personalData = $GLOBALS['TL_LANG'][$table]['personalData'];
     $this->Template->loginDetails = $GLOBALS['TL_LANG'][$table]['loginDetails'];
 }