before listeners are used when we want to change the arguments of an original method or add some behavior before an original method is called.
Looking back at the
beforeGetAddToCartUrl listener method definition, you will see that it has three properties assigned in sequence—
before method listener, the first property is always the
$subject property, which contains the instance of the object type being observed. Properties following the
$subject property match the properties of the observed
getAddToCartUrl method in a sequential order.
This simple rule used for transformation is as follows:
getAddToCartUrl($product, $additional = ) beforeGetAddToCartUrl($subject, $product, ...