TaxSetup.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Tax\Setup;
  7. use Magento\Catalog\Model\ProductTypes\ConfigInterface;
  8. use Magento\Framework\Setup\ModuleDataSetupInterface;
  9. use Magento\Sales\Setup\SalesSetupFactory;
  10. /**
  11. * Tax Setup Resource Model
  12. */
  13. class TaxSetup
  14. {
  15. /**
  16. * @var \Magento\Sales\Setup\SalesSetup
  17. */
  18. protected $salesSetup;
  19. /**
  20. * Product type config
  21. *
  22. * @var ConfigInterface
  23. */
  24. protected $productTypeConfig;
  25. /**
  26. * Init
  27. *
  28. * @param ModuleDataSetupInterface $setup
  29. * @param SalesSetupFactory $salesSetupFactory
  30. * @param ConfigInterface $productTypeConfig
  31. */
  32. public function __construct(
  33. ModuleDataSetupInterface $setup,
  34. SalesSetupFactory $salesSetupFactory,
  35. ConfigInterface $productTypeConfig
  36. ) {
  37. $this->salesSetup = $salesSetupFactory->create(['resourceName' => 'tax_setup', 'setup' => $setup]);
  38. $this->productTypeConfig = $productTypeConfig;
  39. }
  40. /**
  41. * Get taxable product types
  42. *
  43. * @return array
  44. */
  45. public function getTaxableItems()
  46. {
  47. return $this->productTypeConfig->filter('taxable');
  48. }
  49. /**
  50. * Add entity attribute.
  51. *
  52. * @param int|string $entityTypeId
  53. * @param string $code
  54. * @param array $attr
  55. * @return $this
  56. */
  57. public function addAttribute($entityTypeId, $code, array $attr)
  58. {
  59. //Delegate
  60. return $this->salesSetup->addAttribute($entityTypeId, $code, $attr);
  61. }
  62. /**
  63. * Update Attribute data and Attribute additional data.
  64. *
  65. * @param int|string $entityTypeId
  66. * @param int|string $id
  67. * @param string $field
  68. * @param mixed $value
  69. * @param int $sortOrder
  70. * @return $this
  71. */
  72. public function updateAttribute($entityTypeId, $id, $field, $value = null, $sortOrder = null)
  73. {
  74. //Delegate
  75. return $this->salesSetup->updateAttribute($entityTypeId, $id, $field, $value, $sortOrder);
  76. }
  77. }