Skip to content

Commit

Permalink
OXDEV-9101 Add more refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
liulka-oxid committed Jan 24, 2025
1 parent 5cfb82c commit dd495a1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 36 deletions.
65 changes: 34 additions & 31 deletions source/Application/Controller/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,50 +128,53 @@ public function init()
}

/**
* Executes parent::render(), if basket is empty - redirects to main page
* and exits the script (\OxidEsales\Eshop\Application\Model\Order::validateOrder()). Loads and passes payment
* info to template engine. Refreshes basket articles info by additionally loading
* each article object (\OxidEsales\Eshop\Application\Model\Order::getProdFromBasket()), adds customer
* addressing/delivering data (\OxidEsales\Eshop\Application\Model\Order::getDelAddressInfo()) and delivery sets
* info (\OxidEsales\Eshop\Application\Model\Order::getShipping()).
*
* @return string Returns name of template to render order::_sThisTemplate
* @inheritdoc
*/
public function render()
{
$session = Registry::getSession();
if ($this->getIsOrderStep()) {
$oBasket = $this->getBasket();
$myConfig = Registry::getConfig();

if ($myConfig->getConfigParam('blPsBasketReservationEnabled')) {
$session->getBasketReservations()->renewExpiration();
if (!$oBasket || ($oBasket && !$oBasket->getProductsCount())) {
Registry::getUtils()->redirect($myConfig->getShopHomeUrl() . 'cl=basket', true, 302);
$basket = $this->getBasket();
if (Registry::getConfig()->getConfigParam('blPsBasketReservationEnabled')) {
Registry::getSession()->getBasketReservations()->renewExpiration();
if (!$basket || !$basket->getProductsCount()) {
Registry::getUtils()->redirect(
Registry::getConfig()->getShopHomeUrl() . 'cl=basket',
true,
302
);
}
}

// can we proceed with ordering ?
$oUser = $this->getUser();
if (!$oUser && ($oBasket && $oBasket->getProductsCount() > 0)) {
Registry::getUtils()->redirect($myConfig->getShopHomeUrl() . 'cl=basket', false, 302);
} elseif (!$oBasket || !$oUser || ($oBasket && !$oBasket->getProductsCount())) {
Registry::getUtils()->redirect($myConfig->getShopHomeUrl(), false, 302);
$user = $this->getUser();
if (!$user && ($basket && $basket->getProductsCount())) {
Registry::getUtils()->redirect(
Registry::getConfig()->getShopHomeUrl() . 'cl=basket',
false,
302
);
} elseif (!$user || !$basket || !$basket->getProductsCount()) {
Registry::getUtils()->redirect(
Registry::getConfig()->getShopHomeUrl(),
false,
302
);
}

// payment is set ?
if (!$this->getPayment()) {
// redirecting to payment step on error ..
Registry::getUtils()->redirect($myConfig->getShopCurrentURL() . '&cl=payment', true, 302);
Registry::getUtils()->redirect(
Registry::getConfig()->getShopCurrentURL() . '&cl=payment',
true,
302
);
}
}

$this->_aViewData['basketSummaryHash'] = $this->getBasketSummaryHash();

parent::render();

// reload blocker
if (!$session->getVariable('sess_challenge')) {
$session->setVariable('sess_challenge', $this->getUtilsObjectInstance()->generateUID());
if (!Registry::getSession()->getVariable('sess_challenge')) {
Registry::getSession()->setVariable(
'sess_challenge',
$this->getUtilsObjectInstance()->generateUID()
);
}

return $this->_sThisTemplate;
Expand Down
18 changes: 13 additions & 5 deletions tests/Integration/Application/Controller/OrderControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,23 @@ public function testExecuteWithWrongBasketSummaryHashParameterAndNonEmptyBasketW
$this->assertNotEmpty($_SESSION['Errors']);
}

public function testRenderWillSetSessChallengeIfNotAlreadySet(): void
public function testRenderWillSetSessionChallenge(): void
{
$this->basket->method('getProductsCount')->willReturn(1);
$orderController = oxNew(OrderController::class);
$orderController->setIsOrderStep(false);

$orderController = $this->createPartialMock(OrderController::class, ['getPayment']);
$orderController->method('getPayment')->willReturn(true);
$result = $orderController->render();
$orderController->render();

$this->assertNotEmpty($_SESSION['sess_challenge']);
}

public function testRenderWillReturnTemplate(): void
{
$orderController = oxNew(OrderController::class);
$orderController->setIsOrderStep(false);

$result = $orderController->render();

$this->assertEquals('page/checkout/order', $result);
}

Expand Down

0 comments on commit dd495a1

Please sign in to comment.