/** * getDefaultValue * * @return string */ protected function getDefaultValue() { $country = \XLite\Model\Address::getDefaultFieldValue('country'); return $country ? $country->getCode() : ''; }
protected function prepareAddressData(array $data) { unset($data['save_in_book']); $requiredFields = \XLite\Core\Database::getRepo('XLite\\Model\\AddressField')->getShippingRequiredFields(); foreach ($requiredFields as $fieldName) { if (!isset($data[$fieldName]) && \XLite\Model\Address::getDefaultFieldValue($fieldName)) { $data[$fieldName] = \XLite\Model\Address::getDefaultFieldValue($fieldName); } } return $data; }
/** * Sanitize * * @param mixed $data Daa * * @return mixed */ public function sanitize($data) { // Check country if (!isset($data[static::FIELD_COUNTRY]) && !$this->isFieldAvailable(static::FIELD_COUNTRY)) { $data[static::FIELD_COUNTRY] = \XLite\Model\Address::getDefaultFieldValue('country')->getCode(); } // Get country $countryCodeValidator = new \XLite\Core\Validator\Pair\Simple(); $countryCodeValidator->setName(static::FIELD_COUNTRY); $countryCodeValidator->setValidator(new \XLite\Core\Validator\String\ObjectId\Country(true)); $country = $countryCodeValidator->getValidator()->sanitize($data[static::FIELD_COUNTRY]); // Get state if ($country->hasStates()) { $stateValidator = new \XLite\Core\Validator\String\ObjectId\State(true); $state = $stateValidator->sanitize($data[static::FIELD_STATE]); } elseif (!empty($data[static::FIELD_CUSTOM_STATE])) { $state = new \XLite\Model\State(); $state->setState($data[static::FIELD_CUSTOM_STATE]); $state->setCountry($country); $data[static::FIELD_STATE] = $data[static::FIELD_CUSTOM_STATE]; } else { $state = null; } return array('country' => $country, 'state' => $state, static::FIELD_COUNTRY => $data[static::FIELD_COUNTRY], static::FIELD_STATE => $state ? $data[static::FIELD_STATE] : null); }
/** * Get country * * @return XLite\Model\Country */ public function getCountry() { $result = $this->country; if (!$result) { $countryField = \XLite\Core\Database::getRepo('XLite\\Model\\AddressField')->findOneBy(array('serviceName' => 'country_code', 'enabled' => false)); if ($countryField) { $result = \XLite\Model\Address::getDefaultFieldValue('country'); } } return $result; }
/** * Get default customer address * * @return array */ public static function getDefaultAddress() { $config = \XLite\Core\Config::getInstance()->Shipping; $state = \XLite\Model\Address::getDefaultFieldValue('state'); $country = \XLite\Model\Address::getDefaultFieldValue('country'); return array('address' => $config->anonymous_address, 'city' => \XLite\Model\Address::getDefaultFieldValue('city'), 'state' => $state ? $state->getCode() : '', 'custom_state' => \XLite\Model\Address::getDefaultFieldValue('custom_state'), 'zipcode' => \XLite\Model\Address::getDefaultFieldValue('zipcode'), 'country' => $country ? $country->getCode() : '', 'type' => $config->anonymous_address_type); }
/** * Get state * * @return \XLite\Model\State */ protected function getState() { $address = $this->getAddress(); $state = null; // From getDestinationAddress() if ($address && isset($address['state']) && $address['state']) { $state = \XLite\Core\Database::getRepo('XLite\\Model\\State')->find($address['state']); } elseif ($this->getCart()->getProfile() && $this->getCart()->getProfile()->getShippingAddress() && $this->getCart()->getProfile()->getShippingAddress()->getState()) { // From shipping address $state = $this->getCart()->getProfile()->getShippingAddress()->getState(); } elseif (!$address && \XLite\Model\Address::getDefaultFieldValue('custom_state')) { // From config $state = new \XLite\Model\State(); $state->setState(\XLite\Model\Address::getDefaultFieldValue('custom_state')); } return $state; }
/** * Check - if country code is selected option in "SELECT" tag. * * @param string $countryCode Code of country to check. * * @return boolean */ protected function isSelectedCountry($countryCode) { $country = $this->getParam(static::PARAM_COUNTRY); if ('' == $country) { $countryObj = \XLite\Model\Address::getDefaultFieldValue('country'); $country = $countryObj ? $countryObj->getCode() : ''; } return $country === $countryCode; }
/** * Change shipping method * @todo: refactor (decompose) * * @return void */ protected function doActionChangeMethod() { $methodId = \XLite\Core\Request::getInstance()->methodId; $cart = $this->getCart(); if (null !== $methodId && $cart->getShippingId() != $methodId) { $cart->setLastShippingId($methodId); $cart->setShippingId($methodId); $address = $this->getCartProfile()->getShippingAddress(); if (!$address) { // Default address $profile = $this->getCartProfile(); $address = new \XLite\Model\Address(); $addr = $this->getAddress(); // Country $c = 'US'; if ($addr && isset($addr['country'])) { $c = $addr['country']; $country = \XLite\Core\Database::getRepo('XLite\\Model\\Country')->find($c); } elseif (\XLite\Model\Address::getDefaultFieldValue('country')) { $country = \XLite\Model\Address::getDefaultFieldValue('country'); } else { $country = \XLite\Core\Database::getRepo('XLite\\Model\\Country')->find($c); } if ($country) { $address->setCountry($country); } // State $state = null; if ($addr && !empty($addr['state'])) { $state = \XLite\Core\Database::getRepo('XLite\\Model\\State')->find($addr['state']); } elseif (!$addr && \XLite\Model\Address::getDefaultFieldValue('state')) { $state = \XLite\Model\Address::getDefaultFieldValue('state'); } if ($state) { $address->setState($state); } // Zip code if (\XLite\Model\Address::getDefaultFieldValue('zipcode')) { $address->setZipcode(\XLite\Model\Address::getDefaultFieldValue('zipcode')); } $address->setProfile($profile); $address->setIsShipping(true); $profile->addAddresses($address); \XLite\Core\Database::getEM()->persist($address); } $this->updateCart(); } $this->valid = true; $this->setSilenceClose(); }