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

Orders do not show valdation errors #580

Closed
Anubarak opened this issue Nov 22, 2018 · 3 comments
Closed

Orders do not show valdation errors #580

Anubarak opened this issue Nov 22, 2018 · 3 comments
Assignees
Labels

Comments

@Anubarak
Copy link

Description

Orders won't show validation errors in the CP because you don't grab the Element from route params but fetch them again from the DB thus validation errors won't be rendered. I made a custom field that needs to be filled in a certain way and while my errors are displayed in the fronend, nothing is shown in the CP. Are there any reasons why you don't show validation errors?

Steps to reproduce

  1. Create a field
  2. Add the field with certain validation rules in the layout to the Order
  3. produce an error and see nothing is shown

Steps to solve

Change the line here OrderController::actionEditOrder

from

public function actionEditOrder($orderId): Response

to

public function actionEditOrder($orderId, Order $order = null): Response
{
    $plugin = Plugin::getInstance();

    $variables = [
        'orderId' => $orderId,
        'order' => $order, <-- set the order from route variables
        'orderSettings' => $plugin->getOrderSettings()->getOrderSettingByHandle('order')
    ];

Then you need to fix the following bug as well in OrdersController line 454
Since these lines are never called (because there is no reason there is an error) they can't throw an exception.

if ($variables['order']->getErrors($field->getField()->handle)) {

must be

if ($variables['order']->getErrors($field->handle)) {
@lukeholder lukeholder added the bug label Nov 24, 2018
@lukeholder lukeholder added this to the 2.0 milestone Nov 26, 2018
@lukeholder lukeholder self-assigned this Nov 26, 2018
@lukeholder lukeholder removed this from the 2.0 milestone Nov 26, 2018
@lukeholder
Copy link
Member

Fixed for the next release. Thanks!

@Anubarak
Copy link
Author

Anubarak commented Jan 16, 2019

Can you re-open the issue please?
The error is in the latest version of Commerce 2 again https://github.com/craftcms/commerce/blob/master/src/controllers/OrdersController.php#L59

unless I made a mistace in my composer.json but I can't find a branch without the error

lukeholder added a commit that referenced this issue Jan 17, 2019
@lukeholder
Copy link
Member

Thanks, must have been a bad merge a while ago. Fixed again.

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

No branches or pull requests

2 participants