Skip to content

Commit

Permalink
add properties
Browse files Browse the repository at this point in the history
  • Loading branch information
mfilip committed Jun 24, 2024
1 parent f6b078d commit 2ca2fe1
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 45 deletions.
21 changes: 16 additions & 5 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,21 @@ public function usesAutocomplete(
);
}

public function populateOrganisation(
public function removeOrganisation(
$scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $storeId = null
) {
return $this->scopeConfig->isSetFlag(
'idealpostcodes/settings/populate_organisation',
'idealpostcodes/settings/remove_organisation_store',
$scope,
$storeId
);
}

public function removeOrganisationAdmin(
$scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $storeId = null
) {
return $this->scopeConfig->isSetFlag(
'idealpostcodes/settings/remove_organisation_admin',
$scope,
$storeId
);
Expand Down Expand Up @@ -210,7 +220,7 @@ public function toConfiguration(
'api_key' => $this->getApiKey($scope, $storeId),
'postcodeLookup' => $this->usesPostcodeLookup($scope, $storeId),
'addressAutocomplete' => $this->usesAutocomplete($scope, $storeId),
'populateOrganisation' => $this->populateOrganisation($scope, $storeId),
'removeOrganisation' => $this->removeOrganisation($scope, $storeId),
'hoistCountryField' => $this->hoistCountry($scope, $storeId),
'requireCounty' => $this->requireCounty($scope, $storeId),
'autocompleteOverride' => $this->getAutocompleteOverride($scope, $storeId),
Expand All @@ -229,9 +239,10 @@ public function toAdminConfiguration(
'enabled' => $this->isEnabled($scope),
'api_key' => $this->getApiKey($scope),
'addressAutocomplete' => $this->isEnabledAdminAutocomplete($scope),
'populateOrganisation' => $this->populateOrganisation($scope),
'removeOrganisation' => $this->removeOrganisationAdmin($scope),
'hoistCountryField' => $this->hoistCountry($scope),
'requireCounty' => $this->requireCounty($scope)
'requireCounty' => $this->requireCounty($scope),
"customFields" => $this->customFields($scope),
);
return $config;
}
Expand Down
5 changes: 5 additions & 0 deletions lib/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { PostcodeLookup } from "@ideal-postcodes/postcode-lookup";

export interface Config extends BaseConfig {
hoistCountry?: boolean;
removeOrganisation: boolean;
customFields?: OutputFields[];
}

Expand Down Expand Up @@ -160,6 +161,8 @@ export const setupPostcodeLookup = (
checkKey: true,
context: "div.idpc_lookup",
outputFields,
removeOrganisation: config.removeOrganisation,
populateCounty: config.populateCounty,
selectStyle: {
"margin-top": "5px",
"margin-bottom": "5px",
Expand Down Expand Up @@ -223,6 +226,8 @@ export const setupAutocomplete = async (
{
apiKey: config.apiKey,
checkKey: true,
removeOrganisation: config.removeOrganisation,
populateCounty: config.populateCounty,
onLoaded() {
//@ts-expect-error
this.options.outputFields = getFields(outputFields, this.scope);
Expand Down
73 changes: 48 additions & 25 deletions view/adminhtml/templates/admin.phtml
Original file line number Diff line number Diff line change
@@ -1,28 +1,51 @@
<?php /** @var Magento\Framework\View\TemplateEngine\Php $this */
$helper = $this->helper('Idealpostcodes\Ukaddresssearch\Helper\Data');

$script = '
document.addEventListener(\'DOMContentLoaded\', function() {
var apiKey = "' . $helper->getConfig('api_key') . '";
var autocomplete = ' . $helper->getConfig('addressAutocomplete') . ';
var removeOrganisation = ' . $helper->getConfig('removeOrganisation') . ';
var populateCounty = ' . $helper->getConfig('requireCounty') . ';
var enabled = ' . $helper->getConfig('enabled') . ';
var customFields = ' . trim(preg_replace("/\r|\n/", "", $helper->getConfig('customFields'))) . ';
// Exit early if disabled
if (enabled === false) return;
window.idpcConfig = {
apiKey: apiKey,
postcodeLookup: false,
autocomplete: autocomplete,
populateCounty: populateCounty,
removeOrganisation: removeOrganisation,
hoistCountry: false,
customFields: customFields
};
window.idpcStart();
});
';

$secureRenderer->renderTag('script', [], $script, false);
?>
<?php if(!isset($secureRenderer)) { ?>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function() {
var apiKey = "<?= $helper->getAdminConfig('api_key') ?>";
var autocomplete = <?= $helper->getAdminConfig('addressAutocomplete') ?>;
var removeOrganisation = <?= $helper->getAdminConfig('removeOrganisation') ?>;
var populateCounty = <?= $helper->getAdminConfig('requireCounty') ?>;
var enabled = <?= $helper->getAdminConfig('enabled') ?>;
var customFields = <?= trim(preg_replace("/\r|\n/", "", $helper->getAdminConfig('customFields'))) ?>;
// Exit early if disabled
if (enabled === false) return;
window.idpcConfig = {
apiKey: apiKey,
postcodeLookup: false,
autocomplete: autocomplete,
populateCounty: populateCounty,
removeOrganisation: removeOrganisation,
hoistCountry: false,
customFields: customFields
};
window.idpcStart();
});
</script>
<?php } else {
echo $secureRenderer->renderTag('script', [], '
document.addEventListener("DOMContentLoaded", function() {
var apiKey = "' . $helper->getAdminConfig('api_key') . '";
var autocomplete = ' . $helper->getAdminConfig('addressAutocomplete') . ';
var removeOrganisation = ' . $helper->getAdminConfig('removeOrganisation') . ';
var populateCounty = ' . $helper->getAdminConfig('requireCounty') . ';
var enabled = ' . $helper->getAdminConfig('enabled') . ';
var customFields = ' . trim(preg_replace("/\r|\n/", "", $helper->getAdminConfig('customFields'))) . ';
// Exit early if disabled
if (enabled === false) return;
window.idpcConfig = {
apiKey: apiKey,
postcodeLookup: false,
autocomplete: autocomplete,
populateCounty: populateCounty,
removeOrganisation: removeOrganisation,
hoistCountry: false,
customFields: customFields
};
window.idpcStart();
});
', false);
}
?>
60 changes: 45 additions & 15 deletions view/frontend/templates/store.phtml
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
<?php
$helper = $this->helper('Idealpostcodes\Ukaddresssearch\Helper\Data');
$script = '
console.log("should be here");
document.addEventListener(\'DOMContentLoaded\', function() {
var apiKey = "' . $helper->getConfig('api_key') . '";
var postcodeLookup = ' . $helper->getConfig('postcodeLookup') . ';
var autocomplete = ' . $helper->getConfig('addressAutocomplete') . ';
var removeOrganisation = ' . $helper->getConfig('removeOrganisation') . ';
var hoistCountry = ' . $helper->getConfig('hoistCountryField') . ';
var populateCounty = ' . $helper->getConfig('requireCounty') . ';
var autocompleteOverride = ' . $helper->getConfig('autocompleteOverride') . ';
var postcodeLookupOverride = ' . $helper->getConfig('postcodeLookupOverride') . ';
var enabled = ' . $helper->getConfig('enabled') . ';
var customFields = ' . trim(preg_replace("/\r|\n/", "", $helper->getConfig('customFields'))) . ';
?>
<?php if(!isset($secureRenderer)) { ?>
<script type="text/javascript" name="Ideal_Postcodes">
document.addEventListener('DOMContentLoaded', function() {
var apiKey = "<?php echo $helper->getConfig('api_key'); ?>";
var postcodeLookup = <?php echo $helper->getConfig('postcodeLookup'); ?>;
var autocomplete = <?php echo $helper->getConfig('addressAutocomplete'); ?>;
var removeOrganisation = <?php echo $helper->getConfig('removeOrganisation'); ?>;
var hoistCountry = <?php echo $helper->getConfig('hoistCountryField'); ?>;
var populateCounty = <?php echo $helper->getConfig('requireCounty'); ?>;
var autocompleteOverride = <?php echo $helper->getConfig('autocompleteOverride'); ?>;
var postcodeLookupOverride = <?php echo $helper->getConfig('postcodeLookupOverride'); ?>;
var enabled = <?php echo $helper->getConfig('enabled'); ?>;
var customFields = <?php echo trim(preg_replace('/\r|\n/', '', $helper->getConfig('customFields'))); ?>;
// Exit early if disabled
if (enabled === false) return;
window.idpcConfig = {
Expand All @@ -28,6 +29,35 @@ document.addEventListener(\'DOMContentLoaded\', function() {
};
window.idpcStart();
});
';
</script>
<?php } else {
echo $secureRenderer->renderTag('script', [], '
document.addEventListener("DOMContentLoaded", function() {
var apiKey = "' . $helper->getConfig('api_key') . '";
var postcodeLookup = ' . $helper->getConfig('postcodeLookup') . ';
var autocomplete = ' . $helper->getConfig('addressAutocomplete') . ';
var removeOrganisation = ' . $helper->getConfig('removeOrganisation') . ';
var hoistCountry = ' . $helper->getConfig('hoistCountryField') . ';
var populateCounty = ' . $helper->getConfig('requireCounty') . ';
var autocompleteOverride = ' . $helper->getConfig('autocompleteOverride') . ';
var postcodeLookupOverride = ' . $helper->getConfig('postcodeLookupOverride') . ';
var enabled = ' . $helper->getConfig('enabled') . ';
var customFields = ' . trim(preg_replace('/\r|\n/', '', $helper->getConfig('customFields'))) . ';
// Exit early if disabled
if (enabled === false) return;
window.idpcConfig = {
apiKey: apiKey,
postcodeLookup: postcodeLookup,
autocomplete: autocomplete,
populateCounty: populateCounty,
removeOrganisation: removeOrganisation,
hoistCountry: hoistCountry,
autocompleteOverride: autocompleteOverride,
postcodeLookupOverride: postcodeLookupOverride,
customFields: customFields
};
window.idpcStart();
});
', false);
}
?>
<?= /* @noEscape */ $secureRenderer->renderTag('script', ['type' => 'text/javascript', 'id' => 'idpc-config'], $script, false); ?>

0 comments on commit 2ca2fe1

Please sign in to comment.