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
multithreading
gitlab
netsuite
angular-material
react-virtualized
syntax
gis
c#-2.0
ravendb
mvvmcross
autotools
spring-kafka
wheelnav.js
quickbooks
fortumo
msp430
caml
opentracing
progressive-web-apps
propel
excel-vba-mac
google-cloud-speech
zapier
google-search-api
realex-payments-api
android-widget
centos6.5
wpfdatagrid
info.plist
phpfox
greendao
ping
compatibility
windows-server-2000
vision
tasklet
phonegap
kendo-ui-grid
gammu
y86
html5-fullscreen
disassembling
android-browser
jna
leading-zero
bootstrapper
avro4s
estimote
outlook-api
unixodbc
wptoolkit
taffy
zip4j
ionicons
integrity
knpmenubundle
sqlbulkcopy
gcsfuse
spring-mongodb
topbeat
static-ip-address
radtreelist
ctest
clang-static-analyzer
sdf
pagerank
maven-tomcat-plugin
prerequisites
angular-leaflet-directive
sysinternals
iiviewdeckcontroller
skos
notify
offloading
clicktag
c3
cdt
android-imagebutton
xojo
mesa
poller
mechanize-ruby
braille
jboss-weld
cloud-connect
centos5
monomac
inbox
jmapviewer
sharp-repository
ocunit
factory-method
tinn-r
browser-detection
isnullorempty
funscript
jspinclude
enter
netbeans-6.9
removeclass
punbb
qt-jambi
vdsp
gcj
hamachi
yetanotherforum
iphone-web-app
mysql-error-1005
createwindow
getresponsestream
xsdobjectgen
asp.net-profiles
firefox-5
compiler-specific
privilege
spec#
geneva-server

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App