Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entering an invalid coupon code in the basket checkout page causes the "Checkout" button to disappear #218

Open
Physikbuddha opened this issue Oct 30, 2024 · 3 comments

Comments

@Physikbuddha
Copy link

Entering an invalid coupon code in the basket checkout page causes the "Checkout" button to disappear.

Before entering the code:
2024-10-30 13_54_29

After entering the code:
2024-10-30 13_56_10

This is because the template at aimeos/ai-client-html/templates/client/html/basket/standard/body.php performs an additional check about whether to show the button or not. To make the button appear, the view's property standardCheckout must be set to true:

2024-10-30 13_59_47

This property is set in aimeos/ai-client-html/src/Client/Html/Basket/Standard/Standard.php in line 141. However this line will never be reached if an invalid coupon code is entered, as like 108 will throw an exception in that case, so the control flow goes straight to line 146 in the catch block:

2024-10-30 14_01_37

@aimeos
Copy link
Owner

aimeos commented Oct 30, 2024

Maybe moving the "check" block to a finally block may solve that issue?

try
{
	switch( $view->param( 'b_action' ) )
	{
		case 'add':
			$this->addProducts( $view );
			break;
		case 'coupon-delete':
			$this->deleteCoupon( $view );
			break;
		case 'delete':
			$this->deleteProducts( $view );
			break;
		case 'save':
			$this->saveBasket( $view );
			break;
		default:
			$this->updateProducts( $view );
			$this->addCoupon( $view );
	}
}
catch( \Exception $e )
{
	$controller->save();
	throw $e;
}
finally
{
	$check = (int) $view->config( 'client/html/basket/standard/check', 1 );

	switch( $check )
	{
		case 2: if( $view->param( 'b_check', 0 ) == 0 ) { break; }
		case 1: $controller->get()->check( ['order/product'] );
		default: $view->standardCheckout = true;
	}
}

@Physikbuddha
Copy link
Author

In theory it should work, unless the code moved to finally can cause some exceptions as well. But these methods seem to be rather small and well-tested ($view->config(), $view->param()), so it looks like a feasible solution.

@aimeos
Copy link
Owner

aimeos commented Oct 30, 2024

The check() method throws an exception if the basket content isn't valid for checkout but then, the checkout button shouldn't be shown anyway. The change is now available in this commit: cf7fb21 (also available for 2024.10.x-dev)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants