UpdateQuoteShippingAddresses.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\OfflineShipping\Setup\Patch\Data;
  7. use Magento\Framework\Setup\ModuleContextInterface;
  8. use Magento\Framework\Setup\ModuleDataSetupInterface;
  9. use Magento\Framework\Setup\UpgradeDataInterface;
  10. use Magento\Framework\App\ResourceConnection;
  11. use Magento\Framework\Setup\Patch\DataPatchInterface;
  12. use Magento\Framework\Setup\Patch\PatchVersionInterface;
  13. class UpdateQuoteShippingAddresses implements DataPatchInterface, PatchVersionInterface
  14. {
  15. /**
  16. * @var \Magento\Framework\Setup\ModuleDataSetupInterface
  17. */
  18. private $moduleDataSetup;
  19. /**
  20. * PatchInitial constructor.
  21. * @param \Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetup
  22. */
  23. public function __construct(
  24. \Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetup
  25. ) {
  26. $this->moduleDataSetup = $moduleDataSetup;
  27. }
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public function apply()
  32. {
  33. // setup default
  34. $this->moduleDataSetup->getConnection()->startSetup();
  35. $connection = $this->moduleDataSetup->getConnection();
  36. $salesConnection = $this->moduleDataSetup->getConnection('sales');
  37. $checkoutConnection = $this->moduleDataSetup->getConnection('checkout');
  38. $connection->update(
  39. $this->moduleDataSetup->getTable('salesrule'),
  40. ['simple_free_shipping' => 0],
  41. [new \Zend_Db_Expr('simple_free_shipping IS NULL')]
  42. );
  43. $this->moduleDataSetup->getConnection()->endSetup();
  44. // setup sales
  45. $salesConnection->startSetup();
  46. $salesConnection->update(
  47. $this->moduleDataSetup->getTable('sales_order_item'),
  48. ['free_shipping' => 0],
  49. [new \Zend_Db_Expr('free_shipping IS NULL')]
  50. );
  51. $salesConnection->endSetup();
  52. // setup checkout
  53. $checkoutConnection->startSetup();
  54. $checkoutConnection->update(
  55. $this->moduleDataSetup->getTable('quote_address'),
  56. ['free_shipping' => 0],
  57. [new \Zend_Db_Expr('free_shipping IS NULL')]
  58. );
  59. $checkoutConnection->update(
  60. $this->moduleDataSetup->getTable('quote_item'),
  61. ['free_shipping' => 0],
  62. [new \Zend_Db_Expr('free_shipping IS NULL')]
  63. );
  64. $checkoutConnection->endSetup();
  65. }
  66. /**
  67. * {@inheritdoc}
  68. */
  69. public static function getDependencies()
  70. {
  71. return [];
  72. }
  73. /**
  74. * {@inheritdoc}
  75. */
  76. public static function getVersion()
  77. {
  78. return '2.0.1';
  79. }
  80. /**
  81. * {@inheritdoc}
  82. */
  83. public function getAliases()
  84. {
  85. return [];
  86. }
  87. }