0

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
            ->create()
            ->addFieldToFilter('template_type', ['neq' => TemplateType::TYPE_PRODUCT])
            ->addFieldToFilter('template_type', ['neq' => TemplateType::TYPE_SECONDARY_ATTACHMENT])
            ->addFieldToFilter('is_active', ['eq' => TemplateActive::STATUS_ENABLED]);

        $templateCollection->addStoreFilter($order->getStoreId());

        

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

           

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

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


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


              else{

                $splitButtonOptions[] = [somevalue assignment]
                  
                ];

              }
            }
        }

My Plugin have below code

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

       die;
     //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.

2
  • You can use preference or around plugin? Aug 5 at 6:08
  • @AbdulSamadAbbasi , yes working with using around plugin.Thank you for your support.
    – akgola
    Aug 5 at 6:33
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.
1
  • yes it is working with around plugin.
    – akgola
    Aug 5 at 6:33

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.