我正在为Shopware 5.5.8“ Spareparts”开发一个插件,该插件将扩展产品(shopware中的文章)。我在Crosselling选项卡中添加了一个fieldSet并使其起作用。但是我找不到如何在Ext.define('Shopware.apps.MyPlugin.controller.Detail',{。
我也在寻找如何在PHP和ExtJs中扩展Article模型的方法,发现根本不可能扩展核心模型。但是我为Spareparts创建了我的模型-该表与“相关产品”和“相似产品”相似。但是要使代码正常工作,我需要在Article中添加一个字段。也许足以覆盖model / article.js,但我找不到方法。
model / main.js
Ext.define('Shopware.apps.MyPlugin.model.Main', {
extend: 'Shopware.data.Model',
configure: function () {
console.log('Shopware.apps.MyPlugin.model.Main : configure');
return {
controller: 'MyPlugin',
detail: 'Shopware.apps.MyPlugin.view.detail.Container'
};
},
fields: [
{name: 'id', type: 'int'},
{name: 'name', type: 'string'},
{name: 'number', type: 'string', mapping: 'mainDetail.number'}
],
});
store / main.js
Ext.define('Shopware.apps.MyPlugin.store.Main', {
extend: 'Shopware.store.Listing',
/**
* Fields of the store records
* @array
*/
fields: ['id', 'name', 'number'],
configure: function () {
console.log('store/main.js:configure');
return {
controller: 'MyPlugin'
};
},
model: 'Shopware.apps.MyPlugin.model.Main'
});
controller / main.js
Ext.define('Shopware.apps.MyPlugin.controller.Main', {
override: 'Shopware.apps.Article.controller.Crossselling',
init: function () {
var me = this;
console.log('controller/main.js:init');
me.control({
'article-detail-window article-crossselling-base': {
addSparepartArticle: me.onAddSparepartArticle,
removeSparepartArticle: me.onRemoveSparepartArticle
},
});
// me.callParent will execute the init function of the overridden controller
me.callParent(arguments);
},
onAddSparepartArticle: function (form, grid, searchField) {
console.log('controller/main.js:onAddSparepartArticle');
var me = this,
selected = searchField.returnRecord,
store = grid.getStore(),
values = form.getValues();
if (!form.getForm().isValid() || !(selected instanceof Ext.data.Model)) {
return false;
}
var model = Ext.create('Shopware.apps.MyPlugin.model.Main', values);
model.set('id', selected.get('id'));
model.set('name', selected.get('name'));
model.set('number', selected.get('number'));
//check if the article is already assigned
var exist = store.getById(model.get('id'));
if (!(exist instanceof Ext.data.Model)) {
store.add(model);
form.getForm().reset();
} else {
Shopware.Notification.createGrowlMessage(me.snippets.existTitle, Ext.String.format(me.snippets.ersatzteil.exist, model.get('number')), me.ersatzteil.growlMessage);
}
},
onRemoveSparepartArticle: function (grid, record) {
console.log('controller/main.js:onRemoveSparepartArticle');
var me = this,
store = grid.getStore();
if (record instanceof Ext.data.Model) {
store.remove(record);
}
}
});
controller / detail.js
Ext.define('Shopware.apps.MyPlugin.controller.Detail', {
override: 'Shopware.apps.Article.controller.Detail',
onSaveArticle: function (win, article, options) {
console.log('controller/detail.js:onSaveArticle');
var me = this,
originalCallback = options.callback,
mainWindow = me.getMainWindow(),
form;
if (Ext.isEmpty(win)) {
mainWindow = me.getMainWindow();
} else {
mainWindow = win;
}
form = mainWindow.detailForm;
var customCallback = function (newArticle, success) {
Ext.callback(originalCallback, this, arguments);
/* Ext.Ajax.request({
method: 'POST',
url: '{url controller=MyPlugin action=saveData}',
params: {
_foreignKey: newArticle.get('mainDetailId'),
_table: 's_plugin_myplugin_sparepart',
__attribute_my_column: me.getBaseFieldSet().sparepart.getValue()
}
});*/
};
if (!options.callback || options.callback.toString() !== customCallback.toString()) {
options.callback = customCallback;
}
me.callParent([win, article, options]);
},
});