PHP - 无法在结帐页面上获得适当的佣金金额 [英] PHP - Unable to get proper commission amount on checkout page

查看:52
本文介绍了PHP - 无法在结帐页面上获得适当的佣金金额的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所说,我无法在结账页面设置适当的佣金。



以下情况:



佣金按2人计算 - 人K和人J,根据产品的总金额而不是购物车的总金额。



我收到佣金金额,但我无法正确设置。



基于产品A总计,产品B总计和产品C总计,我有计算佣金。所有三种产品的佣金率分别为5%,6%,8%。



现在,产品A和产品C属于人K.产品B属于人员J.含义,产品A和产品C的佣金应转移到人员K的账户,产品B的佣金应转移到人员J的账户。



我已计算while循环中的佣金,正确显示了该人的佣金,并将佣金金额存入$ _SESSION变量。



现在,当我移动$ _SESSION代码时循环,它取最后一个值,意味着它覆盖第一个值。



所以我的问题是,我如何分配佣金金额并将其转移给相应的人账户?



非常感谢任何帮助。谢谢。



这是我想要做的实际源代码..



< pre lang =php> if (isset($ _SESSION [' 购物车])&& $ _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,affiate a WHERE ProdCode IN(;
< span class =code-keyword> 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']。' 。jpgalt = '。$ row [' ProdCode']。' >< a href =product.php?code ='。$ row [' ProdCode']。' >'。$ row [' ProdName']。' < / A>< / TD>';
echo ' < td>'.$row[' ProdCode']。 ' < / td>';
echo ' < td>< p为H.卢比。 '。$ row [' ProdRate']。' < / p>< / td>';
echo ' < td>'.$_SESSION[' cart'] [$ row [' ProdCode']] [' 数量']。' < / td>';

$ sbTotal = $ row [' ProdRate'] * $ _SESSION [' cart'] [$ row [ ' ProdCode']] [' < span class =code-string> quantity'
];
$ subTotal = $ sbTotal ;
echo ' < td>< p>' .number_format($ sbTotal,2)。' < / p>< / td> ;';
$ total + = $ subTotal ;
$ _SESSION [' cartTotalAmount'] = $总;
$ tax = $ row [' CatTaxPercent ];
$ taxAmt =(($ sbTotal * $ tax )/ 100);
$ taxAmount + = $ taxAmt ;
$ amt = 0 ;
$ cartWeightPerProduct =($ row [' 权重'] * $ _SESSION [' cart'] [$ row [' ProdCode']] [' 量']);
echo ' < / tr>' ;
$ totalCartWeight + = $ cartWeightPerProduct ;

$ affComm = $ row [' ProdAffCommision'];
$ affiCode = $ row [' AffiCode ];

$ _SESSION [' ProductCommission'] [' 主持人'] =($ sbTotal * $ row [' < span class =code-string> 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 ;
} 其他 {
$ amt = Rs.0;
}

echo ' < tr>< td>< p>购物车总计:< / p>< / td>< td>< p>' .number_format($ total,2)。 ' < / p>< / td>< / tr>';

echo ' < tr>< td>< p>税收:< / p>< / td>< td>< p>(+)'。 number_format($ totalTaxAmount,2)。' < / p>< / td>< / tr>'< /跨度>;

echo ' < tr>< td>< p>送货:< / 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 GT&;';

echo ' < tr>< td>< p>应用商店积分:< / p>< / td>< td>< p>( - )'。$ cred。' < / p>< / td>< / tr>';

echo ' < tr>< td>< p>总应付金额:< / 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>继续< / button>< / td>< / tr>';
} elseif(isset($ _SESSION [' PaymentMethod'] [' COD'])&& $ _SESSION [' PaymentMethod'] [' COD'] != ){
echo ' < tr>< td>< / td>< td>< button id = btnCODPaymentclass =f_right tr_delay_hover r_corners button_type_16 f_size_medium bg_scheme_color color_light m_xs_bottom_5>完成< / button>< / td>< / tr>';
}

}
}
} 其他 {
echo ' 你的购物车是空的';
}

解决方案

_SESSION变量。



现在,当我将


_SESSION代码移出while循环时,它会取最后一个值,这意味着它会覆盖第一个值。



所以我的问题是,我如何分配佣金金额并将其转移到相应的个人账户?



非常感谢任何帮助。谢谢。



这是我想要做的实际源代码..



< pre lang =php> if (isset(


_SESSION [' cart'])&&


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';
}

解决方案

_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'] ) &&


这篇关于PHP - 无法在结帐页面上获得适当的佣金金额的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆