Skip to content

Commit

Permalink
Member country restrictions were not applicable in Contao 4 (#1803)
Browse files Browse the repository at this point in the history
  • Loading branch information
aschempp committed Jun 29, 2017
1 parent 247c944 commit f7ded78
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 16 deletions.
1 change: 1 addition & 0 deletions system/modules/isotope/docs/CHANGELOG-2.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Version 2.4.2 (2017-??-??)
- Removed usage of mysql_real_escape_string (#1786)
- Fixed PHP7 compatibility for backend overview callback (#1795)
- Always store the country in order addresses (#1811)
- Member country restrictions were not applicable in Contao 4 (#1803)


Version 2.4.1 (2017-03-07)
Expand Down
56 changes: 40 additions & 16 deletions system/modules/isotope/library/Isotope/Backend/Member/Callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,52 @@ class Callback extends \Backend
*/
public function limitCountries($strTable)
{
if ($strTable != 'tl_member' || !Isotope::getConfig()->limitMemberCountries) {
if ('tl_member' !== $strTable || !Isotope::getConfig()->limitMemberCountries) {
return;
}

$arrCountries = array_unique(
array_merge(
Isotope::getConfig()->getBillingCountries(),
Isotope::getConfig()->getShippingCountries()
)
);
$originalField = $GLOBALS['TL_DCA']['tl_member']['fields']['country'];

$arrCountries = array_intersect_key(
$GLOBALS['TL_DCA']['tl_member']['fields']['country']['options'],
array_flip($arrCountries)
);
unset($GLOBALS['TL_DCA']['tl_member']['fields']['country']['options']);

$GLOBALS['TL_DCA']['tl_member']['fields']['country']['options'] = $arrCountries;
$GLOBALS['TL_DCA']['tl_member']['fields']['country']['options_callback'] = function () use ($originalField) {
if (isset($originalField['options_callback'])) {
if (is_array($originalField['options_callback'])) {
$callable = [
\System::importStatic($originalField['options_callback'][0]),
$originalField['options_callback'][1],
];
} else {
$callable = $originalField['options_callback'];
}

if (count($arrCountries) == 1) {
$arrCountryCodes = array_keys($arrCountries);
$GLOBALS['TL_DCA']['tl_member']['fields']['country']['default'] = $arrCountryCodes[0];
}
$options = call_user_func_array(
$callable,
func_get_args()
);
} else {
$options = (array) $originalField['options'];
}

$countries = array_unique(
array_merge(
Isotope::getConfig()->getBillingCountries(),
Isotope::getConfig()->getShippingCountries()
)
);

$countries = array_intersect_key(
$options,
array_flip($countries)
);

if (1 === count($countries)) {
$countryCodes = array_keys($countries);
$GLOBALS['TL_DCA']['tl_member']['fields']['country']['default'] = $countryCodes[0];
}

return $countries;
};
}

/**
Expand Down

0 comments on commit f7ded78

Please sign in to comment.