News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

own tax (TaxBill) - Tip

Started by ernst007, May 19, 2021, 22:58:57 PM

Previous topic - Next topic

ernst007

I created my own plugin with the function
public function plgVmOnUserOrder(&$order)
I need to add a tip to the price. To enter it in the cart, I have a customer field "tip".
I can't or don't want to use billDiscountAmount or billTaxAmount.

I created my own tax (TaxBill). I fill it with a tip in the plugin, I have it correctly in orders.php in $ _orderData. It is also stored correctly in the virtuemart_orders table in the order_billTax field.
To my surprise, the order does not work with this field but with the paired table virtuemart_order_calc_rules.
I can't figure out how to write the calculated tip value into this table. At the moment when my plugin is called, these tables do not exist yet and the entry in the table virtuemart_order_calc_rules does not exist at the moment when I leave the function
private function _createOrder($_cart, $_usr) v /administrator/components/com_virtuemart/models/orders.php

So I can easily add the tip to the total amount of the order, but I can't show the tip amount in the order.
I can't even use the note - order_note, because taj is also not taken later from the virtuemart_orders table but from the virtuemart_order_userinfos table.

The code in the plugin is as follows.
public function plgVmOnUserOrder(&$order) {
        var_dump($order);
        $dane = json_decode($order->order_billTax);
        foreach ($dane as $key => $dan) {
            if ($dan->calc_name == "tip") {
                $spr = $order->tip / 100 * $order->order_salesPrice;
                $order->order_total += $spr;
                $dane->{$key}->result=$spr;
                $dane->{$key}->calc_value=$spr;
                $order->order_billTax = json_encode($dane);
            }
        }
        return true;
     }


Can anyone please advise me how to get the calculated tips into the order?
How to get the calculated tips into the table virtuemart_order_calc_rules (for example by editing in orders.php), in any other way.



ernst007

I solved it by writing tips in the table virtuemart_order_calc_rules, and I also use the plgVmConfirmedOrder trigger to write.