Skip to content

Commit

Permalink
2.2.19 - added tax amount for cart and order items
Browse files Browse the repository at this point in the history
  • Loading branch information
bnayalivne committed Mar 26, 2018
1 parent 84a8264 commit d89c67f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 29 deletions.
71 changes: 44 additions & 27 deletions Model/Api/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Magento\Framework\App\Cache\TypeListInterface;
use Magento\Framework\DataObject;
use Magento\Quote\Model\Quote\Item;
use Magento\Sales\Model\Order;
use Remarkety\Mgconnector\Api\Data\QueueInterface;
use Remarkety\Mgconnector\Api\DataInterface;
use \Magento\Catalog\Model\ProductFactory;
Expand Down Expand Up @@ -189,20 +190,11 @@ class Data implements DataInterface
"fulfillment_status",
"id" => 'entity_id',
"line_items" => [
"product_id" => 'product_id',
"quantity" => 'qty_ordered',
"sku" => 'sku',
"name" => 'name',
"title",
"variant_title",
"vendor",
"price" => 'price',
"taxable",
"tax_lines" => [
"title",
"price",
"rate"
]
"product_id" => "product_id",
"quantity" => "qty_ordered",
"sku" => "sku",
"name" => "name",
"price" => "price"
],
"note" => 'customer_note',
"shipping_lines" => [
Expand All @@ -220,13 +212,12 @@ class Data implements DataInterface
"price",
"rate"
],
"taxes_included" => 'base_tax_amount',
"total_tax" => "tax_amount",
"test",
"total_discounts" => 'base_discount_amount',
"total_line_items_price",
"total_price" => 'grand_total',
"total_shipping" => 'shipping_amount',
"total_tax",
"total_weight" => 'weight',
"updated_at" => 'updated_at'
],
Expand Down Expand Up @@ -254,16 +245,9 @@ class Data implements DataInterface
"quantity" => 'qty',
"sku" => 'sku',
"name" => 'name',
"title",
"variant_title",
"vendor",
"price" => 'price',
"taxable",
"tax_lines" => [
"title",
"price",
"rate"
]
"tax_amount" => "tax_amount"
],
"note" => 'customer_note',
"shipping_address" => [
Expand Down Expand Up @@ -758,6 +742,9 @@ public function getOrders(
$pageNumber = null;
$pageSize = null;

/**
* @var Order[] $orders
*/
$orders = $this->_salesOrderResourceCollectionFactory->create();

$orders->addFieldToFilter('main_table.store_id', array('eq' => $mage_store_id));
Expand Down Expand Up @@ -807,8 +794,6 @@ public function getOrders(
$map = $this->response_mask;
$ordersArray = [];
foreach ($orders as $order) {
$items = $order->getAllItems();

$ord = [];
$orderDetails = $order->getData();
foreach ($map['orders'] as $element => $value) {
Expand Down Expand Up @@ -847,6 +832,10 @@ public function getOrders(
$ord['customer']['default_address']['phone'] = $billingAddressData->getTelephone();
}
$ord['line_items'] = [];
/**
* @var Order\Item[] $items
*/
$items = $order->getAllVisibleItems();
foreach($items as $item){
$newItem = [];
$itemElement = $item->getData();
Expand All @@ -857,6 +846,13 @@ public function getOrders(
}
}
}
$totalTaxAmount = (float)$item->getTaxAmount();
$qty = (int)$item->getQtyOrdered();
if($totalTaxAmount > 0 && $qty > 0){
$newItem['tax_amount'] = ($totalTaxAmount / $qty);
}
$newItem['line_total_incl_tax'] = $item->getRowTotalInclTax();
$newItem['line_total_tax'] = $item->getTaxAmount();
$ord['line_items'][] = $newItem;
}
$ord['status']= $this->getStoreOrderStatusesByCode($orderDetails['status']);
Expand Down Expand Up @@ -940,6 +936,9 @@ public function getQuotes(
$pageNumber = null;
$pageSize = null;

/**
* @var Quote[] $quotes
*/
$quotes = $this->quoteFactory->create()->getCollection();
$quotes->addFieldToFilter('is_active' , 1);

Expand Down Expand Up @@ -1009,11 +1008,13 @@ public function getQuotes(
}
}
}
$quoteArray['total_shipping'] = (float)$defaultShipping['shipping_amount'];
$itemsCollection = $quote->getItemsCollection();
$customer = $this->mapCustomer($quote->getCustomerId());
$quoteArray['customer'] = $customer;

$itemArray = [];
$cartTotalTax = 0;
foreach ($itemsCollection as $item) {
if ($item->getProductType() == 'simple') {
$itemsData = $item->getData();
Expand All @@ -1025,13 +1026,29 @@ public function getQuotes(
}
}
}

$parentItem = $item->getParentItem();
if($parentItem && $parentItem->getProductType() == Configurable::TYPE_CODE){
$itemData['price'] = $parentItem->getPrice();
$qty = (float)$parentItem->getQty();
$totalTax = (float)$parentItem['tax_amount'];
} else {
$qty = (float)$item->getQty();
$totalTax = (float)$itemData['tax_amount'];
}
$cartTotalTax += $totalTax;
$itemData['quantity'] = $qty;

if(!empty($totalTax) && $qty > 0){
$taxAmount = $totalTax / $qty;
} else {
$taxAmount = 0;
}
$itemData['tax_amount'] = $taxAmount;
$itemArray[] = $itemData;
}
}
$quoteArray['total_tax'] = $cartTotalTax;
$quoteArray['line_items'] = $itemArray;
$quoteCartArray[] = $quoteArray;
}
Expand Down Expand Up @@ -1236,7 +1253,7 @@ public function setConfig($mage_store_id, $configName, $scope, $newValue)
*/
public function getVersion()
{
return '2.2.18';
return '2.2.19';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"lib-libxml": "*"
},
"type": "magento2-module",
"version": "2.2.18",
"version": "2.2.19",
"license": [
"OSL-3.0",
"AFL-3.0"
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Remarkety_Mgconnector" setup_version="2.2.18">
<module name="Remarkety_Mgconnector" setup_version="2.2.19">
</module>
</config>

0 comments on commit d89c67f

Please sign in to comment.