I am using third party module for print pdf and now I want to customize the one function with using plugin, currently I am using after plugin and able to print the result of original function in my custom module.

Problem is in original method there is one of foreach loop and final result is based on that loop so how is possible to change the result as per foreach and if else condition.

below is Original Method code:

public function getOptions()
        $order = $this->getOrder();
        $splitButtonOptions = [];

        $templateCollection = $this->collectionFactory
            ->addFieldToFilter('template_type', ['neq' => TemplateType::TYPE_PRODUCT])
            ->addFieldToFilter('template_type', ['neq' => TemplateType::TYPE_SECONDARY_ATTACHMENT])
            ->addFieldToFilter('is_active', ['eq' => TemplateActive::STATUS_ENABLED]);



            there are some more condition but I need to update below code in my override function


            foreach ($templateCollection as $template) {
                if ($templateType !== $template->getTemplateType()) {

                $label =  $templateTypeName . ': ' . $template->getTemplateName();
                if ($templateCount === 1) {
                    $label = $templateTypeName;
                $templateId = $template->getTemplateId();

               if($label=="some value") 
                $splitButtonOptions[] = [some value assignment];


                $splitButtonOptions[] = [somevalue assignment]


My Plugin have below code

public function afterGetOptions(\Vendorname\Modulename\Block\Adminhtml\Sales\Order\PrintPdf $subject,$templateCollection)
        echo "<pre/>";

     //I want here check some conditions and then return the final updated array.
        //return $splitButtonOptions;

Is there any way to change login with foreach loop in my after plugin.

  • You can use preference or around plugin? Commented Aug 5, 2021 at 6:08
  • @AbdulSamadAbbasi , yes working with using around plugin.Thank you for your support.
    – akgola
    Commented Aug 5, 2021 at 6:33

1 Answer 1


According to your requirement you have the following options.

  1. Use Around Plugin to modify that things.
  2. Use Preference Concept to override the class and modify that one.
  • yes it is working with around plugin.
    – akgola
    Commented Aug 5, 2021 at 6:33

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.