Jump to content
  • разработка интернет магазинов на opencart
  • доработка интернет магазинов на opencart

Live Price Update


zik920
 Share

Recommended Posts

Подскажите кто знаток в этом, есть скрипт и котроллер. Все рилииет замечательно, этона меняется, но когда я через +- (тоже скрипт) меняю когдачество, скрипт не срабатывает, кто-то может подправить? 

//--></script> 
<script type="text/javascript"><!--
$(document).on('click', '.number-spinner button', function () {    
  var btn = $(this),
    oldValue = btn.closest('.number-spinner').find('input').val().trim(),
    newVal = 1;
      
  if (btn.attr('data-dir') == 'up') {
    newVal = parseInt(oldValue) + 1;
  } else {
    if (oldValue > 1) {
      newVal = parseInt(oldValue) - 1;
    } else {
      newVal = 1;
    }
  }
  btn.closest('.number-spinner').find('input').val(newVal);
});
//--></script>


 

<script type="text/javascript"><!--
              $(document).ready(function() {
                $('#input-quantity').on('keyup', function() {
                  var currency =" {{ price }}";
                  var price = Number(currency.replace(/[^0-9\.-]+/g,""));
                  var qty = $(this).val();
                  var total = price * qty;
                  var priceText = $('#input-quantity').closest("#content").find("h2");
                  $.ajax({
                    url: 'index.php?route=product/product/pricetocurr',
                    type: 'get',
                    data:{'price': total},
                    dataType: 'json',
                    beforeSend: function() {
                      priceText.fadeOut();
                    },
                    complete: function() {
                    },
                    success: function(json) {
                      setTimeout(function(){
                          priceText.text(json['curr']);
                       }, 300);  // The millis to wait before executing this block
                      priceText.fadeIn();
                    }
                  });
                });
              });
            //--></script>
 public function pricetocurr() {

          		$json = array();
          		if(isset($this->request->get['price']) && is_numeric($this->request->get['price']) ) {
          			$curr = $this->currency->format($this->request->get['price'], $this->session->data['currency']);
          			$json['curr'] = $curr;
          		} else {
          			$json['error'] = 'error data';
          		}
          		$this->response->addHeader('Content-Type: application/json');
          		$this->response->setOutput(json_encode($json));
          	}

 

Link to comment
Share on other sites


  • 3 weeks later...

Попропотому чтовал ик, все зарилиило, но налинает слиить с 3 и слииет как *2, ггде ошибка?
 

<script type="text/javascript"><!--
               $(document).ready(function() {
                $('.input-group-btn-my').on('click', function() {
                  var currency ="{{ price }}";
                  var price = Number(currency.replace(/[^0-9\.-]+/g,""));
                  var qty = $('#input-quantity').val();
                  var total = price * qty;
                  var priceText = $('#input-quantity').closest("#content").find("h2");
                  $.ajax({
                    url: 'index.php?route=product/product/pricetocurr',
                    type: 'get',
                    data:{'price': total},
                    dataType: 'json',
                    beforeSend: function() {
                      priceText.fadeOut();
                    },
                    complete: function() {
                    },
                    success: function(json) {
                      setTimeout(function(){
                          priceText.text(json['curr']);
                       }, 300);  // The millis to wait before executing this block
                      priceText.fadeIn();
                    }
                  });
                });
              });
            //--></script>

 

Edited by zik920
Link to comment
Share on other sites


Все, нашел ошибку, она была не в этом скрипте, а в value +- 
Это 

<script type="text/javascript"><!--
$(document).on('click', '.number-spinner button', function () {    
  var btn = $(this),
    oldValue = btn.closest('.number-spinner').find('input').val().trim(),
    newVal = 1;
      
  if (btn.attr('data-dir') == 'up') {
    newVal = parseInt(oldValue) + 1;
  } else {
    if (oldValue > 1) {
      newVal = parseInt(oldValue) - 1;
    } else {
      newVal = 1;
    }
  }
  btn.closest('.number-spinner').find('input').val(newVal);
});
//--></script>


заменил на это 
 

<script type="text/javascript">
        $(document).ready(function() {
            $('.minus').click(function () {
                var $input = $(this).parent().find('input');
                var count = parseInt($input.val()) - 1;
                count = count < 1 ? 1 : count;
                $input.val(count);
                $input.change();
                return false;
            });
            $('.plus').click(function () {
                var $input = $(this).parent().find('input');
                $input.val(parseInt($input.val()) + 1);
                $input.change();
                return false;
            });
        });
    </script>


Теперь все рилииет игдеально.

Link to comment
Share on other sites


  • 2 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.