5

We have lot of Designers in site (Seller/ Vendor). we assigned each product to one Designer.

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.

Now, Product 1 belongs to Designer1 [kidsdial2]

if any customer buy Product 1 than we will give commission to Designer1 & we need to display commission for designer in Orders.php page for that particular product in both admin & Designer Dashboard.

we are saving commission of each designer in tbl_users table

enter image description here

example: in above image , we assigned "10" as commission for Kidsdial2 Designer . so if any Kidsdial2's product bought by customer, than we need to display "10" as commission for that Ordered Product in both Designer & admin Dashboard.

Edit 2

in Designer account [kidsdial2] commission value is displaying correct value .but when i logged in with admin account [kidsdial1] , commission is displaying as "5" for admin dashboard because for "kidsdial1" we are saving commission as 5 in Database. But as Product belongs to "Kidsdial2", it should display "10" instead of 5 in admin dashboard too.

Designer Dashboard

Designer dashboard

admin Dashboard

enter image description here

if($accountType == "admin")
{ 

$stmt = $user_home->runQuery("SELECT commission1 FROM tbl_users where userID=:uid"); 
$stmt->execute(array(":uid" => $_SESSION['userSession']));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$commission =  $row['commission1'] ;

$responce[] = array( 
$commission
); 
}

related code :

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

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

if ($orderitemsarray[$k] != '0') 
{ 

$productdetail = Mage::getModel('catalog/product')->load($orderitemsarray[$k]); 
$designer_id = $productdetail->getDesignerID() ; 

if($accountType == "admin")
{ 

$stmt = $user_home->runQuery("SELECT commission1 FROM tbl_users where userID=:uid"); 
$stmt->execute(array(":uid" => $_SESSION['userSession']));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$commission =  $row['commission1'] ;

$responce[] = array( 
$commission, 
); 
}

Edit 1 [ Ignore this part, Solved with help of Murtuza's answer ]

i need to display commission value of Designer for that order [row] at last column.

$stmt = $user_home->runQuery("SELECT commission1 FROM tbl_users where userID=:uid"); 
2
  • 2
    Why do you keep opening a bounty for this question ? You already accepted an answer and assigned two different bounties to two other answers Commented Jan 2, 2017 at 15:34
  • @RaphaelatDigitalPianism Thanks for your comment, today only i got an answer , other old answers didt worked for me..... Commented Jan 2, 2017 at 17:02

4 Answers 4

2
+200

Ok you can use this way May be you can achieve what you want

    /* Murtuza */

$stmt = $user_home->runQuery("SELECT commission1 FROM tbl_users where userID=:uid  "); //I assume user_id is field of database in tbl_user table
$stmt->execute(array(":uid" => $productdetail->getDesignerID() ));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$commission =  $row['commission1'] ;

edit

Finally find out your problem

$stmt = $user_home->runQuery("SELECT commission1 FROM tbl_users where userID=:uid");
$stmt->execute(array(":uid" => $_SESSION['userSession']));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$commission =  $row['commission1'] ;

Comment above code start line no 289

14
  • sorry, still its displaying 5 only as commission.... Commented Jan 2, 2017 at 13:12
  • is userID is your primary key in database ? Commented Jan 2, 2017 at 13:21
  • yes, you are right..... Commented Jan 2, 2017 at 13:23
  • @BabyinMagento echo $designer_id; and check what data you get Commented Jan 2, 2017 at 13:26
  • i am getting this : 66666666894545448958444 Commented Jan 2, 2017 at 13:28
5
+50

in your above code

$stmt = $user_home->runQuery("SELECT commission1 FROM tbl_users");
$stmt->execute(array(":uid" => $_SESSION['userSession']));

replace with below

$stmt = $user_home->runQuery("SELECT commission1 FROM tbl_users where user_id=:uid  "); //I assume user_id is field of database in tbl_user table
$stmt->execute(array(":uid" => $_SESSION['userSession']));

you can do below code to your requirement

if($accountType == "admin")
{ 
$designerName = getDesignerName($productdetail->getDesignerID()) . " -(" . $productdetail->getDesignerID() . ")";


   $stmt = $user_home->runQuery("SELECT commission1 FROM tbl_users where name=:designername  "); //I assume user_id is field of database in tbl_user table
$stmt->execute(array(":designername" => $designerName ));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$commission =  $row['commission1'] ;

$responce[] = array( 
$orderData->getIncrementId() , 
$orderData->getIncrementId() , 
$orderitemsarray[$k], 
$productdetail->getName() , 
$designerName, 
$orderData['status'],              // magento  [ pending / processing/complete]
$orderData['grand_total'],         // magento
$orderData['customer_email'],      // magento
$data['commission'],
$paid_status,
$sDate                             // magento
); 

}
10
  • Thanks, now its fetching only one designer commission & displaying 0 at the last row of the table. prnt.sc/dk35zx but i need to display commission for each ordered products row in last column. please help me for this..... Commented Dec 16, 2016 at 9:14
  • @BabyinMagento check my updated answer Commented Dec 16, 2016 at 9:56
  • sorry, still its giving me same result as before..... Commented Dec 16, 2016 at 10:02
  • 1
    @BabyinMagento yes after designer name add my code and edit add that data in responce Commented Dec 16, 2016 at 11:01
  • 1
    @BabyinMagento Have you added commission in response variable and also added that code for particular designer instead of admin Commented Dec 16, 2016 at 11:27
3

Table for Admin display

date    orderid     product_id      name    seller_id   status      commission
1/1/16  O101        101             P101    1           Paid        5
1/1/16  O101        104             P104    4           Paid        15


//Main order loop
foreach ( $orders as $order )
{
    $oitems = $order->getItems();
    if(!empty($oitems)) {
        //Order Items foreach
        foreach($oitems as $oitem)
        {
            echo $order->getOrderDate();
            echo $order->getOrderId();

            $pid = $oitem->getProductId();
            $product = Mage::getModel('catalog/product')->load($pid);
            echo $product->getName();   

            if($accountType  == 'admin') {
                echo $product->getSellerId();
                echo getCommissionByProduct($product);
            } else if($accountType == 'designer' ) {        
                //$user should be already loaded Object designer login
                echo $user->getCommision();
            }

            echo $order->getStatus();

        }
    }   
}

function getCommissionByProduct( $product )
{
    $sid = $product->getSellerId();
    $seller = Mage::getModel('custom/designer')->load($sid);
    if($seller == NULL) {
        return  false;
    }
    $commission = $seller->getCommision();
    return $commission;

}
3
  • Thanks, when i treid your code, i got Fatal error: Call to undefined method Mage_Sales_Model_Resource_Order_Collection::getOrderDate() i in line echo $order->getOrderDate(); Commented Jan 2, 2017 at 5:55
  • please check full code here : pastebin.com/ia8AFA6C Commented Jan 2, 2017 at 5:57
  • Welcome @BabyinMagento
    – sandip
    Commented Jan 2, 2017 at 14:05
1
+100
Here you have fetch data according to designer id not user id

if($accountType == "admin")
{ 

$stmt = $user_home->runQuery("SELECT commission1 FROM tbl_users where userID="'.$desiner_id.'""); 
$stmt->execute(array(":uid" => $_SESSION['userSession']));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$commission =  $row['commission1'] ;

$responce[] = array( 
$commission
); 
}
3
  • let me check and get back to you...... Commented Jan 2, 2017 at 10:34
  • kk because you already getting designer id from order details so basis on that you have to fetch commison Commented Jan 2, 2017 at 10:42
  • i tried your code, now commission is fetching and displaying properly only when there is particular designer value in present in order_Details table. otherwise under Designer & commission column, no values will display.... Commented Jan 2, 2017 at 12:45

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.