# Extending Existing Core Classes and Models

**URL:** <https://forum.shopware.com/t/extending-existing-core-classes-and-models/36224>\
**Category:** Programmierung\
**Created:** [22. April 2016 um 05:23 UTC](https://forum.shopware.com/t/extending-existing-core-classes-and-models/36224 "2016-04-22T05:23:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![abdul.ahad2k14](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@abdul.ahad2k14](https://forum.shopware.com/u/abdul.ahad2k14)\
**Post date:** [22. April 2016 um 05:23 UTC](https://forum.shopware.com/t/extending-existing-core-classes-and-models/36224/1 "2016-04-22T05:23:07Z")

</div>

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&nbsp;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&nbsp;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.&nbsp;

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 🙂

BR

---

<div class="post-metadata">

**Author:** ![DanielNogel](https://avatars.discourse-cdn.com/v4/letter/d/96bed5/32.png) [@DanielNogel](https://forum.shopware.com/u/DanielNogel)\
**Post date:** [22. April 2016 um 06:07 UTC](https://forum.shopware.com/t/extending-existing-core-classes-and-models/36224/2 "2016-04-22T06:07:43Z")

</div>

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:&nbsp;[http://community.shopware.com/\_detail\_1441.html](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:&nbsp;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&nbsp;[Shopware events](https://developers.shopware.com/developers-guide/event-guide/#event-types) 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&nbsp;[Shopware events](https://developers.shopware.com/developers-guide/event-guide/#finding-events) and here:&nbsp;[Best practices of Shopware plugin development](https://developers.shopware.com/blog/2015/11/11/best-practices-of-shopware-plugin-development/#how-to-find-extension-points)

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

Daniel

&nbsp;

&nbsp;

&nbsp;

---

<div class="post-metadata">

**Author:** ![abdul.ahad2k14](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@abdul.ahad2k14](https://forum.shopware.com/u/abdul.ahad2k14)\
**Post date:** [22. April 2016 um 06:16 UTC](https://forum.shopware.com/t/extending-existing-core-classes-and-models/36224/3 "2016-04-22T06:16:47Z")

</div>

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&nbsp;attributes feature.

Or am I missing something?

-Ahad-

---

<div class="post-metadata">

**Author:** ![DanielNogel](https://avatars.discourse-cdn.com/v4/letter/d/96bed5/32.png) [@DanielNogel](https://forum.shopware.com/u/DanielNogel)\
**Post date:** [22. April 2016 um 06:31 UTC](https://forum.shopware.com/t/extending-existing-core-classes-and-models/36224/4 "2016-04-22T06:31:16Z")

</div>

Hi,

check the „createAttributes“ method in this example:&nbsp;[http://community.shopware.com/\_detail\_1441.html?\_ga=1.103929088.1619813372.1429258252#Bootstrap](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.&nbsp;

Best regards,

Daniel
