2016-11-21 86 views
0

我被困在Shopware擴展的開發中。 我想以正確的方式擴展類別的管理。帶有ExtJs的Shopware後臺增強類

實現創建的插件(遺留)。這個插件在類別中追加第一個標籤。

//{block name="backend/category/view/tabs/settings" append} 

這樣做是爲了添加一個帶下拉的字段集。該文件是這樣的:

//{block name="backend/category/view/tabs/settings" append} 
Ext.define('Shopware.apps.HaendlerbundFoobarCategories.view.category.tabs.settings', { 
    override:'Shopware.apps.Category.view.category.tabs.Settings', 

    getItems: function() { 
     var me = this; 
     var items = me.callParent(arguments); 
     me.FooBar = me.getFooBarSection(); 
     items.push(me.FooBar); 
     return items; 
    }, 

    getFooBarSection : function() 
    { 
     var me = this; 
     return Ext.create('Ext.form.FieldSet',{ 
      title: 'FooBar Verlinkung', 
      anchor: '100%', 
      defaults : me.defaults, 
      disabled : false, 
      items : me.getDropdowns() 
     }); 
    }, 

    getDropdowns:function(){ 
     var me = this; 

     return me.templateComboBox = Ext.create('Ext.form.field.ComboBox', { 
      xtype:'combobox', 
      fieldLabel: 'FooBar Product', 
      store: me.fooBarProducts.load(), 
      labelWidth: 155, 
      valueField: 'id', 
      displayField:'title', 
      editable: true, 
      allowBlank:true, 
      name:'fbproduct' 
     }); 
    } 
}); 
//{/block} 

我懷疑的主要問題是商店。像這樣離開它,我得到一個JS 錯誤無法讀取未定義的屬性「負載」。沒有.load()沒有錯誤,但我也無法確定商店是否已加載。

的存儲文件本身是在查看/後端/ haendlerbund_foobar_categories /存儲/ foo_bar_products

和該文件的內容是:

//{block name="backend/haendlerbund_foobar_categories/store/fooBarProducts"} 
Ext.define('Shopware.apps.HaendlerbundFoobarCategories.store.fooBarProducts', { 

//... 
model: 'Shopware.apps.HaendlerbundFoobarCategories.model.fooBarProducts', 
proxy : { 
     type : 'ajax', 
     /** 
     * Configure the url mapping for the different 
     * store operations based on 
     * @object 
     */ 
     api : { 
      read : '{url controller=HaendlerbundFoobarCategories action=getProducts}' 
     }, 
     /** 
     * Configure the data reader 
     * @object 
     */ 
     reader : { 
      type : 'json', 
      root: 'data' 
     } 
    } 
}); 
//{/block} 

編輯: 爲了進一步上下文中,這是商店引用的模型的當前狀態。

Ext.define('Shopware.apps.HaendlerbundFoobarCategories.model.fooBarProducts', { 
    extend: 'Ext.data.Model', 

    /** 
    * If the name of the field is 'id' extjs assumes automatically that 
    * this field is an unique identifier. 
    * @integer 
    */ 
    idProperty : 'id', 

    fields:[ 
     { name : 'id',   type: 'int' }, 
     { name : 'ffid',  type: 'bigint' }, 
     { name : 'title',  type: 'string' }, 
     { name : 'description', type: 'string' }, 
     { name : 'price',  type: 'decimal' }, 
     { name : 'vat',   type: 'decimal' }, 
     { name : 'image',  type: 'text' }, 
     { name : 'active',  type: 'boolean' }, 
     { name : 'createdAt', type: 'datetime' }, 
     { name : 'modfiedAt', type: 'datetime' } 
    ], 


    /*associations: [ 
     { 
      relation: 'OneToMany', 
      storeClass: 'Shopware.apps.HaendlerbundFoobarCategories.store.fooBarProducts', 
      loadOnDemand: true, 

      type: 'hasMany', 
      model: 'Shopware.apps.HaendlerbundFooBarCategories.model.fooBarProducts', 
      name: 'getCategories', 
      associationKey: 'categories' 
     }, 
    ]*/ 
}); 

,而PHP的控制器,店裏的引用以及具有以下內容:

<?php 

class Shopware_Controllers_Backend_HaendlerbundFoobarCategories extends Shopware_Controllers_Backend_Application 
{ 
    protected $model = 'Shopware\CustomModels\Product\FFProduct'; 
    protected $alias = 'ffproducts'; 

    protected function getListQuery() 
    { 
     $builder = parent::getListQuery(); 
     return $builder; 
    } 

    protected function getDetailQuery($id) 
    { 
     $builder = parent::getDetailQuery($id); 
     return $builder; 
    } 

    protected function getAdditionalDetailData(array $data) 
    { 
     return $data; 
    } 

    public function getProducts(){ 
     $builder = $this->getManager()->createQueryBuilder(); 
     $builder->select('*') 
       ->from($model, $alias); 

     $data['id']  = 1; 
     $data['ffid'] = 1; 
     $data['title'] = 'lorem ipsum'; 

     $this->view()->assign([ 
      'success' => true, 
      'data'  => $data, 
      'total'  => 1 

     ]); 

    } 
} 

它應該返回一些虛擬的數據了。

我無法解決問題。正如我所能找到的任何文件都着眼於創建改變現有領域的單獨組件。我懷疑我是在錯誤的範圍內或有一個命名空間錯誤或什麼的。

任何幫助,非常感謝。

回答

1

如果使用

store: somestore.load() 

組合框會結合load返回值。加載函數不會返回任何內容,所以組合的商店配置設置爲undefined

你想要做的可能是

me.fooBarProducts.load(); 
    return me.templateComboBox = Ext.create('Ext.form.field.ComboBox', { 
     xtype:'combobox', 
     fieldLabel: 'FooBar Product', 
     store: me.fooBarProducts, 
     labelWidth: 155, 
     valueField: 'id', 
     displayField:'title', 
     editable: true, 
     allowBlank:true, 
     name:'fbproduct' 
    }); 
+0

我測試你的建議。這沒有什麼區別。 但是,商店可能的輸入不會返回任何數據,這讓我有一個想法來進行測試。 –

+0

請做一個'console.log(me.fooBarProducts)'並檢查你得到了什麼。 – Alexander

+0

當我找到把這個實際看到的迴應的地方時,會做什麼。現在我試着測試類的命名等等。我想也有一些混雜的事情。 無論是商店還是模型是一個純粹的ExtJS的環境,其實我揣摩,如果我至少得到了正確的範圍。 –

1

您的問題是店裏分配給組合框

這行代碼有什麼不正確:

store: me.fooBarProducts.load(),

通常一個店裏只應連接到一個組合框是這樣的:

店: 'fooBarProducts'

繼承人小提琴向您展示:

https://fiddle.sencha.com/#view/editor&fiddle/1kqj

Ext.application({ 
name : 'Fiddle', 

launch : function() { 
    var yourStore=Ext.create('Ext.data.Store',{ 
     fields:[{ 
      name:'text' 
     },{ 
      name:'value' 
     }], 
     data:[ 
      {text:'test1',value:'testVal1'}, 
      {text:'test2',value:'testVal2'}, 
      {text:'test3',value:'testVal3'} 
      ] 
    }); 
    Ext.create({ 
     xtype:'window', 
     width:300, 
     height:200, 
     items:[{ 
      xtype:'combo', 
      displayField:'text', 
      valueField:'value', 
      store:yourStore 
     },{ 
      xtype:'combo', 
      displayField:'text', 
      valueField:'value', 
      store:yourStore 
     }] 
    }).show(); 
} 

}); 

也紛紛這裏看看:http://docs.sencha.com/extjs/6.2.0/classic/Ext.form.field.ComboBox.html

對於ComboBox例如 這裏存放聲明: http://docs.sencha.com/extjs/6.2.0/modern/Ext.data.Store.html

加載你的店,你應該叫店裏載出組合聲明

+0

謝謝你的回答。這有助於理解行爲。我的ExtJs經驗幾乎不存在。 我會嘗試你的答案與@Alexander的一個結合 –