alexm Posted June 24, 2022 Share Posted June 24, 2022 Happy Friday @kongondo I see that getCartTaxTotals() is no longer in use therefor $padloper->cart->getCartTaxTotals() is redundant. There is reference to a utility for this but I can't see it in utilities, only one for orders. Am I missing something or is this yet to be implemented for PadloperCart? Thanks in advance ? Link to comment Share on other sites More sharing options...
alexm Posted June 24, 2022 Author Share Posted June 24, 2022 Or perhaps $padloper->padloperUtilities->calculateTaxOnAmount($padloper->getOrderTotalAmount()) is what I'm after? I'm just getting 0 on cart edit though even if I apply a base 20% tax to all items. ===== Yeah, nah, that won't work cus that's for orders not cart items. Hmmm. Link to comment Share on other sites More sharing options...
alexm Posted June 24, 2022 Author Share Posted June 24, 2022 Ok, looking at your demo, it's calculated at the order confirmation step. I'm assuming this is due to the necessity to know the customer's country first obviously. 1 Link to comment Share on other sites More sharing options...
kongondo Posted June 24, 2022 Share Posted June 24, 2022 Hi @alexm, Yes, the method moved. It is in the docs here. However, currently something has messed up the JavaScript in the docs so the content is not loading. Here's the code from that example: <?php namespace ProcessWire; /** @var WireArray $orderLineItems */ $orderLineItems = $padloper->getOrderLineItems(); /** @var array $orderTaxTotals */ $orderTaxTotals = $padloper->getOrderTaxTotals($orderLineItems); foreach ($orderTaxTotals as $taxShortName => $taxValue) { echo "<span>{$taxShortName}: </span><span>" . $padloper->renderCartPriceAndCurrency($taxValue) . "</span><br>"; } 26 minutes ago, alexm said: I'm assuming this is due to the necessity to know the customer's country first obviously. Exactly. 1 1 Link to comment Share on other sites More sharing options...
alexm Posted June 24, 2022 Author Share Posted June 24, 2022 Thank you kindly for this and for such a swift response mate! Happy weekend to you 1 Link to comment Share on other sites More sharing options...
Jan Fromm Posted June 30, 2022 Share Posted June 30, 2022 Somehow related: $padloper->getOrderTotalAmount() returns 0 once the order is confirmed. I am trying to display the order net amount (Excluding taxes and shipping) in the order-products-table.php template. In /checkout-custom/confirmation/ it works, but in /checkout-custom/success/ it returns 0. Link to comment Share on other sites More sharing options...
kongondo Posted June 30, 2022 Share Posted June 30, 2022 (edited) Hi @Jan Fromm, 5 hours ago, Jan Fromm said: but in /checkout-custom/success/ it returns 0. That's the expected behaviour. This is because for a successful order checkout, when /checkout-custom/success/ is called, the order has been finalised hence Padloper clears the sessions related to the successful order. Hence, $padloper->getOrderTotalAmount() finds nothing. In fact, if you reload the page at this point, you will be redirected to the shop's homepage as their is no current 'cart'. 5 hours ago, Jan Fromm said: I am trying to display the order net amount (Excluding taxes and shipping) in the order-products-table.php template. There's at least two ways to do this. order-products-table.php template receives a number of template variables: <?php namespace ProcessWire; /** @var WireData $order */ /** @var WireArray $orderLineItems */ /** @var float $orderSubtotal */ /** @var bool $isOrderGrandTotalComplete */ /** @var bool $isOrderConfirmed */ We can use those to calculate the order amount minus taxes and shipping. Method #1: ADD TOTAL PRICE OF EACH LINE ITEM <?php namespace ProcessWire; // init empty total price $totalPriceMinusTaxesAndShipping = 0; foreach ($orderLineItems as $orderLineItem) { // @note: there are also aliases to line item 'totalPrice' // if you prefer, i.e. 'lineItemTotalPrice' and 'orderItemTotalPrice' // ------- // add price of each line item /** @var WireData $orderLineItem */ $totalPriceMinusTaxesAndShipping += (float) $orderLineItem->totalPrice; } // @debug: here is your total price without taxes and shipping // @note: if you applied discounts, those will be reflected in this value bd($totalPriceMinusTaxesAndShipping, __METHOD__ . ': $totalPriceMinusTaxesAndShipping at line #' . __LINE__); Method #2: GET ORDER SUBTOTAL AND MINUS ORDER TAX TOTALS <?php namespace ProcessWire; /** @var array $orderTaxTotalsArray */ // get all the taxes applied to order // this returns 'tax_name' => 'total_tax_applied' values $orderTaxTotalsArray = $padloper->getOrderTaxTotals($orderLineItems); // sum the tax totals $orderTaxTotals = array_sum($orderTaxTotalsArray); // $orderSubtotal = order_total + tax_total (it doesn't including shipping) // subtract taxes from order subtotal $totalPriceMinusTaxesAndShipping = (float) $orderSubtotal - $orderTaxTotals; // @debug: here is your total taxes bd($orderTaxTotals, __METHOD__ . ': $orderTaxTotals at line #' . __LINE__); // @debug: here is your total price without taxes and shipping bd($totalPriceMinusTaxesAndShipping, __METHOD__ . ': $totalPriceMinusTaxesAndShipping at line #' . __LINE__); Hope this helps. Edited June 30, 2022 by kongondo Link to comment Share on other sites More sharing options...
Jan Fromm Posted July 1, 2022 Share Posted July 1, 2022 14 hours ago, kongondo said: Hope this helps. It does. Thanks for the explanation, @kongondo! 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now