This repository has been archived by the owner on Jun 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
pat
committed
Aug 4, 2017
0 parents
commit ff63df8
Showing
9 changed files
with
959 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
<?php | ||
/** | ||
* Pmclain_SuccessTest extension | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the GPL v3 License | ||
* that is bundled with this package in the file LICENSE.txt. | ||
* It is also available through the world-wide-web at this URL: | ||
* https://www.gnu.org/licenses/gpl.txt | ||
* | ||
* @category Pmclain | ||
* @package Pmclain_SuccessTest | ||
* @copyright Copyright (c) 2017 | ||
* @license https://www.gnu.org/licenses/gpl.txt GPL v3 License | ||
*/ | ||
namespace Pmclain\SuccessTest\Plugin; | ||
|
||
use Magento\Framework\Event\ManagerInterface; | ||
use Magento\Framework\View\Result\PageFactory; | ||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Store\Model\ScopeInterface; | ||
use Magento\Checkout\Model\Session; | ||
use Magento\Sales\Model\OrderFactory; | ||
use Magento\Sales\Model\Order; | ||
|
||
class Success | ||
{ | ||
/** @var ManagerInterface */ | ||
protected $_eventManager; | ||
|
||
/** @var PageFactory */ | ||
protected $_resultPageFactory; | ||
|
||
/** @var ScopeConfigInterface */ | ||
protected $_scopeConfig; | ||
|
||
/** @var OrderFactory */ | ||
protected $_orderFactory; | ||
|
||
/** @var Order */ | ||
protected $_order; | ||
|
||
/** @var Session */ | ||
protected $_checkoutSession; | ||
|
||
/** | ||
* Success constructor. | ||
* @param ManagerInterface $eventManager | ||
* @param PageFactory $resultPageFactory | ||
* @param ScopeConfigInterface $scopeConfig | ||
* @param OrderFactory $orderFactory | ||
* @param Session $session | ||
*/ | ||
public function __construct( | ||
ManagerInterface $eventManager, | ||
PageFactory $resultPageFactory, | ||
ScopeConfigInterface $scopeConfig, | ||
OrderFactory $orderFactory, | ||
Session $session | ||
) { | ||
$this->_eventManager = $eventManager; | ||
$this->_resultPageFactory = $resultPageFactory; | ||
$this->_scopeConfig = $scopeConfig; | ||
$this->_orderFactory = $orderFactory; | ||
$this->_checkoutSession = $session; | ||
} | ||
|
||
/** | ||
* @param \Magento\Checkout\Controller\Onepage\Success $subject | ||
* @param $result | ||
* @return \Magento\Framework\View\Result\Page | ||
*/ | ||
public function afterExecute(\Magento\Checkout\Controller\Onepage\Success $subject, $result) | ||
{ | ||
if (!$this->_isEnabled()) { | ||
return $result; | ||
} | ||
|
||
$order = $this->_getTestOrder($subject->getRequest()->getParam('order')); | ||
|
||
if (!$order->getId()) { | ||
return $result; | ||
} | ||
|
||
$this->_checkoutSession->setLastRealOrderId($order->getIncrementId()); | ||
|
||
$resultPage = $this->_resultPageFactory->create(); | ||
|
||
$this->_eventManager->dispatch( | ||
'checkout_onepage_controller_success_action', | ||
['order_ids' => [$order->getId()]] | ||
); | ||
|
||
return $resultPage; | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
protected function _isEnabled() | ||
{ | ||
if ($this->_scopeConfig->getValue('dev/debug/success_test', ScopeInterface::SCOPE_STORE)) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* @param $incrementId string|bool | ||
* @return Order | ||
*/ | ||
protected function _getTestOrder($incrementId) | ||
{ | ||
/** @var Order $order */ | ||
$order = $this->_orderFactory->create(); | ||
|
||
$order->loadByIncrementId($incrementId); | ||
|
||
return $order; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Magento 2 Checkout Success Page Testing | ||
|
||
Test the checkout success page of your Magento 2 store without completing the | ||
checkout process. | ||
|
||
### Installation | ||
In your Magento 2 root directory run | ||
`composer require pmclain/magento2-successtest` | ||
`bin/magento setup:upgrade` | ||
|
||
### Configuration and Use | ||
After installation, enable via the Magento admin panel under: | ||
`Stores->Confirugation->Advanced->Developer->Debug->Enable Checkout Success Page Testing` | ||
You can now navigate to your success page with any increment id include as the | ||
query parameter `order`, ex http://mage2.dev/checkout/onepage/success/?order=000000008 | ||
|
||
### License | ||
GNU GENERAL PUBLIC LICENSE Version 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "pmclain/magento2-successtest", | ||
"description": "Magento 2 Checkout Success Page Testing", | ||
"type": "magento2-module", | ||
"license": [ | ||
"GPL-3.0" | ||
], | ||
"require": { | ||
"php": "~5.5.0|~5.6.0|~7.0.0|~7.1.0", | ||
"magento/module-checkout": "~100.0.0|~100.1.0|~100.2.0", | ||
"magento/module-backend": "~100.0.0|~100.1.0|~100.2.0" | ||
}, | ||
"autoload": { | ||
"files": [ | ||
"registration.php" | ||
], | ||
"psr-4": { | ||
"Pmclain\\SuccessTest\\": "" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
/** | ||
* Pmclain_SuccessTest extension | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the GPL v3 License | ||
* that is bundled with this package in the file LICENSE.txt. | ||
* It is also available through the world-wide-web at this URL: | ||
* https://www.gnu.org/licenses/gpl.txt | ||
* | ||
* @category Pmclain | ||
* @package Pmclain_SuccessTest | ||
* @copyright Copyright (c) 2017 | ||
* @license https://www.gnu.org/licenses/gpl.txt GPL v3 License | ||
*/ | ||
--> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd"> | ||
<system> | ||
<section id="dev"> | ||
<group id="debug"> | ||
<field id="success_test" translate="label" type="select" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="0"> | ||
<label>Enable Checkout Success Page Testing</label> | ||
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model> | ||
</field> | ||
</group> | ||
</section> | ||
</system> | ||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
/** | ||
* Pmclain_SuccessTest extension | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the GPL v3 License | ||
* that is bundled with this package in the file LICENSE.txt. | ||
* It is also available through the world-wide-web at this URL: | ||
* https://www.gnu.org/licenses/gpl.txt | ||
* | ||
* @category Pmclain | ||
* @package Pmclain_SuccessTest | ||
* @copyright Copyright (c) 2017 | ||
* @license https://www.gnu.org/licenses/gpl.txt GPL v3 License | ||
*/ | ||
--> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd"> | ||
<default> | ||
<dev> | ||
<debug> | ||
<success_test>0</success_test> | ||
</debug> | ||
</dev> | ||
</default> | ||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
/** | ||
* Pmclain_SuccessTest extension | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the GPL v3 License | ||
* that is bundled with this package in the file LICENSE.txt. | ||
* It is also available through the world-wide-web at this URL: | ||
* https://www.gnu.org/licenses/gpl.txt | ||
* | ||
* @category Pmclain | ||
* @package Pmclain_SuccessTest | ||
* @copyright Copyright (c) 2017 | ||
* @license https://www.gnu.org/licenses/gpl.txt GPL v3 License | ||
*/ | ||
--> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> | ||
<type name="Magento\Checkout\Controller\Onepage\Success"> | ||
<plugin name="pmclain_successtest_checkout_controller_onepage_success" | ||
type="Pmclain\SuccessTest\Plugin\Success" | ||
sortOrder="10" /> | ||
</type> | ||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
/** | ||
* Pmclain_SuccessTest extension | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the GPL v3 License | ||
* that is bundled with this package in the file LICENSE.txt. | ||
* It is also available through the world-wide-web at this URL: | ||
* https://www.gnu.org/licenses/gpl.txt | ||
* | ||
* @category Pmclain | ||
* @package Pmclain_SuccessTest | ||
* @copyright Copyright (c) 2017 | ||
* @license https://www.gnu.org/licenses/gpl.txt GPL v3 License | ||
*/ | ||
--> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> | ||
<module name="Pmclain_SuccessTest" setup_version="0.0.1"> | ||
<sequence> | ||
<module name="Magento_Backend" /> | ||
<module name="Magento_Checkout" /> | ||
</sequence> | ||
</module> | ||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
/** | ||
* Pmclain_SuccessTest extension | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the GPL v3 License | ||
* that is bundled with this package in the file LICENSE.txt. | ||
* It is also available through the world-wide-web at this URL: | ||
* https://www.gnu.org/licenses/gpl.txt | ||
* | ||
* @category Pmclain | ||
* @package Pmclain_SuccessTest | ||
* @copyright Copyright (c) 2017 | ||
* @license https://www.gnu.org/licenses/gpl.txt GPL v3 License | ||
*/ | ||
\Magento\Framework\Component\ComponentRegistrar::register( | ||
\Magento\Framework\Component\ComponentRegistrar::MODULE, | ||
'Pmclain_SuccessTest', | ||
__DIR__ | ||
); |