Add own JavaScript function to AimeosCatalogDetail.init()

Questions around the TYPO3 integration and plugins
Forum rules
Always add your TYPO3, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Moritz
Advanced
Posts: 153
Joined: 07 Nov 2018, 14:05

Add own JavaScript function to AimeosCatalogDetail.init()

Post by Moritz » 30 Nov 2018, 15:44

Hi,
I've added a JavaScript file via TypoScript.
Now I want to call my own function additionally to the init() function in AimeosCatalogDetail.
For that I read your documentation here: https://aimeos.org/docs/Developers/Them ... ing_themes and copy your example:

Code: Select all

    AimeosCatalogDetail.init = (function(fcn) {
        var self = this;
        return function() {
            fcn();
            self.setupYourMethod();
        }
    })(AimeosCatalogDetail.init);
That doesn't work. My debugger displays following error message: "TypeError: this.setupServiceSlider is not a function".
I think because of the decorator pattern the keyword "this" in AimeosCatalogDetail.init() has now a wrong context.
Can you help me with a working example please?
Ubuntu 22.04.01
PHP 7.4.30
Typo3 v11.5.21 LTS
Aimeos web shop 22.10.4-pre3

User avatar
aimeos
Administrator
Posts: 7836
Joined: 01 Jan 1970, 00:00

Re: Add own JavaScript function to AimeosCatalogDetail.init(

Post by aimeos » 03 Dec 2018, 09:16

Can you post your code?
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Moritz
Advanced
Posts: 153
Joined: 07 Nov 2018, 14:05

Re: Add own JavaScript function to AimeosCatalogDetail.init(

Post by Moritz » 03 Dec 2018, 10:03

I only have the following code from your documentation:
js.png
js.png (8.81 KiB) Viewed 2217 times
And I get this error message:
exception.png
exception.png (55.88 KiB) Viewed 2217 times
Ubuntu 22.04.01
PHP 7.4.30
Typo3 v11.5.21 LTS
Aimeos web shop 22.10.4-pre3

User avatar
aimeos
Administrator
Posts: 7836
Joined: 01 Jan 1970, 00:00

Re: Add own JavaScript function to AimeosCatalogDetail.init(

Post by aimeos » 03 Dec 2018, 12:59

Did you add the JS code after the aimeos-detail.js file is loaded?
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Moritz
Advanced
Posts: 153
Joined: 07 Nov 2018, 14:05

Re: Add own JavaScript function to AimeosCatalogDetail.init(

Post by Moritz » 03 Dec 2018, 13:33

Yes, my JS file is the last line inside my <body> Tag.
Ubuntu 22.04.01
PHP 7.4.30
Typo3 v11.5.21 LTS
Aimeos web shop 22.10.4-pre3

User avatar
aimeos
Administrator
Posts: 7836
Joined: 01 Jan 1970, 00:00

Re: Add own JavaScript function to AimeosCatalogDetail.init(

Post by aimeos » 04 Dec 2018, 15:23

This does work properly and the docs have been adapted:

Code: Select all

	AimeosCatalogDetail.setupYourMethod = function() {
		console.log( 'test' );
	};

    AimeosCatalogDetail.init = (function(obj) {
		init = AimeosCatalogDetail.init.bind(obj);
		return function() {
			obj.setupYourMethod();
			init();
		};
    })(AimeosCatalogDetail);
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Moritz
Advanced
Posts: 153
Joined: 07 Nov 2018, 14:05

Re: Add own JavaScript function to AimeosCatalogDetail.init(

Post by Moritz » 04 Dec 2018, 17:00

Thank you for this example and your help!

I've found another solution as well:

Code: Select all

setupYourMethod = function() {
    console.log( 'test' );
};

AimeosCatalogDetail.init = (function(fcn) {
    var self = this;
    return function() {
        fcn.call(AimeosCatalogDetail);
        self.setupYourMethod();
    }
})(AimeosCatalogDetail.init);
With .call(AimeosCatalogDetail) I set the context correctly back to AimeosCatalogDetail.
Ubuntu 22.04.01
PHP 7.4.30
Typo3 v11.5.21 LTS
Aimeos web shop 22.10.4-pre3

Post Reply