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.

asked Aug 4, 2021 at 12:22
2
  • 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. Commented Aug 5, 2021 at 6:33

1 Answer 1

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.
answered Aug 5, 2021 at 6:20
1
  • yes it is working with around plugin. Commented Aug 5, 2021 at 6:33

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.