├── .module.ini ├── Block └── Field │ └── Link.php ├── CHANGELOG.md ├── Config ├── Config.php └── Frontend │ └── Funding.php ├── Controller └── Index │ └── Success.php ├── Exception ├── ForbiddenAccess.php └── InvalidOrderId.php ├── INSTALL.md ├── LICENSE.txt ├── PWA.md ├── README.md ├── Test ├── Integration │ ├── BrowseTest.php │ └── ModuleConfigTest.php └── Unit │ ├── Config │ └── ConfigTest.php │ └── Mock │ ├── BlockContext │ ├── AppStateMock.php │ ├── CacheMock.php │ ├── CacheStateMock.php │ ├── FileResolverMock.php │ └── SidResolverMock.php │ ├── BlockContextMock.php │ ├── Generic │ ├── EventManagerMock.php │ ├── ScopeConfigMock.php │ ├── SessionMock.php │ ├── StoreManagerMock.php │ └── UrlBuilderMock.php │ └── HelperContextMock.php ├── USAGE.md ├── Utility ├── Access.php └── GetOrder.php ├── composer.json ├── etc ├── adminhtml │ └── system.xml ├── config.xml ├── frontend │ └── routes.xml └── module.xml ├── registration.php └── view ├── adminhtml └── templates │ └── funding.phtml └── frontend └── layout └── checkouttester_index_index.xml /.module.ini: -------------------------------------------------------------------------------- 1 | EXTENSION_VENDOR="Yireo" 2 | EXTENSION_NAME="CheckoutTester2" 3 | COMPOSER_NAME="yireo/magento2-checkouttester2" 4 | PHP_VERSIONS=("7.4", "8.1", "8.2") 5 | -------------------------------------------------------------------------------- /Block/Field/Link.php: -------------------------------------------------------------------------------- 1 | getUrl() because of issue 5322 22 | * 23 | * @var Url 24 | */ 25 | protected $urlModel; 26 | 27 | /** 28 | * Link constructor. 29 | * 30 | * @param Url $urlModel 31 | * @param Context $context 32 | * @param array $data 33 | */ 34 | public function __construct( 35 | Url $urlModel, 36 | Context $context, 37 | array $data = [] 38 | ) { 39 | $this->urlModel = $urlModel; 40 | parent::__construct($context, $data); 41 | } 42 | 43 | /** 44 | * Return the elements HTML value 45 | * 46 | * @param AbstractElement $element 47 | * 48 | * @return string 49 | * @throws NoSuchEntityException 50 | */ 51 | protected function _getElementHtml(AbstractElement $element): string 52 | { 53 | $link = $this->getFrontendLink(); 54 | $html = '' 55 | . __('Open success page in new window') 56 | . ''; 57 | 58 | return $html; 59 | } 60 | 61 | /** 62 | * Return the frontend link 63 | * 64 | * @return string 65 | * @throws NoSuchEntityException 66 | */ 67 | public function getFrontendLink(): string 68 | { 69 | $storeId = $this->getStoreId(); 70 | $url = $this->urlModel->setScope($storeId)->getUrl('checkouttester/index/success'); 71 | 72 | return $url; 73 | } 74 | 75 | /** 76 | * Return store id of current configuration scope 77 | * 78 | * @return string 79 | * @throws NoSuchEntityException 80 | */ 81 | protected function getStoreId(): string 82 | { 83 | $storeId = $this->_request->getParam('store'); 84 | if (!empty($storeId)) { 85 | return (string)$storeId; 86 | } 87 | 88 | return (string)$this->_storeManager->getStore()->getCode(); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | All notable changes to this project will be documented in this file. 3 | 4 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 5 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 6 | 7 | ## [Unreleased] 8 | 9 | ## [1.0.4] - 24 October 2024 10 | ### Fixed 11 | - Add funding options 12 | 13 | ## [1.0.3] - 12 September 2023 14 | ### Fixed 15 | - Unit test fixes 16 | 17 | ## [1.0.2] - 12 September 2023 18 | ### Fixed 19 | - PHPStan fixes 20 | 21 | ## [1.0.1] - 19 July 2023 22 | ### Fixed 23 | - Setting to only run this in Developer Mode 24 | 25 | ## [1.0.0] - 22 September 2021 26 | ### Added 27 | - Separate `Config` class 28 | - Added PHP 7.4+ syntax 29 | - Rewrite controller to use `HttpGetActionInterface` only 30 | - More helpful comments with configuration options 31 | 32 | ### Removed 33 | - Remove legacy data-helper 34 | - Removed support for PHP 7.4 35 | - Removed support for Magento 2.2 or older 36 | - Removed unneeded Success-block 37 | - Remove `setup_version` from `module.xml` 38 | 39 | ## [0.0.16] - 4 August 2022 40 | ### Fixed 41 | - Missing order data in event (@JamesFX2) #23 42 | 43 | ## [0.0.15] - 27 August 2021 44 | ### Added 45 | - NOINDEX,NOFOLLOW 46 | - Magento PHPCS compliance 47 | 48 | ## [0.0.14] - 20 October 2020 49 | ### Fixed 50 | - Remove page layout specification in XML layout (which is duplicate) (@GrimLink) 51 | 52 | ## [0.0.13] - 29 July 2020 53 | ### Added 54 | - Magento 2.4 support 55 | 56 | ## [0.0.12] - August 2019 57 | ### Added 58 | - Proper integration testing for browsing depending on config settings 59 | 60 | ### Fixed 61 | - Settings for "enabled" and "ip" were not properly picked up 62 | 63 | ## [0.0.11] - July 2019 64 | ### Added 65 | - Add `version` to `composer.json` 66 | - Add `etc/config.xml` file with default values 67 | - Add KeepAChangeLog support 68 | - Move configuration to separate **Yireo** section 69 | 70 | For older releases, see the GitHub commit messages. 71 | -------------------------------------------------------------------------------- /Config/Config.php: -------------------------------------------------------------------------------- 1 | scopeConfig = $scopeConfig; 19 | $this->appState = $appState; 20 | } 21 | 22 | /** 23 | * Switch to determine whether this extension is enabled or not 24 | * 25 | * @return bool 26 | */ 27 | public function enabled(): bool 28 | { 29 | $onlyInDevMode = (bool)$this->getConfigValue('only_in_dev_mode'); 30 | if ($onlyInDevMode && $this->appState->getMode() !== State::MODE_DEVELOPER) { 31 | return false; 32 | } 33 | 34 | return (bool)$this->getConfigValue('enabled'); 35 | } 36 | 37 | /** 38 | * Get IP address that is allowed access 39 | * 40 | * @return string 41 | */ 42 | public function getIpAddress(): string 43 | { 44 | return (string)$this->getConfigValue('ip'); 45 | } 46 | 47 | /** 48 | * Return the order ID 49 | * 50 | * @return int 51 | */ 52 | public function getOrderIdFromConfig(): int 53 | { 54 | return (int)$this->getConfigValue('order_id'); 55 | } 56 | 57 | /** 58 | * Check whether the module is enabled 59 | * 60 | * @return bool 61 | */ 62 | public function allowDispatchCheckoutOnepageControllerSuccessAction(): bool 63 | { 64 | return (bool)$this->getConfigValue('checkout_onepage_controller_success_action', false); 65 | } 66 | 67 | /** 68 | * Return a configuration value 69 | * 70 | * @param string $key 71 | * @param mixed $defaultValue 72 | * @param bool $prefix 73 | * 74 | * @return mixed 75 | */ 76 | public function getConfigValue(string $key = '', $defaultValue = null, $prefix = true) 77 | { 78 | if ($prefix) { 79 | $key = 'checkouttester2/settings/' . $key; 80 | } 81 | 82 | $value = $this->scopeConfig->getValue( 83 | $key, 84 | ScopeInterface::SCOPE_STORE 85 | ); 86 | 87 | if (empty($value)) { 88 | $value = $defaultValue; 89 | } 90 | 91 | return $value; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /Config/Frontend/Funding.php: -------------------------------------------------------------------------------- 1 | toHtml(); 15 | } 16 | } 17 | 18 | -------------------------------------------------------------------------------- /Controller/Index/Success.php: -------------------------------------------------------------------------------- 1 | resultPageFactory = $resultPageFactory; 59 | $this->registry = $registry; 60 | $this->checkoutSession = $checkoutSession; 61 | $this->moduleConfig = $moduleConfig; 62 | $this->access = $access; 63 | $this->getOrder = $getOrder; 64 | $this->eventManager = $eventManager; 65 | } 66 | 67 | /** 68 | * Success page action 69 | * 70 | * @return Page 71 | * 72 | * @throws ForbiddenAccess 73 | * @throws InvalidOrderId 74 | */ 75 | public function execute() 76 | { 77 | if ($this->moduleConfig->enabled() === false) { 78 | throw new ForbiddenAccess('Module is disabled'); 79 | } 80 | 81 | if ($this->access->hasAccess() === false) { 82 | throw new ForbiddenAccess('Access denied for IP ' . $this->access->getCurrentIpAddress()); 83 | } 84 | 85 | $order = $this->getOrder->get(); 86 | 87 | if (!$order->getEntityId()) { 88 | throw new InvalidOrderId('Invalid order ID'); 89 | } 90 | 91 | /** @var Page $resultPage */ 92 | $resultPage = $this->resultPageFactory->create(); 93 | $resultPage->addHandle('checkouttester_index_index'); 94 | 95 | $this->registerOrder($order); 96 | 97 | return $resultPage; 98 | } 99 | 100 | /** 101 | * Method to register the order in this session 102 | * 103 | * @param OrderInterface $order 104 | */ 105 | protected function registerOrder(OrderInterface $order) 106 | { 107 | $currentOrder = $this->registry->registry('current_order'); 108 | if (empty($currentOrder)) { 109 | $this->registry->register('current_order', $order); 110 | } 111 | 112 | $this->checkoutSession->setLastOrderId($order->getEntityId()) 113 | ->setLastRealOrderId($order->getIncrementId()); 114 | 115 | $this->dispatchEvents($order); 116 | } 117 | 118 | /** 119 | * Method to optionally dispatch order-related events 120 | * 121 | * @param OrderInterface $order 122 | */ 123 | public function dispatchEvents(OrderInterface $order) 124 | { 125 | if (!$this->moduleConfig->allowDispatchCheckoutOnepageControllerSuccessAction()) { 126 | return; 127 | } 128 | 129 | $eventData = [ 130 | 'order_ids' => [$order->getEntityId()], 131 | 'order' => $order 132 | ]; 133 | $this->eventManager->dispatch('checkout_onepage_controller_success_action', $eventData); 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /Exception/ForbiddenAccess.php: -------------------------------------------------------------------------------- 1 | Configuration > Yireo > Yireo CheckoutTester** 17 | * Done 18 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Open Software License ("OSL") v. 3.0 2 | 3 | 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: 4 | 5 | Licensed under the Open Software License version 3.0 6 | 7 | 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: 8 | 9 | 1.1. to reproduce the Original Work in copies, either alone or as part of a collective work; 10 | 11 | 1.2. to translate, adapt, alter, transform, modify, or arrange the Original Work, thereby creating derivative works ("Derivative Works") based upon the Original Work; 12 | 13 | 1.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; 14 | 15 | 1.4. to perform the Original Work publicly; and 16 | 17 | 1.5. to display the Original Work publicly. 18 | 19 | 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. 20 | 21 | 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. 22 | 23 | 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. 24 | 25 | 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). 26 | 27 | 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. 28 | 29 | 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. 30 | 31 | 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. 32 | 33 | 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). 34 | 35 | 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. 36 | 37 | 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. 38 | 39 | 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. 40 | 41 | 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. 42 | 43 | 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. 44 | 45 | 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. 46 | 47 | 16. Modification of This License. This License is Copyright © 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. 48 | -------------------------------------------------------------------------------- /PWA.md: -------------------------------------------------------------------------------- 1 | # PWA compatibility 2 | This frontend extension will be completely replaced by React or Vue functionality, and therefore, this extension 3 | will not be made compatible with PWA. 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CheckoutTester module for Magento 2 2 | 3 | ## See also: 4 | - [Installation](INSTALL.md) 5 | - [Usage](USAGE.md) 6 | -------------------------------------------------------------------------------- /Test/Integration/BrowseTest.php: -------------------------------------------------------------------------------- 1 | expectException(ForbiddenAccess::class); 26 | $this->dispatch('/checkouttester/index/success'); 27 | } 28 | 29 | /** 30 | * @magentoConfigFixture current_store checkouttester2/settings/enabled 1 31 | * @magentoDataFixture Magento/Sales/_files/order.php 32 | */ 33 | public function testIfPageWorksByDefault() 34 | { 35 | $this->dispatch('/checkouttester/index/success'); 36 | $body = (string)$this->getResponse()->getBody(); 37 | $this->assertNotEmpty($body); 38 | $this->assertTrue((bool)strpos($body, 'Thank you for your purchase!')); 39 | } 40 | 41 | /** 42 | * @magentoConfigFixture current_store checkouttester2/settings/enabled 1 43 | */ 44 | public function testIfPageFailsWithoutValidOrder() 45 | { 46 | $this->expectException(InvalidOrderId::class); 47 | $this->dispatch('/checkouttester/index/success'); 48 | } 49 | 50 | /** 51 | * @magentoDataFixture Magento/Sales/_files/order.php 52 | * @magentoConfigFixture current_store checkouttester2/settings/enabled 1 53 | * @magentoConfigFixture current_store checkouttester2/settings/ip 1.1.1.1 54 | */ 55 | public function testIfPageFailsWithWrongIpSettings() 56 | { 57 | $this->expectException(ForbiddenAccess::class); 58 | $this->getRequest()->setServer(new Parameters(['HTTP_CLIENT_IP' => '1.1.1.2'])); 59 | $this->dispatch('/checkouttester/index/success'); 60 | } 61 | 62 | /** 63 | * @magentoDataFixture Magento/Sales/_files/order.php 64 | * @magentoConfigFixture current_store checkouttester2/settings/enabled 1 65 | * @magentoConfigFixture current_store checkouttester2/settings/ip 1.1.1.1 66 | */ 67 | public function testIfPageFailsWithCorrectIpSettings() 68 | { 69 | $this->getRequest()->setServer(new Parameters(['HTTP_CLIENT_IP' => '1.1.1.1'])); 70 | $this->dispatch('/checkouttester/index/success'); 71 | $body = (string)$this->getResponse()->getBody(); 72 | $this->assertNotEmpty($body); 73 | $this->assertTrue((bool)strpos($body, 'Thank you for your purchase!')); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /Test/Integration/ModuleConfigTest.php: -------------------------------------------------------------------------------- 1 | subjectModuleName = 'Yireo_CheckoutTester2'; 40 | $this->objectManager = ObjectManager::getInstance(); 41 | } 42 | 43 | /** 44 | * Test if the module is registered 45 | */ 46 | public function testModuleIsRegistered() 47 | { 48 | $registrar = new ComponentRegistrar(); 49 | $this->assertArrayHasKey($this->subjectModuleName, $registrar->getPaths(ComponentRegistrar::MODULE)); 50 | } 51 | 52 | public function testModuleIsListed() 53 | { 54 | /** @var $moduleList ModuleList */ 55 | $moduleList = $this->objectManager->create(ModuleList::class); 56 | $this->assertTrue($moduleList->has($this->subjectModuleName)); 57 | } 58 | 59 | public function testTheModuleIsConfiguredInTheRealEnvironment() 60 | { 61 | /** @var $objectManager ObjectManager */ 62 | $this->objectManager = ObjectManager::getInstance(); 63 | 64 | // The tests by default point to the wrong config directory for this test. 65 | $directoryList = $this->objectManager->create( 66 | DirectoryList::class, 67 | ['root' => '/'] 68 | ); 69 | 70 | $deploymentConfigReader = $this->objectManager->create( 71 | Reader::class, 72 | ['dirList' => $directoryList] 73 | ); 74 | 75 | $deploymentConfig = $this->objectManager->create( 76 | DeploymentConfig::class, 77 | ['reader' => $deploymentConfigReader] 78 | ); 79 | 80 | /** @var $moduleList ModuleList */ 81 | $moduleList = $this->objectManager->create( 82 | ModuleList::class, 83 | ['config' => $deploymentConfig] 84 | ); 85 | 86 | $this->assertTrue($moduleList->has($this->subjectModuleName)); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /Test/Unit/Config/ConfigTest.php: -------------------------------------------------------------------------------- 1 | setScopeConfigValue('checkouttester2/settings/enabled', 1); 33 | $target = $this->getTargetObject(); 34 | $this->assertSame(true, $target->enabled()); 35 | 36 | $this->setScopeConfigValue('checkouttester2/settings/enabled', 0); 37 | $target = $this->getTargetObject(); 38 | $this->assertSame(false, $target->enabled()); 39 | } 40 | 41 | /** 42 | * Test whether the URL returns some value 43 | */ 44 | public function testGetOrderIdFromConfig() 45 | { 46 | $this->setScopeConfigValue('checkouttester2/settings/order_id', '42'); 47 | $target = $this->getTargetObject(); 48 | $this->assertSame(42, $target->getOrderIdFromConfig()); 49 | $this->assertNotSame(41, $target->getOrderIdFromConfig()); 50 | } 51 | 52 | /** 53 | * Test whether the URL returns some value 54 | */ 55 | public function testAllowDispatchCheckoutOnepageControllerSuccessAction() 56 | { 57 | $this->setScopeConfigValue('checkouttester2/settings/checkout_onepage_controller_success_action', 1); 58 | $target = $this->getTargetObject(); 59 | $this->assertSame(true, $target->allowDispatchCheckoutOnepageControllerSuccessAction()); 60 | 61 | $this->setScopeConfigValue('checkouttester2/settings/checkout_onepage_controller_success_action', 0); 62 | $target = $this->getTargetObject(); 63 | $this->assertSame(false, $target->allowDispatchCheckoutOnepageControllerSuccessAction()); 64 | } 65 | 66 | /** 67 | * @return Target 68 | */ 69 | protected function getTargetObject() 70 | { 71 | $scopeConfig = $this->getScopeConfigMock(); 72 | $appState = $this->createMock(State::class); 73 | $target = new Target($scopeConfig, $appState); 74 | 75 | return $target; 76 | } 77 | 78 | /** 79 | * @return MockObject 80 | */ 81 | protected function getRequestMock() 82 | { 83 | $request = $this->createMock(Http::class); 84 | 85 | $request->expects($this->any()) 86 | ->method('getClientIp') 87 | ->willReturn('127.0.0.1'); 88 | 89 | return $request; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /Test/Unit/Mock/BlockContext/AppStateMock.php: -------------------------------------------------------------------------------- 1 | createMock(State::class); 23 | 24 | $mock->expects($this->any()) 25 | ->method('getAreaCode') 26 | ->willReturn('frontend'); 27 | 28 | return $mock; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Test/Unit/Mock/BlockContext/CacheMock.php: -------------------------------------------------------------------------------- 1 | createMock(CacheInterface::class); 23 | 24 | $mock->expects($this->any()) 25 | ->method('load') 26 | ->willReturn('some data'); 27 | 28 | return $mock; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Test/Unit/Mock/BlockContext/CacheStateMock.php: -------------------------------------------------------------------------------- 1 | createMock(StateInterface::class); 23 | 24 | $mock->expects($this->any()) 25 | ->method('isEnabled') 26 | ->willReturn(true); 27 | 28 | return $mock; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Test/Unit/Mock/BlockContext/FileResolverMock.php: -------------------------------------------------------------------------------- 1 | createMock(Resolver::class); 23 | 24 | $mock->expects($this->any()) 25 | ->method('getTemplateFileName') 26 | ->willReturn('dummy.phtml'); 27 | 28 | return $mock; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Test/Unit/Mock/BlockContext/SidResolverMock.php: -------------------------------------------------------------------------------- 1 | createMock(SidResolverInterface::class); 23 | 24 | $mock->expects($this->any()) 25 | ->method('getSessionIdQueryParam') 26 | ->willReturn(42); 27 | 28 | return $mock; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Test/Unit/Mock/BlockContextMock.php: -------------------------------------------------------------------------------- 1 | getTarget(); 48 | $target->setData('cache_lifetime', 42); 49 | $this->assertNotEmpty($target->toHtml()); 50 | 51 | $target = $this->getTarget(); 52 | $this->assertEmpty($target->toHtml()); 53 | } 54 | 55 | /** 56 | * 57 | */ 58 | public function testBlockOutputIfOutputDisabled() 59 | { 60 | $this->setScopeConfigValue('advanced/modules_disable_output/Yireo_CheckoutTester2', 1); 61 | $target = $this->getTarget(); 62 | $this->assertEmpty($target->toHtml()); 63 | } 64 | 65 | /** 66 | * @return TemplateContext|Context 67 | */ 68 | protected function getContextMock($area = 'frontend') 69 | { 70 | $contextClass = TemplateContext::class; 71 | if ($area == 'adminhtml') { 72 | $contextClass = Context::class; 73 | } 74 | 75 | $context = $this->createMock($contextClass); 76 | 77 | $scopeConfig = $this->getScopeConfigMock(); 78 | $context->expects($this->any()) 79 | ->method('getScopeConfig') 80 | ->will($this->returnValue($scopeConfig)); 81 | 82 | $eventManager = $this->getEventManagerMock(); 83 | $context->expects($this->any()) 84 | ->method('getEventManager') 85 | ->will($this->returnValue($eventManager)); 86 | 87 | $context->expects($this->any()) 88 | ->method('getCache') 89 | ->willReturn($this->getCacheMock()); 90 | 91 | $context->expects($this->any()) 92 | ->method('getCacheState') 93 | ->willReturn($this->getCacheStateMock()); 94 | 95 | $context->expects($this->any()) 96 | ->method('getStoreManager') 97 | ->willReturn($this->getStoreManagerMock()); 98 | 99 | $context->expects($this->any()) 100 | ->method('getAppState') 101 | ->willReturn($this->getAppStateMock()); 102 | 103 | $context->expects($this->any()) 104 | ->method('getSession') 105 | ->willReturn($this->getSessionMock()); 106 | 107 | $context->expects($this->any()) 108 | ->method('getResolver') 109 | ->willReturn($this->getResolverMock()); 110 | 111 | $context->expects($this->any()) 112 | ->method('getSidResolver') 113 | ->willReturn($this->getSidResolverMock()); 114 | 115 | $context->expects($this->any()) 116 | ->method('getUrlBuilder') 117 | ->willReturn($this->getUrlBuilderMock()); 118 | 119 | return $context; 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /Test/Unit/Mock/Generic/EventManagerMock.php: -------------------------------------------------------------------------------- 1 | createMock(ManagerInterface::class); 23 | 24 | return $eventManager; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Test/Unit/Mock/Generic/ScopeConfigMock.php: -------------------------------------------------------------------------------- 1 | createMock(ScopeConfigInterface::class); 28 | 29 | $scopeConfig->expects($this->any()) 30 | ->method('getValue') 31 | ->will($this->returnValueMap($this->getScopeConfigValues())); 32 | 33 | return $scopeConfig; 34 | } 35 | 36 | /** 37 | * @return array 38 | */ 39 | protected function getScopeConfigValues(): array 40 | { 41 | return array_values($this->scopeConfigValues); 42 | } 43 | 44 | /** 45 | * @param string $name 46 | * @param $value 47 | * @return void 48 | */ 49 | protected function setScopeConfigValue(string $name, $value): void 50 | { 51 | $scope = 'store'; 52 | $this->scopeConfigValues[$name] = [$name, $scope, null, $value]; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Test/Unit/Mock/Generic/SessionMock.php: -------------------------------------------------------------------------------- 1 | createMock(SessionManagerInterface::class); 23 | 24 | return $mock; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Test/Unit/Mock/Generic/StoreManagerMock.php: -------------------------------------------------------------------------------- 1 | createMock(StoreManagerInterface::class); 24 | 25 | $mock->expects($this->any()) 26 | ->method('getStore') 27 | ->willReturn($this->getStoreMock()); 28 | 29 | return $mock; 30 | } 31 | 32 | /** 33 | * @return StoreInterface 34 | */ 35 | protected function getStoreMock() 36 | { 37 | $mock = $this->createMock(StoreInterface::class); 38 | 39 | $mock->expects($this->any()) 40 | ->method('getCode') 41 | ->willReturn(42); 42 | 43 | return $mock; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Test/Unit/Mock/Generic/UrlBuilderMock.php: -------------------------------------------------------------------------------- 1 | createMock(UrlInterface::class); 24 | 25 | $mock->expects($this->any()) 26 | ->method('getUrl') 27 | ->willReturn('http://www.example.com/'); 28 | 29 | return $mock; 30 | } 31 | 32 | /** 33 | * @return Url 34 | */ 35 | protected function getUrlMock() 36 | { 37 | $mock = $this->createMock(Url::class); 38 | 39 | $mock->expects($this->any()) 40 | ->method('getUrl') 41 | ->willReturn('http://www.example.com/'); 42 | 43 | return $mock; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Test/Unit/Mock/HelperContextMock.php: -------------------------------------------------------------------------------- 1 | createMock(Context::class); 29 | $scopeConfig = $this->getScopeConfigMock(); 30 | $context->expects($this->any()) 31 | ->method('getScopeConfig') 32 | ->will($this->returnValue($scopeConfig)); 33 | 34 | return $context; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /USAGE.md: -------------------------------------------------------------------------------- 1 | # Usage 2 | When you customize Magento 2 to your needs, conversion is everything. So part of the customization process will definitely include the checkout process, including the success page that is visited once the checkout 3 | is completed. But when you refresh the success page, the session is cleaned up and you are redirected back to the cart. 4 | 5 | This extension is ment to solve this specific issue. Instead of hacking the Magento 2 core, you can install our Magento2 extension in a simple and clean manner, and preview the success-page at any time. You simply 6 | point your browser to the preview URL and voila, there's your success page: 7 | 8 | http://MAGENTO2/checkouttester/index/success 9 | 10 | You can also test a specific order with the following: 11 | 12 | http://MAGENTO2/checkouttester/index/success/order_id/1234 13 | 14 | ## Tip 15 | If you like this extension, make sure to view our EmailTester2 extension. We do not want to build a shop without it. 16 | -------------------------------------------------------------------------------- /Utility/Access.php: -------------------------------------------------------------------------------- 1 | config = $config; 19 | $this->request = $request; 20 | } 21 | 22 | /** 23 | * Method to determine whether the current user has access to this page 24 | * 25 | * @return bool 26 | */ 27 | public function hasAccess(): bool 28 | { 29 | $ip = trim($this->config->getIpAddress()); 30 | if (false === strlen($ip) > 0) { 31 | return true; 32 | } 33 | 34 | $realIp = $this->getCurrentIpAddress(); 35 | if (!$realIp) { 36 | return false; 37 | } 38 | 39 | $ips = explode(',', $ip); 40 | 41 | foreach ($ips as $ip) { 42 | $ip = trim($ip); 43 | 44 | if (empty($ip)) { 45 | continue; 46 | } 47 | 48 | if ($ip !== $realIp) { 49 | continue; 50 | } 51 | 52 | return true; 53 | } 54 | 55 | return false; 56 | } 57 | 58 | /** 59 | * Get the current IP address 60 | * 61 | * @return string 62 | */ 63 | public function getCurrentIpAddress(): string 64 | { 65 | /** @var Request $request */ 66 | $request = $this->request; 67 | $ip = (string)$request->getClientIp(); 68 | $forwarded = explode(', ', $ip); 69 | 70 | return ($forwarded ? $forwarded[0] : $ip); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /Utility/GetOrder.php: -------------------------------------------------------------------------------- 1 | request = $request; 31 | $this->config = $config; 32 | $this->orderFactory = $orderFactory; 33 | $this->orderRepository = $orderRepository; 34 | $this->searchCriteriaBuilder = $searchCriteriaBuilder; 35 | } 36 | 37 | /** 38 | * Method to fetch the current order 39 | * 40 | * @return OrderInterface 41 | */ 42 | public function get(): OrderInterface 43 | { 44 | $orderIdFromUrl = (int)$this->request->getParam('order_id'); 45 | $order = $this->getOrderById($orderIdFromUrl); 46 | if ($order->getEntityId()) { 47 | return $order; 48 | } 49 | 50 | $orderIdFromConfig = $this->config->getOrderIdFromConfig(); 51 | $order = $this->getOrderById($orderIdFromConfig); 52 | if ($order->getEntityId()) { 53 | return $order; 54 | } 55 | 56 | $lastOrderId = $this->getLastInsertedOrderId(); 57 | $order = $this->getOrderById($lastOrderId); 58 | 59 | if ($order->getEntityId()) { 60 | return $order; 61 | } 62 | 63 | return $this->getEmptyOrder(); 64 | } 65 | 66 | /** 67 | * Return the last order ID in this database 68 | * 69 | * @return int 70 | */ 71 | private function getLastInsertedOrderId() 72 | { 73 | $orders = $this->getOrderSearchResult(); 74 | if (false === $orders->getTotalCount() > 0) { 75 | return 0; 76 | } 77 | 78 | $orderItems = $orders->getItems(); 79 | if (count($orderItems) < 1) { 80 | return 0; 81 | } 82 | 83 | $firstOrder = array_shift($orderItems); 84 | if (false === $firstOrder instanceof OrderInterface) { 85 | return 0; 86 | } 87 | 88 | return (int)$firstOrder->getEntityId(); 89 | } 90 | 91 | /** 92 | * @return OrderInterface 93 | */ 94 | private function getEmptyOrder() 95 | { 96 | return $this->orderFactory->create(); 97 | } 98 | 99 | /** 100 | * @param $orderId 101 | * 102 | * @return OrderInterface 103 | */ 104 | private function getOrderById($orderId) 105 | { 106 | if (empty($orderId)) { 107 | return $this->getEmptyOrder(); 108 | } 109 | 110 | try { 111 | return $this->orderRepository->get($orderId); 112 | } catch (NoSuchEntityException $exception) { 113 | return $this->getEmptyOrder(); 114 | } 115 | } 116 | 117 | /** 118 | * @return OrderSearchResultInterface 119 | */ 120 | private function getOrderSearchResult(): OrderSearchResultInterface 121 | { 122 | $searchCriteriaBuilder = $this->searchCriteriaBuilder; 123 | $searchCriteriaBuilder->addSortOrder('created_at', AbstractCollection::SORT_ORDER_DESC); 124 | 125 | $searchCriteria = $searchCriteriaBuilder->create(); 126 | $searchCriteria->setPageSize(1); 127 | $searchCriteria->setCurrentPage(0); 128 | $searchCriteria->getSortOrders(); 129 | 130 | return $this->orderRepository->getList($searchCriteria); 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "yireo/magento2-checkouttester2", 3 | "license": "OSL-3.0", 4 | "version": "1.0.4", 5 | "type": "magento2-module", 6 | "homepage": "https://github.com/yireo/Yireo_CheckoutTester2", 7 | "description": "Checkout Tester for Magento 2", 8 | "keywords": [ 9 | "composer-installer", 10 | "magento" 11 | ], 12 | "authors": [ 13 | { 14 | "name": "Jisse Reitsma (Yireo)", 15 | "email": "jisse@yireo.com" 16 | } 17 | ], 18 | "require": { 19 | "magento/framework": "^102.0|^103.0", 20 | "magento/module-backend": "^100.1|^101.0|^102.0", 21 | "magento/module-checkout": "^100.1", 22 | "magento/module-config": "^100.1|^101.0", 23 | "magento/module-eav": "^100.1|^101.0|^102.0", 24 | "magento/module-sales": "^100.1|^101.0|^102.0|^103.0", 25 | "magento/module-store": "^100.1|^101.0", 26 | "php": ">=7.4.0" 27 | }, 28 | "require-dev": { 29 | "phpunit/phpunit": "*", 30 | "composer/composer": "*" 31 | }, 32 | "autoload": { 33 | "psr-4": { 34 | "Yireo\\CheckoutTester2\\": "" 35 | }, 36 | "files": [ 37 | "registration.php" 38 | ] 39 | }, 40 | "funding": [ 41 | { 42 | "type": "github", 43 | "url": "https://github.com/sponsors/jissereitsma" 44 | }, 45 | { 46 | "type": "github", 47 | "url": "https://github.com/sponsors/yireo" 48 | }, 49 | { 50 | "type": "paypal", 51 | "url": "https://www.paypal.me/yireo" 52 | }, 53 | { 54 | "type": "other", 55 | "url": "https://www.buymeacoffee.com/jissereitsma" 56 | } 57 | ] 58 | } 59 | -------------------------------------------------------------------------------- /etc/adminhtml/system.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | yireo 20 | Yireo_CheckoutTester2::config 21 | 22 | 23 | 24 | 25 | Yireo\CheckoutTester2\Config\Frontend\Funding 26 | 27 | 28 | 29 | Magento\Config\Model\Config\Source\Yesno 30 | 31 | 32 | 33 | Magento\Config\Model\Config\Source\Yesno 34 | 35 | 36 | 37 | 38 | 1 39 | 40 | 41 | 42 | 43 | 44 | 45 | 1 46 | 47 | 48 | 49 | 50 | 51 | 52 | 1 53 | 54 | 55 | Magento\Config\Model\Config\Source\Yesno 56 | 57 | 58 | 59 | 60 | 1 61 | 62 | Yireo\CheckoutTester2\Block\Field\Link 63 | 64 | 65 |
66 |
67 |
68 | -------------------------------------------------------------------------------- /etc/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | 15 | 16 | 1 17 | 1 18 | 0 19 | 20 | 0 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /etc/frontend/routes.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /etc/module.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /registration.php: -------------------------------------------------------------------------------- 1 | 3 |
4 | 10 |
11 |

Consider sponsoring this extension

12 |

13 | This extension is totally free. It takes time to develop and maintain though, all on a voluntary basis. 14 | If you are using this extension in a Magento shop that earns you money (either as an agency, as a developer 15 | or as a merchant), 16 | please consider sponsoring me and/or Yireo via GitHub. It would be appreciated and would help me to build 17 | even more cool things. 18 |

19 | 23 |
24 |
25 | 26 | 49 | -------------------------------------------------------------------------------- /view/frontend/layout/checkouttester_index_index.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | 15 | CheckoutTester Success Page 16 | 17 | 18 | 19 | 20 | 21 | --------------------------------------------------------------------------------