正如标题所说,我无法在结帐页面设置适当的佣金。
情况如下:
佣金是根据产品的总金额收取2个人 - 人K和人J,而不是购物车的总金额。
我收到佣金金额,但我无法正确设置。
例如:
我有购物车
Name Quantity Rate Total Commission
A 3 50.00 150.00 7.50
B 3 80.00 240.00 14.40
C 2 10.00 20.00 1.60
Total 410.00
Taxes 100.00
Shipping 250.00
Net Payable 760.00
根据产品A总计,产品B总计和产品C总计,我必须计算佣金。所有三种产品的佣金率分别为5%,6%,8%。
现在,产品A和产品C属于人员K.产品B属于人员J.含义,产品A和产品C的佣金应转移到人员K的账户,产品B的佣金应转移到人员J的账户
我已经计算了while
循环内的佣金,该佣金正确显示了该人的佣金,并将佣金金额存储在$_SESSION
变量中。
现在,当我将$_SESSION
代码移出while循环时,它会取最后一个值,这意味着它会覆盖第一个值。
所以我的问题是,如何分配佣金金额并将其转移到相应的个人账户?
非常感谢任何帮助。谢谢。
编辑1 :
我尝试过的代码位于while
循环
$_SESSION['ProductCommission']['PersonK'] = ($productTotal * $row['ProductPersonKCommission'] / 100);
$_SESSION['ProductCommission']['PersonJ'] = ($productTotal * $row['ProductPersonJCommission'] / 100);
编辑2 :
完整代码(实际):
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';
}
答案 0 :(得分:1)
您可以按照模式将会话数组设置为低于佣金不会覆盖
<?php
while($basketCount>0)
{
$_SESSION['COMMSSION'][$agentID] += $calculatedCommisiion;
$basketCount--;
}
?>
答案 1 :(得分:0)
并不是说你容易理解。
我会再试一次。
您必须将每个产品ID与佣金的相应收件人相关联。假设产品数量不是天文数字,请为每个产品构建一个关联数组“whoGetsPaid as ProdCode =&gt; PersonPaid。例如
然后在处理每个产品后添加:
$_SESSION[ProductCommission][$whoGetsPaid[$row['ProdCode']] += ($sbTotal * $row['ProdModCommission'] / 100);