AddPaypalOrderStatuses.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Paypal\Setup\Patch\Data;
  7. use Magento\Quote\Setup\QuoteSetupFactory;
  8. use Magento\Sales\Setup\SalesSetupFactory;
  9. use Magento\Framework\App\ResourceConnection;
  10. use Magento\Framework\Setup\Patch\DataPatchInterface;
  11. use Magento\Framework\Setup\Patch\PatchVersionInterface;
  12. /**
  13. * Class AddPaypalOrderStates
  14. * @package Magento\Paypal\Setup\Patch
  15. */
  16. class AddPaypalOrderStatuses implements DataPatchInterface, PatchVersionInterface
  17. {
  18. /**
  19. * @var \Magento\Framework\Setup\ModuleDataSetupInterface
  20. */
  21. private $moduleDataSetup;
  22. /**
  23. * @var QuoteSetupFactory
  24. */
  25. private $quoteSetupFactory;
  26. /**
  27. * @var SalesSetupFactory
  28. */
  29. private $salesSetupFactory;
  30. /**
  31. * AddPaypalOrderStates constructor.
  32. * @param \Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetup
  33. * @param QuoteSetupFactory $quoteSetupFactory
  34. * @param SalesSetupFactory $salesSetupFactory
  35. */
  36. public function __construct(
  37. \Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetup,
  38. QuoteSetupFactory $quoteSetupFactory,
  39. SalesSetupFactory $salesSetupFactory
  40. ) {
  41. $this->moduleDataSetup = $moduleDataSetup;
  42. $this->quoteSetupFactory = $quoteSetupFactory;
  43. $this->salesSetupFactory = $salesSetupFactory;
  44. }
  45. /**
  46. * {@inheritdoc}
  47. */
  48. public function apply()
  49. {
  50. /**
  51. * Prepare database for install
  52. */
  53. $this->moduleDataSetup->getConnection()->startSetup();
  54. $quoteInstaller = $this->quoteSetupFactory->create();
  55. $salesInstaller = $this->salesSetupFactory->create();
  56. /**
  57. * Add paypal attributes to the:
  58. * - sales/flat_quote_payment_item table
  59. * - sales/flat_order table
  60. */
  61. $quoteInstaller->addAttribute('quote_payment', 'paypal_payer_id', []);
  62. $quoteInstaller->addAttribute('quote_payment', 'paypal_payer_status', []);
  63. $quoteInstaller->addAttribute('quote_payment', 'paypal_correlation_id', []);
  64. $salesInstaller->addAttribute(
  65. 'order',
  66. 'paypal_ipn_customer_notified',
  67. ['type' => 'int', 'visible' => false, 'default' => 0]
  68. );
  69. $data = [];
  70. $statuses = [
  71. 'pending_paypal' => __('Pending PayPal'),
  72. 'paypal_reversed' => __('PayPal Reversed'),
  73. 'paypal_canceled_reversal' => __('PayPal Canceled Reversal'),
  74. ];
  75. foreach ($statuses as $code => $info) {
  76. $data[] = ['status' => $code, 'label' => $info];
  77. }
  78. $this->moduleDataSetup->getConnection()->insertArray(
  79. $this->moduleDataSetup->getTable('sales_order_status'),
  80. ['status', 'label'],
  81. $data
  82. );
  83. /**
  84. * Prepare database after install
  85. */
  86. $this->moduleDataSetup->getConnection()->endSetup();
  87. }
  88. /**
  89. * {@inheritdoc}
  90. */
  91. public static function getDependencies()
  92. {
  93. return [];
  94. }
  95. /**
  96. * {@inheritdoc}
  97. */
  98. public static function getVersion()
  99. {
  100. return '2.0.0';
  101. }
  102. /**
  103. * {@inheritdoc}
  104. */
  105. public function getAliases()
  106. {
  107. return [];
  108. }
  109. }