Skip to content

Commit

Permalink
Update integration script (#14)
Browse files Browse the repository at this point in the history
* Update integration script to match the new guidelines
* Push metadata separately using new functions
  • Loading branch information
renato-bylyk authored and ioannis-papikas committed Feb 28, 2019
1 parent d8e0793 commit 037531c
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 57 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG-1.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ in all versions (major and minor)
To get the diff for a specific change, go to https://github.com/esatisfaction/esat-prestashop/commit/XXX where
XXX is the change hash

* 1.0.3 (future-release)
* Update the integration script to match the latest (25th February, 2019) e-satisfaction integration guidelines.
* 1.0.2 (2019-01-17)
* Include send_time as variable on api calls, if necessary
* 1.0.1 (2018-09-13)
Expand Down
19 changes: 1 addition & 18 deletions esatisfaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ public function __construct()

/**
* Install module and register it for hooks displayOrderConfirmation,
* actionOrderStatusPostUpdate, displayHeader,
* displayBackOfficeHeader, displayBeforeBodyClosingTag
* actionOrderStatusPostUpdate, displayHeader, displayBackOfficeHeader
*
* @author e-satisfaction SA
* @copyright (c) 2018, e-satisfaction SA
Expand All @@ -69,7 +68,6 @@ public function install()
return parent::install() &&
$this->registerHook('displayOrderConfirmation') &&
$this->registerHook('actionOrderStatusPostUpdate') &&
$this->registerHook('displayBeforeBodyClosingTag') &&
$this->registerHook('displayBackOfficeHeader') &&
$this->registerHook('displayHeader');
}
Expand Down Expand Up @@ -478,21 +476,6 @@ public function hookDisplayOrderConfirmation($params)
return $this->display(__FILE__, 'checkout.tpl');
}

/**
* Display footer
*
* @author e-satisfaction SA
* @copyright (c) 2018, e-satisfaction SA
*
* @param array $params
*
* @return string
*/
public function hookDisplayBeforeBodyClosingTag($params)
{
return $this->display(__FILE__, 'footer.tpl');
}

/**
* Add script in header
*
Expand Down
28 changes: 10 additions & 18 deletions views/templates/hook/checkout.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,17 @@
<!-- E-sat order confirmation code -->
{literal}
<script>
window.esat_config = {
application_id: "{/literal}{$app_id}{literal}",
collection: {
"{/literal}{$checkout_quest_id}{literal}": {
'questionnaire_id': "{/literal}{$checkout_quest_id}{literal}",
'metadata' : {
'responder' : {
'email': "{/literal}{$customer_email}{literal}",
'phone_number': "{/literal}{$customer_phone}{literal}"
},
'questionnaire' : {
'transaction_id': "{/literal}{$order_id}{literal}",
'transaction_date': "{/literal}{$order_date}{literal}",
'store_pickup': {/literal}{$is_store_pickup}{literal}
}
}
Esat.updateMetadata("{/literal}{$checkout_quest_id}{literal}", {
responder: {
"email": "{/literal}{$customer_email}{literal}",
"phone_number": "{/literal}{$customer_phone}{literal}"
},
questionnaire: {
"transaction_id": "{/literal}{$order_id}{literal}",
"transaction_date": "{/literal}{$order_date}{literal}",
"store_pickup": {/literal}{$is_store_pickup}{literal}
}
}
};
});
</script>
{/literal}
<div id="esat-checkout-questionnaire-container"></div>
Expand Down
18 changes: 0 additions & 18 deletions views/templates/hook/footer.tpl

This file was deleted.

22 changes: 19 additions & 3 deletions views/templates/hook/header.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,25 @@
<!-- E-sat header code -->
{literal}
<script>
window.esat_config = {
application_id: "{/literal}{$app_id}{literal}"
};
(function (win, doc, application_id, jq, collection) {
// Define e-satisfaction collection configuration
win.esat_config = {application_id: application_id, collection: collection || {}};

// Update metadata
win.Esat = win.Esat || {};
win.Esat.updateMetadata = function (questionnaireId, metadata) {
win.esat_config.collection[questionnaireId] = win.esat_config.collection[questionnaireId] || {};
win.esat_config.collection[questionnaireId].metadata = metadata;
};

// Setup script
doc.addEventListener('DOMContentLoaded', function () {
var body = doc.getElementsByTagName('body')[0], script = doc.createElement('script');
script.async = true;
script.src = 'https://collection.e-satisfaction.com/dist/js/integration' + (!!jq ? '' : '.jq') + '.min.js';
body.appendChild(script);
});
})(window, document, "{/literal}{$app_id}{literal}", false, {});
</script>
{/literal}
<!-- /E-sat header code -->

0 comments on commit 037531c

Please sign in to comment.