Created
August 23, 2019 07:39
-
-
Save cgi-caesar/139090350757273d3cd687110db466a6 to your computer and use it in GitHub Desktop.
aMember (site.php): User friendly error message display in case of there is no product to purchase
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
<?php | |
Am_Di::getInstance()->hook->add(Am_Event::AFTER_RENDER, function(Am_Event_AfterRender $e) { | |
if (defined('AM_ADMIN') && AM_ADMIN) return; | |
if ( | |
stripos($e->getOutput(), 'There are no products available for purchase. Please come back later') !== false | |
&& $e->getDi()->request->getControllerName() == 'signup' | |
) { | |
$url = $e->getDi()->url('no-product', ['c' => $e->getDi()->request->getParam('c')], false); | |
header("Location: {$url}"); | |
exit; | |
} | |
}); | |
class NoProductController extends Am_Mvc_Controller | |
{ | |
function indexAction() | |
{ | |
$r = $this->loadForm(); | |
if ($_ = $this->getDi()->navigationUser->findOneById('add-renew-' . ($this->getFiltered('c') ?: 'default'))) { | |
$_->setActive(true); | |
} | |
$v = $this->view; | |
$v->title = $r->title; | |
$v->content = <<<CUT | |
<div style="color:red">There are no products available for purchase. Please come back later</div> | |
CUT; | |
$v->display('member/layout.phtml'); | |
} | |
function loadForm() | |
{ | |
if ($c = $this->getFiltered('c')) { | |
$record = $this->getDi()->savedFormTable->findFirstBy(['code' => $c, 'type' => SavedForm::T_SIGNUP]); | |
} else { | |
$record = $this->getDi()->savedFormTable->getDefault($this->getDi()->auth->getUserId() ? SavedForm::D_MEMBER : SavedForm::D_SIGNUP); | |
} | |
$record = $this->getDi()->hook->filter($record, Am_Event::LOAD_SIGNUP_FORM, [ | |
'request' => $this->getRequest(), | |
'user' => $this->getDi()->auth->getUser(), | |
]); | |
return $record; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment