]> _ Git - fluidbook-html5.git/commitdiff
wip #3977 @3
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 23 Oct 2020 19:37:54 +0000 (21:37 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 23 Oct 2020 19:37:54 +0000 (21:37 +0200)
images/interface.svg
js/libs/fluidbook/cart/fluidbook.cart.puma.js [new file with mode: 0644]
js/libs/fluidbook/fluidbook.cart.js
js/libs/fluidbook/fluidbook.video.js
js/libs/fluidbook/links/fluidbook.links.zoom.js

index 3523ab3ff2ad25463583cbc50c47a5468d230e4d..4f497c6a9bdab627addcf692012df78a1a492752 100644 (file)
         <rect x="26.9" y="27.4" transform="matrix(0.7071 -0.7071 0.7071 0.7071 -10.1163 31.7768)" width="12.7"
               height="1.5"/>
     </symbol>
+    <symbol id="icon-photo" viewBox="0 0 25 25">
+        <g transform="matrix(1.3333333333333333,0,0,1.3333333333333333,0,0)">
+            <path d="M10.8,14.1c-2.2,0-4-1.8-4-4s1.8-4,4-4s4,1.8,4,4S13,14.1,10.8,14.1z M10.8,7.1c-1.6,0-3,1.3-3,3s1.3,3,3,3
+               s3-1.3,3-3S12.4,7.1,10.8,7.1z"/>
+            <path d="M15.8,16.1h-13c-0.8,0-1.5-0.7-1.5-1.5v-8c0-0.8,0.7-1.5,1.5-1.5H7l0.6-1.2c0.3-0.5,0.8-0.8,1.4-0.8h3.8
+               c0.6,0,1.1,0.3,1.4,0.8l0.6,1.2h1.2c0.8,0,1.5,0.7,1.5,1.5v8C17.3,15.4,16.6,16.1,15.8,16.1z M2.8,6.1c-0.3,0-0.5,0.2-0.5,0.5v8
+               c0,0.3,0.2,0.5,0.5,0.5h13c0.3,0,0.5-0.2,0.5-0.5v-8c0-0.3-0.2-0.5-0.5-0.5h-1.5c-0.2,0-0.4-0.1-0.5-0.3l-0.7-1.4
+               c-0.1-0.2-0.2-0.3-0.4-0.3H8.9c-0.2,0-0.3,0.1-0.4,0.3L7.8,5.8C7.7,6,7.5,6.1,7.3,6.1H2.8z"/>
+            <path d="M4,8.6c-0.4,0-0.8-0.4-0.8-0.8c0-0.4,0.4-0.8,0.8-0.8s0.8,0.4,0.8,0.8C4.8,8.3,4.5,8.6,4,8.6z M4,7.6
+               c-0.2,0-0.3,0.1-0.3,0.3C3.8,8,3.9,8.1,4,8.1S4.3,8,4.3,7.8C4.3,7.7,4.2,7.6,4,7.6z"/>
+            <path d="M4.8,6.1c-0.3,0-0.5-0.2-0.5-0.5v-1c0-0.3,0.2-0.5,0.5-0.5c0.3,0,0.5,0.2,0.5,0.5v1C5.3,5.9,5.1,6.1,4.8,6.1z"
+            />
+        </g>
+    </symbol>
+    <symbol id="icon-360" viewBox="0 0 25 25">
+        <path d="M10.4,10.9c-0.4,0-0.7-0.3-0.7-0.7V8c0-1.6,1.3-2.8,2.8-2.8c0.4,0,0.7,0.3,0.7,0.7s-0.3,0.7-0.7,0.7
+                       c-0.8,0-1.4,0.6-1.4,1.4v2.1C11.1,10.6,10.8,10.9,10.4,10.9z"/>
+        <path d="M11.8,12.3c-1.2,0-2.1-1-2.1-2.1s1-2.1,2.1-2.1s2.1,1,2.1,2.1S13,12.3,11.8,12.3z M11.8,9.4
+                       c-0.4,0-0.7,0.3-0.7,0.7c0,0.4,0.3,0.7,0.7,0.7c0.4,0,0.7-0.3,0.7-0.7C12.5,9.8,12.2,9.4,11.8,9.4z"/>
+        <path d="M6.8,12.3c-1,0-1.8-0.6-2-1.6C4.6,10.4,4.9,10,5.2,9.9C5.6,9.8,6,10,6.1,10.4c0.1,0.3,0.4,0.5,0.7,0.5
+                       c0.4,0,0.7-0.3,0.7-0.7c0-0.4-0.3-0.7-0.7-0.7c-0.4,0-0.7-0.3-0.7-0.7S6.4,8,6.8,8c0.3,0,0.6-0.2,0.7-0.5C7.6,7.1,7.4,6.7,7,6.6
+                       c-0.2,0-0.4,0-0.5,0.1C6.3,6.8,6.2,7,6.1,7.1C6,7.5,5.6,7.7,5.2,7.6C4.9,7.5,4.6,7.2,4.7,6.8c0.1-0.5,0.5-1,1-1.3
+                       c0.5-0.3,1.1-0.4,1.6-0.2c1.1,0.3,1.8,1.5,1.5,2.6C8.8,8.2,8.6,8.5,8.4,8.7c0.3,0.4,0.5,0.9,0.5,1.4C8.9,11.3,8,12.3,6.8,12.3z"/>
+        <path d="M16.7,12.3c-1.2,0-2.1-1-2.1-2.1V7.3c0-1.2,1-2.1,2.1-2.1s2.1,1,2.1,2.1v2.8C18.8,11.3,17.8,12.3,16.7,12.3z
+                        M16.7,6.6c-0.4,0-0.7,0.3-0.7,0.7v2.8c0,0.4,0.3,0.7,0.7,0.7c0.4,0,0.7-0.3,0.7-0.7V7.3C17.4,6.9,17.1,6.6,16.7,6.6z"/>
+        <path d="M11.8,19C11.8,19,11.8,19,11.8,19l-1.1,0c-4.8-0.3-8.2-2.2-8.2-4.5c0-0.5,0.1-0.9,0.4-1.4
+                       c0.2-0.3,0.6-0.4,1-0.2c0.3,0.2,0.4,0.6,0.2,1c-0.1,0.2-0.2,0.4-0.2,0.6c0,1.3,2.6,2.8,6.9,3.1l1,0c0.4,0,0.7,0.3,0.7,0.7
+                       C12.5,18.7,12.2,19,11.8,19z"/>
+        <path d="M15.5,18.8c-0.3,0-0.6-0.2-0.7-0.6c-0.1-0.4,0.2-0.7,0.6-0.8c3.3-0.6,5-1.9,5-2.9c0-0.2-0.1-0.4-0.2-0.6
+                       c-0.2-0.3-0.1-0.8,0.2-1c0.3-0.2,0.8-0.1,1,0.2c0.3,0.4,0.4,0.9,0.4,1.4c0,2-2.4,3.6-6.2,4.2C15.6,18.8,15.6,18.8,15.5,18.8z"/>
+        <path d="M10.5,21.2c-0.2,0-0.4-0.1-0.5-0.2c-0.3-0.3-0.2-0.7,0.1-1l1.8-1.6L10,16.7c-0.3-0.3-0.3-0.7-0.1-1
+                       c0.3-0.3,0.7-0.3,1-0.1l2,1.8c0.3,0.2,0.4,0.6,0.4,0.9c0,0.3-0.1,0.7-0.4,0.9L11,21C10.8,21.1,10.7,21.2,10.5,21.2z"/>
+        <path d="M20.8,8.5c-0.9,0-1.6-0.7-1.6-1.6s0.7-1.6,1.6-1.6s1.6,0.7,1.6,1.6S21.7,8.5,20.8,8.5z M20.8,6.6
+               c-0.1,0-0.2,0.1-0.2,0.2c0,0.2,0.4,0.2,0.4,0C21,6.7,20.9,6.6,20.8,6.6z"/>
+    </symbol>
 </svg>
diff --git a/js/libs/fluidbook/cart/fluidbook.cart.puma.js b/js/libs/fluidbook/cart/fluidbook.cart.puma.js
new file mode 100644 (file)
index 0000000..648722d
--- /dev/null
@@ -0,0 +1,427 @@
+function FluidbookCartPuma(cart) {
+    var $this = this;
+    this.cart = cart;
+    this.fluidbook = this.cart.fluidbook;
+    this.items = this.cart.getSavedData();
+    this.data;
+    this.loggedIn = false;
+    this.handleTooltips = true;
+    this.handleTaxes = false;
+    this.minQuantities = {};
+    this.idBySku = {};
+
+    this.initBaseURL();
+    this.init();
+}
+
+FluidbookCartPuma.prototype = {
+    initBaseURL: function () {
+        this.baseURL = window.location.protocol + '//' + window.location.host + '/' + this.fluidbook.l10n.currentLang + '/';
+    },
+    updateCartData: function (callback) {
+        var $this = this;
+        this.sendCookie();
+
+        $.ajax({
+            url: this.baseURL + "customer/section/load/",
+            dataType: 'json',
+            cache: false,
+            xhrFields: {withCredentials: true},
+            success: function (data) {
+                $this.fluidbook.hideLoader();
+                $this.updateCartFromData(data.cart, data.customer, callback);
+            },
+        });
+    },
+
+    updateCartFromData: function (data, customer, callback) {
+        this.data = data;
+        this.loggedIn = customer.websiteId !== undefined && customer.websiteId !== null;
+        if (this.dataok()) {
+            this.updateCart();
+        }
+        this.updateMinQuantities(function () {
+            if (callback !== undefined) {
+                callback();
+            }
+        });
+    },
+
+    init: function () {
+        var $this = this;
+
+        $(document).on('change', '[data-menu="cart"] .input-number', function () {
+            $this.updateCartFromQuantities(this);
+            return true;
+        });
+
+        this.updateCartData(function () {
+
+        });
+
+        setTimeout(function () {
+            $this.updateCartData(function () {
+
+            });
+        }, 60000);
+
+        $(window).on('focus', function () {
+            $this.fluidbook.menu.closeView(function () {
+            }, true, false);
+            $this.updateCartData(function () {
+
+            });
+        });
+
+
+    },
+
+    checkLoginSession: function () {
+        if (!this.loggedIn) {
+            this.fluidbook.links.triggerLinkById('login');
+            return false;
+        }
+        return true;
+    },
+
+    addToCart: function (ref, quantity) {
+        var $this = this;
+        if (!this.checkLoginSession()) {
+            return;
+        }
+        this.fluidbook.displayLoader();
+
+        this.getProductIDBySKU(ref, function (product_id) {
+            if (product_id === null) {
+                var url = this.fluidbook.settings.product_zoom_references[ref][0];
+                $this.fluidbook.hideLoader();
+                $this.fluidbook.openInPopupIframe(url);
+            } else {
+                var minQuantity = $this.minQuantities[ref];
+                if (quantity === undefined || isNaN(quantity) || quantity < minQuantity) {
+                    quantity = minQuantity
+                }
+
+                $.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 () {
+                                $this.fluidbook.menu.openView('cart');
+                            });
+                        }
+                    }
+                });
+            }
+        });
+
+        return false;
+    },
+
+    getMinQuantity: function (sku, callback) {
+        if (this.minQuantities[sku] !== undefined) {
+            callback(this.minQuantities[sku]);
+            return;
+        }
+        var $this = this;
+        console.log('check qty for ' + sku);
+        this.getProductIDBySKU(sku, function (product_id) {
+            if ($this.minQuantities[sku] === undefined) {
+                console.log('no qty for ' + sku);
+                var e = sku.split('.');
+                if (e.length > 1) {
+                    e.pop();
+                    var nsku = e.join('.') + '.';
+                    console.log('check qty for ' + nsku);
+                    $this.getProductIDBySKU(nsku, function (product_id) {
+                        if ($this.minQuantities[nsku] === undefined) {
+                            console.log('no qty for ' + nsku);
+                            var ee = nsku.split('.');
+                            if (ee.length > 1) {
+                                ee.pop();
+                                ee.pop();
+                                var nnsku = ee.join('.') + '.';
+                                console.log('check qty for ' + nnsku);
+                                $this.getProductIDBySKU(nnsku, function (product_id) {
+                                    console.log('no qty for ' + nnsku);
+                                    if ($this.minQuantities[nnsku] === undefined) {
+                                        $this.minQuantities[nnsku] = 1;
+                                    }
+                                    $this.minQuantities[nsku] = $this.minQuantities[nnsku];
+                                    $this.minQuantities[sku] = $this.minQuantities[nnsku];
+                                    callback($this.minQuantities[nnsku]);
+                                });
+                                return;
+                            }
+                        } else {
+                            $this.minQuantities[sku] = $this.minQuantities[nsku];
+                        }
+                        callback($this.minQuantities[nsku]);
+                    });
+                    return;
+                }
+            } else {
+                callback($this.minQuantities[sku]);
+            }
+        });
+    },
+
+    updateMinQuantities: function (callback) {
+        var skus = [];
+        $.each(this.data.items, function (index, item) {
+            skus.push(item.product_sku);
+        });
+        this._updateMinQuantity(skus, callback);
+    },
+
+    _updateMinQuantity: function (list, callback) {
+        if (list.length === 0) {
+            callback();
+            return;
+        }
+        var sku = list.pop();
+        var $this = this;
+        this.getMinQuantity(sku, function () {
+            $this._updateMinQuantity(list, callback);
+        });
+    },
+
+    getProductIDBySKU: function (sku, callback) {
+        if (this.idBySku[sku] !== undefined) {
+            callback(this.idBySku[sku]);
+            return;
+        }
+        var $this = this;
+        $.ajax({
+            url: this.baseURL + 'fastorder/index/search',
+            cache: false,
+            data: {product: sku, sort_order: 0},
+            method: 'post',
+            xhrFields: {withCredentials: true},
+            dataType: 'json',
+            success: function (data) {
+                var product_id;
+                if (data === null || data === undefined || data === '' || data.length === 0 || !data) {
+                    product_id = null;
+                } else {
+                    product_id = data[0].product_id;
+                    var min = 1;
+                    if (data[0].min !== undefined) {
+                        min = data[0].min;
+                    }
+                    console.log('set min qty for ' + sku + ' : ' + min)
+                    $this.minQuantities[sku] = min;
+                }
+                $this.idBySku[sku] = product_id;
+                callback(product_id);
+            }, error: function () {
+                $this.idBySku[sku] = null;
+                callback(null);
+            }
+        });
+    },
+
+    sendCookie: function () {
+    },
+
+    removeFromCart: function (item_id, callback) {
+        var $this = this;
+        this.fluidbook.displayLoader();
+        $.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 () {
+        if (!this.dataok()) {
+            return 0;
+        }
+        return this.data.summary_count;
+    },
+    getAllQuantities: function () {
+        var res = 0;
+        this.data.find('item quantite').each(function () {
+            res += parseInt($(this).text());
+        });
+        return res;
+    },
+
+    updateIcon: function () {
+        $(this.fluidbook).trigger('fluidbook.cart.updateIcon', {number: this.getItemsNumbers()});
+    },
+
+    openMenu: function (p1, p2, callback) {
+        if (!this.dataok()) {
+            callback();
+            return;
+        }
+        this.fluidbook.menu.quickCloseView();
+        return this.openCart(p2, callback);
+    },
+
+    openCart: function (p2, callback) {
+        if (!this.checkLoginSession()) {
+            callback();
+            return;
+        }
+        if (!this.dataok()) {
+            callback();
+            return;
+        }
+        this._endMenu(this.fluidbook.l10n.__('your cart'), this.getCartContent(), function () {
+            $('input[type="number"]').inputNumber();
+
+            callback();
+        });
+    },
+
+    dataok: function () {
+        return this.data !== undefined && this.data !== null;
+    },
+
+    getCartContent: function () {
+        if (this.getItemsNumbers() == 0) {
+            return '<div class="cart-empty">' + this.fluidbook.l10n.__('your cart is empty') + '</div>';
+        }
+        var $this = this;
+        var content = '<table class="cart-items">';
+        var totalht = 0;
+        $.each(this.data.items, function (index, item) {
+            var qty = $this.parseInt(item.qty);
+            var unit = $this.parseFloat(item.product_price_value);
+            var ht = unit * qty;
+
+            var options = {};
+            $.each(item.options, function (k, opt) {
+                options[opt.option_id] = opt.option_value;
+            });
+
+            content += '<tr>';
+            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>';
+            var step = $this.minQuantities[item.product_sku];
+            if (step === undefined) {
+                step = 1;
+            }
+            content += '<td class="quantity"><input data-options=\'' + JSON.stringify(options) + '\' name="' + item.item_id + '" class="cartqty" type="number" step="' + step + '" min="0" max="10000" value="' + qty + '" /></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="' + item.item_id + '">' + getSpriteIcon('interface-close') + '</a></td>';
+            content += '</tr>';
+
+            totalht += ht;
+        });
+
+        content += '</table>';
+        content += '<table class="cart-totals">';
+        content += '<tr><td colspan="2" class="hr"></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">' + $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;
+    },
+
+    getFormKey: function () {
+        return $.cookie('form_key');
+    },
+
+    updateCartFromQuantities: function (el) {
+        var $this = this;
+        var input = $(el).find('input.cartqty');
+        var item_id = $(input).attr('name');
+        var options = $(input).data('options');
+        var newVal = $this.parseInt($(input).val());
+
+        if (newVal === 0) {
+            this.removeFromCart(item_id, function () {
+            });
+        } else {
+            this.fluidbook.displayLoader();
+
+            $.ajax({
+                url: $this.baseURL + 'checkout/cart/updateItemOptions/id/' + item_id,
+                method: "post",
+                data: {item: item_id, qty: newVal, super_attribute: options, form_key: this.getFormKey()},
+                xhrFields: {withCredentials: true},
+                success: function () {
+                    $this.updateCartData(function () {
+
+                    });
+                }
+            })
+        }
+    },
+
+    updateCart: function () {
+        if (!this.dataok()) {
+            return;
+        }
+        $('[data-menu="cart"] .content').html(this.getCartContent());
+        $('input[type="number"]').inputNumber();
+        this.updateIcon();
+        resize();
+
+    },
+
+    formatPrice: function (price, suffix) {
+        if (typeof price == 'number') {
+            price = parseFloat(price);
+        }
+
+        if (suffix == undefined) {
+            suffix = '';
+        }
+
+        return price.toLocaleString("fr-FR", {style: "currency", currency: "EUR"}) + ' ' + suffix;
+    },
+
+    _endMenu: function (title, content, callback) {
+        var view = this.fluidbook.menu.getCaption(title);
+        view += '<div class="content">';
+        view += "" + content;
+        view += '</div>';
+        this.fluidbook.menu.viewWrap(view, 'cart');
+        callback();
+    },
+
+    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);
+    },
+};
\ No newline at end of file
index 3324e37836f352d88124507f1307a0755ca26794..b89910ee0687e08456763c8fbdd750ba68a9cf82 100644 (file)
@@ -44,6 +44,8 @@ FluidbookCart.prototype = {
                 return new FluidbookCartRemarkable(this);
             case 'Mopec':
                 return new FluidbookCartMopec(this);
+            case 'Puma':
+                return new FluidbookCartPuma(this);
             default:
                 return null;
         }
index 1960d46098f9c2cb57ed109ae4fb2910d44eb1b2..578aa77425d2343819870efae3566c1e2f7ee201 100644 (file)
@@ -112,10 +112,12 @@ FluidbookVideo.prototype = {
                 console.warn('Error disposing player #' + id + ' -- ' + exception.message);
             }
         }
-
-
         if (fluidbook.settings.mobileVideosPath == '') {
-            path = "data/links/" + name;
+            if (name.indexOf('data/') !== -1) {
+                path = name;
+            } else {
+                path = "data/links/" + name;
+            }
         } else {
             path = fluidbook.settings.mobileVideosPath + name;
             if (!fluidbook.settings.standalone && path.substr(0, 3) == '../') {
index 84c527f4665f59b2c5bbc160d22ea741f9701c0d..47047c7cdce01b5f593c49ca0fba9cb2e2fd1ac4 100644 (file)
@@ -188,6 +188,9 @@ FluidbookLinksZoom.prototype = {
                             linkClass = " nolabel";
                         }
 
+                        var hash = forge_sha256(data);
+                        var add = '';
+
                         menu += '<a ';
                         if (action === 'video' && data.indexOf('http') === 0) {
                             action = 'link';
@@ -209,6 +212,18 @@ FluidbookLinksZoom.prototype = {
                             menu += ' href="#/webvideo/' + e[0] + '/' + e[1] + '" ';
                         } else if (action === 'addtocart') {
                             menu += ' href="#" data-cart-ref="' + $(zoomLink).data('ref') + '" ';
+                        } else if (action === 'image') {
+                            menu += ' href="#/multimedia/' + hash + '" ';
+                            var markup = '<div class="multimediaContainer "><img src="' + data + '" class="multimedia" /></div>';
+                            menu += ' data-multimedia="' + encodeURIComponent(markup) + '"'
+                        } else if (action === 'videofile') {
+                            menu += ' href="#/video/' + hash + '" ';
+                            var markup = ' <div class="videoContainer" data-loop="0" data-controls="1" data-sound="1" data-autoplay="1" width="1920" height="1080" data-name="' + data + '" data-id="vi_' + hash + '" id="vi_' + hash + '" data-link-id="v_' + hash + '"></div>';
+                            menu += ' data-video="' + encodeURIComponent(markup) + '"'
+                        } else if (action === 'videogif') {
+                            menu += ' href="#/video/' + hash + '" ';
+                            var markup = ' <div class="videoContainer" data-loop="1" data-controls="0" data-sound="0" data-autoplay="1" width="1920" height="1080" data-name="' + data + '" data-id="vi_' + hash + '" id="vi_' + hash + '" data-link-id="v_' + hash + '"></div>';
+                            menu += ' data-video="' + encodeURIComponent(markup) + '"'
                         }
                         menu += 'data-tooltip="' + $this.fluidbook.settings['product_zoom_tooltip_' + j] + '" class="button ' + linkClass + '">' + icon + label + '</a>';
                     }