Skip to content

Commit

Permalink
Add extra config and allow cart and checkout routes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sophie Shanahan-Kluth committed Jun 23, 2020
1 parent 4fb160f commit c65864c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function getConfigValue()
return [
'show_frontend_as' => $this->scopeConfig->getValue('admin/disable_frontend/show_frontend_as', ScopeInterface::SCOPE_WEBSITE),
'redirect_to' => $this->scopeConfig->getValue('admin/disable_frontend/redirect_to', ScopeInterface::SCOPE_WEBSITE),
'allow_checkout' => $this->scopeConfig->getValue('admin/disable_frontend/allow_checkout', ScopeInterface::SCOPE_WEBSITE),
];
}

Expand Down
15 changes: 9 additions & 6 deletions Observer/DisableFrontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,19 @@ public function __construct(
*/
public function execute(Observer $observer)
{
$controller = $observer->getControllerAction();
$destination = $controller->getResponse();
$configValues = $this->disableFrontendHelper->getConfigValue();

// Allow requests to the cart to get through.
$request = $observer->getRequest();
if ($request->getRouteName() === 'cart') {
return;
if ($configValues['allow_checkout']) {
// Allow requests to the cart and checkout to get through.
$request = $observer->getRequest();
if ($request->getRouteName() == 'cart' || $request->getRouteName() == 'checkout') {
return;
}
}

$controller = $observer->getControllerAction();
$destination = $controller->getResponse();

// Shows a blank page if all else fails.
$this->_actionFlag->set('', Action::FLAG_NO_DISPATCH, true);

Expand Down
3 changes: 3 additions & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
<label>Redirect to</label>
<validate>validate-url</validate>
</field>
<field id="allow_checkout" translate="label" type="checkbox" sortOrder="3" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Allow checkout routes</label>
</field>
</group>
</section>
</system>
Expand Down

0 comments on commit c65864c

Please sign in to comment.