本文整理汇总了PHP中State::LoadByCode方法的典型用法代码示例。如果您正苦于以下问题:PHP State::LoadByCode方法的具体用法?PHP State::LoadByCode怎么用?PHP State::LoadByCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类State
的用法示例。
在下文中一共展示了State::LoadByCode方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: IdByCode
public static function IdByCode($strCode, $intCountry)
{
$objState = State::LoadByCode($strCode, $intCountry);
if ($objState instanceof State) {
return $objState->id;
} else {
return '';
}
}
示例2: actionGetStateByCode
/**
* Get state by state code.
*
* Returns JSON with state ID and name.
*/
public function actionGetStateByCode($stateCode = null, $countryId)
{
$state = State::LoadByCode($stateCode, $countryId);
if (isset($state)) {
$response = array('status' => 'success', 'state' => $state);
} else {
$response = array('status' => 'error', 'errors' => Yii::t('profile', 'Invalid state'));
}
$this->renderJSON($response);
}
示例3: parseListOrders
/**
* This function will run parse an order that we get from Amazon MWS.
* It saves orders of the customers to the DB.
* @param $response ListOrderItemsResponse Contains the orders from Amazon
* Marketplace WebService
* @return void
*/
public function parseListOrders($response)
{
$checkDate = date("Y-m-d", strtotime($this->amazon_check_time));
$listOrdersResult = $response->getListOrdersResult();
if ($listOrdersResult->isSetOrders()) {
$orders = $listOrdersResult->getOrders();
$orderList = $orders->getOrder();
foreach ($orderList as $order) {
if ($order->isSetAmazonOrderId()) {
$strOrderId = $order->getAmazonOrderId();
Yii::log("Found Amazon Order " . $strOrderId, 'info', 'application.' . __CLASS__ . "." . __FUNCTION__);
$objCart = Cart::LoadByIdStr($strOrderId);
if (!$objCart instanceof Cart) {
//We ignore orders we've already downloaded
$objCart = new Cart();
$objCart->id_str = $strOrderId;
$objCart->origin = 'amazon';
//We mark this as just a cart, not an order, because we download the items next
$objCart->cart_type = CartType::cart;
$objOrderTotal = $order->getOrderTotal();
Yii::log("Order total information " . print_r($objOrderTotal, true), 'info', 'application.' . __CLASS__ . "." . __FUNCTION__);
$objCart->total = $objOrderTotal->getAmount();
$objCart->currency = $objOrderTotal->getCurrencyCode();
$objCart->status = OrderStatus::Requested;
$objCart->datetime_cre = $order->getPurchaseDate();
$objCart->modified = $order->getLastUpdateDate();
if (!$objCart->save()) {
Yii::log("Error saving cart " . print_r($objCart->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
}
//Since email from is Anonymous, we probably will have to create a shell record
$objCustomer = Customer::LoadByEmail($order->getBuyerEmail());
if (!$objCustomer) {
$customerName = $this->_getCustomerName($order->getBuyerName());
$objCustomer = new Customer();
$objCustomer->email = $order->getBuyerEmail();
$objCustomer->first_name = $customerName['first_name'];
$objCustomer->last_name = $customerName['last_name'];
$objCustomer->record_type = Customer::EXTERNAL_SHELL_ACCOUNT;
$objCustomer->allow_login = Customer::UNAPPROVED_USER;
$objCustomer->save();
}
$objCart->customer_id = $objCustomer->id;
if (!$objCart->save()) {
Yii::log("Error saving cart " . print_r($objCart->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
}
if ($order->isSetShippingAddress()) {
$shippingAddress = $order->getShippingAddress();
$countrycode = Country::IdByCode($shippingAddress->getCountryCode());
if ($shippingAddress->isSetStateOrRegion()) {
$objState = State::LoadByCode($shippingAddress->getStateOrRegion(), $countrycode);
}
$customerName = $this->_getCustomerName($shippingAddress->getName());
$config = array('address_label' => 'amazon', 'customer_id' => $objCustomer->id, 'first_name' => $customerName['first_name'], 'last_name' => $customerName['last_name'], 'address1' => $shippingAddress->getAddressLine1(), 'address2' => trim($shippingAddress->getAddressLine2() . " " . $shippingAddress->getAddressLine3()), 'city' => $shippingAddress->getCity(), 'state_id' => $objState->id, 'postal' => $shippingAddress->getPostalCode(), 'country_id' => $countrycode, 'phone' => $shippingAddress->getPhone());
$objCustAddress = CustomerAddress::findOrCreate($config);
$objCustomer->default_billing_id = $objCustAddress->id;
$objCustomer->default_shipping_id = $objCustAddress->id;
$objCustomer->save();
$objCart->shipaddress_id = $objCustAddress->id;
$objCart->billaddress_id = $objCustAddress->id;
//Amazon doesn't provide billing data, just dupe
if (!$objCart->save()) {
Yii::log("Error saving cart " . print_r($objCart->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
}
Yii::log("Looking for destination " . $objState->country_code . " " . $objState->code . " " . $shippingAddress->getPostalCode(), 'info', 'application.' . __CLASS__ . "." . __FUNCTION__);
$objDestination = Destination::LoadMatching($objState->country_code, $objState->code, $shippingAddress->getPostalCode());
if ($objDestination === null) {
Yii::log("Did not find destination, using default in Web Store ", 'info', 'application.' . __CLASS__ . "." . __FUNCTION__);
$objDestination = Destination::getAnyAny();
}
$objCart->tax_code_id = $objDestination->taxcode;
$objCart->recalculateAndSave();
}
if ($order->isSetShipServiceLevel()) {
$strShip = $order->getShipServiceLevel();
//If we have a shipping object already, update it, otherwise create it
if (isset($objCart->shipping)) {
$objShipping = $objCart->shipping;
} else {
//create
$objShipping = new CartShipping();
if (!$objShipping->save()) {
Yii::log("Error saving shipping info for cart " . print_r($objShipping->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
}
}
if ($order->isSetShipmentServiceLevelCategory()) {
$strShip = $order->getShipmentServiceLevelCategory();
}
$objShipping->shipping_module = get_class($this);
$objShipping->shipping_data = $strShip;
$objShipping->shipping_method = $this->objModule->getConfig('product');
$objShipping->shipping_cost = 0;
$objShipping->shipping_sell = 0;
$objShipping->save();
//.........这里部分代码省略.........
示例4: actionConvertDestinationTables
/**
* 18 Change destination tables and map to country/state ids
*/
protected function actionConvertDestinationTables()
{
//Convert Wish List items to new formats
//Ship to me
//Ship to buyer
//Keep in store
//find and remove any destinations with an erroneous taxcode
$sql = 'SELECT `id` FROM `xlsws_destination` WHERE `taxcode` NOT IN (SELECT xlsws_tax_code.lsid FROM xlsws_tax_code);';
$array = Yii::app()->db->createCommand($sql)->queryAll();
foreach ($array as $a) {
Yii::log('Destination id ' . $a['id'] . 'deleted due to erroneous tax code', 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
_dbx('DELETE FROM `xlsws_destination` WHERE `id`=' . $a['id'] . ';');
}
$objDestinations = Destination::model()->findAll();
foreach ($objDestinations as $objDestination) {
if ($objDestination->country == "*") {
$objDestination->country = null;
} else {
if (!is_numeric($objDestination->country)) {
$objC = Country::LoadByCode($objDestination->country);
$objDestination->country = $objC->id;
}
}
if ($objDestination->state == "*" || $objDestination->state == null) {
$objDestination->state = null;
} else {
if (!is_numeric($objDestination->state)) {
$objS = State::LoadByCode($objDestination->state, $objDestination->country);
$objDestination->state = $objS->id;
}
}
if (!$objDestination->save()) {
return print_r($objDestination->getErrors());
}
}
//Need to map destinations to IDs before doing this
_dbx("update `xlsws_destination` set country=null where country=0;");
_dbx("update `xlsws_destination` set state=null where state=0;");
_dbx("ALTER TABLE `xlsws_destination` CHANGE `country` `country` INT(11) UNSIGNED NULL DEFAULT NULL;");
_dbx("ALTER TABLE `xlsws_destination` CHANGE `state` `state` INT(11) UNSIGNED NULL DEFAULT NULL;");
_dbx("ALTER TABLE `xlsws_destination` CHANGE `taxcode` `taxcode` INT(11) UNSIGNED NULL DEFAULT NULL;");
_dbx("ALTER TABLE `xlsws_destination` ADD FOREIGN KEY (`state`) REFERENCES `xlsws_state` (`id`);");
_dbx("ALTER TABLE `xlsws_destination` ADD FOREIGN KEY (`country`) REFERENCES `xlsws_country` (`id`);");
_dbx("ALTER TABLE `xlsws_destination` ADD FOREIGN KEY (`taxcode`) REFERENCES `xlsws_tax_code` (`lsid`);");
_dbx("ALTER TABLE `xlsws_category` CHANGE `custom_page` `custom_page` INT(11) UNSIGNED NULL DEFAULT NULL;");
_dbx("UPDATE `xlsws_category` set `custom_page`=null where `custom_page`=0;");
_dbx("ALTER TABLE `xlsws_category` ADD FOREIGN KEY (`custom_page`) REFERENCES `xlsws_custom_page` (`id`);");
_dbx("ALTER TABLE `xlsws_country` DROP `code_a3`;");
_dbx("update `xlsws_shipping_tiers` set `class_name`='tieredshipping';");
return array('result' => "success", 'makeline' => 19, 'tag' => 'Applying database schema changes', 'total' => 50);
}
示例5: LoadMatching
/**
* Match a given address to the most accurate Destination
* @param string $country
* @param string $state
* @param string $zip
* @return object :: The matching destination
*/
public static function LoadMatching($country, $state, $zip)
{
//We may get id numbers instead of text strings so convert here
if (is_numeric($country)) {
$country = Country::CodeById($country);
}
if (is_numeric($state)) {
$state = State::CodeById($state);
}
$arrDestinations = Destination::LoadByCountry($country);
if (is_array($arrDestinations) === false && $arrDestinations instanceof Traversable === false) {
return null;
}
$objState = State::LoadByCode($state, $country);
$zip = preg_replace('/[^A-Z0-9]/', '', strtoupper($zip));
foreach ($arrDestinations as $objDestination) {
if ($objDestination->state == null || $objState !== null && $objState->id == $objDestination->state) {
$zipStart = $objDestination->Zipcode1;
$zipEnd = $objDestination->Zipcode2;
if ($zipStart <= $zip && $zipEnd >= $zip || $zipStart == '' || $zipStart == '*' || $zip == '') {
return $objDestination;
}
}
}
return null;
}
示例6: getShippingState
/**
* Virtual method for getting the shipping state id.
*
* @return integer The state country id.
*/
public function getShippingState()
{
$objShippingState = State::LoadByCode($this->shippingStateCode, $this->shippingCountry);
if ($objShippingState === null) {
return null;
}
return $objShippingState->id;
}