From Magento 2 (http://devdocs.magento.com/guides/v2.1/extension-dev-guide/plugins.html)
Prioritizing plugins
The sortOrder property for plugins determine when their before, after, or around methods get called when several plugins are observing the same method.
The prioritization rules for ordering plugins:
Prior to execution of the observed method, plugins will be executed from lowest to greatest sortOrder.
During each plugin execution, the current plugin’s before method is executed first. After the before plugin is executed, the current plugin’s around method will wrap and execute the next plugin or observed method. Following the execution of the observed method, plugins will be executed from greatest to lowest sortOrder.
During each plugin execution, the current plugin will first finish executing its around method. When the around method is complete, the plugin executes its after method before moving on to the next plugin.
However, I want to stop / remove a process in a function of a third party / custom plugin. So I don't want it runs if a condition broken. It means I don't want the function can run in some situations. So how can I override that function to do that ?
I can create a plugin has a method with lower priority than the method, then it can be run earlier than the method. But as I understand, after my function runs then the function runs too. I can not stop it to run as Magento states.
More details about the function I want to override:
public function aroundSavePaymentInformation(
\Magento\Checkout\Model\GuestPaymentInformationManagement $subject,
\Closure $proceed,
$cartId,
$email,
\Magento\Quote\Api\Data\PaymentInterface $paymentMethod,
\Magento\Quote\Api\Data\AddressInterface $billingAddress = null
)
{
$orderAttributes = $billingAddress->getOrderAttributes(); => It will be fail if there is no $billingAddress, so I want to add a check to make sure if we have $billingAddress, then the process will be called, if not then return.
$this->sessionHelper->setOrderAttributesToSession($cartId, $orderAttributes);
return $proceed($cartId, $email, $paymentMethod, $billingAddress);
}
Please suggest some solutions that you may have, I am really appreciate it.