1

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();
        $this->resource->delete($rule);
        $this->taxRuleRegistry->removeTaxRule($ruleId);
        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.

0

You have created plugin of class

Magento\Tax\Model\TaxRuleRepository

but you have to create plugin of

Magento\Tax\Api\TaxRuleRepositoryInterface

For example

<type name="Magento\Tax\Api\TaxRuleRepositoryInterface">
    <plugin name="some_name" type="Vendor\Module\Plugin\TaxRuleRepository" sortOrder="1"/>
</type>
  • I have changed TaxRuleRepository to TaxRuleRepositoryInterface and now the plugin is not being called. – Anshu Mishra May 10 '18 at 10:51
  • @AnshuMishra Have you change complete path like I have done Magento\Tax\Api\TaxRuleRepositoryInterface – Murtuza Zabuawala May 10 '18 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, – Anshu Mishra May 10 '18 at 11:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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