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.
-
You can use preference or around plugin?Abdul Samad Abbasi– Abdul Samad Abbasi2021年08月05日 06:08:12 +00:00Commented Aug 5, 2021 at 6:08
-
@AbdulSamadAbbasi , yes working with using around plugin.Thank you for your support.akgola– akgola2021年08月05日 06:33:42 +00:00Commented Aug 5, 2021 at 6:33
1 Answer 1
According to your requirement you have the following options.
- Use
Around Pluginto modify that things. - Use
PreferenceConcept to override the class and modify that one.
-
yes it is working with around plugin.akgola– akgola2021年08月05日 06:33:02 +00:00Commented Aug 5, 2021 at 6:33