6

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 displaying all the orders in custom page : www.1234.com/php/site6/orders.php

if we login as admin we can see all orders in page .

if we login as Designer1, than we can see all orders that contains Designer1's Products.

if we login as Designer2, than we can see all orders that contains Designer2's Products.

enter image description here

Now, Product 1 belongs to Designer1 [kidsdial2] , Product 2 belongs to Designer2 [kidsdial3].

if we login as Designer1 or Designer2 , we can see as above image.

It contains Products of both Designer 1 & Designer 2 as because customer ordered both products in single order.

but I want to display only Designer 1 product if we login as Designer1 & same for Designer 2

We are saving Designer id & Designer names in custom database with table tbl_users , columns : userID [Designer ID] , name [Designer]

function getDesignerCollection()
    {

    $user_home = new USER();
    require_once '../../app/Mage.php';

    Mage::app();

    $stmts = $user_home->runQuery("SELECT * FROM tbl_users WHERE userID=:uid");
    $stmts->execute(array(
        ":uid" => $_SESSION['userSession']
    ));
    $rows = $stmts->fetch(PDO::FETCH_ASSOC);

    $accountType = $rows['type'];
    if ($accountType == "admin")
        {
        $is_admin = true;
        $order = Mage::getModel('sales/order')->getCollection()->addAttributeToFilter('designer_id', array(
            'nin' => '0'
        ));

        }
      else
        {
        $order = Mage::getModel('sales/order')->getCollection()->addAttributeToFilter('designer_id', array(
            'like' => '%' . $_SESSION['userSession'] . '%'
        ));

        }

    $i = 0;

    foreach($order as $orderData)
        {
        $orderitems = $orderData['dproduct_id'];
        $orderitemsarray = explode(",", $orderitems);
        $k = 0;
        $oDate = new DateTime($orderData['created_at']);
        $sDate = $oDate->format("M d, Y");

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

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

                $productdetail = Mage::getModel('catalog/product')->load($orderitemsarray[$k]);
                $designerName = getDesignerName($productdetail->getDesignerID()) . " -(" . $productdetail->getDesignerID() . ")";
                $responce[] = array(
                    $orderData->getIncrementId() ,
                    $orderData->getIncrementId() ,
                    $orderitemsarray[$k],
                    $productdetail->getName() ,
                    $designerName,
                    $orderData['status'],
                    $orderData['grand_total'],
                    $orderData['customer_email'],
                    $commission,
                    $dorderStatus,              
                    $sDate
                );

                }

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

    echo json_encode($responce);
    }

Edit : Sales_flat_order table

enter image description here

Edit 2

Below code is reason for displaying both Designers Products, what code i need to use for displaying only that designer products

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

20
  • designer column represent the current user? Commented Nov 28, 2016 at 7:16
  • @QaisarSatti yes , in image if you see kidsdial2 is owner of product product1 & kidsdial3 is owner of product product2 Commented Nov 28, 2016 at 7:17
  • what represent the kidsdial2 -(4) in that -(4) Commented Nov 28, 2016 at 7:19
  • @QaisarSatti 4 is Designer id , we will enter that under catalog > manage Products section.... Commented Nov 28, 2016 at 7:19
  • these are values of tbl_users table? what is column name for username? Commented Nov 28, 2016 at 7:20

4 Answers 4

1
+50

AFter Long Discussion WE come to this conclusion

$order = Mage::getModel('sales/order')->getCollection()->addAttributeToFilter('designer_id', array(
'like' => '%' . $_SESSION['userSession'] . '%'
))
->addAttributeToSelect('designer_id')
->addAttributeToSelect('created_at')
->addAttributeToSelect('dproduct_id')
->addAttributeToSelect('customer_id')
->addAttributeToSelect('increment_id')
->addAttributeToSelect('updated_at')
->addAttributeToSelect('status')
->addAttributeToSelect('entity_id')
->addAttributeToSelect('state');

and In foreach Loop

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

        $oDate = new DateTime($orderData['created_at']);
        $sDate = $oDate->format("M d, Y");

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

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



                if($data['type']=="admin")continue;

                if($data['dpaid_status']=='P'){$dorderStatus='Paid';}
                if($data['dpaid_status']=='U'){$dorderStatus='Unpaid';}
                if($data['dpaid_status']=='R'){$dorderStatus='Returned';}
                if($data['dpaid_status']==''){$dpaid_status='';}

                if ($roworders[

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

                if ($roworders['dproduct_id'] == '')
                    {
                    $commission = "comm";
                    }
                  else
                    {
                    $commission = $roworders['commission'];
                    }

                $productdetail = Mage::getModel('catalog/product')->load($orderitemsarray[$k]);
                $designer_id = $productdetail->getDesignerID() ;
                if($accountType == "admin"){
                    $designerName = getDesignerName($productdetail->getDesignerID()) . " -(" . $productdetail->getDesignerID() . ")";
                    $responce[] = array(
                        $orderData->getIncrementId() ,
                        $orderData->getIncrementId() ,
                        $orderitemsarray[$k],
                        $productdetail->getName() ,
                        $designerName,
                        $orderData['status'],
                        $orderData['grand_total'],
                        $orderData['customer_email'],
                        $commission,
                        $dorderStatus,             
                        $sDate
                    );

                }else{

                if( $designer_id== $_SESSION['userSession'] ){
                    $designerName = getDesignerName($productdetail->getDesignerID()) . " -(" . $productdetail->getDesignerID() . ")";
                    $responce[] = array(
                        $orderData->getIncrementId() ,
                        $orderData->getIncrementId() ,
                        $orderitemsarray[$k],
                        $productdetail->getName() ,
                        $designerName,
                        $orderData['status'],
                        $orderData['grand_total'],
                        $orderData['customer_email'],
                        $commission,
                        $dorderStatus,             
                        $sDate
                    );
                }
              }

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

}
18
  • stilll same result is displaying..... link , email : [email protected] , pw : kidsdial2 Commented Dec 9, 2016 at 13:40
  • @BabyinMagento still loading there is something problem with your url Commented Dec 9, 2016 at 13:45
  • sorry for that , please wait for some time or try in another window, it take some time, i will improve performance once i done with features.... Commented Dec 9, 2016 at 13:49
  • @BabyinMagento please check my updated answer I have removed extra space Commented Dec 9, 2016 at 13:52
  • 1
    @BabyinMagento let me check again from my side Commented Dec 12, 2016 at 7:52
2

This will be your query

$designers= $rows['name'].' ('.$rows['id'].')';
$userbasedorder = $user_home->runQuery("SELECT * FROM order_details WHERE Designer=:designer");
$userbasedorder->execute(array(":designer"=>$designers));
19
  • its not displaying any orders of Designer , i replaced your code by else part code : $order = Mage::getModel('sales/order')->getCollection()->addAttributeToFilter('designer_id',array('like' => '%'.$_SESSION['userSession'].'%')); Commented Nov 28, 2016 at 7:34
  • you said it is order_details table Commented Nov 28, 2016 at 7:35
  • check the value of $designers= $rows['name'].' ('.$rows['id'].')'; it is correct or not? Commented Nov 28, 2016 at 7:36
  • sorry, we need to filter with help of sales_flat_order table , please check Edit part in question . Designer id 4 is owner of product id 15517 Commented Nov 28, 2016 at 7:49
  • The image is of table of sales_flat_order or other? Commented Nov 28, 2016 at 7:51
1

You can get designer_id from sales_flat_order table using finset query condition to get correct result from comma separated value,

Replace your else part in query,

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

With below one,

$order = Mage::getModel('sales/order')->getCollection();

$order->addAttributeToFilter('designer_id',array(  array('finset'=> array($_SESSION['userSession']) ) ) );
14
  • i tried your code, still if we login with 1st designer account, designer2 products information are displaying.... Commented Dec 9, 2016 at 13:34
  • link , email : [email protected] , pw : kidsdial2 Commented Dec 9, 2016 at 13:40
  • in $order not any data return for you? Commented Dec 12, 2016 at 6:32
  • i am getting this : Notice: Undefined variable: order when i used this : print $order; Commented Dec 12, 2016 at 6:34
  • I think you have to debug from first line of your code, first check $rows value is found or not? Commented Dec 12, 2016 at 6:36
1

By looking at the way you're saving the Designer ids, there are 4 ways a designer id can be saved, so you just need to add all those in your condition.

$order = Mage::getModel('sales/order')->getCollection()->addAttributeToFilter(
    array('designer_id', 'like' => $_SESSION['userSession'] . ',%'), // When the designer id appears at the first
    array('designer_id', 'like' => '%,' . $_SESSION['userSession'] . ',%'), // when the designer id appears in the middle
    array('designer_id', 'like' => '%,' . $_SESSION['userSession']), // when the designer id appears at last
    array('designer_id', 'eq' => $_SESSION['userSession']) // when that is the only designer id
)

The above code applies OR condition to the filter conditions according to this reference. (Search for Filter Condition Codes and you can find the code after condition table.

If the above doesn't work, try to replace addAttributeToFilter with addFieldToFilter as suggested by @Murtuza

4
  • let me check now..... Commented Dec 10, 2016 at 16:52
  • Hope it helps...
    – V.S
    Commented Dec 10, 2016 at 16:57
  • I can see the table when I log in
    – V.S
    Commented Dec 10, 2016 at 17:01
  • Can we continue this in chat (chat.stackexchange.com/…)?
    – V.S
    Commented Dec 10, 2016 at 17:07

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.