如标题所述,我无法在结帐页面上设置适当的佣金金额。

情况如下:

佣金是根据产品的总金额(而不是购物车的总金额)由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';
}

最佳答案

您可以在下面按模式设置会话数组,然后佣金不会被覆盖

<?php
while($basketCount>0)
{
    $_SESSION['COMMSSION'][$agentID] += $calculatedCommisiion;
    $basketCount--;
}
?>

关于php - PHP-无法在结帐页面上获得适当的佣金金额,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27996339/

10-10 20:41