Extending Existing Core Classes and Models

Hi experts,

I am new to Shopware development and I have developed some minor internal projects. But I have been facing problem when it comes to extending some class or models. I am also an OXID developer and honestly I find OXID achitecture much more simpler than Shopware architecture. OXID allows extending of any classes even Core classes with a simple syntax. I tried to implement the same logic in shopware when I planned to create the same module for Shopware. But unfortunately I haven’t found any proper solution.

Let me give an example:

I added some new columns to articles table and I want to now set functions for them like setValue or getValue in modelEntity. Or I want to write new function in article Repository. But I have no idea how to do that. The examples I find on Shopware Community are not that much helpful. No idea on how to use events or Hooks for this. As a result I had to create separate model, repository for my functionality. Another think I can think of is using Doctrine ORM Relations to combine to tables.

Another example: I know how dispatch and hooks works, but compared to hooks dispatch method completely useless. I mean if I want to change something in the middle of an event_controller or action e.g. getListAction, how can I do that? Hooks does allows it, but all classes are not hookable right? Same goes for the Bundle classes, I wanted to add just one line of condition to make it work as per my requirement. But I could not find any way. 

Please please please, help me get more information on development process. I have more similar doubts but one at a time will be better.

Appreciate your feedback :slight_smile:

BR

Hi,

always happy to help. As there are some general questions, its hard to point out a single document, that will answer all your questions. Regarding the database schema extension: http://community.shopware.com/_detail_1441.html

We do not extending the schema of existing tables directly. For those cases, we usually have the *_attributes table, which we generate the Models for automatically. So if you want to add a “shoe size” to the users, you can create that column in the “s_user_attribute” table and the rest will work out of the box (see the link above for details). This, however, will only work for TO_ONE relations. If you have more complex relations, you wil need to create custom tables / models and work with those. It could be more convenient - but it does the job pretty well.

Regarding what to use when: We have “hooks” for some generic cases, special application events (like “do you want to allow to purchase this product”) and framework events like “after a page was rendered” / PostDispatch. See Shopware events for more details. In addition to that, we heavily encourage using decorators where services and interfaces are available. We tried to document the process of “finding” a good extension point here Shopware events and here: Best practices of Shopware plugin development

Ok, I hope I could help you a little - don’t hesitate to create new topics for specific problems.

Daniel

 

 

 

1 „Gefällt mir“

Thanks Daniel,

Since you brought up attribute part, I had similar case where I had to add additional columns for s_blog_attributes, but its not accesible as you mentioned before. I checked and found that the maximum attributes handled in some cases are 6. Only article has dynamic attributes feature.

Or am I missing something?

-Ahad-

Hi,

check the „createAttributes“ method in this example: http://community.shopware.com/_detail_1441.html?_ga=1.103929088.1619813372.1429258252#Bootstrap

It works for all attributes-Tables, so you can *add* new Columns for those tables - and then with the „generateAttrbuteModels()“ call shopware will actually create the doctrine model. I think, that is what you are looking for. The „default“ attributes like „attr1“, „attr2“ are just some defaults - you can always add custom ones from your plugin. 

Best regards,

Daniel

1 „Gefällt mir“