Question

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.";
                }
            } 
    }
Was it helpful?

Solution

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

OTHER TIPS

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."' ;";
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top