Item.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Model\ResourceModel\Order\Tax;
  7. /**
  8. * Sales order tax resource model
  9. */
  10. class Item extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
  11. {
  12. /**
  13. * Resource initialization
  14. *
  15. * @return void
  16. */
  17. protected function _construct()
  18. {
  19. $this->_init('sales_order_tax_item', 'tax_item_id');
  20. }
  21. /**
  22. * Get Tax Items with order tax information
  23. *
  24. * @param int $orderId
  25. * @return array
  26. */
  27. public function getTaxItemsByOrderId($orderId)
  28. {
  29. $connection = $this->getConnection();
  30. $select = $connection->select()->from(
  31. ['item' => $this->getTable('sales_order_tax_item')],
  32. [
  33. 'tax_id',
  34. 'tax_percent',
  35. 'item_id',
  36. 'taxable_item_type',
  37. 'associated_item_id',
  38. 'real_amount',
  39. 'real_base_amount',
  40. ]
  41. )->join(
  42. ['tax' => $this->getTable('sales_order_tax')],
  43. 'item.tax_id = tax.tax_id',
  44. ['code', 'title', 'order_id']
  45. )->where(
  46. 'tax.order_id = ?',
  47. $orderId
  48. );
  49. return $connection->fetchAll($select);
  50. }
  51. }