Search code examples
javascriptphpextjs4.1shopware

How to access system stores for shopping world element?


I am trying to add a dropdown with category selection to custom shopping world element, I have tried to create plugin based on this example. I have added a new combobox field

$vimeoElement->createComboBoxField([
    'name' => 'cat',
    'fieldLabel' => 'Category',
    'supportText' => 'Select category',
    'allowBlank' => false,
    'store' => 'Shopware.apps.Base.store.Category'
]);

It has appeared in shopping element form, but when I click on it, there is a JavaScript error:

"Cannot read property 'type' of undefined"

which happens while preparing combobox template. I have not been able to determine what exactly causes this error, so I have tried alternatively to create my own field with JavaScript, but I cannot get categories list from store with JavaScript too.

Ext.create('Ext.form.field.ComboBox', {
    xtype:'combobox',
    fieldLabel: 'Select Category',
    store: Shopware.apps.Base.store.Category,
    name: 'category'
});

This fails with:

"Cannot read property 'getProxy' of undefined".

Trying to get items directly from store with .getRange() or load items with .load() is not working - there is no such methods in object.

Am I trying to access a wrong store? There is also a Shopware.store.Category but it seems to be a link to the same object and does not work the same.


Solution

  • You can use this Example for the Category Selection

    $ekElement->createComboBoxField([
      'name' => 'heroChangerCategory',
      'fieldLabel' => 'KategorieLink',
      'supportText' => 'Kategorie auf die verlinkt werden soll',
      'xtype' => 'emotion-components-fields-category-selection'
    ]);
    

    or for your way, you must define the values for displayField and valueField

    $ekElement->createComboBoxField([
      'name' => 'cat',
      'fieldLabel' => 'Category',
      'supportText' => 'Select category',
      'displayField' => 'name',
      'valueField' => 'id',
      'allowBlank' => false,
      'store' => 'Shopware.apps.Base.store.Category'
    ]);