As the title says, I am unable to set the proper amount of commission on checkout page.
Here's the situation:
The commission is charged for 2 peoples - Person K and Person J, based on the product's total amount, and not on the cart's total amount.
I am getting the commission amount, but I cannot set it correctly.
Based on Product A Total, Product B Total, and Product C Total, I have to calculate the commission. Commission rates are 5%, 6%, 8% respectively for all three products.
Now, Product A and Product C belongs to the Person K. Product B belongs to the Person J. Meaning, Product A's and Product C's commission should be transferred to Person K's account and Product B's commission should be transferred to Person J's account.
I have calculated the commission inside while loop which shows the person's commission correctly and stored the commission amount in $_SESSION variable.
Now, when I move the $_SESSION code out of the while loop, it takes the last value, meaning it overrides the first value.
So my question is, how do I bifurcate the commission amount and transfer it to the respective person account ?
Any help is greatly appreciated. Thank you.
Here's the actual source code of what I am trying to do..
if ( isset( $_SESSION['cart'] ) && $_SESSION['cart'] != "" ) {
$total = 0;
$subTotal = 0; $sbTotal = 0;
$taxAmount = $tax = $totalTaxAmount = $taxAmt = 0;
$cartWeightPerProduct = $totalCartWeight = $amtWeight = 0;
$affiliateCommission = $affComm = 0;
$affiCode = "";
$sql = "SELECT p.*, c.*, ws.*, m.*, a.* FROM products p, categories c, weight_shipping ws, moderators m, affiliates a WHERE ProdCode IN (";
foreach ( $_SESSION['cart'] as $id => $value ) {
$sql .= '"'.$id.'",';
}
$sql = substr( $sql, 0, -1 ) . ") AND p.CatId = c.CatId AND ws.ProdId = p.ProdId AND m.ModCode = p.ModCode AND a.AffiCode = p.AffiCode";
if ($validate->Query($sql) == TRUE) {
if ($validate->NumRows() >= 1) {
while ( $row = $validate->FetchAllDatas() ) {
echo '<td><img src="images/Products/'.$row['ProdCode'].'.jpg" alt="'.$row['ProdCode'].'"><a href="product.php?code='.$row['ProdCode'].'" >'.$row['ProdName'].'</a></td>';
echo '<td>'.$row['ProdCode'].'</td>';
echo '<td><p>Rs. '.$row['ProdRate'].'</p></td>';
echo '<td>'.$_SESSION['cart'][$row['ProdCode']]['quantity'].'</td>';
$sbTotal = $row['ProdRate'] * $_SESSION['cart'][$row['ProdCode']]['quantity'];
$subTotal = $sbTotal;
echo '<td><p>'.number_format($sbTotal, 2).'</p></td>';
$total += $subTotal;
$_SESSION['cartTotalAmount'] = $total;
$tax = $row['CatTaxPercent'];
$taxAmt = (($sbTotal * $tax ) / 100);
$taxAmount += $taxAmt;
$amt = 0;
$cartWeightPerProduct = ($row['weight'] * $_SESSION['cart'][$row['ProdCode']]['quantity']);
echo '</tr>';
$totalCartWeight += $cartWeightPerProduct;
$affComm = $row['ProdAffCommision'];
$affiCode = $row['AffiCode'];
$_SESSION['ProductCommission']['Moderator'] = ($sbTotal * $row['ProdModCommission'] / 100);
$_SESSION['ProductCommission']['Affiliate'] = ($sbTotal * $affComm / 100);
}
$totalTaxAmount += $taxAmount;
$_SESSION['cartWeight'] = $totalCartWeight;
if ( isset( $_SESSION['credits'] ) && $_SESSION['credits'] != "" ) {
$cred = number_format( $_SESSION['credits'], 2 );
} else {
$cred = number_format( 0, 2 );
}
$sessAmnt = ($total + $totalTaxAmount);
$totalPayableAmnt = $sessAmnt + $_SESSION['TotalWeight'];
$_SESSION['sessionTotalPayable'] = ( $totalPayableAmnt - $cred );
$_SESSION['Presentation']['TotalPayableAmount'] = ( $totalPayableAmnt - $cred );
if ( isset( $_SESSION['sessionTotalPayable'] ) ) {
$amt = $totalPayableAmnt;
} else {
$amt = "Rs. 0";
}
echo '<tr><td><p>Cart Total:</p></td><td><p>'.number_format($total, 2).'</p></td></tr>';
echo '<tr><td><p>Taxes:</p></td><td><p>(+) '. number_format($totalTaxAmount, 2) .'</p></td></tr>';
echo '<tr><td><p>Shipping:</p></td><td><p id="shippingAmount">(+) '.number_format($_SESSION['TotalWeight'], 2).'</p></td></tr>';
echo '<tr><t><p><b>Gross Payable:</b></p></td><td><p><b>'.number_format( $totalPayableAmnt ,2 ).'</b></p></td></tr>';
echo '<tr><td><p>Applied Store Credits:</p></td><td><p >(-) '.$cred.'</p></td></tr>';
echo '<tr><td><p>Total Payable Amount:</p></td><td><p >'.number_format( ($amt - $cred ), 2).'</p></td></tr>';
if ( isset( $_SESSION['PaymentMethod']['NetBanking'] ) && $_SESSION['PaymentMethod']['NetBanking'] != "" ) {
echo '<tr><td></td><td><button class="f_right tr_delay_hover r_corners button_type_16 f_size_medium bg_scheme_color color_light m_xs_bottom_5">Proceed</button></td></tr>';
} elseif ( isset( $_SESSION['PaymentMethod']['COD'] ) && $_SESSION['PaymentMethod']['COD'] != "" ) {
echo '<tr><td></td><td><button id="btnCODPayment" class="f_right tr_delay_hover r_corners button_type_16 f_size_medium bg_scheme_color color_light m_xs_bottom_5">Done</button></td></tr>';
}
}
}
} else {
echo 'Your Cart Is Empty';
}