Problem/Motivation

In the shipping information pane, we display the available rates.
When no rates are available for the chosen address, there is a text displayed.
This text "There are no shipping rates available for this address." is not overridable easily (without overriding the whole plugin).

Proposed resolution

Use a theme function for rendering this text, so themes can easily override it and style it.

Remaining tasks

Define a theme function, a template, replace the markup with the proper render array.

User interface changes

None

API changes

None

Data model changes

None

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Renrhaf created an issue. See original summary.

renrhaf’s picture

Title: Use a theme function for rendering "there is not shipping rate" » Use a theme function for rendering "there is no shipping rate"

renrhaf’s picture

Assigned: renrhaf » Unassigned
Status: Active » Needs review
anybody’s picture

Great! We should combine this with #3473333: Improve "no shipping rates" message. in one of both issues, I think.

I think instead of the <p> we should use a <div> with a dedicated and a general (warning / error) class.

Furthermore, we should decide for one of both issues to also discuss the other points mentioned over there in #3473333: Improve "no shipping rates" message..

This is the older issue, but due to the discussion and other points over there, I'd suggest to move the solution from here over and close this issue!

Please don't forget crediting @renrhaf!

grevil’s picture

Status: Needs review » Needs work

From the other issue:

Thanks @Grevil, I agree that this is currently a bit confusing. Would be even better to also adjust the Drupal form message (empty required field) if no shipping method matches.

Maybe we should even allow defining a configurable fallback message for that case as a setting, so that shop owners can explain the potential reasons in this case instead of a hard-coded message?

Let's wait for Centarro feedback on that.

Regarding the class: I think it would make sense to add a context class like you did, and also add a Drupal error or warning message class to show the message appropriately by default.

I'm unsure if such a class exists, or if that means we'd have to use something like the message's markup?

@jsacksick what are your thoughts here?

grevil’s picture

I'd rather fix the issue here.

grevil changed the visibility of the branch 8.x-2.x to hidden.

grevil’s picture

Status: Needs work » Needs review

Done. Please review!

grevil’s picture

StatusFileSize
new31.31 KB

Thanks, @Anybody! I used a bad example to implement the attributes. LGTM now!
screenshot

<div class="commerce-shipping-no-shipping-rates" data-drupal-selector="edit-shipping-information-shipments-0-shipping-method-0">
  Es sind keine Versandkosten für diese Adresse verfügbar.
</div>
anybody’s picture

Status: Needs review » Reviewed & tested by the community

@grevil thanks! Could you provide a before / after screenshot perhaps?

Code-wise I think this is helpful and a lot more flexible than before! RTBC from my side. For further discussion:

It would be great to add a warning class, but I think also Olivero has no warning-styles outside of messages and I don't think it would be correct to add message markup here?
It would be a wrapper with
.messages.messages--error / --warning / --status / --info

Another thing I thought about is, if it might be helpful for any case to pass the $shipment variable to the twig file?

Let's wait for maintainer feedback on this in general and these points.

grevil’s picture

grevil’s picture

grevil’s picture

Status: Reviewed & tested by the community » Needs review

Added the shipment entity to the theme, might make sense to get the title of the shipment or something along those lines.

anybody’s picture

Status: Needs review » Reviewed & tested by the community

Nice and thank you for the before / after screenshots! RTBC

jsacksick’s picture

hm... I don't really see any difference between the before / after? Are we supposed to see any?

grevil’s picture

hm... I don't really see any difference between the before / after? Are we supposed to see any?

No not really! But it's easily overridable now. :)

jsacksick’s picture

Not really RTBC, there are phpcs failures, tests are failing too with D11, but I don't think the failures are related.

anybody’s picture

Status: Reviewed & tested by the community » Needs work

As of #19, thanks for the feedback. PHPCS also seem unrelated in large parts, but we'll check that...

grevil’s picture

Current changes don't contain anything that would violate the Drupal coding standards, the phpunit test seems very unrelated as well. I bet, if we rerun the pipeline on the current dev build, we get the same errors.

grevil’s picture

Status: Needs work » Reviewed & tested by the community

Yep, simply adding another hashtag in the .gitlab-ci.yml will result in the same pipeline failures (see MR !50). The pipeline in 8.x-2.x will have the same errors if rebuilt.

Setting back to RTBC, as the failures are unrelated.

jsacksick’s picture

Shouldn't we have a class name consistent with the theme function? (i.e. commerce-shipping-rates-empty?)

grevil’s picture

Sure! Adjusted accordingly.

  • jsacksick committed 53d1da3a on 8.x-2.x authored by grevil
    Issue #3465474: Use a theme function for rendering the no shipping rates...
jsacksick’s picture

Status: Reviewed & tested by the community » Fixed
grevil’s picture

Thanks, @jsacksick! 🎉

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.