I am trying to create after plugin for delete function of Magento\Tax\Model\TaxRuleRepository function looks like follows

public function delete(TaxRuleInterface $rule)
        $ruleId = $rule->getId();
        return true;

My afterDelete function look like:

public function afterDelete(
        \Magento\Tax\Model\TaxRuleRepository $subject,
        \Magento\Tax\Api\Data\TaxRuleInterface $rule
    ) { //my code }

Why it is throwing error Argument 1 passed to class_name::afterDelete() must implement interface Magento\Tax\Api\Data\TaxRuleInterface, instance of Magento\Tax\Model\TaxRuleRepository\Interceptor given

I have created the similar after plugin for save function and it is working fine as expected. Only difference between save and delete function that I can see is return type.

Save returns object whereas delete returns boolean.


1 Answer 1


You have created plugin of class


but you have to create plugin of


For example

<type name="Magento\Tax\Api\TaxRuleRepositoryInterface">
    <plugin name="some_name" type="Vendor\Module\Plugin\TaxRuleRepository" sortOrder="1"/>
  • I have changed TaxRuleRepository to TaxRuleRepositoryInterface and now the plugin is not being called. May 10, 2018 at 10:51
  • @AnshuMishra Have you change complete path like I have done Magento\Tax\Api\TaxRuleRepositoryInterface May 10, 2018 at 10:55
  • After changing to interface I amfacing issue Argument 2 passed to class_path::afterDelete() must implement interface Magento\Tax\Api\Data\TaxRuleInterface, boolean given, May 10, 2018 at 11:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.