Drupal commerce, currency resolver, quickly change currency

If you are using currency resolver module in d8 you might need to change resolved currency quickly go to

namespace Drupal\commerce_currency_resolver;

and in getCurrency method, put 

$this->currency[$request] = "EUR";

for example, to get EUR currency in your checkout.

CheckoutController and formPage method, troubles with checkout flow

If you are having any problems with checkout flow (designing custom checkout flow or new payment gateway) check in 
Drupal\commerce_checkout\Controller;  and see formPage method, debug it and you can track what is step sent from URL, what is step set in order and do they match and adjust accordingly when needed.

Delete all user carts from particular user

If for some reason your commerce site gets stuck while in development with some bad data for user cart, to get rid of all the carts you can fire this code to delete all the carts for that user (probably admin or user 1)
 

Running A PHPUnit Test

There are different ways in which we can run our PHPUnit tests. We can either run a full unit test, a test suite or one specific test as shown in following commands:

To run all the tests available from the custom modules directory:

How to swap class for drupal 8 services

One of the reasons we are using services instead of plain classes is possibility to swap out class that each service uses.  So what we need to do is we need to create a new class that's overriding an existing service class, and then we need to alter the service container to use our new class.

Jquery once in drupal 8

Jquery is still standard part of drupal core and when using JavaScript or Ajax you will probably use Jquery and Jquery once function. Code can be found in core/assets/vendor/jquery-once/jquery.once.js  so you could look how it works. It is pretty similar as in D7, look at the comments on how to use it.

Swapping out classes in plugins

In drupal 8 plugins are everywhere, so to get most out of them you will sometimes want to alter them. If you look at definitions of each plugin manager, you will see that all of them have something specific in their constructors, it is the line below

When entity get returns array, do this

You are using get with fieldname and you are getting array as result, to get value as string, use getString() method like below

$entity->get("fieldName")->getString()