How can we override component function

Hy,

How can we override a public component function ?

Thanks

Hi @ridha82,

You can override a public function by redefining it in the PHP section of the page:

Another option is to override the component’s partials (Pages - October CMS - 3.x) and use your own AJAX handler:
Building CMS Components - October CMS - 3.x

Here’s more info about the page execution life cycle:

Hy,

Thanks, but what i want to override is not an ajax function, but a function used in the component

public function getPageOptions()
    {
        return [
            'orders'    => trans('offline.mall::lang.components.myAccount.pages.orders'),
            'profile'   => trans('offline.mall::lang.components.myAccount.pages.profile'),
            'addresses' => trans('offline.mall::lang.components.myAccount.pages.addresses'),
        ];
    }

When i try to override it in the PHP section of the page, it not work.

Thanks

Hi @ridha82,

You could create an extension component.

<?php namespace Author\Plugin\Components;

use OFFLINE\Mall\Components\MyAccount;

class MyAccountExtension extends MyAccount
{
    public function getPageOptions()
    {
        $original = parent::getPageOptions();
        // Add your custom options
        $original['wishlist'] = 'Wishlist';
        $original['downloads'] = 'Downloads';
        
        return $original;
    }
}

Register it in your Plugin.php file and then use [myAccountExtension] instead of [myAccount] in your page.

Thanks, i will do that