Hallo zusammen! Durch eine Individualanpassung der Artikelverwaltung muss ich eigentlich das aktuelle Artikelfenster im Backend komplett neu laden. Leider habe ich hierzu keine passende Funktion gefunden. Hat jemand eine Lösung, wie ich den Artikel in der Detailansicht komplett neu laden kann incl. Varianten etc. Vielen Dank, Rafael Kutscha
Hi, ab Shopware 4.1 funktioniert das ganze wie folgt: var me = this; me.batchStore = me.getStore('Batch'); me.batchStore.getProxy().extraParams.articleId = id; me.batchStore.load({ callback: function(records, operation) { var storeData = records[0]; me.subApplication.fireEvent('batchStoreLoaded', storeData, operation, true); } });
Dies kannst du dann in deinem Controller ausführen. Die Artikel ID kannst du über me.subApplication.article.get(‘id’) ermitteln. Mit freundlichen Grüßen Oliver Denter
Danke. Unter 4.0.8 gibt es noch nichts dazu?
Hallo Oliver, wenn ich unter 4.1 den genannten Code ausführe, habe ich alle Felder doppelt in der Eingabemaske. Was mir also noch fehlt ist die Möglichkeit vorweg die Artikelmaske zu leeren. Kannst Du mir bitte noch ein entsprechendes Beispiel nennen, wie ich den Artikeleditor leeren kann?
Hi, wenn du nur die Artikel Daten nachladen möchtest kannst du dir auch die Funktion “onSplitViewStoreChange” im Main Controller mal anschauen. Diese lädt die Artikel Daten in die Maske wenn in der Artikel Liste der Datensatz gewechselt wird. Andernfalls müsstest du wirklich die Container vorher leeren. Hier ist das schöne das in Ext JS fast alles ein Container ist oder von diesem ableitet und dir die Funktion “container.removeAll()” zur Verfügung stellt mit der du alle Elemente entfernen kannst. Gruß Olli
Hallo Oliver, danke für die Tipps. Leider bekomme ich den Reload nicht korrekt ans laufen. Hier mal die modifizierte „onSaveArticle“: /\*\* \* Event listener function of the save button of the main window. \* Saves the current article \* \* @param { Object } win \* @param { Object } article \* @param { Object } options \* @return { Boolean|void } \*/ onSaveArticle: function(win, article, options) { var me = this, priceStore, lastFilter, message, mainWindow = me.getMainWindow(), form = me.getDetailForm(); //first, check if the detail form panel is valid, otherwise return. if ( !form.getForm().isValid() ) { if (options !== Ext.undefined && options !== null && Ext.isFunction(options.callback)) { options.callback(null, false, 'no\_valid\_form'); } return; } priceStore = article.getPrice(); //update the article record with the form data. form.getForm().updateRecord(article); article = me.prepareAvoidCustomerGroups(article); if (!article.get('isConfigurator')) { article.set('configuratorSetId', null); } // If supplierId is string we want to create a new supplier in our backend var baseField = me.getBaseFieldSet(); var supplierId = baseField.supplierCombo.getModelData().supplierId; var supplierNeedsReload = false; if (typeof supplierId === "string") { article.set('supplierName', supplierId); supplierNeedsReload = true; } article.getConfiguratorSetStore = Ext.create('Ext.data.Store', { model: 'Shopware.apps.Article.model.ConfiguratorSet' }); //save last price store filter to filter again after the article saved. lastFilter = priceStore.filters.items; priceStore.clearFilter(); if (article.getConfiguratorTemplateStore instanceof Ext.data.Store && article.getConfiguratorTemplateStore.getCount() \> 0) { var template = article.getConfiguratorTemplateStore.first(); if (template.getPrice() instanceof Ext.data.Store) { template.getPrice().clearFilter(); } } if (!me.hasArticlePrice(priceStore)) { priceStore.filter(lastFilter); Shopware.Notification.createGrowlMessage(me.snippets.saved.errorTitle, me.snippets.saved.noPriceGiven, me.snippets.growlMessage); if (options !== Ext.undefined && options !== null && Ext.isFunction(options.callback)) { options.callback(null, false); } return false; } //remove all prices with a clone flag. me.removeClonedPrices(priceStore); article.setDirty(); // INDIVIDUALANPASSUNG article.save({ success: function(record, operation) { var newArticle = operation.getResultSet().records[0], message = Ext.String.format(me.snippets.saved.message, article.get('name')); if (supplierNeedsReload) { mainWindow.supplierStore.filters.clear(); mainWindow.supplierStore.load(); } me.prepareArticleProperties(record); newArticle.getPrice().filter(lastFilter); me.reconfigureAssociationComponents(newArticle); Shopware.Notification.createGrowlMessage(me.snippets.saved.title, message, me.snippets.growlMessage); me.refreshArticleList(); if (options !== Ext.undefined && options !== null && Ext.isFunction(options.callback)) { options.callback(newArticle, true); } if (article.get('isConfigurator')) { Ext.Ajax.request({ url: '/do\_something.php?articleid=' + article.get('id'), success: function (response) { x = Ext.decode( response.responseText ); console.log(x); //me.reconfigureAssociationComponents(newArticle); //variantListing = me.getVariantListing(); me.getVariantListing().getStore().load(); me.batchStore = me.getStore('Batch'); me.batchStore.getProxy().extraParams.articleId = article.get('id'); me.batchStore.load({ callback: function(records, operation) { var storeData = records[0]; me.reloadArticle(newArticle.get('id')); me.getVariantListing().getStore().load(); //me.subApplication.fireEvent('batchStoreLoaded', storeData, operation, true); } }); }, failure: function () { console.log('failure'); }, headers: { 'my-header': 'foo' }, params: { foo: 'bar' } }); } }, failure: function(record, operation) { var rawData = record.getProxy().getReader().rawData, fields = rawData.fields, message = rawData.message; if (fields && fields.length \> 0) { Shopware.Notification.createGrowlMessage(me.snippets.saved.errorTitle, me.snippets.saved.fieldsViolation, me.snippets.growlMessage); } else { Shopware.Notification.createGrowlMessage(me.snippets.saved.errorTitle, me.snippets.saved.errorMessage + message, me.snippets.growlMessage); } priceStore.filter(lastFilter); if (options !== Ext.undefined && options !== null && Ext.isFunction(options.callback)) { options.callback(null, false); } } }); },
Wenn ich hier me.subApplication.fireEvent(‚batchStoreLoaded‘, storeData, operation, true); verwende, erscheinen alle Daten im Artikelfenster doppelt. Ich müsste Shopware also eigentlich beibringen ein „Update“ der Daten zu machen und nicht alle Felder erneut anzulegen. Danke für weitere Hinweise, wie dies zu lösen ist.
*PUSH*
*PUSH*
*PUSH*