├── .coveralls.yml ├── .gitignore ├── .travis.yml ├── Api ├── Data │ └── InvoiceProcessItemInterface.php └── InvoiceProcessInterface.php ├── Block └── Adminhtml │ └── Form │ └── Field │ ├── CaptureMode.php │ ├── Email.php │ ├── PaymentMethod.php │ ├── ProcessingRule.php │ └── Status.php ├── Console └── ProcessCommand.php ├── Cron └── InvoiceProcess.php ├── Helper └── Data.php ├── LICENSE.txt ├── Model ├── Adminhtml │ └── System │ │ └── Config │ │ └── ProcessingRule.php ├── InvoiceProcess.php └── InvoiceProcessItem.php ├── README.md ├── Test └── Unit │ ├── Console │ └── ProcessCommandTest.php │ ├── Cron │ └── InvoiceProcessTest.php │ ├── Helper │ └── DataTest.php │ ├── Model │ ├── InvoiceProcessItemTest.php │ └── InvoiceProcessTest.php │ └── bootstrap.php ├── composer.json ├── etc ├── adminhtml │ └── system.xml ├── config.xml ├── crontab.xml ├── di.xml └── module.xml ├── phpunit.xml.dist ├── registration.php └── screenshots └── settings.png /.coveralls.yml: -------------------------------------------------------------------------------- 1 | coverage_clover: Test/Unit/logs/clover.xml 2 | json_path: Test/Unit/logs/coveralls-upload.json 3 | service_name: travis-ci 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /composer.lock 2 | /magento-coding-standard/ 3 | /Test/Unit/logs/ 4 | /vendor/ 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | 3 | language: php 4 | 5 | php: 6 | - 7.1 7 | - 7.2 8 | - 7.3 9 | 10 | install: 11 | - mkdir -p ~/.composer/ 12 | - echo "{\"http-basic\":{\"repo.magento.com\":{\"username\":\"${MAGENTO_USERNAME}\",\"password\":\"${MAGENTO_PASSWORD}\"}}}" > ~/.composer/auth.json 13 | - composer install --prefer-dist 14 | - composer create-project magento/magento-coding-standard magento-coding-standard 15 | 16 | script: 17 | - php magento-coding-standard/vendor/bin/phpcs Api/ Block/ Console/ Cron/ Helper/ Model/ Test/ --standard=Magento2 --severity=10 18 | - php vendor/bin/phpmd Api/,Block/,Console/,Cron/,Helper/,Model/,Test/ text cleancode,codesize,controversial,design,naming,unusedcode --ignore-violations-on-exit 19 | - php vendor/phpunit/phpunit/phpunit --coverage-clover Test/Unit/logs/clover.xml Test 20 | 21 | after_script: 22 | - php vendor/bin/coveralls -v 23 | 24 | env: 25 | global: 26 | - secure: "aYyUmsObfCxq7qLOkg+VJ5NUomWQE4zQLzt60KG5VWYue5bcV4yTe0QM8XUDN01qJn0A2X0qWVL8KsUt1EpzjlvdSvSjZFKdDQL2ROt3yvsJNJx+GEHfMiod/p2hc6MdhoeJkdxv8JZ6pzkAugSmc13jBucMD1Z2oNzY6jt+FwgsmqUWhQuMMhpiDxdAWguE0PpsAR3SnytnSp+mO0mrAG3TPAE5n23Rr9k0/euF7QTnpLfZkGRcvYX4SRc2Hp+v7XKy52t2eEtINGh/4i2C0lH3KfrPOVJWPnNyZJLPnjZjTrptZ/nYHShxUnenaPoYeeIHb43ZE0d1qY4+XSgDPuptZ6ENpCcVu25Y0itiakwFjVPu9Ujljh69/B+oEQHvSUsoedVG+iP9rwqeqvcV7G6NcxwvC+Ghi01ePKK9z54SCWf7zXJYFzwRwMUW3E57qAp3SHEfzs6J3LZr1uiqGwCWzJZ82pa1axLjwqzAO8xfeWSFkSaRDKcAKMO6Gw6WZHbleRt6BpaXJdhWN9XiYrUM8hOAQ9id27L9naMJdCctOUwgPvxPHSVuWUOIHl3+oiYmCyOGGD1NSUDkYZxSY0gJrHEA180EBlLIDG4HWWYikFDKwNBEa66F/YQP/6+TqcXVOCdHVGHET90A+TYKFSyPnmCa4QHzznq4RaGdISo=" 27 | - secure: "G6MUkeEcAj7hJ0J/uFPn87GOGh0HJQqG/Fd2Cusjos9cs1KCDLlTSYOkRdpNbXc2sg8POWje6pIjukMyb03dzRM119bvocyhPHqUgjzGlelEGfon6vxQPYWeLQD8wc+cc3/6vKhbAkTFtqYnrcuyYlmYMp71J4eDLqvK9/uh1zliAdakW/BR179tf4dUYGSkOKgNGFLdwd4QW3dmGG6jdMIxUeF/55h8v3y2xdMgafgKOjfG4os2Yy2ijQNlogs80BsTbTdKdeWBIWVEv1CxMKfXUKZhLMPConOtXlopBd6+pq9tmF9DV7ey1Um8VUWzBpGMJGya8BwD6V+xvxq68ewyMqBhq4XF+J2gGObAuA4qXE0nLJMteeGkydyu3RvdVESSdrp9dbmEV7ylhnKR8qxF0uowl9bnPWS/S7Pdc5tv2SCfnuSqSqdvqSDOBJpChKR8F8Ya4NwB0uVRqCYHN7ti0lYpYgzhTqQQHqUxEnOeaz4C5Kx6HfcgZx8QkBVUamtW8SxObD4SROvXxrnpwlK8cliKWx9tc650TZdDXmjxsYSJzzvx3ff8+jbY1vWq+FU/Md6F0mzWWdtit7iyDveuneVajtwT+vfF/cu0Z8kvaI+/SxcCMLn/m2u3Q6sPyMVLCMNf8t0eqV+6/Xq31LAirpoQVFah67Edk9W06Io=" 28 | -------------------------------------------------------------------------------- /Api/Data/InvoiceProcessItemInterface.php: -------------------------------------------------------------------------------- 1 | Invoice::CAPTURE_OFFLINE, 24 | 'label' => __('Offline'), 25 | ], [ 26 | 'value' => Invoice::CAPTURE_ONLINE, 27 | 'label' => __('Online'), 28 | ]]; 29 | 30 | $this->setOptions($options); 31 | 32 | return parent::_toHtml(); 33 | } 34 | 35 | /** 36 | * Sets name for input element 37 | * 38 | * @param string $value 39 | * @return $this 40 | */ 41 | public function setInputName($value) 42 | { 43 | return $this->setName($value); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Block/Adminhtml/Form/Field/Email.php: -------------------------------------------------------------------------------- 1 | 'true', 23 | 'label' => __('Yes'), 24 | ], [ 25 | 'value' => 'false', 26 | 'label' => __('No'), 27 | ]]; 28 | 29 | $this->setOptions($options); 30 | 31 | return parent::_toHtml(); 32 | } 33 | 34 | /** 35 | * Sets name for input element 36 | * 37 | * @param string $value 38 | * @return $this 39 | */ 40 | public function setInputName($value) 41 | { 42 | return $this->setName($value); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Block/Adminhtml/Form/Field/PaymentMethod.php: -------------------------------------------------------------------------------- 1 | paymentHelper = $paymentHelper; 32 | 33 | parent::__construct($context, $data); 34 | } 35 | 36 | /** 37 | * Render block HTML 38 | * 39 | * @return string 40 | */ 41 | protected function _toHtml() 42 | { 43 | if (!$this->getOptions()) { 44 | $options = [ 45 | ['value' => HelperData::RULE_PAYMENT_METHOD_ALL, 'label' => __('Any')] 46 | ]; 47 | 48 | $options = array_merge($options, $this->paymentHelper->getPaymentMethodList(true, true)); 49 | 50 | $this->setOptions($options); 51 | } 52 | 53 | return parent::_toHtml(); 54 | } 55 | 56 | /** 57 | * Sets name for input element 58 | * 59 | * @param string $value 60 | * @return $this 61 | */ 62 | public function setInputName($value) 63 | { 64 | return $this->setName($value); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /Block/Adminhtml/Form/Field/ProcessingRule.php: -------------------------------------------------------------------------------- 1 | srcStatusRenderer) { 46 | $this->srcStatusRenderer = $this->getLayout()->createBlock( 47 | Status::class, 48 | '', 49 | ['data' => ['is_render_to_js_template' => true]] 50 | ); 51 | } 52 | 53 | return $this->srcStatusRenderer; 54 | } 55 | 56 | /** 57 | * Returns renderer for destination status element 58 | */ 59 | protected function getDstStatusRenderer() 60 | { 61 | if (!$this->dstStatusRenderer) { 62 | $this->dstStatusRenderer = $this->getLayout()->createBlock( 63 | Status::class, 64 | '', 65 | ['data' => ['is_render_to_js_template' => true]] 66 | ); 67 | } 68 | 69 | return $this->dstStatusRenderer; 70 | } 71 | 72 | /** 73 | * Returns renderer for payment method 74 | */ 75 | protected function getPaymentMethodRenderer() 76 | { 77 | if (!$this->paymentMethodRenderer) { 78 | $this->paymentMethodRenderer = $this->getLayout()->createBlock( 79 | PaymentMethod::class, 80 | '', 81 | ['data' => ['is_render_to_js_template' => true]] 82 | ); 83 | } 84 | return $this->paymentMethodRenderer; 85 | } 86 | 87 | /** 88 | * Returns renderer for capture mode 89 | */ 90 | protected function getCaptureModeRenderer() 91 | { 92 | if (!$this->captureModeRenderer) { 93 | $this->captureModeRenderer = $this->getLayout()->createBlock( 94 | CaptureMode::class, 95 | '', 96 | ['data' => ['is_render_to_js_template' => true]] 97 | ); 98 | } 99 | return $this->captureModeRenderer; 100 | } 101 | 102 | /** 103 | * Returns renderer for E-Mail sending 104 | */ 105 | protected function getEmailRenderer() 106 | { 107 | if (!$this->emailRenderer) { 108 | $this->emailRenderer = $this->getLayout()->createBlock( 109 | Email::class, 110 | '', 111 | ['data' => ['is_render_to_js_template' => true]] 112 | ); 113 | } 114 | return $this->emailRenderer; 115 | } 116 | /** 117 | * Prepare to render 118 | * 119 | * @return void 120 | */ 121 | protected function _prepareToRender() 122 | { 123 | $this->addColumn( 124 | 'src_status', 125 | [ 126 | 'label' => __('Source Status'), 127 | 'renderer' => $this->getSrcStatusRenderer(), 128 | ] 129 | ); 130 | $this->addColumn( 131 | 'payment_method', 132 | [ 133 | 'label' => __('Payment Method'), 134 | 'renderer' => $this->getPaymentMethodRenderer(), 135 | ] 136 | ); 137 | $this->addColumn( 138 | 'dst_status', 139 | [ 140 | 'label' => __('Destination Status'), 141 | 'renderer' => $this->getDstStatusRenderer(), 142 | ] 143 | ); 144 | $this->addColumn( 145 | 'capture_mode', 146 | [ 147 | 'label' => __('Capture Mode'), 148 | 'renderer' => $this->getCaptureModeRenderer(), 149 | ] 150 | ); 151 | $this->addColumn( 152 | 'email', 153 | [ 154 | 'label' => __('Send invoice to customer'), 155 | 'renderer' => $this->getEmailRenderer(), 156 | ] 157 | ); 158 | 159 | $this->_addAfter = false; 160 | $this->_addButtonLabel = __('Add Rule'); 161 | } 162 | 163 | /** 164 | * Prepare existing row data object 165 | * 166 | * @param DataObject $row 167 | * @return void 168 | */ 169 | protected function _prepareArrayRow(DataObject $row) 170 | { 171 | $srcStatus = $row->getSrcStatus(); 172 | $dstStatus = $row->getDstStatus(); 173 | $paymentMethod = $row->getPaymentMethod(); 174 | $captureMode = $row->getCaptureMode(); 175 | $email = $row->getEmail(); 176 | 177 | $options = []; 178 | /** @var Magento\Framework\View\Element\BlockInterface */ 179 | $statusRenderer = $this->getSrcStatusRenderer(); 180 | /** @var Magento\Framework\View\Element\BlockInterface */ 181 | $dstRenderer = $this->getDstStatusRenderer(); 182 | /** @var Magento\Framework\View\Element\BlockInterface */ 183 | $paymentMethodRenderer = $this->getPaymentMethodRenderer(); 184 | /** @var Magento\Framework\View\Element\BlockInterface */ 185 | $getCaptureModeRenderer = $this->getCaptureModeRenderer(); 186 | /** @var Magento\Framework\View\Element\BlockInterface */ 187 | $emaiRenderer = $this->getEmailRenderer(); 188 | if ($srcStatus) { 189 | $options['option_' . $statusRenderer->calcOptionHash($srcStatus)] 190 | = 'selected="selected"'; 191 | 192 | $options['option_' . $dstRenderer->calcOptionHash($dstStatus)] 193 | = 'selected="selected"'; 194 | 195 | $options['option_' . $paymentMethodRenderer->calcOptionHash($paymentMethod)] 196 | = 'selected="selected"'; 197 | 198 | $options['option_' . $getCaptureModeRenderer->calcOptionHash($captureMode)] 199 | = 'selected="selected"'; 200 | 201 | $options['option_' . $emaiRenderer->calcOptionHash($email)] 202 | = 'selected="selected"'; 203 | } 204 | 205 | $row->setData('option_extra_attrs', $options); 206 | } 207 | } 208 | -------------------------------------------------------------------------------- /Block/Adminhtml/Form/Field/Status.php: -------------------------------------------------------------------------------- 1 | orderConfig = $orderConfig; 43 | 44 | parent::__construct($context, $data); 45 | } 46 | 47 | /** 48 | * Render block HTML 49 | * 50 | * @return string 51 | */ 52 | protected function _toHtml() 53 | { 54 | if (!$this->getOptions()) { 55 | $statuses = $this->stateStatuses 56 | ? $this->orderConfig->getStateStatuses($this->stateStatuses) 57 | : $this->orderConfig->getStatuses(); 58 | 59 | $this->setOptions($statuses); 60 | } 61 | return parent::_toHtml(); 62 | } 63 | 64 | /** 65 | * Sets name for input element 66 | * 67 | * @param string $value 68 | * @return $this 69 | */ 70 | public function setInputName($value) 71 | { 72 | return $this->setName($value); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Console/ProcessCommand.php: -------------------------------------------------------------------------------- 1 | state = $state; 47 | $this->logger = $logger; 48 | $this->invoiceProcessFactory = $invoiceProcessFactory; 49 | 50 | parent::__construct(); 51 | } 52 | 53 | /** 54 | * Configure command options 55 | */ 56 | protected function configure() 57 | { 58 | $options = [ 59 | new InputOption( 60 | self::OPTION_DRY_RUN, 61 | null, 62 | InputOption::VALUE_OPTIONAL, 63 | 'Simulation mode', 64 | false 65 | ) 66 | ]; 67 | 68 | $this->setName(self::COMMAND_NAME) 69 | ->setDescription(self::COMMAND_DESCRIPTION) 70 | ->setDefinition($options); 71 | 72 | parent::configure(); 73 | } 74 | 75 | /** 76 | * Execute the command 77 | * 78 | * @param InputInterface $input 79 | * @param OutputInterface $output 80 | * @throws \Exception 81 | * @return void 82 | */ 83 | protected function execute(InputInterface $input, OutputInterface $output) 84 | { 85 | try { 86 | $this->state->getAreaCode(); 87 | } catch (\Exception $e) { 88 | $this->state->setAreaCode('adminhtml'); 89 | } 90 | 91 | $output->writeln('Starting auto invoice procedure'); 92 | $dryRun = $input->getOption(self::OPTION_DRY_RUN); 93 | if ($dryRun) { 94 | $output->writeln('This is a dry run, no orders will actually be invoiced.'); 95 | } 96 | 97 | $invoiceProcess = $this->invoiceProcessFactory->create(); 98 | $items = $invoiceProcess->getItemsToProcess(); 99 | foreach ($items as $item) { 100 | try { 101 | 102 | $order = $item->getOrder(); 103 | $message = sprintf( 104 | 'Invoicing order #%s %s', 105 | $order->getIncrementId(), 106 | $item->getCaptureMode() 107 | ); 108 | $output->writeln('' . $message . ''); 109 | 110 | if ($dryRun) { 111 | continue; 112 | } 113 | 114 | $this->logger->info($message); 115 | $invoiceProcess->invoice($item); 116 | 117 | } catch (\Exception $ex) { 118 | $output->writeln(sprintf( 119 | '%s', 120 | $ex->getMessage() 121 | )); 122 | $this->logger->critical($ex->getMessage()); 123 | } 124 | } 125 | 126 | $output->writeln('Auto invoice procedure completed.'); 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /Cron/InvoiceProcess.php: -------------------------------------------------------------------------------- 1 | helperData = $helperData; 37 | $this->logger = $logger; 38 | $this->invoiceProcessFactory = $invoiceProcessFactory; 39 | } 40 | 41 | /** 42 | * Process completed orders with no invoice, if cron is enabled 43 | */ 44 | public function execute() 45 | { 46 | if (!$this->helperData->isCronEnabled()) { 47 | return; 48 | } 49 | 50 | $this->logger->info('Starting auto invoice procedure.'); 51 | $invoiceProcess = $this->invoiceProcessFactory->create(); 52 | $items = $invoiceProcess->getItemsToProcess(); 53 | 54 | foreach ($items as $item) { 55 | try { 56 | 57 | $order = $item->getOrder(); 58 | $this->logger->info(sprintf( 59 | 'Invoicing order #%s', 60 | $order->getIncrementId() 61 | )); 62 | $invoiceProcess->invoice($item); 63 | 64 | } catch (\Exception $ex) { 65 | $this->logger->critical($ex->getMessage()); 66 | } 67 | } 68 | 69 | $this->logger->info('Auto invoice procedure completed.'); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Helper/Data.php: -------------------------------------------------------------------------------- 1 | scopeConfig = $scopeConfig; 41 | $this->serializer = $serializer; 42 | } 43 | 44 | /** 45 | * Return whether the orders should be automatically processed via cron 46 | */ 47 | public function isCronEnabled() 48 | { 49 | return (bool) $this->scopeConfig->isSetFlag(self::XML_PATH_CRON_ENABLED); 50 | } 51 | 52 | /** 53 | * Return processing rules 54 | */ 55 | public function getProcessingRules() 56 | { 57 | $value = $this->scopeConfig->getValue(self::XML_PATH_PROCESSING_RULES); 58 | $value = $value ? $this->serializer->unserialize($value) : []; 59 | 60 | $rules = []; 61 | foreach ($value as $key => $value) { 62 | $parts = explode(self::RULE_KEY_SEPARATOR, $key); 63 | 64 | if (is_array($value)) { 65 | $dstStatus = $value[self::RULE_DESTINATION_STATUS]; 66 | $captureMode = $value[self::RULE_CAPTURE_MODE]; 67 | $email = $value[self::RULE_EMAIL]; 68 | } else { 69 | $dstStatus = $value; 70 | $captureMode = Invoice::CAPTURE_OFFLINE; 71 | $email = ''; 72 | } 73 | 74 | $rules []= [ 75 | self::RULE_SOURCE_STATUS => $parts[0], 76 | self::RULE_PAYMENT_METHOD => $parts[1], 77 | self::RULE_DESTINATION_STATUS => $dstStatus, 78 | self::RULE_CAPTURE_MODE => $captureMode, 79 | self::RULE_EMAIL => $email, 80 | ]; 81 | } 82 | 83 | return $rules; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | 2 | Open Software License ("OSL") v. 3.0 3 | 4 | This Open Software License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following licensing notice adjacent to the copyright notice for the Original Work: 5 | 6 | Licensed under the Open Software License version 3.0 7 | 8 | 1. Grant of Copyright License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, for the duration of the copyright, to do the following: 9 | 10 | 1. to reproduce the Original Work in copies, either alone or as part of a collective work; 11 | 12 | 2. to translate, adapt, alter, transform, modify, or arrange the Original Work, thereby creating derivative works ("Derivative Works") based upon the Original Work; 13 | 14 | 3. to distribute or communicate copies of the Original Work and Derivative Works to the public, with the proviso that copies of Original Work or Derivative Works that You distribute or communicate shall be licensed under this Open Software License; 15 | 16 | 4. to perform the Original Work publicly; and 17 | 18 | 5. to display the Original Work publicly. 19 | 20 | 2. Grant of Patent License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, for the duration of the patents, to make, use, sell, offer for sale, have made, and import the Original Work and Derivative Works. 21 | 22 | 3. Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work. 23 | 24 | 4. Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior permission of the Licensor. Except as expressly stated herein, nothing in this License grants any license to Licensor's trademarks, copyrights, patents, trade secrets or any other intellectual property. No patent license is granted to make, use, sell, offer for sale, have made, or import embodiments of any patent claims other than the licensed claims defined in Section 2. No license is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under terms different from this License any Original Work that Licensor otherwise would have a right to license. 25 | 26 | 5. External Deployment. The term "External Deployment" means the use, distribution, or communication of the Original Work or Derivative Works in any way such that the Original Work or Derivative Works may be used by anyone other than You, whether those works are distributed or communicated to those persons or made available as an application intended for use over a network. As an express condition for the grants of license hereunder, You must treat any External Deployment by You of the Original Work or a Derivative Work as a distribution under section 1(c). 27 | 28 | 6. Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent, or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work. 29 | 30 | 7. Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately preceding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of non-infringement, merchantability or fitness for a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to the Original Work is granted by this License except under this disclaimer. 31 | 32 | 8. Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to anyone for any indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to the extent applicable law prohibits such limitation. 33 | 34 | 9. Acceptance and Termination. If, at any time, You expressly assented to this License, that assent indicates your clear and irrevocable acceptance of this License and all of its terms and conditions. If You distribute or communicate copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. This License conditions your rights to undertake the activities listed in Section 1, including your right to create Derivative Works based upon the Original Work, and doing so without honoring these terms and conditions is prohibited by copyright law and international treaty. Nothing in this License is intended to affect copyright exceptions and limitations (including 'fair use' or 'fair dealing'). This License shall terminate immediately and You may no longer exercise any of the rights granted to You by this License upon your failure to honor the conditions in Section 1(c). 35 | 36 | 10. Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware. 37 | 38 | 11. Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of copyright or patent law in the appropriate jurisdiction. This section shall survive the termination of this License. 39 | 40 | 12. Attorneys' Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License. 41 | 42 | 13. Miscellaneous. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. 43 | 44 | 14. Definition of "You" in This License. "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. 45 | 46 | 15. Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You. 47 | 48 | 16. Modification of This License. This License is Copyright (C) 2005 Lawrence Rosen. Permission is granted to copy, distribute, or communicate this License without modification. Nothing in this License permits You to modify this License as applied to the Original Work or to Derivative Works. However, You may modify the text of this License and copy, distribute or communicate your modified version (the "Modified License") and apply it to other original works of authorship subject to the following conditions: (i) You may not indicate in any way that your Modified License is the "Open Software License" or "OSL" and you may not use those names in the name of your Modified License; (ii) You must replace the notice specified in the first paragraph above with the notice "Licensed under " or with a notice of your own that is not confusingly similar to the notice in this License; and (iii) You may not claim that your original works are open source software unless your Modified License has been approved by Open Source Initiative (OSI) and You comply with its license review and certification process. 49 | -------------------------------------------------------------------------------- /Model/Adminhtml/System/Config/ProcessingRule.php: -------------------------------------------------------------------------------- 1 | mathRandom = $mathRandom; 52 | $this->serializer = $serializer; 53 | 54 | parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data); 55 | } 56 | 57 | /** 58 | * Prepare data before save 59 | * 60 | * @return $this 61 | */ 62 | public function beforeSave() 63 | { 64 | /** @var array */ 65 | $value = $this->getValue(); 66 | $result = []; 67 | foreach ($value as $data) { 68 | if (empty($data[HelperData::RULE_SOURCE_STATUS]) 69 | || empty($data[HelperData::RULE_PAYMENT_METHOD]) 70 | || empty($data[HelperData::RULE_DESTINATION_STATUS])) { 71 | 72 | continue; 73 | } 74 | 75 | $key = implode(HelperData::RULE_KEY_SEPARATOR, [ 76 | $data[HelperData::RULE_SOURCE_STATUS], 77 | $data[HelperData::RULE_PAYMENT_METHOD], 78 | $data[HelperData::RULE_EMAIL], 79 | ]); 80 | 81 | $result[$key] = [ 82 | HelperData::RULE_DESTINATION_STATUS => $data[HelperData::RULE_DESTINATION_STATUS], 83 | HelperData::RULE_CAPTURE_MODE => $data[HelperData::RULE_CAPTURE_MODE], 84 | HelperData::RULE_EMAIL => $data[HelperData::RULE_EMAIL], 85 | ]; 86 | } 87 | 88 | $this->setValue($this->serializer->serialize($result)); 89 | 90 | return $this; 91 | } 92 | 93 | /** 94 | * Process data after load 95 | * 96 | * @return $this 97 | */ 98 | public function afterLoad() 99 | { 100 | if ($this->getValue()) { 101 | $value = $this->serializer->unserialize($this->getValue()); 102 | if (is_array($value)) { 103 | $this->setValue($this->encodeArrayFieldValue($value)); 104 | } 105 | } 106 | return $this; 107 | } 108 | 109 | /** 110 | * Encode value to be used in \Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray 111 | * 112 | * @param array $value 113 | * @return array 114 | */ 115 | protected function encodeArrayFieldValue(array $value) 116 | { 117 | $result = []; 118 | foreach ($value as $key => $value) { 119 | 120 | $parts = explode(HelperData::RULE_KEY_SEPARATOR, $key); 121 | $id = $this->mathRandom->getUniqueHash('_'); 122 | 123 | if (is_array($value)) { 124 | $dstStatus = $value[HelperData::RULE_DESTINATION_STATUS]; 125 | $captureMode = $value[HelperData::RULE_CAPTURE_MODE]; 126 | $email = $value[HelperData::RULE_EMAIL]; 127 | } else { 128 | $dstStatus = $value; 129 | $captureMode = Invoice::CAPTURE_OFFLINE; 130 | $email = ''; 131 | } 132 | 133 | $result[$id] = [ 134 | HelperData::RULE_SOURCE_STATUS => $parts[0], 135 | HelperData::RULE_PAYMENT_METHOD => $parts[1], 136 | HelperData::RULE_DESTINATION_STATUS => $dstStatus, 137 | HelperData::RULE_CAPTURE_MODE => $captureMode, 138 | HelperData::RULE_EMAIL => $email, 139 | ]; 140 | } 141 | return $result; 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /Model/InvoiceProcess.php: -------------------------------------------------------------------------------- 1 | helperData = $helperData; 90 | $this->orderCollectionFactory = $orderCollectionFactory; 91 | $this->orderStatusCollectionFactory = $orderStatusCollectionFactory; 92 | $this->invoiceProcessItemFactory = $invoiceProcessItemFactory; 93 | $this->transactionFactory = $transactionFactory; 94 | $this->invoiceServiceFactory = $invoiceServiceFactory; 95 | $this->invoiceSender = $invoiceSender; 96 | $this->_logger = $logger; 97 | } 98 | 99 | /** 100 | * @inheritdoc 101 | */ 102 | public function getItemsToProcess() 103 | { 104 | $items = []; 105 | $rules = $this->helperData->getProcessingRules(); 106 | 107 | foreach ($rules as $rule) { 108 | $collection = $this->orderCollectionFactory->create() 109 | ->addFieldToFilter('status', ['eq' => $rule[HelperData::RULE_SOURCE_STATUS]]) 110 | ->addFieldToFilter('total_invoiced', ['null' => true]); 111 | 112 | foreach ($collection as $order) { 113 | if ($rule[HelperData::RULE_PAYMENT_METHOD] != HelperData::RULE_PAYMENT_METHOD_ALL 114 | && $rule[HelperData::RULE_PAYMENT_METHOD] != $this->getPaymentMethodCode($order)) { 115 | 116 | continue; 117 | } 118 | 119 | $items[$order->getId()] = $this->invoiceProcessItemFactory->create() 120 | ->setOrder($order) 121 | ->setDestinationStatus($rule[HelperData::RULE_DESTINATION_STATUS]) 122 | ->setCaptureMode($rule[HelperData::RULE_CAPTURE_MODE]) 123 | ->setEmail($rule[HelperData::RULE_EMAIL]); 124 | } 125 | } 126 | 127 | return $items; 128 | } 129 | 130 | /** 131 | * Returns payment method code of the given order 132 | * 133 | * @param Order $order 134 | */ 135 | private function getPaymentMethodCode(Order $order) 136 | { 137 | try { 138 | /** @var OrderPaymentInterface */ 139 | $payment = $order->getPayment(); 140 | return $payment->getMethodInstance()->getCode(); 141 | } catch (\Exception $ex) { 142 | return ''; 143 | } 144 | } 145 | 146 | /** 147 | * Returns the order status to state map 148 | */ 149 | private function getOrderStatusToStateMap() 150 | { 151 | if ($this->orderStatusToStateMap != null) { 152 | return $this->orderStatusToStateMap; 153 | } 154 | 155 | $collection = $this->orderStatusCollectionFactory->create() 156 | ->joinStates(); 157 | 158 | $this->orderStatusToStateMap = []; 159 | foreach ($collection as $status) { 160 | $this->orderStatusToStateMap[$status->getStatus()] = $status->getState(); 161 | } 162 | 163 | return $this->orderStatusToStateMap; 164 | } 165 | 166 | /** 167 | * Return the order state given a status 168 | * 169 | * @param string $status 170 | */ 171 | private function getOrderStateByStatus(string $status) 172 | { 173 | $map = $this->getOrderStatusToStateMap(); 174 | return empty($map[$status]) ? false : $map[$status]; 175 | } 176 | 177 | /** 178 | * @inheritdoc 179 | */ 180 | public function invoice(InvoiceProcessItemInterface $item) 181 | { 182 | $order = $item->getOrder(); 183 | 184 | $status = $item->getDestinationStatus(); 185 | $order->setStatus($status); 186 | 187 | $state = $this->getOrderStateByStatus($status); 188 | if ($state) { 189 | $order->setState($state); 190 | } 191 | 192 | $invoice = $this->invoiceServiceFactory->create() 193 | ->prepareInvoice($order); 194 | $invoice->setRequestedCaptureCase($item->getCaptureMode()); 195 | $invoice->register(); 196 | 197 | if ($order->getStatus() !== $item->getDestinationStatus()) { 198 | // Capture may overwrite order status, reset it 199 | $order->setStatus($item->getDestinationStatus()); 200 | if ($state) { 201 | $order->setState($state); 202 | } 203 | } 204 | 205 | $transactionSave = $this->transactionFactory->create() 206 | ->addObject($invoice) 207 | ->addObject($order); 208 | 209 | $transactionSave->save(); 210 | $email = $item->getEmail(); 211 | if ($email=='true') { 212 | try { 213 | $this->invoiceSender->send($invoice); 214 | $invoice->setEmailSent(true); 215 | } catch (\Exception $e) { 216 | $this->_logger->debug("Error while sending invoice-E-Mail: ".$e); 217 | } 218 | } 219 | } 220 | } 221 | -------------------------------------------------------------------------------- /Model/InvoiceProcessItem.php: -------------------------------------------------------------------------------- 1 | getData(self::KEY_ORDER); 16 | } 17 | 18 | /** 19 | * @inheritdoc 20 | */ 21 | public function setOrder(\Magento\Sales\Api\Data\OrderInterface $order) 22 | { 23 | return $this->setData(self::KEY_ORDER, $order); 24 | } 25 | 26 | /** 27 | * @inheritdoc 28 | */ 29 | public function getDestinationStatus() 30 | { 31 | return $this->getData(self::KEY_DESTINATION_STATUS); 32 | } 33 | 34 | /** 35 | * @inheritdoc 36 | */ 37 | public function setDestinationStatus(string $status) 38 | { 39 | return $this->setData(self::KEY_DESTINATION_STATUS, $status); 40 | } 41 | 42 | /** 43 | * @inheritdoc 44 | */ 45 | public function getCaptureMode() 46 | { 47 | return $this->getData(self::KEY_CAPTURE_MODE); 48 | } 49 | 50 | /** 51 | * @inheritdoc 52 | */ 53 | public function setCaptureMode(string $captureMode) 54 | { 55 | return $this->setData(self::KEY_CAPTURE_MODE, $captureMode); 56 | } 57 | 58 | /** 59 | * @inheritdoc 60 | */ 61 | public function getEmail() 62 | { 63 | return $this->getData(self::KEY_EMAIL); 64 | } 65 | 66 | /** 67 | * @inheritdoc 68 | */ 69 | public function setEmail(string $email) 70 | { 71 | return $this->setData(self::KEY_EMAIL, $email); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Magento 2 Auto Invoice 2 | Magento 2 procedure to automatically invoice orders in a given status. 3 | 4 | [![Build Status](https://travis-ci.org/aune-io/magento2-autoinvoice.svg?branch=master)](https://travis-ci.org/aune-io/magento2-autoinvoice) 5 | [![Coverage Status](https://coveralls.io/repos/github/aune-io/magento2-autoinvoice/badge.svg?branch=master)](https://coveralls.io/github/aune-io/magento2-autoinvoice?branch=master) 6 | [![Latest Stable Version](https://poser.pugx.org/aune-io/magento2-autoinvoice/v/stable)](https://packagist.org/packages/aune-io/magento2-autoinvoice) 7 | [![Latest Unstable Version](https://poser.pugx.org/aune-io/magento2-autoinvoice/v/unstable)](https://packagist.org/packages/aune-io/magento2-autoinvoice) 8 | [![Total Downloads](https://poser.pugx.org/aune-io/magento2-autoinvoice/downloads)](https://packagist.org/packages/aune-io/magento2-autoinvoice) 9 | [![License](https://poser.pugx.org/aune-io/magento2-autoinvoice/license)](https://packagist.org/packages/aune-io/magento2-autoinvoice) 10 | 11 | ## System requirements 12 | This extension supports the following versions of Magento: 13 | 14 | * Community Edition (CE) versions 2.2.x and 2.3.x and 2.4.x 15 | * Enterprise Edition (EE) versions 2.2.x and 2.3.x and 2.4.x 16 | 17 | ## Installation 18 | 1. Require the module via Composer 19 | ```bash 20 | $ composer require aune-io/magento2-autoinvoice 21 | ``` 22 | 23 | 2. Enable the module 24 | ```bash 25 | $ bin/magento module:enable Aune_AutoInvoice 26 | $ bin/magento setup:upgrade 27 | ``` 28 | 29 | ## Configuration 30 | The configuration of this module is under _Stores > Configuration > Sales > Auto Invoice_. 31 | There, you will be able to activate processing via cron job, and choose the behaviour of the procedure. 32 | 33 | The configuration matrix will allow you to set on for which combinations of status and payment method the extension should invoice the orders, as well as the destination status and capture mode. 34 | A configuration example follows. 35 | 36 | 37 | 38 | ## Usage 39 | The module supports two different usage methods. 40 | 41 | ### Command line 42 | The following command will execute the procedure: 43 | 44 | ```bash 45 | $ bin/magento aune:autoinvoice:process 46 | ``` 47 | 48 | A dry run mode is also available, just to see what orders would be affected by the procedure: 49 | ```bash 50 | $ bin/magento aune:autoinvoice:process --dry-run=1 51 | ``` 52 | 53 | ### Cron 54 | By activating the cron, the procedure will be automatically executed every hour. 55 | 56 | 1. Login to the admin 57 | 2. Go to Stores > Configuration > Sales > Auto Invoice 58 | 3. Set _Schedule procedure_ to yes 59 | 4. Specify a custom cron expression, if needed 60 | 5. Clean the cache 61 | 62 | ## Authors, contributors and maintainers 63 | 64 | Author: 65 | - [Renato Cason](https://github.com/renatocason) 66 | 67 | ## License 68 | Licensed under the Open Software License version 3.0 69 | -------------------------------------------------------------------------------- /Test/Unit/Console/ProcessCommandTest.php: -------------------------------------------------------------------------------- 1 | stateMock = $this->getMockBuilder(State::class) 42 | ->disableOriginalConstructor() 43 | ->getMock(); 44 | 45 | $this->loggerMock = $this->getMockForAbstractClass(LoggerInterface::class); 46 | $this->invoiceProcessMock = $this->getMockForAbstractClass(InvoiceProcessInterface::class); 47 | 48 | $this->processCommand = new ProcessCommand( 49 | $this->stateMock, 50 | $this->loggerMock, 51 | $this->invoiceProcessMock 52 | ); 53 | } 54 | 55 | /** 56 | * @covers \Aune\AutoInvoice\Console\ProcessCommand::configure 57 | */ 58 | public function testConfigure() 59 | { 60 | $this->assertEquals( 61 | $this->processCommand->getName(), 62 | ProcessCommand::COMMAND_NAME 63 | ); 64 | 65 | $this->assertEquals( 66 | $this->processCommand->getDescription(), 67 | ProcessCommand::COMMAND_DESCRIPTION 68 | ); 69 | } 70 | 71 | /** 72 | * @covers \Aune\AutoInvoice\Console\ProcessCommand::execute 73 | */ 74 | public function testExecuteDryRun() 75 | { 76 | $inputMock = $this->getMockBuilder(InputInterface::class) 77 | ->disableOriginalConstructor() 78 | ->getMock(); 79 | 80 | $inputMock->expects(self::exactly(1)) 81 | ->method('getOption') 82 | ->with(ProcessCommand::OPTION_DRY_RUN) 83 | ->willReturn(true); 84 | 85 | $outputMock = $this->getMockBuilder(OutputInterface::class) 86 | ->disableOriginalConstructor() 87 | ->getMock(); 88 | 89 | $itemMocks = []; 90 | for ($i=0; $i<10; $i++) { 91 | $orderMock = $this->getMockBuilder(Order::class) 92 | ->disableOriginalConstructor() 93 | ->getMock(); 94 | 95 | $itemMock = $this->getMockForAbstractClass(InvoiceProcessItemInterface::class); 96 | $itemMock->expects(self::any()) 97 | ->method('getOrder') 98 | ->willReturn($orderMock); 99 | 100 | $itemMocks []= $itemMock; 101 | } 102 | 103 | $this->invoiceProcessMock->expects(self::once()) 104 | ->method('getItemsToProcess') 105 | ->willReturn($itemMocks); 106 | 107 | $this->invoiceProcessMock->expects(self::exactly(0)) 108 | ->method('invoice'); 109 | 110 | $this->processCommand->run($inputMock, $outputMock); 111 | } 112 | 113 | /** 114 | * @covers \Aune\AutoInvoice\Console\ProcessCommand::execute 115 | */ 116 | public function testExecute() 117 | { 118 | $inputMock = $this->getMockBuilder(InputInterface::class) 119 | ->disableOriginalConstructor() 120 | ->getMock(); 121 | 122 | $inputMock->expects(self::exactly(1)) 123 | ->method('getOption') 124 | ->with(ProcessCommand::OPTION_DRY_RUN) 125 | ->willReturn(false); 126 | 127 | $outputMock = $this->getMockBuilder(OutputInterface::class) 128 | ->disableOriginalConstructor() 129 | ->getMock(); 130 | 131 | $itemMocks = []; 132 | for ($i=0; $i<10; $i++) { 133 | $orderMock = $this->getMockBuilder(Order::class) 134 | ->disableOriginalConstructor() 135 | ->getMock(); 136 | 137 | $itemMock = $this->getMockForAbstractClass(InvoiceProcessItemInterface::class); 138 | $itemMock->expects(self::any()) 139 | ->method('getOrder') 140 | ->willReturn($orderMock); 141 | 142 | $itemMocks []= $itemMock; 143 | } 144 | 145 | $this->invoiceProcessMock->expects(self::once()) 146 | ->method('getItemsToProcess') 147 | ->willReturn($itemMocks); 148 | 149 | $this->invoiceProcessMock->expects(self::exactly(count($itemMocks))) 150 | ->method('invoice'); 151 | 152 | $this->processCommand->run($inputMock, $outputMock); 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /Test/Unit/Cron/InvoiceProcessTest.php: -------------------------------------------------------------------------------- 1 | helperDataMock = $this->getMockBuilder(HelperData::class) 40 | ->disableOriginalConstructor() 41 | ->getMock(); 42 | 43 | $this->loggerMock = $this->getMockForAbstractClass(LoggerInterface::class); 44 | $this->invoiceProcessMock = $this->getMockForAbstractClass(InvoiceProcessInterface::class); 45 | 46 | $this->invoiceProcess = new InvoiceProcess( 47 | $this->helperDataMock, 48 | $this->loggerMock, 49 | $this->invoiceProcessMock 50 | ); 51 | } 52 | 53 | /** 54 | * @covers \Aune\AutoInvoice\Cron\InvoiceProcess::execute 55 | */ 56 | public function testExecuteDisabled() 57 | { 58 | $this->helperDataMock->expects(self::exactly(1)) 59 | ->method('isCronEnabled') 60 | ->willReturn(false); 61 | 62 | $this->invoiceProcessMock->expects(self::exactly(0)) 63 | ->method('getItemsToProcess'); 64 | 65 | $this->invoiceProcessMock->expects(self::exactly(0)) 66 | ->method('invoice'); 67 | 68 | $this->invoiceProcess->execute(); 69 | } 70 | 71 | /** 72 | * @covers \Aune\AutoInvoice\Cron\InvoiceProcess::execute 73 | */ 74 | public function testExecute() 75 | { 76 | $this->helperDataMock->expects(self::exactly(1)) 77 | ->method('isCronEnabled') 78 | ->willReturn(true); 79 | 80 | $itemMocks = []; 81 | for ($i=0; $i<10; $i++) { 82 | $orderMock = $this->getMockBuilder(Order::class) 83 | ->disableOriginalConstructor() 84 | ->getMock(); 85 | 86 | $itemMock = $this->getMockForAbstractClass(InvoiceProcessItemInterface::class); 87 | $itemMock->expects(self::any()) 88 | ->method('getOrder') 89 | ->willReturn($orderMock); 90 | 91 | $itemMocks []= $itemMock; 92 | } 93 | 94 | $this->invoiceProcessMock->expects(self::once()) 95 | ->method('getItemsToProcess') 96 | ->willReturn($itemMocks); 97 | 98 | $this->invoiceProcessMock->expects(self::exactly(count($itemMocks))) 99 | ->method('invoice'); 100 | 101 | $this->invoiceProcess->execute(); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /Test/Unit/Helper/DataTest.php: -------------------------------------------------------------------------------- 1 | scopeConfigMock = $this->getMockForAbstractClass(ScopeConfigInterface::class); 28 | 29 | $this->helperData = new HelperData( 30 | $this->scopeConfigMock, 31 | new Json() 32 | ); 33 | } 34 | 35 | /** 36 | * @dataProvider getConfigDataProvider 37 | */ 38 | public function testGetConfigValue($key, $isFlag, $method, $in, $out) 39 | { 40 | $this->scopeConfigMock->expects(self::once()) 41 | ->method($isFlag ? 'isSetFlag' : 'getValue') 42 | ->with($key) 43 | ->willReturn($in); 44 | 45 | self::assertEquals( 46 | $out, 47 | $this->helperData->$method() 48 | ); 49 | } 50 | 51 | /** 52 | * @return array 53 | */ 54 | public function getConfigDataProvider() 55 | { 56 | return [ 57 | ['key' => HelperData::XML_PATH_CRON_ENABLED, 58 | 'isFlag' => true, 'method' => 'isCronEnabled', 'in' => '1', 'out' => true], 59 | ['key' => HelperData::XML_PATH_CRON_ENABLED, 60 | 'isFlag' => true, 'method' => 'isCronEnabled', 'in' => '0', 'out' => false], 61 | ['key' => HelperData::XML_PATH_PROCESSING_RULES, 62 | 'isFlag' => false, 'method' => 'getProcessingRules', 'in' => '', 'out' => []], 63 | ]; 64 | } 65 | 66 | /** 67 | * @dataProvider getProcessingRulesDataProvider 68 | */ 69 | public function testGetProcessingRules($in, $out) 70 | { 71 | $this->scopeConfigMock->expects(self::once()) 72 | ->method('getValue') 73 | ->with(HelperData::XML_PATH_PROCESSING_RULES) 74 | ->willReturn($in); 75 | 76 | self::assertEquals( 77 | $out, 78 | $this->helperData->getProcessingRules() 79 | ); 80 | } 81 | 82 | /** 83 | * @return array 84 | */ 85 | public function getProcessingRulesDataProvider() 86 | { 87 | return [[ 88 | 'in' => '{"pending|*":"complete"}', 89 | 'out' => [[ 90 | HelperData::RULE_SOURCE_STATUS => 'pending', 91 | HelperData::RULE_PAYMENT_METHOD => HelperData::RULE_PAYMENT_METHOD_ALL, 92 | HelperData::RULE_DESTINATION_STATUS => 'complete', 93 | HelperData::RULE_CAPTURE_MODE => Invoice::CAPTURE_OFFLINE, 94 | ]], 95 | ], [ 96 | 'in' => '{"pending|*":"complete","pending|free":"processing"}', 97 | 'out' => [[ 98 | HelperData::RULE_SOURCE_STATUS => 'pending', 99 | HelperData::RULE_PAYMENT_METHOD => HelperData::RULE_PAYMENT_METHOD_ALL, 100 | HelperData::RULE_DESTINATION_STATUS => 'complete', 101 | HelperData::RULE_CAPTURE_MODE => Invoice::CAPTURE_OFFLINE, 102 | ], [ 103 | HelperData::RULE_SOURCE_STATUS => 'pending', 104 | HelperData::RULE_PAYMENT_METHOD => 'free', 105 | HelperData::RULE_DESTINATION_STATUS => 'processing', 106 | HelperData::RULE_CAPTURE_MODE => Invoice::CAPTURE_OFFLINE, 107 | ]], 108 | ], [ 109 | 'in' => '{"pending|*":"complete","processing|*":"complete","pending|free":"processing"}', 110 | 'out' => [[ 111 | HelperData::RULE_SOURCE_STATUS => 'pending', 112 | HelperData::RULE_PAYMENT_METHOD => HelperData::RULE_PAYMENT_METHOD_ALL, 113 | HelperData::RULE_DESTINATION_STATUS => 'complete', 114 | HelperData::RULE_CAPTURE_MODE => Invoice::CAPTURE_OFFLINE, 115 | ], [ 116 | HelperData::RULE_SOURCE_STATUS => 'processing', 117 | HelperData::RULE_PAYMENT_METHOD => HelperData::RULE_PAYMENT_METHOD_ALL, 118 | HelperData::RULE_DESTINATION_STATUS => 'complete', 119 | HelperData::RULE_CAPTURE_MODE => Invoice::CAPTURE_OFFLINE, 120 | ], [ 121 | HelperData::RULE_SOURCE_STATUS => 'pending', 122 | HelperData::RULE_PAYMENT_METHOD => 'free', 123 | HelperData::RULE_DESTINATION_STATUS => 'processing', 124 | HelperData::RULE_CAPTURE_MODE => Invoice::CAPTURE_OFFLINE, 125 | ]], 126 | ],[ 127 | 'in' => '{"pending|*":{"dst_status":"complete","capture_mode":"online"}}', 128 | 'out' => [[ 129 | HelperData::RULE_SOURCE_STATUS => 'pending', 130 | HelperData::RULE_PAYMENT_METHOD => HelperData::RULE_PAYMENT_METHOD_ALL, 131 | HelperData::RULE_DESTINATION_STATUS => 'complete', 132 | HelperData::RULE_CAPTURE_MODE => Invoice::CAPTURE_ONLINE, 133 | ]], 134 | ], [ 135 | 'in' => '{"pending|*":{"dst_status":"complete","capture_mode":"online"},"pending|free":{"dst_status":"processing","capture_mode":"online"}}', 136 | 'out' => [[ 137 | HelperData::RULE_SOURCE_STATUS => 'pending', 138 | HelperData::RULE_PAYMENT_METHOD => HelperData::RULE_PAYMENT_METHOD_ALL, 139 | HelperData::RULE_DESTINATION_STATUS => 'complete', 140 | HelperData::RULE_CAPTURE_MODE => Invoice::CAPTURE_ONLINE, 141 | ], [ 142 | HelperData::RULE_SOURCE_STATUS => 'pending', 143 | HelperData::RULE_PAYMENT_METHOD => 'free', 144 | HelperData::RULE_DESTINATION_STATUS => 'processing', 145 | HelperData::RULE_CAPTURE_MODE => Invoice::CAPTURE_ONLINE, 146 | ]], 147 | ], [ 148 | 'in' => '{"pending|*":{"dst_status":"complete","capture_mode":"online"},"processing|*":{"dst_status":"complete","capture_mode":"online"},"pending|free":{"dst_status":"processing","capture_mode":"online"}}', 149 | 'out' => [[ 150 | HelperData::RULE_SOURCE_STATUS => 'pending', 151 | HelperData::RULE_PAYMENT_METHOD => HelperData::RULE_PAYMENT_METHOD_ALL, 152 | HelperData::RULE_DESTINATION_STATUS => 'complete', 153 | HelperData::RULE_CAPTURE_MODE => Invoice::CAPTURE_ONLINE, 154 | ], [ 155 | HelperData::RULE_SOURCE_STATUS => 'processing', 156 | HelperData::RULE_PAYMENT_METHOD => HelperData::RULE_PAYMENT_METHOD_ALL, 157 | HelperData::RULE_DESTINATION_STATUS => 'complete', 158 | HelperData::RULE_CAPTURE_MODE => Invoice::CAPTURE_ONLINE, 159 | ], [ 160 | HelperData::RULE_SOURCE_STATUS => 'pending', 161 | HelperData::RULE_PAYMENT_METHOD => 'free', 162 | HelperData::RULE_DESTINATION_STATUS => 'processing', 163 | HelperData::RULE_CAPTURE_MODE => Invoice::CAPTURE_ONLINE, 164 | ]], 165 | ]]; 166 | } 167 | } 168 | -------------------------------------------------------------------------------- /Test/Unit/Model/InvoiceProcessItemTest.php: -------------------------------------------------------------------------------- 1 | invoiceProcessItem = new InvoiceProcessItem(); 19 | } 20 | 21 | /** 22 | * Test class service contract 23 | */ 24 | public function testServiceContract() 25 | { 26 | $this->assertInstanceOf( 27 | InvoiceProcessItemInterface::class, 28 | $this->invoiceProcessItem 29 | ); 30 | } 31 | 32 | /** 33 | * @dataProvider getFieldsDataProvider 34 | */ 35 | public function testGettersAndSetters($field, $getter, $setter, $value) 36 | { 37 | $this->assertEquals( 38 | $this->invoiceProcessItem->$setter($value), 39 | $this->invoiceProcessItem 40 | ); 41 | 42 | $this->assertEquals( 43 | $this->invoiceProcessItem->getData($field), 44 | $value 45 | ); 46 | 47 | $this->assertEquals( 48 | $this->invoiceProcessItem->$getter(), 49 | $value 50 | ); 51 | } 52 | 53 | /** 54 | * @return array 55 | */ 56 | public function getFieldsDataProvider() 57 | { 58 | $orderMock = $this->getMockBuilder(Order::class) 59 | ->disableOriginalConstructor() 60 | ->getMock(); 61 | 62 | return [ 63 | ['field' => InvoiceProcessItemInterface::KEY_ORDER, 'getter' => 'getOrder', 'setter' => 'setOrder', 'value' => $orderMock], 64 | ['field' => InvoiceProcessItemInterface::KEY_DESTINATION_STATUS, 'getter' => 'getDestinationStatus', 'setter' => 'setDestinationStatus', 'value' => 'complete'], 65 | ]; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /Test/Unit/Model/InvoiceProcessTest.php: -------------------------------------------------------------------------------- 1 | helperDataMock = $this->getMockBuilder(HelperData::class) 66 | ->disableOriginalConstructor() 67 | ->getMock(); 68 | 69 | $this->orderCollectionFactoryMock = $this->getMockBuilder(OrderCollectionFactory::class) 70 | ->disableOriginalConstructor() 71 | ->getMock(); 72 | 73 | $this->orderStatusCollectionFactoryMock = $this->getMockBuilder(OrderStatusCollectionFactory::class) 74 | ->disableOriginalConstructor() 75 | ->setMethods(['create']) 76 | ->getMock(); 77 | 78 | $this->invoiceProcessItemFactoryMock = $this->getMockBuilder(InvoiceProcessItemInterfaceFactory::class) 79 | ->disableOriginalConstructor() 80 | ->setMethods(['create']) 81 | ->getMock(); 82 | 83 | $this->transactionMock = $this->getMockBuilder(Transaction::class) 84 | ->disableOriginalConstructor() 85 | ->getMock(); 86 | 87 | $this->invoiceServiceFactoryMock = $this->getMockBuilder(InvoiceServiceFactory::class) 88 | ->disableOriginalConstructor() 89 | ->setMethods(['create']) 90 | ->getMock(); 91 | 92 | $this->invoiceProcess = new InvoiceProcess( 93 | $this->helperDataMock, 94 | $this->orderCollectionFactoryMock, 95 | $this->orderStatusCollectionFactoryMock, 96 | $this->invoiceProcessItemFactoryMock, 97 | $this->transactionMock, 98 | $this->invoiceServiceFactoryMock 99 | ); 100 | } 101 | 102 | /** 103 | * Test class service contract 104 | */ 105 | public function testServiceContract() 106 | { 107 | $this->assertInstanceOf( 108 | InvoiceProcessInterface::class, 109 | $this->invoiceProcess 110 | ); 111 | } 112 | 113 | /** 114 | * @covers \Aune\AutoInvoice\Model\InvoiceProcess::getItemsToProcess 115 | */ 116 | public function testGetItemsToProcess() 117 | { 118 | $dstStatus = 'complete'; 119 | $captureMode = 'offline'; 120 | 121 | $this->helperDataMock->expects(self::once()) 122 | ->method('getProcessingRules') 123 | ->willReturn([[ 124 | HelperData::RULE_SOURCE_STATUS => 'processing', 125 | HelperData::RULE_PAYMENT_METHOD => HelperData::RULE_PAYMENT_METHOD_ALL, 126 | HelperData::RULE_DESTINATION_STATUS => $dstStatus, 127 | HelperData::RULE_CAPTURE_MODE => $captureMode, 128 | ]]); 129 | 130 | $orderCollectionMock = $this->getMockBuilder(OrderCollection::class) 131 | ->disableOriginalConstructor() 132 | ->getMock(); 133 | 134 | $this->orderCollectionFactoryMock->expects(self::once()) 135 | ->method('create') 136 | ->willReturn($orderCollectionMock); 137 | 138 | $orderCollectionMock->expects(self::exactly(2)) 139 | ->method('addFieldToFilter') 140 | ->willReturn($orderCollectionMock); 141 | 142 | $orders = [ 143 | $this->getOrderMock(1, 'paypal'), 144 | $this->getOrderMock(2, 'paypal_express'), 145 | $this->getOrderMock(3, 'braintree'), 146 | $this->getOrderMock(4, 'braintree'), 147 | $this->getOrderMock(5, 'aune_stripe'), 148 | ]; 149 | 150 | $orderCollectionMock->expects(self::once()) 151 | ->method('getIterator') 152 | ->willReturn(new ArrayIterator($orders)); 153 | 154 | $items = []; 155 | foreach ($orders as $order) { 156 | $itemMock = $this->getMockForAbstractClass(InvoiceProcessItemInterface::class); 157 | 158 | $itemMock->expects(self::once()) 159 | ->method('setOrder') 160 | ->with($order) 161 | ->willReturn($itemMock); 162 | 163 | $itemMock->expects(self::once()) 164 | ->method('setDestinationStatus') 165 | ->with($dstStatus) 166 | ->willReturn($itemMock); 167 | 168 | $itemMock->expects(self::once()) 169 | ->method('setCaptureMode') 170 | ->with($captureMode) 171 | ->willReturn($itemMock); 172 | 173 | $items[$order->getId()] = $itemMock; 174 | } 175 | 176 | $this->invoiceProcessItemFactoryMock->expects(self::exactly(count($items))) 177 | ->method('create') 178 | ->willReturnOnConsecutiveCalls(...$items); 179 | 180 | $this->assertEquals( 181 | $this->invoiceProcess->getItemsToProcess(), 182 | $items 183 | ); 184 | } 185 | 186 | /** 187 | * @covers \Aune\AutoInvoice\Model\InvoiceProcess::getItemsToProcess 188 | */ 189 | public function testGetItemsToProcessPaymentMethods() 190 | { 191 | $srcStatus = 'processing'; 192 | $dstStatusPaypal = 'complete'; 193 | $captureModePaypal = 'offline'; 194 | $dstStatusBraintree = 'processing'; 195 | $captureModeBraintree = 'online'; 196 | 197 | $this->helperDataMock->expects(self::once()) 198 | ->method('getProcessingRules') 199 | ->willReturn([[ 200 | HelperData::RULE_SOURCE_STATUS => $srcStatus, 201 | HelperData::RULE_PAYMENT_METHOD => 'paypal', 202 | HelperData::RULE_DESTINATION_STATUS => $dstStatusPaypal, 203 | HelperData::RULE_CAPTURE_MODE => $captureModePaypal, 204 | ], [ 205 | HelperData::RULE_SOURCE_STATUS => $srcStatus, 206 | HelperData::RULE_PAYMENT_METHOD => 'braintree', 207 | HelperData::RULE_DESTINATION_STATUS => $dstStatusBraintree, 208 | HelperData::RULE_CAPTURE_MODE => $captureModeBraintree, 209 | ]]); 210 | 211 | $paypalOrders = [ 212 | $this->getOrderMock(1, 'paypal'), 213 | ]; 214 | $braintreeOrders = [ 215 | $this->getOrderMock(3, 'braintree'), 216 | $this->getOrderMock(4, 'braintree') 217 | ]; 218 | $otherOrders = [ 219 | $this->getOrderMock(2, 'paypal_express'), 220 | $this->getOrderMock(5, 'aune_stripe'), 221 | ]; 222 | 223 | $allData = [ 224 | [$dstStatusPaypal, $captureModePaypal, $paypalOrders], 225 | [$dstStatusBraintree, $captureModeBraintree, $braintreeOrders], 226 | ]; 227 | 228 | $items = []; 229 | $orderCollectionMocks = []; 230 | 231 | foreach ($allData as $data) { 232 | $dstStatus = $data[0]; 233 | $captureMode = $data[1]; 234 | $orders = $data[2]; 235 | 236 | $orderCollectionMock = $this->getMockBuilder(OrderCollection::class) 237 | ->disableOriginalConstructor() 238 | ->getMock(); 239 | 240 | $orderCollectionMock->expects(self::exactly(2)) 241 | ->method('addFieldToFilter') 242 | ->withConsecutive( 243 | ['status', ['eq' => $srcStatus]], 244 | ['total_invoiced', ['null' => true]] 245 | ) 246 | ->willReturnOnConsecutiveCalls($orderCollectionMock, $orderCollectionMock); 247 | 248 | $orderCollectionMock->expects(self::once()) 249 | ->method('getIterator') 250 | ->willReturn(new ArrayIterator(array_merge($orders, $otherOrders))); 251 | 252 | $orderCollectionMocks []= $orderCollectionMock; 253 | 254 | foreach ($orders as $order) { 255 | $itemMock = $this->getMockForAbstractClass(InvoiceProcessItemInterface::class); 256 | $itemMock->expects(self::once()) 257 | ->method('setOrder') 258 | ->with($order) 259 | ->willReturn($itemMock); 260 | 261 | $itemMock->expects(self::once()) 262 | ->method('setDestinationStatus') 263 | ->with($dstStatus) 264 | ->willReturn($itemMock); 265 | 266 | $itemMock->expects(self::once()) 267 | ->method('setCaptureMode') 268 | ->with($captureMode) 269 | ->willReturn($itemMock); 270 | 271 | $items[$order->getId()] = $itemMock; 272 | } 273 | } 274 | 275 | $this->orderCollectionFactoryMock->expects(self::exactly(count($orderCollectionMocks))) 276 | ->method('create') 277 | ->willReturnOnConsecutiveCalls(...$orderCollectionMocks); 278 | 279 | $this->invoiceProcessItemFactoryMock->expects(self::exactly(count($items))) 280 | ->method('create') 281 | ->willReturnOnConsecutiveCalls(...$items); 282 | 283 | $this->assertEquals( 284 | $this->invoiceProcess->getItemsToProcess(), 285 | $items 286 | ); 287 | } 288 | 289 | /** 290 | * Returns new mock order with given payment method 291 | */ 292 | private function getOrderMock(int $orderId, string $paymentMethod) 293 | { 294 | $methodInstanceMock = $this->getMockForAbstractClass(\Magento\Payment\Model\MethodInterface::class); 295 | 296 | $methodInstanceMock->expects(self::any()) 297 | ->method('getCode') 298 | ->willReturn($paymentMethod); 299 | 300 | $paymentMock = $this->getMockBuilder(\Magento\Sales\Model\Order\Payment::class) 301 | ->disableOriginalConstructor() 302 | ->getMock(); 303 | 304 | $paymentMock->expects(self::any()) 305 | ->method('getMethodInstance') 306 | ->willReturn($methodInstanceMock); 307 | 308 | $orderMock = $this->getMockBuilder(Order::class) 309 | ->disableOriginalConstructor() 310 | ->getMock(); 311 | 312 | $orderMock->expects(self::any()) 313 | ->method('getId') 314 | ->willReturn($orderId); 315 | 316 | $orderMock->expects(self::any()) 317 | ->method('getPayment') 318 | ->willReturn($paymentMock); 319 | 320 | return $orderMock; 321 | } 322 | 323 | /** 324 | * @covers \Aune\AutoInvoice\Model\InvoiceProcess::invoice 325 | */ 326 | public function testInvoiceOffline() 327 | { 328 | $status = 'complete'; 329 | $captureMode = 'offline'; 330 | 331 | $orderStatusCollectionMock = $this->getMockBuilder(OrderStatusCollection::class) 332 | ->disableOriginalConstructor() 333 | ->getMock(); 334 | 335 | $orderStatusCollectionMock->expects(self::once()) 336 | ->method('joinStates') 337 | ->willReturn($orderStatusCollectionMock); 338 | 339 | $this->orderStatusCollectionFactoryMock->expects(self::once()) 340 | ->method('create') 341 | ->willReturn($orderStatusCollectionMock); 342 | 343 | $statuses = [ 344 | $this->getOrderStatusMock('processing', 'processing'), 345 | $this->getOrderStatusMock('pending', 'pending'), 346 | $this->getOrderStatusMock('complete', 'complete'), 347 | $this->getOrderStatusMock('closed', 'closed'), 348 | ]; 349 | 350 | $orderStatusCollectionMock->expects(self::once()) 351 | ->method('getIterator') 352 | ->willReturn(new ArrayIterator($statuses)); 353 | 354 | $orderMock = $this->getMockBuilder(Order::class) 355 | ->disableOriginalConstructor() 356 | ->getMock(); 357 | 358 | $orderMock->expects(self::once()) 359 | ->method('setStatus') 360 | ->with($status) 361 | ->willReturn($orderMock); 362 | 363 | $orderMock->expects(self::once()) 364 | ->method('setState') 365 | ->with($status) 366 | ->willReturn($orderMock); 367 | 368 | $itemMock = $this->getMockForAbstractClass(InvoiceProcessItemInterface::class); 369 | 370 | $itemMock->expects(self::once()) 371 | ->method('getOrder') 372 | ->willReturn($orderMock); 373 | 374 | $itemMock->expects(self::once()) 375 | ->method('getDestinationStatus') 376 | ->willReturn($status); 377 | 378 | $itemMock->expects(self::once()) 379 | ->method('getCaptureMode') 380 | ->willReturn($captureMode); 381 | 382 | $invoiceMock = $this->getMockBuilder(OrderInvoice::class) 383 | ->disableOriginalConstructor() 384 | ->setMethods(['setRequestedCaptureCase', 'register']) 385 | ->getMock(); 386 | 387 | $invoiceServiceMock = $this->getMockBuilder(InvoiceService::class) 388 | ->disableOriginalConstructor() 389 | ->getMock(); 390 | 391 | $invoiceServiceMock->expects(self::once()) 392 | ->method('prepareInvoice') 393 | ->with($orderMock) 394 | ->willReturn($invoiceMock); 395 | 396 | $this->invoiceServiceFactoryMock->expects(self::once()) 397 | ->method('create') 398 | ->willReturn($invoiceServiceMock); 399 | 400 | $invoiceMock->expects(self::once()) 401 | ->method('setRequestedCaptureCase') 402 | ->with($captureMode); 403 | 404 | $invoiceMock->expects(self::once()) 405 | ->method('register'); 406 | 407 | $this->transactionMock->expects(self::exactly(2)) 408 | ->method('addObject') 409 | ->willReturn($this->transactionMock); 410 | 411 | $this->transactionMock->expects(self::once()) 412 | ->method('save'); 413 | 414 | $this->invoiceProcess->invoice($itemMock); 415 | } 416 | 417 | /** 418 | * @covers \Aune\AutoInvoice\Model\InvoiceProcess::invoice 419 | */ 420 | public function testInvoiceOnline() 421 | { 422 | $status = 'complete'; 423 | $captureMode = 'online'; 424 | 425 | $orderStatusCollectionMock = $this->getMockBuilder(OrderStatusCollection::class) 426 | ->disableOriginalConstructor() 427 | ->getMock(); 428 | 429 | $orderStatusCollectionMock->expects(self::once()) 430 | ->method('joinStates') 431 | ->willReturn($orderStatusCollectionMock); 432 | 433 | $this->orderStatusCollectionFactoryMock->expects(self::once()) 434 | ->method('create') 435 | ->willReturn($orderStatusCollectionMock); 436 | 437 | $statuses = [ 438 | $this->getOrderStatusMock('processing', 'processing'), 439 | $this->getOrderStatusMock('pending', 'pending'), 440 | $this->getOrderStatusMock('complete', 'complete'), 441 | $this->getOrderStatusMock('closed', 'closed'), 442 | ]; 443 | 444 | $orderStatusCollectionMock->expects(self::once()) 445 | ->method('getIterator') 446 | ->willReturn(new ArrayIterator($statuses)); 447 | 448 | $orderMock = $this->getMockBuilder(Order::class) 449 | ->disableOriginalConstructor() 450 | ->getMock(); 451 | 452 | $orderMock->expects(self::once()) 453 | ->method('setStatus') 454 | ->with($status) 455 | ->willReturn($orderMock); 456 | 457 | $orderMock->expects(self::once()) 458 | ->method('setState') 459 | ->with($status) 460 | ->willReturn($orderMock); 461 | 462 | $itemMock = $this->getMockForAbstractClass(InvoiceProcessItemInterface::class); 463 | 464 | $itemMock->expects(self::once()) 465 | ->method('getOrder') 466 | ->willReturn($orderMock); 467 | 468 | $itemMock->expects(self::once()) 469 | ->method('getDestinationStatus') 470 | ->willReturn($status); 471 | 472 | $itemMock->expects(self::once()) 473 | ->method('getCaptureMode') 474 | ->willReturn($captureMode); 475 | 476 | $invoiceMock = $this->getMockBuilder(OrderInvoice::class) 477 | ->disableOriginalConstructor() 478 | ->setMethods(['setRequestedCaptureCase', 'register']) 479 | ->getMock(); 480 | 481 | $invoiceServiceMock = $this->getMockBuilder(InvoiceService::class) 482 | ->disableOriginalConstructor() 483 | ->getMock(); 484 | 485 | $invoiceServiceMock->expects(self::once()) 486 | ->method('prepareInvoice') 487 | ->with($orderMock) 488 | ->willReturn($invoiceMock); 489 | 490 | $this->invoiceServiceFactoryMock->expects(self::once()) 491 | ->method('create') 492 | ->willReturn($invoiceServiceMock); 493 | 494 | $invoiceMock->expects(self::once()) 495 | ->method('setRequestedCaptureCase') 496 | ->with($captureMode); 497 | 498 | $invoiceMock->expects(self::once()) 499 | ->method('register'); 500 | 501 | $this->transactionMock->expects(self::exactly(2)) 502 | ->method('addObject') 503 | ->willReturn($this->transactionMock); 504 | 505 | $this->transactionMock->expects(self::once()) 506 | ->method('save'); 507 | 508 | $this->invoiceProcess->invoice($itemMock); 509 | } 510 | 511 | /** 512 | * Returns new mock status with given a status/state pair 513 | */ 514 | private function getOrderStatusMock(string $status, string $state) 515 | { 516 | $orderStatusMock = $this->getMockBuilder(\Magento\Sales\Model\Order\Status::class) 517 | ->disableOriginalConstructor() 518 | ->setMethods(['getStatus', 'getState']) 519 | ->getMock(); 520 | 521 | $orderStatusMock->expects(self::once()) 522 | ->method('getStatus') 523 | ->willReturn($status); 524 | 525 | $orderStatusMock->expects(self::once()) 526 | ->method('getState') 527 | ->willReturn($state); 528 | 529 | return $orderStatusMock; 530 | } 531 | } 532 | -------------------------------------------------------------------------------- /Test/Unit/bootstrap.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 | 6 | 7 | 8 | 9 | Magento\Config\Model\Config\Source\Yesno 10 | 11 | 12 | 13 | Format: * * * * * 14 | 15 | 16 | 17 | Aune\AutoInvoice\Block\Adminhtml\Form\Field\ProcessingRule 18 | Aune\AutoInvoice\Model\Adminhtml\System\Config\ProcessingRule 19 | 20 | 21 |
22 |
23 |
24 | -------------------------------------------------------------------------------- /etc/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 1 7 | 0 * * * * 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /etc/crontab.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | sales/autoinvoice/cron_schedule 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /etc/di.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 9 | 10 | 11 | 12 | 13 | 14 | Aune\AutoInvoice\Console\ProcessCommand 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /etc/module.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | Test/Unit 9 | 10 | 11 | 12 | ./Block 13 | ./Console 14 | ./Cron 15 | ./Helper 16 | ./Model 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /registration.php: -------------------------------------------------------------------------------- 1 |