X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (X-Cart 5) (https://forum.x-cart.com/forumdisplay.php?f=56)
-   -   Problem with custom module (https://forum.x-cart.com/showthread.php?t=76885)

welly 03-22-2019 06:09 AM

Problem with custom module
 
Hi there

I am using the Loyalty Program module, and I am using a static page to describe how it works rather than the standard blurb.

The static page has it's own page heading, but if I use the '?target=loyalty_program_details' method reference the loyalty program, the page heading is hardcoded as 'Loyalty Program Details'. My page heading is ignored.

I thought the page heading might be a label, but it isn't. It seems to be defined in the file classes/XLite/Module/QSL/LoyaltyProgram/Controller/Customer/LoyaltyProgramDetails.php in the getTitle() function.

I can edit this file and change the heading, and I will do if I have to, but I think the correct method would be to create a custom module, and replace this function with my own version. Unfortunately, even though I am fairly sure I have done this correctly (I have created other simple modules which seem to work fine), I just can't get this one to do what I want.

So, I created my customer module with a copy of the LoyaltyProgramDetails.php file, which now contains the following:

-----------------------------
<?php

namespace XLite\Module\<mydevdir>\LoyaltyProgram\Module\QSL\ LoyaltyProgram\Controller\Customer;

/**
* Controller for the "Loyalty Program Details" page.
*/
abstract class LoyaltyProgramDetails extends \XLite\Controller\Customer\ACustomer implements \XLite\Base\IDecorator
{
/**
* Return the current page title (for the content area).
*
* @return string
*/
public function getTitle()
{
return 'Earn as you shop with our Loyalty Programme';
}
}
-----------------------------

The module is visible/available on the admin side and is switched on, and the differences between my version and the original are the namespace declaration, the class declaration (was 'class LoyaltyProgramDetails extends \XLite\Controller\Customer\ACustomer'), and the function's return line (was 'return 'Loyalty Program Details';'). I also removed the only other function, getLocation(), but not surprisingly it makes no difference whether it is in my php file or not.

My understanding is that the class declaration with 'implements \XLite\Base\IDecorator' means that I am replacing something in the class and not extending it, but for whatever reason, my changes aren't having any effect.

Is there anything I'm missing? Am I making a simple schoolboy error that I just can't see for looking?

I'm not sure how to go about diagnosing it or where to look to see what is going on, and although it isn't a major problem and I can edit the original file to achieve what I want, I feel that this is the right way to do it and that I must surely be close to getting it right!

I'm hoping it will be easy to put track down.

Many thanks

Welly

qualiteam 03-22-2019 12:45 PM

Re: Problem with custom module
 
I think you should extend XLite\Module\QSL\LoyaltyProgram\Controller\Custome r\LoyaltyProgramDetails class instead of XLite\Controller\Customer\ACustomer in your module.
I would try that out first.

welly 03-22-2019 02:33 PM

Re: Problem with custom module
 
Hi Alex

I think you are right, but I have changed my class line as follows, and it still doesn't work:

abstract class LoyaltyProgramDetails extends \XLite\Module\QSL\LoyaltyProgram\Controller\Custom er\LoyaltyProgramDetails implements \XLite\Base\IDecorator

Is that what you had in mind?

Many thanks for the suggestion.

Welly

tony_sologubov 03-25-2019 03:08 AM

Re: Problem with custom module
 
Hi @welly,

The problem is likely to be caused by wrong namespace.
Could you please let me know what namespace of your custom class?
And what path it is at?

Thanks.

Tony

welly 03-25-2019 05:47 AM

Re: Problem with custom module
 
Hi Tony

It seems that the problem was more simple than that.

As I was copying and pasting the relevant lines from the original and my version of the php file into this reply, I noticed that I had added a comment with the previous version of the class declaration in it. I assume I had not formatted it correctly because now I have removed it, the module works as intended.

Many thanks for your help.

Welly


All times are GMT -8. The time now is 12:16 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.