Visualizzazione dei risultati da 1 a 7 su 7
  1. #1
    Utente di HTML.it
    Registrato dal
    Feb 2020
    Messaggi
    6

    Implementare mail riepilogativa ordine su plugin carrello

    Un saluto a tutti i membri, ho un plugin jquery per un carrello e-commerce che funziona benissimo dove i dati raccolti dall'utente vengono memorizzati in memoria di sessione, infatti quando si passa da una pagina all'altra nel browser i dati vengono visualizzati correttamente. Vorrei che quando l'utente clicca sul bottone paga mi arrivasse mail riepilogativa dell'ordine, dai dati inseriti nel form dall'utente (nome, indirizzo ecc.) ai dati del carrello (prodotto, prezzo, quantita' e totale) salvati in session storage.
    In poche parole vorrei che i dati immagazinati nella memoria di sessione venissero richiamati e inviati via mail.


    Spero possiate aiutarmi.
    Grazie anticipatamente.


    Posto alcuni frammenti di codice jquery per farvi un idea:


    Codice dati form

    codice:
    _saveFormData: function( form ) {
    var self = this;
    var $visibleSet = form.find( "fieldset:visible" );
    
    
    $visibleSet.each(function() {
    var $set = $( this );
    if( $set.is( "#fieldset-billing" ) ) {
    var name = $( "#name", $set ).val();
    var email = $( "#email", $set ).val();
    var phone = $( "#phone", $set ).val();
    var city = $( "#city", $set ).val();
    var province = $( "#province", $set ).val();
    var address = $( "#address", $set ).val();
    var zip = $( "#zip", $set ).val();
    var country = $( "#country", $set ).val();
    
    
    self.storage.setItem( "billing-name", name );
    self.storage.setItem( "billing-email", email );
    self.storage.setItem( "billing-phone", phone );
    self.storage.setItem( "billing-city", city );
    self.storage.setItem( "billing-province", province );
    self.storage.setItem( "billing-address", address );
    self.storage.setItem( "billing-zip", zip );
    self.storage.setItem( "billing-country", country );
    } else {
    var sName = $( "#sname", $set ).val();
    var sEmail = $( "#semail", $set ).val();
    var sCity = $( "#scity", $set ).val();
    var sProvince = $( "#sprovince", $set ).val();
    var sAddress = $( "#saddress", $set ).val();
    var sZip = $( "#szip", $set ).val();
    var sCountry = $( "#scountry", $set ).val();
    
    
    self.storage.setItem( "shipping-name", sName );
    self.storage.setItem( "shipping-email", sEmail );
    self.storage.setItem( "shipping-city", sCity );
    self.storage.setItem( "shipping-province", sProvince );
    self.storage.setItem( "shipping-address", sAddress );
    self.storage.setItem( "shipping-zip", sZip );
    self.storage.setItem( "shipping-country", sCountry );
    
    
    }
    });
    }
    };



    Codice dati carrello


    codice:
    // Aggiunge articoli al carrello
    
    
    handleAddToCartForm: function() {
    var self = this;
    self.$formAddToCart.each(function() {
    var $form = $( this );
    var $product = $form.parent();
    var price = self._convertString( $product.data( "price" ) );
    var name = $product.data( "name" );
    
    
    $form.on( "submit", function() {
    var qty = self._convertString( $form.find( ".qty" ).val() );
    var subTotal = qty * price;
    var total = self._convertString( self.storage.getItem( self.total ) );
    var sTotal = total + subTotal;
    self.storage.setItem( self.total, sTotal );
    self._addToCart({
    product: name,
    price: price,
    qty: qty
    });
    var shipping = self._convertString( self.storage.getItem( self.shippingRates ) );
    var shippingRates = self._calculateShipping( qty );
    var totalShipping = shipping + shippingRates;
    
    
    self.storage.setItem( self.shippingRates, totalShipping );
    });
    });
    },
    
    
    
    // Visualizza il carrello
    
    
    displayCart: function() {
    if( this.$formCart.length ) {
    var cart = this._toJSONObject( this.storage.getItem( this.cartName ) );
    var items = cart.items;
    var $tableCart = this.$formCart.find( ".shopping-cart" );
    var $tableCartBody = $tableCart.find( "tbody" );
    
    
    if( items.length == 0 ) {
    $tableCartBody.html( "" );
    } else {
    
    
    
    
    for( var i = 0; i < items.length; ++i ) {
    var item = items[i];
    var product = item.product;
    var price = this.currency + " " + item.price;
    var qty = item.qty;
    var html = "<tr><td class='pname'>" + product + "</td>" + "<td class='pqty'><input type='text' value='" + qty + "' class='qty'/></td>";
    html += "<td class='pprice'>" + price + "</td><td class='pdelete'><a href='' data-product='" + product + "'>&times;</a></td></tr>";
    
    
    $tableCartBody.html( $tableCartBody.html() + html );
    }
    
    
    }
    
    
    if( items.length == 0 ) {
    this.$subTotal[0].innerHTML = this.currency + " " + 0.00;
    } else {
    
    
    var total = this.storage.getItem( this.total );
    this.$subTotal[0].innerHTML = this.currency + " " + total;
    }
    } else if( this.$checkoutCart.length ) {
    var checkoutCart = this._toJSONObject( this.storage.getItem( this.cartName ) );
    var cartItems = checkoutCart.items;
    var $cartBody = this.$checkoutCart.find( "tbody" );
    
    
    if( cartItems.length > 0 ) {
    
    
    for( var j = 0; j < cartItems.length; ++j ) {
    var cartItem = cartItems[j];
    var cartProduct = cartItem.product;
    var cartPrice = this.currency + " " + cartItem.price;
    var cartQty = cartItem.qty;
    var cartHTML = "<tr><td class='pname'>" + cartProduct + "</td>" + "<td class='pqty'>" + cartQty + "</td>" + "<td class='pprice'>" + cartPrice + "</td></tr>";
    
    
    $cartBody.html( $cartBody.html() + cartHTML );
    }
    } else {
    $cartBody.html( "" );
    }
    
    
    if( cartItems.length > 0 ) {
    
    
    var cartTotal = this.storage.getItem( this.total );
    var cartShipping = this.storage.getItem( this.shippingRates );
    var subTot = this._convertString( cartTotal ) + this._convertString( cartShipping );
    
    
    this.$subTotal[0].innerHTML = this.currency + " " + this._convertNumber( subTot );
    this.$shipping[0].innerHTML = this.currency + " " + cartShipping;
    } else {
    this.$subTotal[0].innerHTML = this.currency + " " + 0.00;
    this.$shipping[0].innerHTML = this.currency + " " + 0.00;
    }
    
    
    }
    },

  2. #2
    Amministratore L'avatar di Vincent.Zeno
    Registrato dal
    May 2003
    residenza
    Emilia-Romagna (tortellini und cappelletti land!)
    Messaggi
    20,657
    visto che si parla di un e-commerce esistente immagino che i dati vengano salvati in un database.
    l'eventuale email bisogna che parta con uno script lato server, non certamente lato client.

    normalmente un e-commerce è configurato per questa opzione. hai verificato questa possibilità?

  3. #3
    Utente di HTML.it
    Registrato dal
    Feb 2020
    Messaggi
    6
    Ciao, ti ringrazio per la risposta!
    Purtroppo non e' configurabile per questa azione solo via checkout paypal ma anche li riscontro problemi con i dati inseriti dall'utente nel form che non compaiono. Vorrei che mi illuminaste sull'argomento con alcuni esempi.
    Grazie di nuovo.

  4. #4
    Amministratore L'avatar di Vincent.Zeno
    Registrato dal
    May 2003
    residenza
    Emilia-Romagna (tortellini und cappelletti land!)
    Messaggi
    20,657
    un e-commerce che non conservi i dati dell'ordine in un database, prima di inviarli al pagamento, è un programma con una grave carenza.
    prima cosa controlla bene questa cosa.

    inviarti una mail è secondario, ma ci devo essere i dai salvati.
    tramite paypal è bene inviare e ricevere solo i dati necessari come il numero d'ordine e un po' di descrizione.
    eviterei la lunga lista degli articoli.

    è comunque un argomento complesso e delicato.
    al prossimo post potesti indicare il nome dell'e-commerce?

  5. #5
    Utente di HTML.it
    Registrato dal
    Feb 2020
    Messaggi
    6
    I dati vengono salvati in memoria di sessione non lato server e funziona benissimo.
    Per evitare di inserire link il nome del plugin e' "jquery-sessionStorage-shopping-cart" (demo che vende vini) facilmente reperibile in rete.
    Per quanto riguarda paypal vorrei che i dati inseriti dall'utente (nome, indirizzo ecc.) venissero traferiti a paypal.

  6. #6
    Amministratore L'avatar di Vincent.Zeno
    Registrato dal
    May 2003
    residenza
    Emilia-Romagna (tortellini und cappelletti land!)
    Messaggi
    20,657
    quindi, se qualcosa va storto durante le operazioni, non hai alcuna intenzione di tenere traccia dell'ordine?

    per quanto riguarda paypal, lo stesso e-commerce dovrebbe darti le istruzioni per specificare i dati da trasferire.

    la questione non riguarda solo il plug-in jquery: la mail deve partire dal server. non dal client.

    i dati dell'ordine vanno recuperati sul server, poi registrati, si crea un numero d'ordine, e si invia tutto a PP. prima o dopo l'invio a PP puoi mandarti un mail di riepilogo (meglio dopo: a ordine recepito/pagato).
    fare tutto questo lato client è contorto e inaffidabile (compreso il fatto che non salvi l'ordine e i dati dell'utente, non gestisci il magazzino...)

    c'è già un'interazione con PP, quindi sul server qualcosa succede. è li che bisogna verificare come muoversi.

  7. #7
    Utente di HTML.it
    Registrato dal
    Feb 2020
    Messaggi
    6
    Grazie ancora per la risposta, si la cosa e' un po complessa e credo che a questo punto optero' sul discorso paypal.
    Il problema che ho con paypal e' che non vengono inoltrati i dati inseriti nel modulo del sito ma vengono inoltrati soltanto prodotto, quantita', spedizione e totale. Ho letto su una guida che bisogna inserire le variabili nel form paypal ma ho inserito il possibile per testare ma non funziona.
    Spero possiate aiutarmi.


    Posto il codice del form paypal ed il codice jquery:

    codice:
    <form id="paypal-form" action="" method="post">
    <input type="hidden" name="cmd" value="_ext-enter" />
    <input type="hidden" name="redirect_cmd" value="_cart">
    <input type="hidden" name="business" value="business@example.it" />
    <input type="hidden" name="upload" value="1" />
    <input type="hidden" name="email" value="1" />
    <input type="hidden" name="first_name" value="1" />
    <input type="hidden" name="last_name" value="1" />
    <input type="hidden" name="address1" value="1" />
    <input type="hidden" name="address2" value="1" />
    <input type="hidden" name="city" value="1" />
    <input type="hidden" name="state" value="1" />
    <input type="hidden" name="zip" value="1" />
    <input type="hidden" name="day_phone_a" value="1" />
    <input type="hidden" name="quantity" value="1" />
    <input type="hidden" name="item_number" value="1" />
    <input type="hidden" name="notify_url" value="http://www.miosito.it/shop.html" />
    <input type="hidden" name="cancel_return" value="http://www.miosito.it/shop.html" />
    <input type="hidden" name="image_url" value="1" />
    <input type="hidden" name="cs" value="1" />
    <input type="hidden" name="custom" value="1" />
    <input type="hidden" name="currency_code" value="EUR" />
    <input type="hidden" name="Ic" value="IT">
    <input type="hidden" name="item_name" value="mio sito" />
    <input type="hidden" name="amount" value="2" />
    <input type="hidden" name="shipping" value="2">
    <input type="hidden" name="return" value="http://www.miosito.it/shop.html">
    <input type="hidden" name="rm" value="1">
    <input type="submit" id="paypal-btn" class="btn" value="Paga con PayPal" />
    </form>

    codice:
            // Aggiunge i valori nascosti richiesti al modulo di PayPal prima di inviare
            
            populatePayPalForm: function() {
                var self = this;
                if( self.$paypalForm.length ) {
                    var $form = self.$paypalForm;
                    var cart = self._toJSONObject( self.storage.getItem( self.cartName ) );
                    var shipping = self.storage.getItem( self.shippingRates );
                    var numShipping = self._convertString( shipping );
                    var cartItems = cart.items; 
                    var singShipping = Math.floor( numShipping / cartItems.length );
                    
                    $form.attr( "action", self.paypalURL );
                    $form.find( "input[name='business']" ).val( self.paypalBusinessEmail );
                    $form.find( "input[name='currency_code']" ).val( self.paypalCurrency );
                    
                    for( var i = 0; i < cartItems.length; ++i ) {
                        var cartItem = cartItems[i];
                        var n = i + 1;
                        var name = cartItem.product;
                        var price = cartItem.price;
                        var qty = cartItem.qty;
                        
                        $( "<div/>" ).html( "<input type='hidden' name='quantity_" + n + "' value='" + qty + "'/>" ).
                        insertBefore( "#paypal-btn" );
                        $( "<div/>" ).html( "<input type='hidden' name='item_name_" + n + "' value='" + name + "'/>" ).
                        insertBefore( "#paypal-btn" );
                        $( "<div/>" ).html( "<input type='hidden' name='item_number_" + n + "' value='Art. " + name + "'/>" ).
                        insertBefore( "#paypal-btn" );
                        $( "<div/>" ).html( "<input type='hidden' name='amount_" + n + "' value='" + self._formatNumber( price, 2 ) + "'/>" ).
                        insertBefore( "#paypal-btn" );
                        $( "<div/>" ).html( "<input type='hidden' name='shipping_" + n + "' value='" + self._formatNumber( singShipping, 2 ) + "'/>" ).
                        insertBefore( "#paypal-btn" );
                        
                    }
                    
                    
                    
                }
            },



    Codice form dati utente

    codice:
        // Visualizza le informazioni dell'utente        
            
            displayUserDetails: function() {
                if( this.$userDetails.length ) {
                    if( this.storage.getItem( "shipping-name" ) == null ) {
                        var name = this.storage.getItem( "billing-name" );
                        var email = this.storage.getItem( "billing-email" );
                        var phone = this.storage.getItem( "billing-phone" );
                        var city = this.storage.getItem( "billing-city" );
                        var province = this.storage.getItem( "billing-province" );
                        var address = this.storage.getItem( "billing-address" );
                        var zip = this.storage.getItem( "billing-zip" );
                        var country = this.storage.getItem( "billing-country" );
                        
                        var html = "<div class='detail'>";
                            html += "<h2>Fatturazione e spedizione</h2>";
                            html += "<ul>";
                            html += "<li>" + name + "</li>";
                            html += "<li>" + email + "</li>";
                            html += "<li>" + phone + "</li>";
                            html += "<li>" + city + "</li>";
                            html += "<li>" + province + "</li>";
                            html += "<li>" + address + "</li>";
                            html += "<li>" + zip + "</li>";
                            html += "<li>" + country + "</li>";
                            html += "</ul></div>";
                            
                        this.$userDetails[0].innerHTML = html;
                    } else {
                        var name = this.storage.getItem( "billing-name" );
                        var email = this.storage.getItem( "billing-email" );
                        var phone = this.storage.getItem( "billing-phone" );
                        var city = this.storage.getItem( "billing-city" );
                        var province = this.storage.getItem( "billing-province" );
                        var address = this.storage.getItem( "billing-address" );
                        var zip = this.storage.getItem( "billing-zip" );
                        var country = this.storage.getItem( "billing-country" );
                        
                        var sName = this.storage.getItem( "shipping-name" );
                        var sCity = this.storage.getItem( "shipping-city" );
                        var sProvince = this.storage.getItem( "shipping-province" );
                        var sAddress = this.storage.getItem( "shipping-address" );
                        var sZip = this.storage.getItem( "shipping-zip" );
                        var sCountry = this.storage.getItem( "shipping-country" );
                        
                        var html = "<div class='detail'>";
                            html += "<h2>Fatturazione</h2>";
                            html += "<ul>";
                            html += "<li>" + name + "</li>";
                            html += "<li>" + email + "</li>";
                            html += "<li>" + phone + "</li>";
                            html += "<li>" + city + "</li>";
                            html += "<li>" + province + "</li>";
                            html += "<li>" + address + "</li>";
                            html += "<li>" + zip + "</li>";
                            html += "<li>" + country + "</li>";
                            html += "</ul></div>";
                            
                            html += "<div class='detail right'>";
                            html += "<h2>Spedizione</h2>";
                            html += "<ul>";
                            html += "<li>" + sName + "</li>";
                            html += "<li>" + sCity + "</li>";
                            html += "<li>" + sProvince + "</li>";
                            html += "<li>" + sAddress + "</li>";
                            html += "<li>" + sZip + "</li>";
                            html += "<li>" + sCountry + "</li>";
                            html += "</ul></div>";
                            
                        this.$userDetails[0].innerHTML = html;    
                    
                    }
                }
            },
    Ultima modifica di m-power; 03-02-2020 a 14:47

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.