クラス
RedirectRouteGuards
ソース ソース
ファイル: src/Routing/RedirectRouteGuards.php
class RedirectRouteGuards
{
/**
* Amazon Pay module object
*
* @var AmazonPay
*/
private $module;
/**
* REST route guard instance for using methods with the same logic
*
* @var RestRouteGuards
*/
private $restRouteGuards;
/**
* Instantiates redirect route guards
*
* @author Evan D Shaw <evandanielshaw@gmail.com>
* @param AmazonPay $module
* @param RestRouteGuards $restRouteGuards
*/
public function __construct(AmazonPay $module, RestRouteGuards $restRouteGuards) {
$this->module = $module;
$this->restRouteGuards = $restRouteGuards;
}
/**
* Exits to home page if cart is empty
*
* @author Evan D Shaw <evandanielshaw@gmail.com>
* @return Closure&#Function#dcce1cbb
*/
public function cartNotEmptyOrExit() {
return function () {
$cartCheck = $this->restRouteGuards->cartNotEmptyCheck();
if (!empty($cartCheck())) {
header('location: ' . get_option('home'));
exit();
}
};
}
/**
* Exits to cart page if errors are returned by `zaiko_check()` method
*
* @author Evan D Shaw <evandanielshaw@gmail.com>
* @return Closure&#Function#dca610cf
*/
public function itemsInStockOrCartRedirect() {
return function () {
$stockCheck = $this->restRouteGuards->itemsInStockCheck();
if (!empty($stockCheck())) {
wp_safe_redirect(USCES_CART_URL);
exit;
}
};
}
/**
* Redirects to QuickPay page if customer page login was successful
*
* @author Evan D Shaw <evandanielshaw@gmail.com>
* @return Closure&#Function#dda597e7
*/
public function quickPayRedirectOnLoginSuccess() {
return function () {
global $usces;
$redirectUrl = isset($_REQUEST['wcexaapRedirect']) ? $_REQUEST['wcexaapRedirect'] : '';
if (isset($_POST['customerlogin']) && !empty($redirectUrl)) {
if ($usces->page === 'delivery') {
// Login succeeded. Redirect to QuickPay page
if (isset($_POST['allowAmazonLogin']) && !empty($_SESSION['usces_member']['ID'])) {
(new MemberMeta((int)$_SESSION['usces_member']['ID']))->updateAllowAmazonToWelcartLogin(true);
}
wp_safe_redirect($redirectUrl);
exit;
}
}
};
}
/**
* Redirects to customer login page for DLSeller items
*
* @author Evan D Shaw <evandanielshaw@gmail.com>
* @return Closure&#Function#da83ff64
*/
public function dlsellerLoginRedirect() {
return function () {
if (defined('WCEX_DLSELLER')) {
if (dlseller_have_dlseller_content() && !usces_is_login()) {
$reqkey = WordPressRequestKeyRouteCollector::ROUTE_KEY;
$currentRoute = isset($_REQUEST[$reqkey]) ? $_REQUEST[$reqkey] : '';
$sessionId = isset($_REQUEST['amazonCheckoutSessionId']) ? $_REQUEST['amazonCheckoutSessionId'] : '';
if (!empty($currentRoute) && !empty($sessionId)) {
$redirectAfterLoginUrl = add_query_arg(
[
$reqkey => rawurlencode($currentRoute),
'amazonCheckoutSessionId' => $sessionId,
],
USCES_CART_URL
);
$dlsellerRedirectUrl = $this->module->redirectRoutes->createPublicQueryUrl(
'/checkout/quickpay/dlsellerLogin',
USCES_CART_URL,
[
'wcexaapRedirect' => rawurlencode($redirectAfterLoginUrl),
]
);
wp_safe_redirect($dlsellerRedirectUrl);
exit();
}
}
}
};
}
/**
* Sets `addressError` in `$_SESSION` if address is not valid
*
* @author Evan D Shaw <evandanielshaw@gmail.com>
* @return Closure&#Function#ef4848a9
*/
public function addressCheck() {
return function () {
$_SESSION['amazonCheckoutSession']['addressError'] = '';
$addressCheck = $this->restRouteGuards->addressCheck();
$res = $addressCheck();
if ($res instanceof GenericError) {
if ($res->errorcode === GenericErrorStore::USCES_DELIVERY_PREF_INVALID) {
$_SESSION['amazonCheckoutSession']['addressError'] = __('The prefecture is not valid.', 'wcexaap');
}
if ($res->errorcode === GenericErrorStore::USCES_COUNTRY_NOT_TARGET_MARGET) {
$_SESSION['amazonCheckoutSession']['addressError'] = __(
'International shipping is unavailable for the country you selected.',
'wcexaap'
);
}
}
};
}
}
- __construct — Instantiates redirect route guards
- addressCheck — Sets `addressError` in `$_SESSION` if address is not valid
- cartNotEmptyOrExit — Exits to home page if cart is empty
- dlsellerLoginRedirect — Redirects to customer login page for DLSeller items
- itemsInStockOrCartRedirect — Exits to cart page if errors are returned by `zaiko_check()` method
- quickPayRedirectOnLoginSuccess — Redirects to QuickPay page if customer page login was successful