]> _ Git - fluidbook-html5.git/commitdiff
wip #3828 @6
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 3 Sep 2020 16:39:49 +0000 (18:39 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 3 Sep 2020 16:39:49 +0000 (18:39 +0200)
_index.html
js/libs/fluidbook/cart/fluidbook.cart.mopec.js
js/libs/fluidbook/fluidbook.cart.js
js/libs/fluidbook/fluidbook.js
js/libs/fluidbook/fluidbook.menu.js
js/libs/fluidbook/links/fluidbook.links.zoom.js

index 17d7f920bccbc4fe03bf5c2b23a77ebca162996c..5ce8c44c6f3a4ade9061a226bb5d22c39d82cd74 100644 (file)
 <div id="searchHints"></div>
 <div id="viewOverlay" aria-hidden="true"></div>
 <div id="view" aria-hidden="true"></div>
-<div id="innerView" aria-hidden="tr ue"></div>
+<div id="innerView" aria-hidden="true"></div>
 <div id="pagesContents" aria-hidden="true"><!-- $pagesContents --></div>
 <div id="op" aria-hidden="true"></div>
 <div id="ol" aria-hidden="true"></div>
index b9225628a5bf3fbec46a436d957651f78274db24..44782f34b08f22961b22ae280fd7d69f70c0a9a3 100644 (file)
@@ -6,10 +6,14 @@ function FluidbookCartMopec(cart) {
     this.data;
     this.handleTooltips = true;
     this.handleTaxes = false;
+    this.initBaseURL();
     this.init();
 }
 
 FluidbookCartMopec.prototype = {
+    initBaseURL: function () {
+        this.baseURL = window.location.protocol + '//' + window.location.host + '/' + this.fluidbook.l10n.currentLang + '/';
+    },
     updateCartData: function (callback) {
         var $this = this;
         this.sendCookie();
@@ -36,8 +40,9 @@ FluidbookCartMopec.prototype = {
 
     init: function () {
         var $this = this;
+
         $(document).on('change', '[data-menu="cart"] .input-number', function () {
-            $this.updateCartFromQuantities();
+            $this.updateCartFromQuantities(this);
             return true;
         });
 
@@ -57,64 +62,72 @@ FluidbookCartMopec.prototype = {
             });
         });
 
-        this.baseURL = 'http://www.mopec.es/' + this.fluidbook.l10n.currentLang + '/';
+
     },
     addToCart: function (ref, quantity) {
         var $this = this;
         this.fluidbook.displayLoader();
-        if (quantity == undefined) {
+        if (quantity === undefined) {
             quantity = 1;
         }
 
+        this.getProductIDBySKU(ref, function (product_id) {
+            $.ajax({
+                url: $this.baseURL + 'checkout/cart/add',
+                cache: false,
+                data: {product: product_id, qty: quantity, form_key: $this.getFormKey()},
+                method: 'post',
+                xhrFields: {withCredentials: true},
+                dataType: 'json',
+                success: function (data) {
+                    if (data.backUrl) {
+                        $this.fluidbook.hideLoader();
+                        $this.fluidbook.openInPopupIframe(data.backUrl);
+                    } else {
+                        $this.fluidbook.tooltip.displayTooltip($this.fluidbook.l10n.__("the item has been added to your cart"), 'invert');
+                        $this.fluidbook.hideLoader();
+                        $this.updateCartData(function () {
+
+                        });
+                    }
+                }
+            });
+        });
+
+        return false;
+
+    },
+
+    getProductIDBySKU: function (sku, callback) {
         $.ajax({
-            url: 'https://www.remarkable.fr/boutique/com_act.cfm?code_lg=lg_fr&idsite=1',
+            url: this.baseURL + 'fastorder/index/search',
             cache: false,
-            data: {ref: ref, qte: quantity, ref_fille: '', radio_bloc: 'on'},
+            data: {product: sku, sort_order: 0},
             method: 'post',
             xhrFields: {withCredentials: true},
+            dataType: 'json',
             success: function (data) {
-                var alert = $(data).find('#texte_message_alert').text();
-                if (alert !== '') {
-                    $this.fluidbook.tooltip.displayTooltip($(data).find('#texte_message_alert').text(), 'error');
-                } else {
-                    $this.fluidbook.tooltip.displayTooltip($this.fluidbook.l10n.__("the item has been added to your cart"), 'invert');
-                }
-                $this.fluidbook.hideLoader();
-                $this.updateCartData(function () {
-
-                });
-
+                var product_id = data[0].product_id;
+                callback(product_id);
             }
-        })
-        return false;
-
+        });
     },
 
     sendCookie: function () {
-        // $.cookie("fsremarkablefr=4lnqzxer2votqppqbw6", 1, {
-        //     expires: 10,
-        //     path: '/',
-        //     domain: 'remarkable.fr',
-        //     secure: true
-        // });
     },
 
-    removeFromCart: function (ref, callback) {
+    removeFromCart: function (item_id, callback) {
         var $this = this;
         this.fluidbook.displayLoader();
-        this.data.find('item reference').each(function () {
-            if ($(this).text() === ref) {
-                $.ajax({
-                    url: 'https://www.remarkable.fr/boutique/com_act.cfm?ModeEdit=delete&line=' + $(this).closest('item').attr('id'),
-                    xhrFields: {withCredentials: true},
-                    success: function () {
-                        $this.fluidbook.hideLoader();
-                        $this.updateCartData(callback);
-                    }
-                })
-                return true;
+        $.ajax({
+            url: $this.baseURL + 'checkout/sidebar/removeItem',
+            method: 'post',
+            data: {item_id: item_id, form_key: this.getFormKey()},
+            xhrFields: {withCredentials: true},
+            success: function () {
+                $this.updateCartData(callback);
             }
-        });
+        })
     },
     getItemsNumbers: function () {
         return this.data.summary_count;
@@ -126,18 +139,8 @@ FluidbookCartMopec.prototype = {
         });
         return res;
     },
-    hasItem: function (itemReference) {
-        var res = false;
-        this.data.find('item reference').each(function () {
-            if ($(this).text() == itemReference) {
-                res = true;
-                return true;
-            }
-        });
-        return res;
-    },
+
     updateIcon: function () {
-        //$(this.fluidbook).trigger('fluidbook.cart.updateIcon', {number: this.getAllQuantities()});
         $(this.fluidbook).trigger('fluidbook.cart.updateIcon', {number: this.getItemsNumbers()});
     },
 
@@ -163,18 +166,17 @@ FluidbookCartMopec.prototype = {
         var content = '<table class="cart-items">';
         var totalht = 0;
         $.each(this.data.items, function (index, item) {
-            var ref = item.product_sku;
             var qty = $this.parseInt(item.qty);
             var unit = $this.parseFloat(item.product_price_value);
             var ht = unit * qty;
 
             content += '<tr>';
-            content += '<td class="name">' + item.product_name + '<div class="m">Prix unitaire: ' + $this.formatPrice(unit);
-            content += '<br />Prix : ' + $this.formatPrice(ht, 'HT') + '</div></td>';
-            content += '<td class="quantity"><input name="' + ref + '" class="cartqty" type="number" min="0" max="10000" value="' + qty + '" step="1" /></td>';
+            content += '<td class="name">' + item.product_name + '<div class="m">' + $this.fluidbook.l10n.__('unit price') + ': ' + $this.formatPrice(unit);
+            content += '<br />' + $this.fluidbook.l10n.__('price') + ': ' + $this.formatPrice(ht) + '</div></td>';
+            content += '<td class="quantity"><input name="' + item.item_id + '" class="cartqty" type="number" min="0" max="10000" value="' + qty + '" step="1" /></td>';
             content += '<td class="price_unit">' + $this.formatPrice(unit) + '</td>';
             content += '<td class="price_excluding_taxes">' + $this.formatPrice(ht) + '</td>';
-            content += '<td class="delete"><a href="#" data-cart-delete="' + ref + '">' + getSpriteIcon('interface-close') + '</a></td>';
+            content += '<td class="delete"><a href="#" data-cart-delete="' + item.item_id + '">' + getSpriteIcon('interface-close') + '</a></td>';
             content += '</tr>';
 
             totalht += ht;
@@ -183,51 +185,43 @@ FluidbookCartMopec.prototype = {
         content += '</table>';
         content += '<table class="cart-totals">';
         content += '<tr><td colspan="2" class="hr"></td></tr>';
-        content += '<tr class="total"><td>Total</td><td>' + $this.formatPrice(this.data.subtotalAmount) + '</td></tr>';
+        content += '<tr class="total"><td>' + $this.fluidbook.l10n.__('total') + '</td><td>' + $this.formatPrice($this.parseFloat(this.data.subtotalAmount)) + '</td></tr>';
         content += '</table>';
 
         content += '<div class="cart-footer">';
-        content += '<div class="fonctions"><a href="#/closeview" class="back">Continuer mes achats</a><a href="https://www.remarkable.fr/boutique/panierb.cfm' + aff + '" target="_blank">Valider</a></div>';
+        content += '<div class="fonctions"><a href="#/closeview" class="back">' + $this.fluidbook.l10n.__('continue shopping') + '</a><a href="' + this.baseURL + 'checkout/cart" target="_blank">' + $this.fluidbook.l10n.__('proceed to checkout') + '</a></div>';
         content += '</div>';
 
         return content;
     },
 
-    updateCartFromQuantities: function () {
-        var $this = this;
-        var data = {ModeEdit: 'update'};
-        var i = 1;
-
-        var del = '';
-        $(".cartqty").each(function () {
-            var v = parseInt($(this).val());
-            if (v === 0) {
-                del = $(this).attr('name');
-                return true;
-            }
-            data['Item_' + i] = v;
-            i++;
-        });
+    getFormKey: function () {
+        return $.cookie('form_key');
+    },
 
-        if (del != '') {
-            this.removeFromCart(del, function () {
+    updateCartFromQuantities: function (el) {
+        var $this = this;
+        var input = $(el).find('input.cartqty');
+        var item_id = $(input).attr('name');
+        var newVal = $this.parseInt($(input).val());
 
+        if (newVal === 0) {
+            this.removeFromCart(item_id, function () {
             });
-            return;
+        } else {
+            this.fluidbook.displayLoader();
+            $.ajax({
+                url: $this.baseURL + 'checkout/cart/updateItemOptions/id/' + item_id,
+                method: "post",
+                data: {item: item_id, qty: newVal, form_key: this.getFormKey()},
+                xhrFields: {withCredentials: true},
+                success: function () {
+                    $this.updateCartData(function () {
+
+                    });
+                }
+            })
         }
-
-        this.fluidbook.displayLoader();
-        $.ajax({
-            url: 'https://www.remarkable.fr/boutique/com_act.cfm?pay=35&code_lg=lg_fr',
-            method: "post",
-            data: data,
-            xhrFields: {withCredentials: true},
-            success: function () {
-                $this.updateCartData(function () {
-
-                });
-            }
-        })
     },
 
     updateCart: function () {
@@ -262,11 +256,23 @@ FluidbookCartMopec.prototype = {
     },
 
     parseFloat: function (s) {
+        if (typeof s === 'number') {
+            return s;
+        }
+        if (s === undefined || s === null || s === '') {
+            return 0;
+        }
         s = s.replace(/\s/g, '');
         return parseFloat(s);
     },
 
     parseInt: function (s) {
+        if (typeof s === 'number') {
+            return Math.round(s);
+        }
+        if (s === undefined || s === null || s === '') {
+            return 0;
+        }
         s = s.replace(/\s/g, '');
         return parseInt(s);
     },
index 8f0c72c91a680850b5531797bada52d8d3d2b33d..3324e37836f352d88124507f1307a0755ca26794 100644 (file)
@@ -22,7 +22,7 @@ FluidbookCart.prototype = {
 
         $(document).on('click', '[data-cart-ref]', function () {
             var qty = 1;
-            if ($(this).attr('data-cart-qty') !== null) {
+            if ($(this).data('cart-qty') !== null) {
                 qty = parseInt($(this).attr('data-cart-qty'));
             }
 
index 5b6e4ac0fa07a5171607d6c2e7ee06fdae9474e3..5728e5116fa3c19cf53d3759e9cf6d8fdad8efb5 100644 (file)
@@ -391,7 +391,7 @@ Fluidbook.prototype = {
             }
         }
 
-        $(this).trigger('fluidbook.hashchange',[args.slice()]);
+        $(this).trigger('fluidbook.hashchange', [args.slice()]);
 
         if (args[1] === 'closeview') {
             return this.setCurrentPage(this.currentPage);
@@ -945,6 +945,7 @@ Fluidbook.prototype = {
             win = window;
         }
 
+        console.log('target');
 
         if (target == undefined) {
             target = '_self';
@@ -991,6 +992,10 @@ Fluidbook.prototype = {
             replace = undefined;
         }
         // Open the window
+        if (mtarget === '_popupiframe') {
+            $this.openInPopupIframe(url);
+            return false;
+        }
         var w;
         if (options == undefined && replace == undefined) {
             if (this.support.IE == 0) {
@@ -1018,6 +1023,14 @@ Fluidbook.prototype = {
         return w;
     },
 
+    openInPopupIframe: function (url, callback) {
+        this.menu.openView('freeiframe', url, '', function () {
+            if (callback !== undefined) {
+                callback();
+            }
+        });
+    },
+
     setFlag: function (name, value) {
         if (value === undefined) {
             value = true;
index 989789453f3c8a9101e9e754687fb62a8192d98f..b6d08269bac4200eb1c06600a8be7d2423e35523 100644 (file)
@@ -105,6 +105,8 @@ FluidbookMenu.prototype = {
             this.openSlideshow(param1, cb);
         } else if (view === 'iframe') {
             this.openIframe(param1, cb);
+        } else if (view === 'freeiframe') {
+            this.openFreeiframe(param1, cb);
         } else if (view === 'search') {
             this.openSearch(param1, cb);
         } else if (view === 'print') {
@@ -157,7 +159,7 @@ FluidbookMenu.prototype = {
         }, 420);
     },
 
-    viewWrap: function (content, menu, attributes, cls,replace) {
+    viewWrap: function (content, menu, attributes, cls, replace) {
         if (attributes === undefined) {
             attributes = '';
         }
@@ -165,9 +167,9 @@ FluidbookMenu.prototype = {
             cls = '';
         }
         var res = '<div class="mview ' + cls + '" data-menu="' + menu + '" role="dialog" aria-labelledby="mview-dialog-title"' + attributes + '>' + content + '</div>';
-        if(replace===true){
+        if (replace === true) {
             $("#view").html(res);
-        }else {
+        } else {
             $("#view").append(res);
         }
     },
@@ -222,24 +224,22 @@ FluidbookMenu.prototype = {
         }
     },
 
-    openIframe: function (iframe, callback) {
+    openFreeiframe: function (url, callback) {
+        var markup = '<div class="iframeContainer" data-type="free">';
+        markup += '<iframe src="' + url + '" width="100%" height="100%" frameborder="0" marginwidth="0" marginheight="0" scrolling="auto" allowfullscreen mozallowfullscreen="true" webkitallowfullscreen="true" onmousewheel=""></iframe>';
+        markup += '</div>';
+        this._openiframe(markup, '', callback);
+    },
+
+    _openiframe: function (markup, maxWidth, callback) {
+
         var $this = this;
-        var href = '#/iframe/' + iframe;
-        var a = $('a[href="' + href + '"]');
-        if ($(a).length === 0) {
-            a = this.fluidbook.links.getLinkByHref(href);
-        }
-        var markup = decodeURIComponent($(a).attr('data-iframe'));
+
         var view = this.getCaption();
         view += '<div class="content noscroll"><div class="iframeHolder">';
         view += markup;
         view += '</div></div>';
 
-        var maxWidth = '';
-        if ($(a).data('max-width')) {
-            maxWidth = ' data-max-width="' + $(a).data('max-width') + '"';
-        }
-
         this.viewWrap(view, 'iframe', maxWidth + ' dir="ltr"');
         if (callback != undefined) {
             callback();
@@ -259,6 +259,21 @@ FluidbookMenu.prototype = {
         });
     },
 
+    openIframe: function (iframe, callback) {
+        var href = '#/iframe/' + iframe;
+        var a = $('a[href="' + href + '"]');
+        if ($(a).length === 0) {
+            a = this.fluidbook.links.getLinkByHref(href);
+        }
+        var markup = decodeURIComponent($(a).attr('data-iframe'));
+
+        var maxWidth = '';
+        if ($(a).data('max-width')) {
+            maxWidth = ' data-max-width="' + $(a).data('max-width') + '"';
+        }
+        this._openiframe(markup, maxWidth, callback);
+    },
+
     openVideo: function (video, callback) {
         var a = $('a[href="#/video/' + video + '"]');
         var markup = decodeURIComponent($(a).attr('data-video'));
index 05d5ca0e03d63ecbf8767d7d1dd40d6d94353cd5..33e4f76328008a23446f523d2e089e9686e6c55e 100644 (file)
@@ -171,8 +171,14 @@ FluidbookLinksZoom.prototype = {
 
                 for (var i = from; increment === 1 ? i <= to : i >= to; i += increment) {
                     var data = zoomLink.data('d-' + i);
-                    if (data !== undefined) {
-                        var j = i + 1;
+
+                    var j = i + 1;
+                    var action = $this.fluidbook.settings['product_zoom_action_' + j];
+                    
+                    if (!action) {
+                        action = 'link';
+                    }
+                    if (data !== undefined || action === 'addtocart') {
                         var label = $this.fluidbook.settings['product_zoom_label_' + j];
                         var icon = getSpriteIcon($this.fluidbook.settings['product_zoom_icon_' + j]) !== 'none' ? getSpriteIcon($this.fluidbook.settings['product_zoom_icon_' + j]) : '';
                         var linkClass = "";
@@ -182,31 +188,27 @@ FluidbookLinksZoom.prototype = {
                             linkClass = " nolabel";
                         }
 
-                        var action = $this.fluidbook.settings['product_zoom_action_' + j];
-                        if (!action) {
-                            action = 'link';
-                        }
-
-                        if (!data) {
-                            continue;
-                        }
-
                         menu += '<a ';
                         if (action === 'video' && data.indexOf('http') === 0) {
                             action = 'link';
                         }
-
-                        if (action === 'link') {
+                        if (action === 'link' || action === 'iframe') {
                             var l = $this.getLink(data);
                             if (l !== undefined) {
+                                if (action === 'iframe') {
+                                    l.target = '_popupiframe';
+                                }
                                 menu += 'href="' + l.url + '"  target="' + l.target + '"';
                                 linkClass += ' ext';
+
                             }
                         } else if (action === 'copy') {
                             menu += 'data-clipboard-text="' + escapeHtml(data) + '" ';
                         } else if (action === 'video') {
                             var e = data.split(':', 2);
                             menu += ' href="#/webvideo/' + e[0] + '/' + e[1] + '" ';
+                        } else if (action === 'addtocart') {
+                            menu += ' href="#" data-cart-ref="' + $(zoomLink).data('group') + '" ';
                         }
                         menu += 'data-tooltip="' + $this.fluidbook.settings['product_zoom_tooltip_' + j] + '" class="button ' + linkClass + '">' + icon + label + '</a>';
                     }