2015-10-16 90 views
2

我需要編寫一個Shopware插件,用於擴展external_id字段的客戶模型。此字段應可通過管理界面和API編輯。如何擴展Shopware客戶

我發現,我可以像這樣添加屬性用戶:

public function addAttributes() { 
    $this->Application()->Models()->addAttribute(
     's_user_attributes', 
     'bla', 
     'externalId', 
     'INT(11)', 
     true, 
     null 
    ); 

    $this->Application()->Models()->generateAttributeModels(array(
     's_user_attributes' 
    )); 
} 

我應該怎麼做,以顯示在用戶界面和API這個領域?

PS:Shopware 5

回答

3

addAttribute在Shopware 5 使用shopware_attribute.crud_serviceShopware() -container棄用代替。

$service = Shopware()->Container()->get('shopware_attribute.crud_service'); 
$service->update('s_user_attributes', 'bla', 'integer', [ 
    'label' => '', 
    'supportText' => '', 
    'helpText' => '', 
    'translatable' => false, 
    'displayInBackend' => true, 
    'position' => 1 
]); 

Shopware()->Models()->generateAttributeModels(
    array(
     's_user_attributes' 
    ) 
); 

如果設置displayInBackendtrue,你可以在後端,用戶在哪裏進行編輯。

更多在Shopware Developer Guide