2

magento site : www.1234.com

We have lot of Designers in site (Seller/ Vendor). we assigned each product to one Designer with help of attribute Designer ID as below image under Catalog > Manage Products section

enter image description here

We are using below code in www.1234.com/php/site6/padistatus.php to display form & saving form values in order_details column. [ custom database ]

enter image description here

here once we select Designer from dropdown, than related Order numbers of that designer will display, after selecting order number , it will display related Products Ids of that Order Number.

here for "Product ids" , we are saving values in "dproduct_id" column.

enter image description here

what we need is Previously selected & saved Product Ids should not display again in dropdown

example : here we already saved 15517 product Id in Database, so it should not display again in form. only 15515 product Id should display in dropdown.

full code : http://pastebin.com/PT6A0wrA

Edit

With help of below code , Previously saved product ids are not displaying per designer but i need solution for Previously saved product ids should not display for all designers.

assume In one order [ order id : 100000136 ] , 2 designers products will be sold [ ex : sudeep's product id : 15442 & Darshan product id : 152] , so that when we select Darshan in dropdown, only Darshan's product id 152 should display, but now product id 152 is displaying for both Sudeep & Darshan. same happening for Another product id also.

updated code :

 <table>
      <tr><td> Designer  </td><td>

          <select onchange="getOrderDetail(event);" name="designer_id" id="designer_id" >
            <option value="">Select Designer</option>
                  <?php 
                       while($data = $stmt->fetch())  
                        { 
                           if($data['type']=="admin")continue;
                  ?>
            <option value="<?php echo $data['userID'];?>">
                  <?php 
                     echo $data['name'];
                  ?>
            </option>
                  <?php } ?>
          </select>

     </td><td><p id="error_para1" ></p></td></tr> 


      <tr><td>Order Number: </td><td>


        <div id="ordernumbers">
          <select name="designerorder_id" id="designerorder_id" class="designerorder_id" onchange='getProductDetail(this.value)'>
            <option value="">Select Order</option>
          </select>
          </div>

        </td><td><p id="error_para2" ></p></td></tr> 




      <tr><td>Product</td><td>


        <div id="productnumbers" name="dproduct_id" id="dproduct_id" >
          <select id="mySelect" >
            <option>Select Products</option>
          </select>

        </div>


       </td><td><p id="error_para3" ></p></td> </tr>

Designerpaidstatus.php

$htmltext='';   
//$htmltext.="<select id='designerpaidstatus.php' name='designerorder_id' onchange='getProductDetail(this.value)' class='selectvalue'><option value=''>Select Order</option>";
$htmltext.="<option value=''>Select Order</option>";
$data=array();

foreach ($order as $orderData)  
{

$sqlq1="select dproduct_id from order_details where designer_id='".$id."' and designerorder_id='".$orderData->getIncrementId()."'";
$sqlq=mysqli_query($conVar,$sqlq1);

while($rdata=mysqli_fetch_assoc($sqlq))
{
$data[]=$rdata['dproduct_id'];

}


$orderitems=$orderData['dproduct_id'];
$oitem=explode(',',$orderitems);
$finalValue=$orderData->getIncrementId()."-".$orderitemsarray[$k];
$result=array_diff($oitem,$data);
$result1=implode(',',$result);

if(count($result)>1){  

$htmltext=$htmltext.'<option class="'.$result1.'" name="'.$result1.'" value="'.$orderData->getIncrementId().'">'. $orderData->getIncrementId().'</option>';

} }

$htmltext=$htmltext."</select>";
echo $htmltext;
exit;

script

function getOrderDetail(e)
  {
    var designerId=e.target.options[e.target.selectedIndex].value;    
    var url="http://sbdev2.kidsdial.com:81/php/site6/designerpaidstatus.php?designer_id="+designerId+"&opration=2";
       var request = jQuery.ajax( {
                url: url ,
                type: 'POST',                      
            } );

            request.done( function (result)
            {  
              //document.getElementById('ordernumbers').innerHTML =result;
              $(".designerorder_id").html(result);

            } );
            request.fail( function ( error )
            {
                console.dir(error);             
            } );
     }

    function getProductDetail(e)
      {    
        var productId = $(".designerorder_id option:selected").attr("class");  //$('option:selected', this).attr('class'); 

        var finalstrig=productId.split(",");

        var select='';
        select+='<select class="test" multiple="multiple" name="dproduct_ids" id="dproduct_ids">';

        for(i=0;i<finalstrig.length;i++)
        {
          if(finalstrig[i]!=0)
          {
            select +='<option value="'+finalstrig[i]+'">'+finalstrig[i]+'</option>';
          }
        }
        select +='</select>';   
        document.getElementById('productnumbers').innerHTML =select;
        (function($) {
        $(function() {
            $('.test').fSelect();
        });
    })(jQuery);

      }

    $(function(){
      $("#button_reset").click(function() { 
        $("#productnumbers").html('<select id="mySelect"><option>Select Products</option></select>');
      });
    });

enter image description here

enter image description here

Edit 2

what below query do is

1.it first execute a like query with designer id and fetches all the orders :

$order = Mage::getModel('sales/order')->getCollection()->addAttributeToFilter('designer_id',array('like' => '%'.$id.'%'));

2. Iterates through the order and fetches all the product ids....

$sqlq1="select dproduct_id from order_details where designer_id='".$id."' and designerorder_id='".$orderData->getIncrementId()."'";

so when i execute any of below queries, there will be a common row and all the product id from that row will appear for all these designers.

when i ran below query in magento database, i got result as below image.

select * from sales_flat_order where designer_id like '%4%'; 
select * from sales_flat_order where designer_id like '%5%'; 
select * from sales_flat_order where designer_id like '%8%'; 
select * from sales_flat_order where designer_id like '%9%';

enter image description here

  • What is the logic to already saved product_id find in your database? – Dhiren Vasoya Nov 28 '16 at 13:13
  • I second @DhirenVasoya question. Without the code that retrieves the product id no one can help you here – Raphael at Digital Pianism Dec 1 '16 at 11:26
  • @RaphaelatDigitalPianism please check script function getProductDetail(e) ..... – Baby in Magento Dec 1 '16 at 12:00
  • But how are those values retrieved from the database ? – Raphael at Digital Pianism Dec 1 '16 at 12:03
  • @RaphaelatDigitalPianism please check Edit part in question, we are using only those code i posted in question..... – Baby in Magento Dec 1 '16 at 12:05
2
+200
<?php
require_once 'class.user.php';

$deliverydDate=date('Y-m-d');
$user_homes = new USER();
$id=$_GET['designer_id'];

require_once '../../app/Mage.php';
Mage::app();
$order = Mage::getModel('sales/order')->getCollection()->addAttributeToFilter('designer_id',array('like' => '%'.$id.'%'));

$conVar=mysqli_connect($host,$user,$password,$dbName);

    $htmltext='<select>';  
$htmltext.="<option value=''>Select Order</option>";



foreach ($order as $orderData) 
{

/* for order hide */

    $data=array();
    $sqlq1="select dproduct_id from order_details where designer_id='".$id."' and designerorder_id='".$orderData->getIncrementId()."'";
    $sqlq=mysqli_query($conVar,$sqlq1);

    while($rdata=mysqli_fetch_assoc($sqlq))
    {
        $data[]=$rdata['dproduct_id'];

    }
    $orderitems=$orderData->getData('dproduct_id');
    $oitem=explode(',',$orderitems);
    $finalValue=$orderData->getIncrementId()."-".$orderitemsarray[$k];
    $result=array_diff($oitem,$data);
    $result1=implode(',',$result);
    //$result1 = explode(',',$orderitems);
    //$result1 = $sqlq1;
    if(count($result)>1){  
        $result2=array();
        foreach($result as $product)
        {
            $_product = Mage::getModel('catalog/product')->load($product);
            $_productDesignerId = $_product->getDesignerId();
            if(trim($_productDesignerId) == trim($id))
            {
                $result2[] = trim($product);
            }
        }
        $result2=implode(',',$result2);

        $htmltext=$htmltext.'<option class="'.$result2.'" name="'.$result2.'" value="'.$orderData->getIncrementId().'">'. $orderData->getIncrementId().'</option>';
    } 
/* for order hide end */
/* for designer hide */
/* for designer end */

}

    $htmltext=$htmltext."</select>";
    echo $htmltext;exit;
 ?>
  • updated code, still same result..... – Baby in Magento Jan 2 '17 at 13:57
  • @BabyinMagento, Please check my updated answer. Also let me know if you have any field in magento order table like "dproduct_id" ? – Ashish Jagnani Jan 3 '17 at 12:02
  • please check Edit2 part in question..... – Baby in Magento Jan 5 '17 at 6:06
  • Updated code, sorry still same result..... – Baby in Magento Jan 5 '17 at 7:38
  • updated code, please visit link , email : kidsdial1@gmail.com , pw : kidsdial1 , link , now i can not able to sleect values from order number dropdown – Baby in Magento Jan 5 '17 at 7:50
1
+50

You can do this things to,

  1. Before showing product value in dropdown, Call one Ajax Requestion
  2. In Ajax Request pass that Product Id
  3. Now on that ajax url, in php code check that product_id is show or not in dropdown
  4. Based on Ajax request result can add that value in dropdown or not.

    function getProductDetail(e)
      {    
        var productId = $("#dproductselect option:selected").attr("class");  
        var finalstrig=productId.split(",");
    
        var select='';
        select+='<select class="test" multiple="multiple" name="dproduct_ids" id="dproduct_ids">';
    
        for(i=0;i<finalstrig.length;i++)
        {
           //CREATE ONE AJAX CALL TO CHECK IS THIS PRODUCT ID SHOW IN DROPDOWN OR NOT 
           var returnresult = 0;
           var url="http://sbdev2.kidsdial.com:81/php/site6/productdropdown.php?p_id="+finalstrig[i]; 
           var request = jQuery.ajax( {
                url: url ,
                type: 'POST',                      
            } );
    
            request.done( function (result)
            {  
               returnresult = 1;
    
            });
            request.fail( function ( error )
            {
                console.dir(error);             
            } );
    
          if(finalstrig[i]!=0 && returnresult)
          {
            select +='<option value="'+finalstrig[i]+'">'+finalstrig[i]+'</option>';
          }
        }
        select +='</select>';   
        document.getElementById('productnumbers').innerHTML =select;
        (function($) {
        $(function() {
            $('.test').fSelect();
        });
    })(jQuery);
    
      }
    
  • if you update an answer with ajax request , that will be really helpfull..... – Baby in Magento Nov 28 '16 at 13:55
  • create file productdropdown.php and do the code to check where this id display or not. – Dhiren Vasoya Nov 28 '16 at 13:58
1
+100
dont add any file.. In your designerpaidstatus.php file check if id already exist or not. if exist then compare values of your both tables.... 


 $sqlq1="select dproduct_id from order_details where designer_id='".$id."' and designerorder_id='".$orderData->getIncrementId()."'";
$sqlq=mysqli_query($conVar,$sqlq1);

while($rdata=mysqli_fetch_assoc($sqlq))
{
$data[]=$rdata['dproduct_id'];

}

$orderitems=$orderData['dproduct_id'];
        $oitem=explode(',',$orderitems);
            $finalValue=$orderData->getIncrementId()."-".$orderitemsarray[$k];
$result=array_diff($oitem,$data);
$result1=implode(',',$result);

            if(count($result)>1){  

$htmltext=$htmltext.'<option class="'.$result1.'" name="'.$result1.'" value="'.$orderData->getIncrementId().'">'. $orderData->getIncrementId().'</option>';
  • please check Edit2 part in question..... – Baby in Magento Jan 5 '17 at 6:06
1

@NishantSaini code i doubt on below line

$orderitems=$orderData['dproduct_id'];

above line should be

$orderitems=$orderData->getDproductId();  //because its part of order collection 

In the line no 15 change below line

$order = Mage::getModel('sales/order')->getCollection()->addAttributeToFilter('designer_id',array('like' => '%'.$id.'%'));

TO

$order = Mage::getModel('sales/order')->getCollection()
         ->addAttributeToSelect('*')
         ->addAttributeToFilter('designer_id',array('like' => '%'.$id.'%'));
1

in file update_paidstatus.php change the code like

if(isset($_POST) && $_POST!="" && !empty($_POST)){ // checking if form submision is occured or not.

    $sucessFlag=true;
    $productIds=explode(",",$_POST['dproduct_id']);

    $oDate = new DateTime($_POST['dueDate']);
    $sDate = $oDate->format("Y-m-d");   
    if(isset($conVar) && !empty($conVar) && $conVar!="")
    {
       for ($i=0; $i< count($productIds); $i++) {   

         $sqlQueryToUpdate="INSERT INTO order_details ( designer_id,designerorder_id,dproduct_id,dpaid_status,delivery_status,due_date) VALUES('".$_POST['designer_id']."','".$_POST['designerorder_id']."','".$productIds[$i]."','".$_POST['PaidStatus']."','".$_POST['PaidStatus']."','".$sDate."')";

            $sucessFlag=mysqli_query($conVar,$sqlQueryToUpdate);
                if($sucessFlag==TRUE)
                    {
                       echo "UPDATE SUCESSFULLY";
                    }
                    else
                    {
                    echo " not done.";
                    }           
         }
        header('Location: '.$newURL);  
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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