2

I have added the custom attribute referral_code of type static to the customer entity. The attribute showing up correctly, and I can get/set it in easy way with $customer->getReferralCode() and with $customer->setReferralCode(value). But these methods, of course, don't really exist inside the Customer Model (I think that behind the scene there is some magic method). The problem is that in this way I don't have any hint/intellisense by IDE. The others developer, if they don't know the existence about the attribute,don't receive any suggestion by theirs IDE. So, it's "normal" that this happen or I can extend the Customer Base Model and add the get/set methods of my custom attributes? If it's possible to do this, what are the steps to reach it?

  • You have raised a good point. +1 for that – Shoaib Munir Mar 24 at 3:44
0

This is not the issue, you are doing it correctly, as you already know these are magic function and it has no definitions of their own. But you can add a description of these function on class-level in comment like this:

/**
 * @method static someClass setReferralCode(int $ref) Description here
 * @method static someClass getReferralCode() Description here
 */
abstract class a {
...

Description here

Reference: https://stackoverflow.com/questions/15634021/how-to-document-magic-call-and-callstatic-methods-for-ides

  • uhm so this is the best way? It's very "ugly" ahaha. Now another question is: where should I add that comment? Because the Customer model is inside the vendor magento/module-customer, so I can't edit it. If I have a Block class and I need to call the method getReferralCode() I must specify that comment inside my Block class? I have tried it, but it doesn't work (I'm using PHPStorm as IDE). – Mirko Rapisarda Mar 24 at 6:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.