• 19-04-2017, 03:09:01
    #1
    foreach ile aldığım ürünlerin fiyatını seçeneklere göre anlık değiştirmeye çalışıyorum. tek üründe sorun yok, kategori kısmında ise ürün id sorunsuz alıyor, değişen fiyatı ilgili üründe değil, son sıradaki ürüne göre yapmak istiyor. son ürünün id tuttuğu için sorun yok, diğer ürünlerde ise id farklı olduğu için herhangi bir güncelleneme yapmıyor.

    gözden kaçırdığım birşey var ama ne olduğu göremiyorum... lütfen yardım arkadaşlar.

    var price_with_options_ajax_call = function() {
    				jQuery.ajax({
    					type: 'POST',
    					url: 'index.php?route=product/live_options/index&product_id=$product_id',
    					data: $('{$this->options_container} input[type=\'text\'], {$this->options_container} input[type=\'number\'], {$this->options_container} input[type=\'hidden\'], {$this->options_container} input[type=\'radio\']:checked, {$this->options_container} input[type=\'checkbox\']:checked, {$this->options_container} select, {$this->options_container} textarea'),
    					dataType: 'json',
    					beforeSend: function() {
    					},
    					complete: function() {
    					},
    					success: function(json) {
    						if (json.success) {
    							if ($('{$this->options_container} {$this->tax_price_container}$product_id').length > 0 && json.new_price.tax) {
    								animation_on_change_price_with_options('{$this->options_container} {$this->tax_price_container}$product_id', json.new_price.tax);
    							}
    							if ($('{$this->options_container} {$this->special_price_container}$product_id').length > 0 && json.new_price.special) {
    								animation_on_change_price_with_options('{$this->options_container} {$this->special_price_container}$product_id', json.new_price.special);
    							}
    							if ($('{$this->options_container} {$this->price_container}$product_id').length > 0 && json.new_price.price) {
    								animation_on_change_price_with_options('{$this->options_container} {$this->price_container}$product_id', json.new_price.price);
    							}
    							// points
    							if ($('{$this->options_container} {$this->points_container}$product_id').length > 0 && json.new_price.points) {
    								animation_on_change_price_with_options('{$this->options_container} {$this->points_container}$product_id', json.new_price.points);
    							}
    							// reward
    							if ($('{$this->options_container} {$this->reward_container}$product_id').length > 0 && json.new_price.reward) {
    								animation_on_change_price_with_options('{$this->options_container} {$this->reward_container}$product_id', json.new_price.reward);
    							}
    						}
    					},
    					error: function(error) {
    						console.log('error: '+error);
    					}
    				});
    			}
    			
    			var animation_on_change_price_with_options = function(selector_class_or_id, new_html_content) {
    				$(selector_class_or_id).fadeOut(150, function() {
    					$(this).html(new_html_content).fadeIn(50);
    				});
    			}
    
    			if ( jQuery.isFunction(jQuery.fn.on) ) 
    			{
    				$(document).on('change', '{$this->options_container} input[type=\'text\'], {$this->options_container} input[type=\'number\'], {$this->options_container} input[type=\'hidden\'], {$this->options_container} input[type=\'radio\']:checked, {$this->options_container} input[type=\'checkbox\'], {$this->options_container} select, {$this->options_container} textarea, {$this->options_container} input[name=\'quantity\']', function () {
    					
    					price_with_options_ajax_call();
    				});
    			} 
    			else 
    			{
    				$('{$this->options_container} input[type=\'text\'], {$this->options_container} input[type=\'number\'], {$this->options_container} input[type=\'hidden\'], {$this->options_container} input[type=\'radio\']:checked, {$this->options_container} input[type=\'checkbox\'], {$this->options_container} select, {$this->options_container} textarea, {$this->options_container} input[name=\'quantity\']').live('change', function() {
    					price_with_options_ajax_call();
    				});
    			}
    			// Support spinner_quantity
    			if( $('.number-spinner button').length ){
    				$(document).on('click', '.number-spinner button', function () {
    					setTimeout(function() {
    						price_with_options_ajax_call();
    					}, 100);
    				});
    			}
    			// Support bt_claudine
    			if( $('.increase').length || $('.decrease').length ){
    				$(document).on('click', '.increase', function () {
    					setTimeout(function() {
    						price_with_options_ajax_call();
    					}, 100);
    				});
    				$(document).on('click', '.decrease', function () {
    					setTimeout(function() {
    						price_with_options_ajax_call();
    					}, 100);
    				});
    			}
    			// Support Pav theme
    			if( $('.quantity-adder .add-action').length ){
    				$(".quantity-adder .add-action").bind( "mouseup touchend", function(e){
    					setTimeout(function() {
    						price_with_options_ajax_call();
    					}, 100);
    				});
    			}
    			// Support vitalia
    			if( $('#q_up').length || $('#q_down').length ){
    				$('#q_up,#q_down').click(function(){
    					setTimeout(function() {
    						price_with_options_ajax_call();
    					}, 100);
    				});
    			}
  • 19-04-2017, 18:55:42
    #2
    Üyeliği durduruldu
    soru yanlış anlamadıysam, şuanki kodlara bakılırsa her döngüde aynı değişken değeri üzerine gidiyorsun değişkenleri globalden çıkartman ve var olarak tanımlaman gerekir yoksa for forech each gibi döngülerde sonraki veri önceki verinin üzerine biner

    for....
    price_with_options_ajax_call();
    end for...
    
    yerine 
    
    for...
    var x = price_with_options_ajax_call();
    end for..
    -----------------------------
    for....
    animation_on_change_price_with_options('{$this->o
    end for..
    
    yerine
    
    for....
    var y = animation_on_change_price_with_options('{$this->o
    end for..
    
    gibi
    
    umarım doğru anlamışımdır sorunuzu
  • 19-04-2017, 22:09:08
    #3
    aynen üstad, çok doğru tespit.
    işlemler doğru yapılıyor ama değişken sonucu php'de foreach ile gelen son id üzerinden yürüdüğü için sonuç alamıyordum. çok teşekkürler.

    jooker adlı üyeden alıntı: mesajı görüntüle
    soru yanlış anlamadıysam, şuanki kodlara bakılırsa her döngüde aynı değişken değeri üzerine gidiyorsun değişkenleri globalden çıkartman ve var olarak tanımlaman gerekir yoksa for forech each gibi döngülerde sonraki veri önceki verinin üzerine biner

    for....
    price_with_options_ajax_call();
    end for...
    
    yerine 
    
    for...
    var x = price_with_options_ajax_call();
    end for..
    -----------------------------
    for....
    animation_on_change_price_with_options('{$this->o
    end for..
    
    yerine
    
    for....
    var y = animation_on_change_price_with_options('{$this->o
    end for..
    
    gibi
    
    umarım doğru anlamışımdır sorunuzu