1

we are displaying orders in custom orders.php page in www.1234.com/site6/orders.php

I am trying to change status of each order from Paid to unpaid & viceversa.....

i can select required status & click on "submit" button & but it displaying error "NO record selected"....

enter image description here

enter image description here

php

function getDesignerCollection()
    {

    $user_home = new USER();    
    $i = 0;

    foreach($order as $orderData) 
{ 
$k = 0; 
$orderitems = $orderData['dproduct_id']; 
$orderitemsarray = explode(",", $orderitems); 

while ($k < count($orderitemsarray)) 
{ 

if ($orderitemsarray[$k] != '0') 
{ 
$stmtorders = $user_home->runQuery("SELECT * FROM order_details");  
$roworders = $stmtorders->fetch(PDO::FETCH_ASSOC);
print_r($roworders);    

if($data['type']=="admin")continue; 
if($data['dpaid_status']==''){$dpaid_status='';}
if($data['dpaid_status']=='P'){$dorderStatus='Paid';} 
if($data['dpaid_status']=='U'){$dorderStatus='Unpaid';} 


if ($roworders[ 

'dproduct_id'] == '') 
{ 
$dorderStatus = "Unpaid"; 
} 
else 
{ 
$dorderStatus = $roworders['dpaid_status']; 
} 

$k++; 
$i++; 
} 
}

    echo json_encode($responce);
    } 

form

<form  action='' method="post" enctype="multipart/form-data">
       <input type="hidden" name="delete_package_id" id="delete_package_id" value=""/>
       Action:

    <select name="massaction" id="massaction">
           <option value="">Select</option>
           <option value="P">Paid</option>
           <option value="U">Unpaid</option>
    </select>

        <input type="button" value="Submit" id="delete-grid-button" onclick="massAction()" />
    </form>

script

function massAction()
{
    var e=document.getElementById("massaction");
    var strUser = e.options[e.selectedIndex].value;

    massStatusChangeVerified(strUser);

}


function massStatusChangeVerified(status)
    {       
        var checkboxes = document.getElementsByName('dorder_id');   
        var vals = "";      
        for (var i=0, n=checkboxes.length;i<n;i++) {
          if (checkboxes[i].checked) 
          {
          vals += ","+checkboxes[i].value;
          }
        }
        if(vals=='')
        {
            alert("No record selected");
            return false;
        }
        retactiveVal=confirm("Are you sure want to Change the status");
        if( retactiveVal == true )
        {
        if (vals) vals = vals.substring(1);     
        document.getElementsByName('delete_package_id').value=vals;     
        var url="http://sbdev2.kidsdial.com:81/php/site6/update_order_status.php?designer_id="+vals+"&order_status="+status;
           var request = jQuery.ajax( {
                url: url ,
                type: 'POST',                      
            } );

            request.done( function (result)
            {  
                document.getElementById('msgresult').style.display="block";
                var explode = function(){
                 location.reload();
                };
                setTimeout(explode, 2000);


            } );
            request.fail( function ( error )
            {
                console.dir(error);             
            } );return true;
            }else{                   
              return false;
        }       
    }

enter image description here

script reuslts for creating grid :

function my_renderId(value ,record,columnObj,grid,colNo,rowNo)
{
    var no= record[columnObj.fieldIndex];

    return "<input type='checkbox' value='"+record[0]+"' name='userID'/>";
}


    var colsOption = [
        {id: '' , header: "" , width :"15",renderer : my_renderId , width :"60"},
        {id: 'created_at' , header: "Order Date" , width :"120"},
        {id: 'entity_id' , header: "Order Id" , width :"75"},    
        {id: 'dpaid_status' , header: "Paid status" , width :"80"},
    ];

Edit : updateorderstatus.php

if( isset($_GET['order_status']) && !empty($_GET['order_status']) && $_GET['order_status']!="" )
    {  $staus=$_GET['order_status']; }else{ $staus="";}

    if( isset($_GET['designer_id']) && !empty($_GET['designer_id']) && $_GET['designer_id']!="" )
    {  $allCheckedBoxes=$_GET['designer_id'];  }
    else{ $allCheckedBoxes="";} 
    $ArrallCheckedBoxes=explode(",",$allCheckedBoxes);
    if(isset($conVar) && !empty($conVar) && $conVar!=""){       
        foreach($ArrallCheckedBoxes as $tempBoxes){
                $sqlQueryToUpdate=" UPDATE order_details SET dpaid_status = '".$staus."'  WHERE userID = '".$tempBoxes."' ;";
                $sucessFlag=mysqli_query($conVar,$sqlQueryToUpdate);
                    if($sucessFlag==TRUE){
                    echo "Records Updated Sucessfully.";
                }else{
                    echo " Record already Updated.";
                }
            } 
    }
12
  • I think there should be some other problem then this Commented Dec 13, 2016 at 11:00
  • @MurtuzaZabuawala really not getting where went wrong, you may be right,.... Commented Dec 13, 2016 at 11:03
  • got the point send me example of one input type check box for dorder_id Commented Dec 13, 2016 at 11:12
  • @MurtuzaZabuawala pls check updated question with db table..... Commented Dec 13, 2016 at 11:15
  • I am talking about the checkbox html code for dorder_id Commented Dec 13, 2016 at 11:18

2 Answers 2

1
+50

I reckon use the jquery for that

 var vals = ""; 
            var checkboxes=$("input[name='userID[]']:checked").each( function () {

          vals += ","+$(this).val();

                            })
                 alert(vals);

change the name in userID to userID[]

    function my_renderId(value ,record,columnObj,grid,colNo,rowNo)
     {
        var no= record[columnObj.fieldIndex];

        return "<input type='checkbox' value='"+record[0]+"-"+record[3]+' name='userID[]'/>";
     }

updateorderstatus.php

if( isset($_GET['order_status']) && !empty($_GET['order_status']) && $_GET['order_status']!="" )
    {  $staus=$_GET['order_status']; }else{ $staus="";}

    if( isset($_GET['designer_id']) && !empty($_GET['designer_id']) && $_GET['designer_id']!="" )
    {  $allCheckedBoxes=$_GET['designer_id'];  }
    else{ $allCheckedBoxes="";} 
    $ArrallCheckedBoxes=explode(",",$allCheckedBoxes);
    if(isset($conVar) && !empty($conVar) && $conVar!=""){       
        foreach($ArrallCheckedBoxes as $tempBoxes){

             $newtempBoxes=explode('-',$tempBoxes);

                $sqlQueryToUpdate=" UPDATE order_details SET dpaid_status = '".$staus."'  WHERE userID = '".$tempBoxes."' and designerorder_id = '".$newtempBoxes[0]."' and dproduct_id = '".$newtempBoxes[1]."' ";
                $sucessFlag=mysqli_query($conVar,$sqlQueryToUpdate);
                    if($sucessFlag==TRUE){
                    echo "Records Updated Sucessfully.";
                }else{
                    echo " Record already Updated.";
                }
            } 
    }

as reference to this question

5
  • okay i will check & let you know.... Commented Dec 15, 2016 at 10:27
  • its working, but once i get solution for this : magento.stackexchange.com/questions/149411/… than only i can check correctly, once you get free time, please help me for that link..... Commented Dec 15, 2016 at 13:12
  • status changing working on order basis not on per product basis.... if we change status for " order id - 100000138 , product id - 15515" it should work only for this product id, but now its changing for other product ids also related to that order.... Commented Dec 16, 2016 at 6:55
  • in your updated code, you missed closing "[double quotes] , so it was displaying blank, now i changed that as return "<input type='checkbox' value='"+record[0]+"-"+record[3]+"' name='userID[]'/>"; now table is displaying, but `status changing is not working..... Commented Dec 16, 2016 at 11:13
  • @BabyinMagento is ajax is working? can you share url of your ajax call Commented Dec 16, 2016 at 11:24
1

Try to replace this code

var checkboxes = document.getElementsByName('dorder_id');

with this on everywhere

var checkboxes = document.getElementsByName('userID');

remove my second change of link and replace this

$sqlQueryToUpdate=" UPDATE order_details SET dpaid_status = '".$staus."'  WHERE userID = '".$tempBoxes."' ;";

with :

$sqlQueryToUpdate=" UPDATE order_details SET dpaid_status = '".$staus."'  WHERE designerorder_id = '".$tempBoxes."' ;";
17
  • no receord selected error gone, now i need to update the values in database, but that is not happening, please help me..... Commented Dec 13, 2016 at 13:07
  • updated, still its not changing values, please check link once Commented Dec 13, 2016 at 13:28
  • updated question with update_order_status.php file , i replaced with this code : var url="http://sbdev2.kidsdial.com:81/php/site6/update_order_status.php?designer_id=<?php echo $_SESSION['userSession'];?>&order_status="+status; Commented Dec 13, 2016 at 13:32
  • in view page source displaying : var url="http://sbdev2.kidsdial.com:81/php/site6/update_order_status.php?designer_id=3&order_status="+status; that is 3, that is correct value of designer id Commented Dec 13, 2016 at 13:33
  • also if you want to check, this is full code : pastebin.com/s8waxhA5 Commented Dec 13, 2016 at 13:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.