@@ -14,9 +14,36 @@ module.exports = Backbone.View.extend({
1414
1515 initialize : function ( ) {
1616 "use strict" ;
17- var currentShippingPrice = 0 ,
17+ var recipient = this . model . get ( 'page' ) . profile . handle || this . model . get ( 'page' ) . profile . guid ;
18+
19+ this . model . set ( 'recipient' , recipient ) ;
20+
21+ this . listenTo ( this . model , 'change:selectedModerator change:selectedAddress' , this . render ) ;
22+ this . render ( ) ;
23+ } ,
24+
25+ render : function ( ) {
26+ var self = this ,
27+ currentShippingPrice = 0 ,
1828 currentShippingBTCPrice = 0 ,
19- recipient = this . model . get ( 'page' ) . profile . handle || this . model . get ( 'page' ) . profile . guid ;
29+ shippingType = "" ,
30+ templJSON = { } ;
31+ console . log ( this . model )
32+
33+ //set prices before each render
34+ if ( this . model . get ( 'vendor_offer' ) . listing . shipping . free !== true && this . model . get ( 'selectedAddress' ) ) {
35+ if ( this . model . get ( 'selectedAddress' ) . country != this . model . get ( 'vendor_offer' ) . listing . shipping . shipping_origin ) {
36+ currentShippingPrice = this . model . get ( 'internationalShipping' ) ;
37+ currentShippingBTCPrice = this . model . get ( 'internationalShippingBTC' ) ;
38+ this . model . set ( 'shippingType' , 'international' ) ;
39+ shippingType = 'international' ;
40+ } else {
41+ currentShippingPrice = this . model . get ( 'domesticShipping' ) ;
42+ currentShippingBTCPrice = this . model . get ( 'domesticShippingBTC' ) ;
43+ this . model . set ( 'shippingType' , 'domestic' ) ;
44+ shippingType = 'domestic' ;
45+ }
46+ }
2047
2148 this . model . set ( 'currentShippingPrice' , currentShippingPrice ) ;
2249 this . model . set ( 'currentShippingBTCPrice' , currentShippingBTCPrice ) ;
@@ -28,49 +55,10 @@ module.exports = Backbone.View.extend({
2855 currency : this . model . get ( 'userCurrencyCode' )
2956 } ) . format ( currentShippingPrice ) ) ;
3057
31- this . model . set ( 'recipient' , recipient ) ;
32-
33- this . listenTo ( this . model , 'change:selectedModerator change:selectedAddress' , function ( ) {
34- this . render ( ) ;
35- } ) ;
36-
37- this . render ( ) ;
38- } ,
39-
40-
41- render : function ( ) {
42- var self = this ;
4358 loadTemplate ( './js/templates/buyDetails.html' , function ( loadedTemplate ) {
44- var currentShippingPrice = 0 ,
45- currentShippingBTCPrice = 0 ,
46- shipToCountry = self . model . get ( 'selectedAddress' ) ? self . model . get ( 'selectedAddress' ) . country : "" ;
47-
48- if ( shipToCountry && self . model . get ( 'vendor_offer' ) . listing . shipping . free !== true ) {
49- if ( shipToCountry != self . model . get ( 'vendor_offer' ) . listing . shipping . shipping_origin ) {
50- currentShippingPrice = self . model . get ( 'internationalShipping' ) ;
51- currentShippingBTCPrice = self . model . get ( 'internationalShippingBTC' ) ;
52- self . model . set ( 'shippingType' , 'international' ) ;
53- } else {
54- currentShippingPrice = self . model . get ( 'domesticShipping' ) ;
55- currentShippingBTCPrice = self . model . get ( 'domesticShippingBTC' ) ;
56- self . model . set ( 'shippingType' , 'domestic' ) ;
57- }
58- }
59- self . model . set ( 'currentShippingPrice' , currentShippingPrice ) ;
60- self . model . set ( 'currentShippingBTCPrice' , currentShippingBTCPrice ) ;
61-
62- self . model . set ( 'currentShippingDisplayPrice' , new Intl . NumberFormat ( window . lang , {
63- style : 'currency' ,
64- minimumFractionDigits : 2 ,
65- maximumFractionDigits : 2 ,
66- currency : this . model . get ( 'userCurrencyCode' )
67- } ) . format ( currentShippingPrice ) ) ;
68-
6959 self . $el . html ( loadedTemplate ( self . model . toJSON ( ) ) ) ;
70-
7160 //this does not add it to the DOM, that is done by the parent view
7261 self . setQuantity ( 1 ) ;
73-
7462 numberSpinners ( self . $el ) ;
7563 } ) ;
7664 return this ;
@@ -83,7 +71,6 @@ module.exports = Backbone.View.extend({
8371
8472 setQuantity : function ( quantity ) {
8573 "use strict" ;
86- console . log ( this . model . get ( 'currentShippingBTCPrice' ) )
8774 var self = this ,
8875 newAttributes = { } ,
8976 userCurrency = this . model . get ( 'userCurrencyCode' ) ,
0 commit comments