Rate.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Tax rate resource model
  8. *
  9. * @author Magento Core Team <core@magentocommerce.com>
  10. */
  11. namespace Magento\Tax\Model\ResourceModel\Calculation;
  12. class Rate extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
  13. {
  14. /**
  15. * Resource initialization
  16. *
  17. * @return void
  18. */
  19. protected function _construct()
  20. {
  21. $this->_init('tax_calculation_rate', 'tax_calculation_rate_id');
  22. }
  23. /**
  24. * Initialize unique fields
  25. *
  26. * @return $this
  27. */
  28. protected function _initUniqueFields()
  29. {
  30. $this->_uniqueFields = [['field' => ['code'], 'title' => __('Code')]];
  31. return $this;
  32. }
  33. /**
  34. * Delete all rates
  35. *
  36. * @return $this
  37. */
  38. public function deleteAllRates()
  39. {
  40. $this->getConnection()->delete($this->getMainTable());
  41. return $this;
  42. }
  43. /**
  44. * Check if this rate exists in rule
  45. *
  46. * @param int $rateId
  47. * @return array
  48. */
  49. public function isInRule($rateId)
  50. {
  51. $connection = $this->getConnection();
  52. $select = $connection->select()->from(
  53. $this->getTable('tax_calculation'),
  54. ['tax_calculation_rate_id']
  55. )->where(
  56. 'tax_calculation_rate_id = ?',
  57. $rateId
  58. );
  59. return $connection->fetchCol($select);
  60. }
  61. }