Post by Orikh » Mon Jul 23, 2018 7:04 pm

Good day to all,

I have file with class which consist of several functions. This file I have included to controller and use returned data to build table. I need to change column data by `onkeyup` of different column. To do this, i need to pass number `onkeyup` to my array(in controller ) which will return data from function and set this data to my view. Here is my controller:

Code: Select all

require_once('catalog/controller/product/onlinecredit.php');
$credonl = new OnlineCredit();

foreach ($data['credittules'] as $rndb) {
    //echo $rndb['model'];
    $array = array(
        'Rule' => array(
            'rule_id' => $rndb['credit_rule_id'],
            'rule_name' => '' . $rndb['rule_name'] . '',
            'interest' => $rndb['interest'],
            'comission' => $rndb['comission'],
            'best_offer_downpayment' => $rndb['best_offer_downpayment'],
            'best_offer_duration' => $rndb['best_offer_duration']
        ),
        'Product' => array(
            'product_id' => $rndb['product_id'],
            'category_id' => $rndb['best_offer_duration'],
            'manufacturer_id' => $rndb['manufacturer_id'],
            'product_price' => $rndb['price']
        ),
        'Credit' => array(
            'downpayment' => $rndb['best_offer_downpayment'],
            'duration' => $rndb['best_offer_duration']
        )
    );
}

$data['credits']=$credonl->BuildCreditTable($array);
Here is my View:

Code: Select all

<div class="table-responsive" style="text-align: center">
   <div class="crhead"><h1 class="h1size">Hissə-hissə ödə!</h1></div>

   <table id="kreditable" width="100%">
      <thead>
      <tr>
         <th>{{ text_choise }}</th>
         <th>{{ text_vznos }}</th>
         <th>{{ text_month }}</th>
         <th>{{ text_monthly }}</th>
         <th>{{ text_total }}</th>
      </tr>
      </thead>
      <tbody>
      {% for credit_item in credits.Options %}
         <tr class="tr_row">
              {% if credit_id %}
               <td>
                  <label class="containerk">
                     <input type="radio" name="credit_id" {% if credit_item.duration == credit_id %} checked {% endif %} value="{{ credit_item.duration }}">
                     <span class="checkmarkk"></span>
                  </label>
               </td>
               {% else %}
               <td>
                  <label class="containerk">
                     <input type="radio" name="credit_id" value="{{ credit_item.duration }}">
                     <span class="checkmarkk"></span>
                  </label>
               </td>
              {% endif %}
            <td> <input type="text" class="inptsize" id="publicname-change" value="{{ credit_item.downpayment }}" onkeyup="setprice()"></td>
            <td>{{ credit_item.duration }}</td>
            <td>{{ credit_item.monthly }}</td>
            <td>{{ credit_item.total }}</td>
         </tr>
      {% endfor %}
      </tbody>
   </table>
   <div class="cb"></div>
   <a href="{{ action_credit }}&product_id={{product_id}}" class="button btn btn-cart kredit-type" onclick="kredit_click('{{ product_id }}'); return false;"/>
{{ text_nuraceiet_et }}
   </a>
</div>

Newbie

Posts

Joined
Sat Jun 30, 2018 8:06 pm

Post by straightlight » Mon Jul 23, 2018 7:14 pm

onkeyup="setprice()
The function setprice is being called but this function itself has not been created in that TWIG file or not originating from any JS, according to your posted codes. Without the actual function, your onKeyUp event will return false.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by Orikh » Tue Jul 24, 2018 5:32 am

straightlight wrote:
Mon Jul 23, 2018 7:14 pm
onkeyup="setprice()
The function setprice is being called but this function itself has not been created in that TWIG file or not originating from any JS, according to your posted codes. Without the actual function, your onKeyUp event will return false.
Thank you reply. I use ajax to send data and get data back, but on send it gives my error that did not find controller.
`<b>Fatal error</b>: Class 'Controller' not found in <b>mypathtofile\product\product.php</b> on line <b>2</b><br />`
Here is ajax form

Code: Select all

function calculate_monthly() {

        var downpayment = $('#publicname-change').val();

        $.ajax({
            url:'catalog/controller/product/product.php',
            type: 'POST',
            crossDomain:true,
            cache:false,
            data: {
                'action': 'get_data','price_value': downpayment
            },
            success: function(data) {
                console.log(data);
            },
            error: function(e) {
                console.log(e);

            }
        });
    }
here is controller side:

Code: Select all

 
 if (isset($_POST["action"]) && $_POST["action"] = "get_data" && isset($_POST["price_value"]) && $_POST["price_value"] != "") {
echo 'comething';
}

Newbie

Posts

Joined
Sat Jun 30, 2018 8:06 pm

Post by straightlight » Tue Jul 24, 2018 5:34 am

There are plenty of examples from the admin/controller/catalog/product.php and admin/view/template/catalog/product_form.twig file you can refer regarding the Ajax requests. As for the controller, each controllers starts with the class, then the method named: index() . After creating the index(), you need to create another method which will be your route for Ajax to use.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: ravikumar22 and 80 guests