]> _ Git - fluidbook-html5.git/commitdiff
wip #6889 @3
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 7 May 2024 16:54:29 +0000 (18:54 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 7 May 2024 16:54:29 +0000 (18:54 +0200)
js/libs/fluidbook/cart/fluidbook.cart.bastide-resah.js
js/libs/fluidbook/fluidbook.stats.js

index c971bb8c355d531776a3dbee4ffbb6b5c5d91d17..677f9d1bbe16df2229535faadb0e97c83a899871 100644 (file)
@@ -3,6 +3,8 @@ function FluidbookCartBastideResah(cart) {
     this.fluidbook = this.cart.fluidbook;
     this.data = this.fluidbook.settings.basketReferences;
     this.form_endpoint = this.fluidbook.service.getBaseURL() + 'bastide'; // Where cart form is processed
+    this.matomo_items = [];
+    this.matomo_total = 0;
     this.init();
 }
 
@@ -31,23 +33,28 @@ FluidbookCartBastideResah.prototype = {
         $(document).on(this.fluidbook.input.clickEvent, '#Bastide_cart [data-validate-cart]', function (event) {
             event.preventDefault();
 
+            $this.updateCart();
+
             $.ajax('/fluidbook/order', {
-                method: 'POST',
-                data: {details: $this.getItems()},
+                method: 'POST', data: {details: $this.getItems()},
             }).done(function (data) {
-                $this.fluidbook.stats.trackEcommerceOrder(data.order, data.total);
+                $this.fluidbook.stats.trackEcommerceOrder($this.matomo_items, data.order, data.total, data.subTotal, data.taxes);
             });
 
             $this.fluidbook.menu.quickCloseView();
-            $this.openModal("Merci !", '<div class="cart-sent">Vous recevrez un devis ainsi que les conditions générales de vente de la part du RESAH à l’adresse mail que vous avez mentionnée dans un délai d’environ 72h (pensez à vérifier votre dossier spam).<br><br>' +
-                'La validation de ce devis auprès du RESAH nécessitera l’établissement et l’envoi au RESAH d’un bon de commande valant pour acceptation pleine et entière.<br><br>' +
-                'Nos équipes commerciales se tiennent à votre disposition : <a href="mailto:resah@bastide-medical.fr">resah@bastide-medical.fr</a></div>', function () {
-
+            $this.openModal("Merci !", '<div class="cart-sent">Vous recevrez un devis ainsi que les conditions générales de vente de la part du RESAH à l’adresse mail que vous avez mentionnée dans un délai d’environ 72h (pensez à vérifier votre dossier spam).<br><br>' + 'La validation de ce devis auprès du RESAH nécessitera l’établissement et l’envoi au RESAH d’un bon de commande valant pour acceptation pleine et entière.<br><br>' + 'Nos équipes commerciales se tiennent à votre disposition : <a href="mailto:resah@bastide-medical.fr">resah@bastide-medical.fr</a></div>', function () {
             });
-
         });
     },
 
+    getCartItemsForMatomo: function () {
+        return this.matomo_items;
+    },
+
+    getCartTotalForMatomo: function () {
+        return this.matomo_total;
+    },
+
 
     getCartItemIndex: function (reference) {
         let cartItems = this.getItems();
@@ -80,6 +87,7 @@ FluidbookCartBastideResah.prototype = {
         return true;
     },
 
+
     removeFromCart: function (index) {
         if (index >= 0) {
             this.items.splice(index, 1);
@@ -90,6 +98,10 @@ FluidbookCartBastideResah.prototype = {
     save: function () {
         this.fluidbook.cache.set('cart', this.getItems());
         this.updateIcon();
+        if (this.fluidbook.stats.isMatomoEnabled()) {
+            this.updateCart();
+            this.fluidbook.stats.matomoCartUpdate(this.matomo_items, this.matomo_total);
+        }
         //this.fluidbook.cart.updateLinks();
     },
 
@@ -114,8 +126,9 @@ FluidbookCartBastideResah.prototype = {
     },
 
     updateCart: function () {
+        let content = this.getCartContent();
         if ($('#Bastide_cart').length > 0) {
-            $('#Bastide_cart .content').html(this.getCartContent());
+            $('#Bastide_cart .content').html(content);
             this.fluidbook.resize.resize();
         }
     },
@@ -177,7 +190,15 @@ FluidbookCartBastideResah.prototype = {
         return $('.cart-sent').length > 0 ? 440 : 1385;
     },
 
+    emptyCart: function () {
+        this.items = [];
+        this.save();
+    },
+
     getCartContent: function () {
+        this.matomo_items = [];
+        this.matomo_total = 0;
+
         if (this.getItemCount() === 0) {
             return `<div class="cart-empty">${this.fluidbook.l10n.__('your cart is empty')}</div>`;
         }
@@ -202,6 +223,7 @@ FluidbookCartBastideResah.prototype = {
                </thead>
                <tbody>`;
 
+
         $.each(this.getItems(), function (index, item) {
 
             content += '<tr>';
@@ -211,6 +233,8 @@ FluidbookCartBastideResah.prototype = {
             let pvht = $this.parseFloat($this.data[item.reference]['PV RESAH HT']);
             let tht = q * (pvht + et);
 
+            let matomo_item = {categories: [], price: pvht, quantity: q, reference: item.reference};
+
             total_ht += tht;
             eco_taxe += item.quantity * et;
             tva += $this.parseFloat($this.data[item.reference]['TVA']) * tht * 0.01;
@@ -257,6 +281,10 @@ FluidbookCartBastideResah.prototype = {
                                     ${getSpriteIcon('interface-close')}
                                  </a>`;
                         break;
+                    case 'DESIGNATION':
+                        output = value;
+                        matomo_item.name = value;
+                        break;
                     default:
                         output = value;
                 }
@@ -266,15 +294,20 @@ FluidbookCartBastideResah.prototype = {
                 content += `<td data-name="${key}" data-label="${title}">${output}</td>`;
             });
 
+
+            $this.matomo_items.push(matomo_item);
+
             content += '</tr>';
         });
 
+
         total_ttc = tva + total_ht;
 
+        this.matomo_total = total_ht;
+
         content += '</tbody>';
         content += '</table>';
 
-
         content += '</form>';
 
         content += '<hr>';
@@ -299,9 +332,7 @@ FluidbookCartBastideResah.prototype = {
 
         content += '<div class="clear"></div>'
 
-        content += '<p class="legal">Ce portail vous permet d’obtenir un document quantitatif estimatif.<br>'
-            + 'Vous recevrez un devis ainsi que les conditions générales de vente de la part du RESAH à l’adresse mail que vous avez mentionné dans un délai d’environ 72H.<br>' + 'La validation de ce devis auprès du RESAH nécessitera l’établissement et l’envoi au RESAH d’un bon de commande valant pour acceptation pleine et entière.<br>'
-            + 'Nos équipes commerciales se tiennent à votre disposition : <a href="mailto:resah@bastide-medical.fr">resah@bastide-medical.fr</a></p>';
+        content += '<p class="legal">Ce portail vous permet d’obtenir un document quantitatif estimatif.<br>' + 'Vous recevrez un devis ainsi que les conditions générales de vente de la part du RESAH à l’adresse mail que vous avez mentionné dans un délai d’environ 72H.<br>' + 'La validation de ce devis auprès du RESAH nécessitera l’établissement et l’envoi au RESAH d’un bon de commande valant pour acceptation pleine et entière.<br>' + 'Nos équipes commerciales se tiennent à votre disposition : <a href="mailto:resah@bastide-medical.fr">resah@bastide-medical.fr</a></p>';
         content += '</div><!-- .inner-content -->';
 
         return content;
index a9bdfa37eb9c2645668c9942e9e6ed4aa7adb72b..6347934459d4a5f2c64af93e2813145055cf3401 100644 (file)
@@ -1,6 +1,7 @@
 function FluidbookStats() {
     this.hasMatomoTagManager = this.setupMatomoTagManager();
     this.pixel_pv_id;
+    this.matomo_stack = [];
     this.setupMatomo();
 }
 
@@ -148,7 +149,25 @@ FluidbookStats.prototype = {
                 break;
             case 15://
                 this.matomoPush(['trackEvent', 'cart', 'addproduct', extra]);
-                this.matomoPush(['setEcommerceView', extra]);
+                break;
+        }
+    },
+
+    matomoCartUpdate: function (items, total) {
+        this.matomoSetCartItems(items);
+        _paq.push(['trackEcommerceCartUpdate', total]);
+    },
+
+    matomoSetCartItems: function (items) {
+        for (var i in items) {
+            let item = items[i];
+            this.matomoPush(['addEcommerceItem',
+                item.reference, // (Required) productSKU
+                item.name, // (Optional) productName
+                item.categories, // (Optional) productCategory
+                item.price, // (Recommended) price
+                item.quantity
+            ]);
         }
     },
 
@@ -210,10 +229,29 @@ FluidbookStats.prototype = {
     },
 
     matomoPush(data) {
+
+        let stack = data[0] === 'addEcommerceItem';
+        if (stack) {
+            this.matomo_stack.push(data);
+            return;
+        }
+
         for (let i in this.matomoServers) {
             let dataCopy = data.slice(0);
+            if (this.matomo_stack.length > 0) {
+                for (let j in this.matomo_stack) {
+                    let copy = this.matomo_stack[j].slice(0);
+                    this.matomoPushToServer(copy, this.matomoServers[i]);
+                }
+            }
             this.matomoPushToServer(dataCopy, this.matomoServers[i]);
         }
+
+        this.matomo_stack = [];
+    },
+
+    isMatomoEnabled: function () {
+        return this.matomoServers.length > 0;
     },
 
     setup: function (fluidbook) {
@@ -458,8 +496,9 @@ FluidbookStats.prototype = {
         }
     },
 
-    trackEcommerceOrder: function (orderId, total) {
-        this.matomoPush(['trackEcommerceOrder', orderId, total]);
+    trackEcommerceOrder: function (items, orderId, total, subTotal, taxes) {
+        this.matomoSetCartItems(items);
+        this.matomoPush(['trackEcommerceOrder', orderId, total, subTotal, taxes]);
     },
 
     trackGoogleAnalytics: function (type, page, extra, url) {