Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- foreach($data->cart->getLineItems() as $lineItem) {
- $priceDefinition = $lineItem->getPriceDefinition();
- $temp = [];
- foreach($priceDefinition->getTaxRules() as $taxRule) {
- $taxRate = $taxRule->getTaxRate();
- $taxMultiplier = 1 + ($taxRate / 100);
- $temp['taxRate'] = $taxRate;
- $temp['taxMultiplier'] = $taxMultiplier;
- $temp['taxValue'] = 0;
- if(count($data->cart->taxItems) == 0) {
- array_push($data->cart->taxItems, $temp);
- }
- if(count($data->cart->taxItems) > 0) {
- foreach($data->cart->taxItems as $taxItem) {
- if($taxItem['taxRate'] != $temp['taxRate']) {
- array_push($data->cart->taxItems, $temp);
- }
- }
- }
- }
- $calculatedTaxes = $lineItem->getPrice()->getCalculatedTaxes();
- foreach($calculatedTaxes as $calculatedTax) {
- $taxRate = $calculatedTax->getTaxRate();
- $taxValue = $calculatedTax->getTax();
- if(count($data->cart->taxItems) > 0) {
- $i = 0;
- foreach($data->cart->taxItems as $taxItem) {
- if($taxItem['taxRate'] === $taxRate) {
- if(array_key_exists('taxValue', $taxItem)) {
- $data->cart->taxItems[$i]['taxValue'] += round($taxValue);
- } else {
- $data->cart->taxItems[$i]['taxValue'] = round($taxValue);
- }
- }
- $i++;
- }
- }
- }
- $singleTotalPrice = $priceDefinition->getPrice();
- $singleNetPrice = $singleTotalPrice / $taxMultiplier;
- $allTotalPrice = $singleTotalPrice * $priceDefinition->getQuantity();
- $allNetPrice = $singleNetPrice * $priceDefinition->getQuantity();
- $data->cart->allPositionsNet += $allNetPrice;
- $data->cart->allPositionsTotal += $allTotalPrice;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement