اذهب إلى المحتوى
  • 0

اين الخلل في هذا الكود

mrshokri mhmd

السؤال

//get product price const regex = /.[+-]?\d+(\.\d+)?/g; const price = Number($('#price').text().match(regex)[0]); console.log(price);

 

تم اضافة هذا الكود في صفحة منتجات الاوبن كارد

المشكلة في هذا الكود

عند مسح السطر الاول

يتم احتساب البرودكت الي عليها خصم ويضيف سعر الاضافات بشكل طبيعي

اما الي ماعليها خصم يبقى السعر بدون تعديل عن اختيار اضافات

وانا بقى كما هو 

يتم احتساب البرودكت الي ماعليها خصم

وما هو فوق 1000 يصبح 1 وماهو فوق 2000 يصبح 2 وهكذا في جميع المنتجات الي عليها او ماعليها خصم

اعينوني عليها ولو بشكل مدفوع

رابط هذا التعليق
شارك على الشبكات الإجتماعية

Recommended Posts

  • 0

الكود بالكامل

 

 

	<script type="text/javascript">
		$(document).ready(function(){



			//get product bar offsit
				const mm = $("#product .price").offset() ;

			//make offset
				const newoffset= mm.top - 100;

			//get currency	
			const currency = "<?php echo $currency ?>" ;

			//lets make array for total price
			const totalPrice = {};
			//get product price 

			const regex = /[+-]?\d+(\.\d+)?/g;

			const price =  Number($('#price').text().match(regex)[0]);
			console.log(price);
			const discount = /"quota":([0-9.]+)([^}]*)"discount":([0-9.]+)/g;
        	
			//get the radio elemnt 
			var element = $('input[type="radio"]');
				
			//lets play with code 
			$(element).click(function(){


				
				//get product option price
				var optionPrice = '';
				if($(this).context.alt){
				 optionPrice =  Number($(this).context.alt.match(regex)['0']);
			}else{

				 optionPrice = Number(0);
			}



				//get product option id to sum only one time
				var OprionId =$(this).context.name;

				//add option price by option id 

				totalPrice[OprionId] = +optionPrice ;
				totalPrice['product'] = price;

				//lets take total = 0 
				var total = 0 ;

				//array loop
				for(var key in totalPrice){

					total= total  + totalPrice[key];
					
				}

				var totalTax = total*(5/100);

				
			$('html, body').animate({ scrollTop: newoffset});

			

			$('#price').animate( {'opacity': 0}, 400, function(){

       		 $(this).text(currency+" "+total.toFixed(2)).animate({'opacity': 1}, 400) ;    });
				    
				     $('#OnlyTax').animate({'opacity': 0}, 400, function(){
        $(this).text(currency+" "+totalTax.toFixed(2)).animate({'opacity': 1}, 400);    });
				         });
			});




		

	</script>

 

رابط هذا التعليق
شارك على الشبكات الإجتماعية

  • 0

عند تعديل هذا السطر 

 

const regex = /[+-]?\d+(\.\d+)?/g;

 

إلى 

 

            const regex = /[+-]?\d+\.(\d+)?/g;
 

عندما تكون القيمة مثلا 1250 عند اختيار اضافة بقيمة 10 ريال مثلا يصبح السعر 260 اي يحذف الألف كامله ويبقي اعداد في 100 فقط

مثلا اذا السعر 2500 والاضافة مجانية يصبح السعر 500

رابط هذا التعليق
شارك على الشبكات الإجتماعية

  • 0

حرف ال g الموجود آخر الجملة البرمجية ما فائدته؟
فهذا هو السطر البرمجي بشكل كامل 
 /[+-]?\d+\.(\d+)?/
ماذا يحصل لو حذفنا حرف ال g من الجملة؟

هل يمكن ارفاق الموقع الخاص بكم للاطلاع عليه؟

رابط هذا التعليق
شارك على الشبكات الإجتماعية

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...