Skip to content

Commit

Permalink
Unique Script (#216)
Browse files Browse the repository at this point in the history
* Unique Script

* added plugin version to payload
  • Loading branch information
eduardogomez97 authored Jun 4, 2024
1 parent c35aa64 commit 2df7c32
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
5 changes: 3 additions & 2 deletions doofinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ class Doofinder extends Module
const DOOMANAGER_URL = 'https://admin.doofinder.com';
const GS_SHORT_DESCRIPTION = 1;
const GS_LONG_DESCRIPTION = 2;
const VERSION = '4.7.35';
const VERSION = '4.8.0';
const YES = 1;
const NO = 0;

public function __construct()
{
$this->name = 'doofinder';
$this->tab = 'search_filter';
$this->version = '4.7.35';
$this->version = '4.8.0';
$this->author = 'Doofinder (http://www.doofinder.com)';
$this->ps_versions_compliancy = ['min' => '1.5', 'max' => _PS_VERSION_];
$this->module_key = 'd1504fe6432199c7f56829be4bd16347';
Expand Down Expand Up @@ -1686,6 +1686,7 @@ public function createStore($shop)
'primary_language' => $primary_lang->language_code,
'site_url' => $shop_url,
'search_engines' => [],
'plugin_version' => $this->version,
];

foreach ($languages as $lang) {
Expand Down
38 changes: 19 additions & 19 deletions views/templates/front/scriptV9.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,45 +12,45 @@
* @license GPLv3
*}
{if isset($installation_ID) && $installation_ID}
<!-- START OF DOOFINDER SCRIPT -->
<!-- START OF DOOFINDER ADD TO CART SCRIPT -->
<script>
const dfLayerOptions = {
installationId: "{$installation_ID|escape:'htmlall':'UTF-8'}",
zone: "{$df_region|escape:'htmlall':'UTF-8'}",
language: "{$lang|escape:'htmlall':'UTF-8'}",
currency: "{$currency|escape:'htmlall':'UTF-8'}"
};
(function (l, a, y, e, r, s) {
r = l.createElement(a); r.onload = e; r.async = 1; r.src = y;
s = l.getElementsByTagName(a)[0]; s.parentNode.insertBefore(r, s);
})(document, 'script', 'https://cdn.doofinder.com/livelayer/1/js/loader.min.js', function () {
doofinderLoader.load(dfLayerOptions);
});
document.addEventListener('doofinder.cart.add', function(event) {
const checkIfCartItemHasVariation = (cartObject) => {
return (cartObject.item_id === cartObject.grouping_id) ? false : true;
};
}
/**
* Returns only ID from string
*/
const sanitizeVariationID = (variationID) => {
return variationID.replace(/\D/g, "")
};
}
doofinderManageCart({
cartURL : "{if isset($urls)}{$urls.pages.cart|escape:'htmlall':'UTF-8'}{/if}", /* required for prestashop 1.7, in previous versions it will be empty. */
cartURL : "{if isset($urls)}{$urls.pages.cart|escape:'htmlall':'UTF-8'}{/if}", //required for prestashop 1.7, in previous versions it will be empty.
cartToken : "{$static_token|escape:'htmlall':'UTF-8'}",
productID : checkIfCartItemHasVariation(event.detail) ? event.detail.grouping_id : event.detail.item_id,
customizationID : checkIfCartItemHasVariation(event.detail) ? sanitizeVariationID(event.detail.item_id) : 0, /* If there are no combinations, the value will be 0 */
customizationID : checkIfCartItemHasVariation(event.detail) ? sanitizeVariationID(event.detail.item_id) : 0, // If there are no combinations, the value will be 0
quantity : event.detail.amount,
statusPromise : event.detail.statusPromise,
itemLink : event.detail.link,
group_id : event.detail.group_id
});
});
</script>
<!-- END OF DOOFINDER SCRIPT -->
<!-- END OF DOOFINDER ADD TO CART SCRIPT -->

<!-- START OF DOOFINDER UNIQUE SCRIPT -->
<script data-keepinline>
{literal}
(function(w, k) {w[k] = window[k] || function () { (window[k].q = window[k].q || []).push(arguments) }})(window, "doofinderApp")
{/literal}
// Custom personalization:
doofinderApp("config", "language", "{$lang|escape:'htmlall':'UTF-8'}");
doofinderApp("config", "currency", "{$currency|escape:'htmlall':'UTF-8'}");
</script>
<script src="https://{$df_region|escape:'htmlall':'UTF-8'}-config.doofinder.com/2.x/{$installation_ID|escape:'htmlall':'UTF-8'}.js" async></script>
<!-- END OF DOOFINDER UNIQUE SCRIPT -->
{/if}

0 comments on commit 2df7c32

Please sign in to comment.