2017-02-22 60 views
-1

点击立即购买按钮产品应添加到购物车按钮,但它不显示购物车按钮即使控制不进入成功功能它显示内部服务器错误,当我刷新我的网页在购物车按钮产品正在显示,但它应该点击工作。如何解决这个问题? 错误在控制台示出象下面这样:数据不发布显示内部服务器错误

未能加载资源:服务器回应500 (内部服务器错误)

HTML代码的状态:

<button type="button" id="button-cart" data-loading-text="Loading..." class="btn btn-primary btn-lg btn-block buynow"><span class="bagImg mybtm"><i></i>Buy Now</span></button> 

Jquery的代码:

$('#button-cart').on('click', function() { 
    $.ajax({ 
    url: 'index.php?route=checkout/cart/add', 
    type: 'post', 
    data: $('#product input[type=\'text\'], #product input[type=\'hidden\'], #product input[type=\'radio\']:checked, #product input[type=\'checkbox\']:checked, #product select, #product textarea'), 
    dataType: 'json', 
    beforeSend: function() { 
     $('#button-cart').button('loading'); 
    }, 
    complete: function() { 
     $('#button-cart').button('reset'); 
    }, 
    success: function(json) { 
     console.log(json); 
     $('.alert, .text-danger').remove(); 
     $('.form-group').removeClass('has-error'); 

     if (json['error']) { 
     if (json['error']['option']) { 
      for (i in json['error']['option']) { 
      var element = $('#input-option' + i.replace('_', '-')); 

      if (element.parent().hasClass('input-group')) { 
       $('.breadcrumb').after('<div class="alert alert-danger">' + json['error']['option'][i] + '</div>'); 
      } else { 
       $('.breadcrumb').after('<div class="alert alert-danger">' + json['error']['option'][i] + '</div>'); 
      } 
      } 
     } 

     if (json['error']['recurring']) { 
      $('select[name=\'recurring_id\']').after('<div class="text-danger">' + json['error']['recurring'] + '</div>'); 
     } 

     // Highlight any found errors 
     $('.text-danger').parent().addClass('has-error'); 
     } 

     if (json['success']) { 
     $('.breadcrumb').after('<div class="alert alert-success">' + json['success'] + '<button type="button" class="close" data-dismiss="alert">&times;</button></div>'); 

     $('#cart-total').html(json['total']); 

     $('#cart > ul').load('index.php?route=common/cart/info ul li'); 
     } 
     $('html, body').animate({ scrollTop: 0 }, 'slow'); 
     window.location.href='checkout/checkout'; 
    }, 
    error: function(json){ 
     console.log(json); 
    } 
    }); 
}); 

控制器功能:

public function add() { 

     $this->load->language('checkout/cart'); 

     $json = array(); 

     if (isset($this->request->post['product_id'])) { 
      $product_id = (int)$this->request->post['product_id']; 
     } else { 
      $product_id = 0; 
     } 

     $this->load->model('catalog/product'); 

     $product_info = $this->model_catalog_product->getProduct($product_id); 

     if ($product_info) { 
      if (isset($this->request->post['quantity'])) { 
       $quantity = (int)$this->request->post['quantity']; 
      } else { 
       $quantity = 1; 
      } 

      if (isset($this->request->post['option'])) { 
       $option = array_filter($this->request->post['option']); 
      } else { 
       $option = array(); 
      } 

      $product_options = $this->model_catalog_product->getProductOptions($this->request->post['product_id']); 

      foreach ($product_options as $product_option) { 
       if ($product_option['required'] && empty($option[$product_option['product_option_id']])) { 
        $json['error']['option'][$product_option['product_option_id']] = sprintf($this->language->get('error_required'), $product_option['name']); 
       } 
      } 

      if (isset($this->request->post['recurring_id'])) { 
       $recurring_id = $this->request->post['recurring_id']; 
      } else { 
       $recurring_id = 0; 
      } 

      $recurrings = $this->model_catalog_product->getProfiles($product_info['product_id']); 

      if ($recurrings) { 
       $recurring_ids = array(); 

       foreach ($recurrings as $recurring) { 
        $recurring_ids[] = $recurring['recurring_id']; 
       } 

       if (!in_array($recurring_id, $recurring_ids)) { 
        $json['error']['recurring'] = $this->language->get('error_recurring_required'); 
       } 
      } 

      if (!$json) { 
       $this->cart->add($this->request->post['product_id'], $this->request->post['quantity'], $option, $recurring_id); 

       $json['success'] = sprintf($this->language->get('text_success'), $this->url->link('product/product', 'product_id=' . $this->request->post['product_id']), $product_info['name'], $this->url->link('checkout/cart')); 

       unset($this->session->data['shipping_method']); 
       unset($this->session->data['shipping_methods']); 
       unset($this->session->data['payment_method']); 
       unset($this->session->data['payment_methods']); 

       // Totals 
       $this->load->model('extension/extension'); 

       $total_data = array(); 
       $total = 0; 
       $taxes = $this->cart->getTaxes(); 

       // Display prices 
       if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) { 
        $sort_order = array(); 

        $results = $this->model_extension_extension->getExtensions('total'); 

        foreach ($results as $key => $value) { 
         $sort_order[$key] = $this->config->get($value['code'] . '_sort_order'); 
        } 

        array_multisort($sort_order, SORT_ASC, $results); 

        foreach ($results as $result) { 
         if ($this->config->get($result['code'] . '_status')) { 
          $this->load->model('total/' . $result['code']); 

          $this->{'model_total_' . $result['code']}->getTotal($total_data, $total, $taxes); 
         } 
        } 

        $sort_order = array(); 

        foreach ($total_data as $key => $value) { 
         $sort_order[$key] = $value['sort_order']; 
        } 

        array_multisort($sort_order, SORT_ASC, $total_data); 
       } 

       $json['total'] = sprintf($this->language->get('text_items'), $this->cart->countProducts() + (isset($this->session->data['vouchers']) ? count($this->session->data['vouchers']) : 0), $this->currency->format($total)); 
      } else { 
       $json['redirect'] = str_replace('&amp;', '&', $this->url->link('product/product', 'product_id=' . $this->request->post['product_id'])); 
      } 
     } 

     $this->response->addHeader('Content-Type: application/json'); 
     $this->response->setOutput(json_encode($json)); 
    } 
+0

你可以发布错误信息吗? http://stackoverflow.com/a/845025/3676614 –

+0

你的ajax请求正在调用吗? –

+0

@ricardo错误信息是'对象{readyState:4,responseText:“{”success“:”成功:您已添加!”,“total”:“4 item(s ) - Rs 2,126“}”,responseJSON:Object,status:500,statusText:“Internal Server Error”}' – Mohan

回答

0

解决它......没有什么错的脚本/代码..在服务器启用了755的权限,通过了现场和缓存/上传文件夹由777 ...这做的把戏......

Thx all for the help and response ... :)

相关问题