本文整理汇总了PHP中eZShopFunctions::getPreferredUserCountry方法的典型用法代码示例。如果您正苦于以下问题:PHP eZShopFunctions::getPreferredUserCountry方法的具体用法?PHP eZShopFunctions::getPreferredUserCountry怎么用?PHP eZShopFunctions::getPreferredUserCountry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eZShopFunctions
的用法示例。
在下文中一共展示了eZShopFunctions::getPreferredUserCountry方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fetchUserCountry
function fetchUserCountry()
{
// Get country saved in user preferences.
$country = eZShopFunctions::getPreferredUserCountry();
if ( !$country )
{
// If not found, get country from user object
// and save it to the preference.
$country = eZShopFunctions::getUserCountry();
if ( $country )
eZShopFunctions::setPreferredUserCountry( $country );
}
return array( 'result' => $country );
}
示例2: getUserCountry
/**
* Determine user's country.
*
* \public
* \static
*/
static function getUserCountry( $user = false, $considerPreferedCountry = true )
{
$requireUserCountry = eZVATManager::isUserCountryRequired();
// If current user has set his/her preferred country via the toolbar
if ( $considerPreferedCountry )
{
// return it
$country = eZShopFunctions::getPreferredUserCountry();
if ( $country )
{
eZDebug::writeDebug( "Applying user's preferred country <$country> while charging VAT" );
return $country;
}
}
// Otherwise fetch country saved in the user object.
if ( $user === false )
{
$user = eZUser::currentUser();
}
$userObject = $user->attribute( 'contentobject' );
$countryAttributeName = eZVATManager::getUserCountryAttributeName( $requireUserCountry );
if ( $countryAttributeName === null )
return null;
$userDataMap = $userObject->attribute( 'data_map' );
if ( !isset( $userDataMap[$countryAttributeName] ) )
{
if ( $requireUserCountry )
{
eZDebug::writeError( "Cannot find user country: there is no attribute '$countryAttributeName' in object '" .
$userObject->attribute( 'name' ) .
"' of class '" .
$userObject->attribute( 'class_name' ) . "'.",
__METHOD__ );
}
return null;
}
$countryAttribute = $userDataMap[$countryAttributeName];
$countryContent = $countryAttribute->attribute( 'content' );
if ( $countryContent === null )
{
if ( $requireUserCountry )
{
eZDebug::writeError( "User country is not specified in object '" .
$userObject->attribute( 'name' ) .
"' of class '" .
$userObject->attribute( 'class_name' ) . "'." ,
__METHOD__ );
}
return null;
}
if ( is_object( $countryContent ) )
$country = $countryContent->attribute( 'value' );
elseif ( is_array( $countryContent ) )
{
if ( is_array( $countryContent['value'] ) )
{
foreach ( $countryContent['value'] as $item )
{
$country = $item['Alpha2'];
break;
}
}
else
{
$country = $countryContent['value'];
}
}
else
{
if ( $requireUserCountry )
{
eZDebug::writeError( "User country is not specified or specified incorrectly in object '" .
$userObject->attribute( 'name' ) .
"' of class '" .
$userObject->attribute( 'class_name' ) . "'." ,
__METHOD__ );
}
return null;
}
return $country;
}