UpdateTierPriceAttribute.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\ConfigurableProduct\Setup\Patch\Data;
  7. use Magento\Eav\Setup\EavSetup;
  8. use Magento\Eav\Setup\EavSetupFactory;
  9. use Magento\Framework\App\ResourceConnection;
  10. use Magento\Framework\Setup\ModuleDataSetupInterface;
  11. use Magento\Framework\Setup\Patch\DataPatchInterface;
  12. use Magento\Framework\Setup\Patch\PatchVersionInterface;
  13. use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
  14. /**
  15. * Class UpdateTierPriceAttribute
  16. * @package Magento\ConfigurableProduct\Setup\Patch
  17. */
  18. class UpdateTierPriceAttribute implements DataPatchInterface, PatchVersionInterface
  19. {
  20. /**
  21. * @var ModuleDataSetupInterface
  22. */
  23. private $moduleDataSetup;
  24. /**
  25. * @var EavSetupFactory
  26. */
  27. private $eavSetupFactory;
  28. /**
  29. * UpdateTierPriceAttribute constructor.
  30. * @param ModuleDataSetupInterface $moduleDataSetup
  31. * @param EavSetupFactory $eavSetupFactory
  32. */
  33. public function __construct(
  34. ModuleDataSetupInterface $moduleDataSetup,
  35. EavSetupFactory $eavSetupFactory
  36. ) {
  37. $this->moduleDataSetup = $moduleDataSetup;
  38. $this->eavSetupFactory = $eavSetupFactory;
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. public function apply()
  44. {
  45. /** @var EavSetup $eavSetup */
  46. $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
  47. $relatedProductTypes = explode(
  48. ',',
  49. $eavSetup->getAttribute(\Magento\Catalog\Model\Product::ENTITY, 'tier_price', 'apply_to')
  50. );
  51. $key = array_search(Configurable::TYPE_CODE, $relatedProductTypes);
  52. if ($key !== false) {
  53. unset($relatedProductTypes[$key]);
  54. $eavSetup->updateAttribute(
  55. \Magento\Catalog\Model\Product::ENTITY,
  56. 'tier_price',
  57. 'apply_to',
  58. implode(',', $relatedProductTypes)
  59. );
  60. }
  61. }
  62. /**
  63. * {@inheritdoc}
  64. */
  65. public static function getDependencies()
  66. {
  67. return [
  68. InstallInitialConfigurableAttributes::class,
  69. ];
  70. }
  71. /**
  72. * {@inheritdoc}\
  73. */
  74. public static function getVersion()
  75. {
  76. return '2.2.0';
  77. }
  78. /**
  79. * {@inheritdoc}
  80. */
  81. public function getAliases()
  82. {
  83. return [];
  84. }
  85. }