shopware


Extends Shopware Models


I need to extend Shopware variants models in order to add some custom attributes such as the type of metal,the type of stone a jewel, which is the base article.
These attributes will be used both in backend and frontend.
How can I do that? Thanks
Extending the Shopware core model itself is not possible at all. Depending on what specific model you are trying to extend there would be two different ways for some workaround:
If its the article itself that you want to extend you could use the custom attribute fields as described here: http://community.shopware.com/Anlegen,-Anpassen-und-Ausgabe-von-Artikel-Attributen_detail_1208.html
Another way would be to write a plugin where you create attribute fields by code on plugin install(). This is only possible on entities that do have an attribute table which belongs to the entity itself. For example s_order and s_order_attributes
For the second way create a method in your plugin's Bootstrap.php like the following and call the method in the plugin's install() method:
public function installOrderAttributes()
{
Shopware()->Models()->addAttribute(
's_order_attributes',
'ordermod',
'Random1',
'DECIMAL(12,4)',
false,
0.0000);
Shopware()->Models()->addAttribute(
's_order_attributes',
'ordermod',
'Random2',
'DECIMAL(12,4)',
false,
0.0000);
$metaDataCacheDoctrine = Shopware()->Models()->getConfiguration()->getMetadataCacheImpl();
$metaDataCacheDoctrine->deleteAll();
Shopware()->Models()->generateAttributeModels(array('s_order_attributes'));
}
The addAttribute() function in /engine/Shopware/Components/Model/ModelManager.php has the following signature:
/**
* Shopware helper function to extend an attribute table.
*
* #param string $table Full table name. Example: "s_user_attributes"
* #param string $prefix Column prefix. The prefix and column parameter will be the column name. Example: "swag".
* #param string $column The column name
* #param string $type Full type declaration. Example: "VARCHAR( 5 )" / "DECIMAL( 10, 2 )"
* #param bool $nullable Allow null property
* #param null $default Default value of the column
* #throws \InvalidArgumentException
*/
public function addAttribute($table, $prefix, $column, $type, $nullable = true, $default = null);
Hope this will help.
Kind regards!

Related Links

shopware sample website is not redirecting to checkout page
Product Variants - Frontend
Call Order Controller after Backend Login Shopware
Changing the frontend language & multiple countries support in Shopware
Extends Shopware Models
Custom search result page in shopware5
TypeError: jQuery.subscribe is not a function on shopware5
Working with Forms in Shopware
Use different template for my contact us form in shopware5
Shopware 5 accessing controller variables (Template Variables) on frontend
Shopware 5 Responsive theme inheritance
Deactivate HTTP cache in Shopware 5 in a plugin
Any risk in using numeric item numbers in Shopware?

Categories

HOME
compiler-construction
google-chrome-extension
wso2-am
blogger
openstack
mockito
angular-material
alfresco
android-4.4-kitkat
q
gis
jira
elm
c#-2.0
ip
alpha
mvvmcross
yum
onelogin
podio
bs4
windows-10-universal
floating-action-button
fallback
flask-wtforms
hapi
telephony
pugjs
conemu
kryo
xlsxwriter
arabic
language-agnostic
autosys
smb
microsoft-sync-framework
vlsi
social-media
opentype
subdomains
key-value-observing
contact-form
winrt-xaml-toolkit
gammu
atl
google-api-nodejs-client
android-ble
withings
splice
streamreader
mime
modelmapper
node-sass
xml-documentation
theming
alphabet
aurelia-validation
lowpass-filter
pg-dump
capacity
orthogonal
eventkit
android-textview
ado.net-entity-data-model
asp.net-4.5
xml-attribute
angstrom-linux
react-native-listview
rhino-servicebus
pervasive-sql
srand
lemon
endeca-workbench
deis
sysinternals
dereference
bridge.net
dd
knuth
tt-news
fpml
castle
fluentautomation
.aspxauth
qt-faststart
orchardcms-1.7
http-unit
bitsharp
isnullorempty
dsn
appconkit
custom-backend
netdna-api
gnu-prolog
external-accessory
invite
xtype
javax.script
recent-documents
lang
gamma
ncqrs
ti-dsp
phonon

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App