|
| 1 | +<?php |
| 2 | +namespace PostFinanceCheckout\Payment\Setup\Patch\Data; |
| 3 | +use \Magento\Framework\Setup\Patch\DataPatchInterface; |
| 4 | +use \Magento\Framework\Setup\Patch\PatchVersionInterface; |
| 5 | +use \Magento\Framework\Module\Setup\Migration; |
| 6 | +use \Magento\Framework\Setup\ModuleDataSetupInterface; |
| 7 | + |
| 8 | + |
| 9 | +/** |
| 10 | + * Class AddSetupData |
| 11 | + * @package PostFinanceCheckout\Payment\Setup\Patch\Data |
| 12 | + */ |
| 13 | + |
| 14 | +class AddSetupDataStateProcessing implements DataPatchInterface |
| 15 | +{ |
| 16 | + private $status; |
| 17 | + protected $moduleDataSetup; |
| 18 | + |
| 19 | + /** |
| 20 | + * |
| 21 | + * @param \PostFinanceCheckout\Payment\Model\Author $status |
| 22 | + * @param \Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetup |
| 23 | + */ |
| 24 | + |
| 25 | + public function __construct( |
| 26 | + \Magento\Sales\Model\Order\Status $status, |
| 27 | + ModuleDataSetupInterface $moduleDataSetup |
| 28 | + ) { |
| 29 | + $this->status = $status; |
| 30 | + $this->moduleDataSetup = $moduleDataSetup; |
| 31 | + } |
| 32 | + |
| 33 | + |
| 34 | + /** |
| 35 | + * It will create and remove some status/states. |
| 36 | + * We've rolled back the first patch, which means we're using the processing status again. |
| 37 | + * Also I'm making sure we're setting processing, shipped_postfinancecheckout and pending_payment as default. |
| 38 | + * @return:none |
| 39 | + */ |
| 40 | + |
| 41 | + public function apply() |
| 42 | + { |
| 43 | + $statuses = array( |
| 44 | + array('status' => 'pending', 'label' => 'Hold Delivery') |
| 45 | + ); |
| 46 | + |
| 47 | + foreach ($statuses as $statusData) { |
| 48 | + $this->status->addData($statusData); |
| 49 | + $this->status->getResource()->save($this->status); |
| 50 | + $this->status->assignState('pending', 'pending', true); |
| 51 | + } |
| 52 | + |
| 53 | + $tableName = $this->moduleDataSetup->getTable('sales_order_status_state'); |
| 54 | + $updateSql = "UPDATE " . $tableName . " SET is_default = 1, visible_on_front = 0 WHERE status = 'pending_payment'"; |
| 55 | + $this->moduleDataSetup->getConnection()->query($updateSql); |
| 56 | + |
| 57 | + $tableName = $this->moduleDataSetup->getTable('sales_order_status_state'); |
| 58 | + $updateSql = "UPDATE " . $tableName . " SET state = 'shipped_postfinancecheckout', is_default = 1 WHERE status = 'shipped_postfinancecheckout'"; |
| 59 | + $this->moduleDataSetup->getConnection()->query($updateSql); |
| 60 | + |
| 61 | + $tableName = $this->moduleDataSetup->getTable('sales_order_status_state'); |
| 62 | + $updateSql = "UPDATE " . $tableName . " SET state = 'processing', is_default = 1 WHERE status = 'processing'"; |
| 63 | + $this->moduleDataSetup->getConnection()->query($updateSql); |
| 64 | + |
| 65 | + $stateToRemove = 'processing_postfinancecheckout'; |
| 66 | + $status = $this->status->load($stateToRemove); |
| 67 | + |
| 68 | + if ($status->getStatus()) { |
| 69 | + $this->status->getResource()->delete($status); |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 74 | + * @return array: |
| 75 | + */ |
| 76 | + |
| 77 | + public static function getDependencies(){ |
| 78 | + return []; |
| 79 | + } |
| 80 | + |
| 81 | + /** |
| 82 | + * @return array: |
| 83 | + */ |
| 84 | + |
| 85 | + public function getAliases(){ |
| 86 | + return []; |
| 87 | + } |
| 88 | +} |
0 commit comments