2016-11-21 3 views
0

Shopware를위한 확장 기능 개발에 박차를 가하고 있습니다. 올바른 방식으로 카테고리 관리를 확장하고 싶습니다.Shopware 백엔드가 ExtJs로 카테고리를 개선했습니다

만들어진 플러그인 (레거시)을 달성하려면. 이 플러그인은 카테고리 내의 첫 번째 탭을 추가합니다.

//{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

당신이 load에 의해를 반환 값으로 바인딩

store: somestore.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'는

는 Heres는 바이올린 당신을 보여 :

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

및 : http://docs.sencha.com/extjs/6.2.0/modern/Ext.data.Store.html

상점을로드하려면 콤보 선언에서 상점로드를 호출해야합니다.

+0

답변 해 주셔서 감사합니다. 이것은 행동을 이해하는데 조금 도움이됩니다. ExtJs에 대한 나의 경험은 거의 존재하지 않는다. 답변을 @Alexander의 답변과 결합하려고합니다. –