Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. foreach($data->cart->getLineItems() as $lineItem) {
  2. $priceDefinition = $lineItem->getPriceDefinition();
  3.  
  4.  
  5. $temp = [];
  6. foreach($priceDefinition->getTaxRules() as $taxRule) {
  7. $taxRate = $taxRule->getTaxRate();
  8. $taxMultiplier = 1 + ($taxRate / 100);
  9.  
  10. $temp['taxRate'] = $taxRate;
  11. $temp['taxMultiplier'] = $taxMultiplier;
  12. $temp['taxValue'] = 0;
  13.  
  14. if(count($data->cart->taxItems) == 0) {
  15. array_push($data->cart->taxItems, $temp);
  16. }
  17. if(count($data->cart->taxItems) > 0) {
  18. foreach($data->cart->taxItems as $taxItem) {
  19. if($taxItem['taxRate'] != $temp['taxRate']) {
  20.  
  21. array_push($data->cart->taxItems, $temp);
  22. }
  23. }
  24. }
  25. }
  26.  
  27. $calculatedTaxes = $lineItem->getPrice()->getCalculatedTaxes();
  28. foreach($calculatedTaxes as $calculatedTax) {
  29. $taxRate = $calculatedTax->getTaxRate();
  30. $taxValue = $calculatedTax->getTax();
  31.  
  32. if(count($data->cart->taxItems) > 0) {
  33. $i = 0;
  34. foreach($data->cart->taxItems as $taxItem) {
  35. if($taxItem['taxRate'] === $taxRate) {
  36.  
  37. if(array_key_exists('taxValue', $taxItem)) {
  38. $data->cart->taxItems[$i]['taxValue'] += round($taxValue);
  39. } else {
  40. $data->cart->taxItems[$i]['taxValue'] = round($taxValue);
  41. }
  42. }
  43. $i++;
  44. }
  45. }
  46.  
  47. }
  48.  
  49. $singleTotalPrice = $priceDefinition->getPrice();
  50. $singleNetPrice = $singleTotalPrice / $taxMultiplier;
  51. $allTotalPrice = $singleTotalPrice * $priceDefinition->getQuantity();
  52. $allNetPrice = $singleNetPrice * $priceDefinition->getQuantity();
  53.  
  54. $data->cart->allPositionsNet += $allNetPrice;
  55. $data->cart->allPositionsTotal += $allTotalPrice;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement