/** * Return specific data for address entry. Helper. * * @param \XLite\Model\Address $address Address * @param boolean $showEmpty Show empty fields OPTIONAL * * @return array */ protected function getAddressSectionData(\XLite\Model\Address $address, $showEmpty = false) { $result = array(); $hasStates = $address->getCountry() ? $address->getCountry()->hasStates() : false; foreach (\XLite\Core\Database::getRepo('XLite\\Model\\AddressField')->findAllEnabled() as $field) { $method = 'get' . \Includes\Utils\Converter::convertToCamelCase($field->getViewGetterName() ?: $field->getServiceName()); $addressFieldValue = $address->{$method}(); $cssFieldName = $field->getCSSFieldName(); switch ($field->getServiceName()) { case 'state_id': $addressFieldValue = $hasStates ? $addressFieldValue : null; if (null === $addressFieldValue && $hasStates) { $addressFieldValue = $address->getCustomState(); } break; case 'custom_state': $addressFieldValue = $hasStates ? null : $address->getCustomState(); $cssFieldName = $hasStates ? $cssFieldName : 'address-state'; break; default: } if ($addressFieldValue || $showEmpty) { $result[$field->getServiceName()] = array('css_class' => $cssFieldName, 'title' => $field->getName(), 'value' => $addressFieldValue); } } return $result; }
/** * Return Country field value. if no country defined we should use '' value * * @param \XLite\Model\Address $address Address model (could be shipping or billing address) * * @return string */ protected function getCountryField($address) { return $address->getCountry() ? $address->getCountry()->getCode() : ''; }
/** * Get field value * * @param string $fieldName Field name * @param \XLite\Model\Address $address Field name * @param boolean $processValue Process value flag OPTIONAL * * @return string */ public function getFieldValue($fieldName, \XLite\Model\Address $address, $processValue = false) { $result = ''; if (null !== $address) { $methodName = 'get' . \XLite\Core\Converter::getInstance()->convertToCamelCase($fieldName); // $methodName assembled from 'get' + camelized $fieldName $result = $address->{$methodName}(); if ($result && false !== $processValue) { switch ($fieldName) { case 'state_id': $result = $address->getCountry()->hasStates() ? $address->getState()->getState() : null; break; case 'custom_state': $result = $address->getCountry()->hasStates() ? null : $result; break; case 'country_code': $result = $address->getCountry()->getCountry(); break; case 'type': $result = $address->getTypeName(); break; default: } } } return $result; }
/** * {@inheritDoc} */ public function getCountry() { $this->__initializer__ && $this->__initializer__->__invoke($this, 'getCountry', array()); return parent::getCountry(); }
/** * Prepare the specific data format for address * * @param \XLite\Model\Address $address Address * * @return array */ public static function prepareAddressData($address) { return $address ? array('address' => $address->getStreet(), 'city' => $address->getCity(), 'state' => $address->getState()->getStateId(), 'custom_state' => $address->getCustomState(), 'zipcode' => $address->getZipcode(), 'country' => $address->getCountry() ? $address->getCountry()->getCode() : '', 'type' => $address->getType() ?: \XLite\Core\Config::getInstance()->Shipping->anonymous_address_type) : null; }