Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use getClassForModelType to build the new surcharge instead of "new static()" #2397

Open
rhymeadam opened this issue Jan 10, 2023 · 4 comments

Comments

@rhymeadam
Copy link
Contributor

I was trying to create a custom "rule" surcharge that extends the one in isotope_rules. I registered my class as the "rule" model type in config.php but when this line runs on the front end, TypeAgent throws an exception in the constructor because it can't find Isotope\Model\ProductCollectionSurcharge\Rule in the static $arrModelTypes array. I believe this would be easily solved if the code at this line used getClassForModelType method to see what class is set as the "rule" model type first.

@aschempp
Copy link
Member

I don't think replacing the model class is a supported use case … what are you trying to do?

@rhymeadam
Copy link
Contributor Author

I wanted to extend the Isotope\Model\ProductCollectionSurcharge\Rule methods to implement my own logic for specific product classes. I figured changing line 60 to this would work, and most likely not break anything down the line, or am I mistaken?

        $strClass = static::getClassForModelType('rule');
        $objSurcharge = new $strClass();

@aschempp
Copy link
Member

It would probably be better to implement your own calculatePrice hook instead, since that's the supported "gateway".

@aschempp
Copy link
Member

just looking at this again, wouldn't this use your new class if yours is extending the Isotope rule class?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants