Post by dynamoproductions » Mon May 22, 2017 10:47 pm

Hi, I am customizing a open cart installation, and I need to create a model with the method getPrice() for example

Code: Select all

class ModelCatalogProductGrid extends Model {
float getPrice( ... ) {}
and other models like

Code: Select all

class ModelCatalogProductVolantini extends ModelCatalogProductGrid   {
float getPrice( ... ) {}
where getPrice will override the function of ModelCatalogProductGrid. I tried but it seems Open Cart does not find/extends the Model ModelCatalogProductGrid, it gives me this error:

Fatal error: Class 'ModelCatalogProductGrid' not found in C:\www\ic-stampa\catalog\model\catalog\product_bigliettidavisita.php on line 2

Why it doesn't find it? How can i implement these kind of models and then use a Factory Design Pattern to instantiate the correct model?

thanks.

Image


User avatar

Posts

Joined
Thu Jun 19, 2014 5:14 pm


Post by artcore » Tue May 23, 2017 1:48 am

All model class files are included by calling the model loader. You can track this down by opening the startup.php and framework.php or for OC1+ just the index.php

For your situation you can just include the base class yourself on top, like

Code: Select all

require DIR_CATALOG . 'model/catalog/product_grid.php';
class ModelCatalogProductVolantini extends ModelCatalogProductGrid   {
float getPrice( ... ) {}
Or add your own autoloader. I use the latter to keep things dry :)
Cheers

Attn: I no longer provide OpenCart extensions, nor future support - this includes forum posts.
Reason: OpenCart version 3+ ;D

Thanks!


User avatar
Active Member

Posts

Joined
Tue Jul 09, 2013 4:13 am
Location - The Netherlands

User avatar
Guru Member

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by dynamoproductions » Wed May 24, 2017 11:50 pm

artcore wrote:
Tue May 23, 2017 1:48 am
All model class files are included by calling the model loader. You can track this down by opening the startup.php and framework.php or for OC1+ just the index.php

For your situation you can just include the base class yourself on top, like

Code: Select all

require DIR_CATALOG . 'model/catalog/product_grid.php';
class ModelCatalogProductVolantini extends ModelCatalogProductGrid   {
float getPrice( ... ) {}
Or add your own autoloader. I use the latter to keep things dry :)
Cheers
Thank you very much, is working! Now i can implement a design pattern and use formula to calculate prices, showing a grid!
https://www.awesomescreenshot.com/image ... 147c174f92

Image


User avatar

Posts

Joined
Thu Jun 19, 2014 5:14 pm


Post by artcore » Thu May 25, 2017 2:15 am

Looks nice! And you're welcome :)

Attn: I no longer provide OpenCart extensions, nor future support - this includes forum posts.
Reason: OpenCart version 3+ ;D

Thanks!


User avatar
Active Member

Posts

Joined
Tue Jul 09, 2013 4:13 am
Location - The Netherlands
Who is online

Users browsing this forum: No registered users and 25 guests