Skip to content
This repository has been archived by the owner on Jun 2, 2022. It is now read-only.

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
pat committed Aug 4, 2017
0 parents commit ff63df8
Show file tree
Hide file tree
Showing 9 changed files with 959 additions and 0 deletions.
674 changes: 674 additions & 0 deletions LICENSE.txt

Large diffs are not rendered by default.

122 changes: 122 additions & 0 deletions Plugin/Success.php
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;
}
}
18 changes: 18 additions & 0 deletions README.md
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
21 changes: 21 additions & 0 deletions composer.json
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\\": ""
}
}
}
29 changes: 29 additions & 0 deletions etc/adminhtml/system.xml
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>
26 changes: 26 additions & 0 deletions etc/config.xml
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>
24 changes: 24 additions & 0 deletions etc/frontend/di.xml
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>
25 changes: 25 additions & 0 deletions etc/module.xml
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>
20 changes: 20 additions & 0 deletions registration.php
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__
);

0 comments on commit ff63df8

Please sign in to comment.