如何使用插件在magento2的集合数组中添加属性

时间:2019-02-07 12:01:40

标签: magento2

public function aroundGetData(\Magento\Catalog\Ui\DataProvider\Product\ProductDataProvider $subject, callable $proceed)
{
    // what is do here    
}

1 个答案:

答案 0 :(得分:0)

感觉跳水不够深

对于全局使用而言,简便的方法是使用addField甚至更改SQL以从某些相关表中添加数据。

public function aroundGetData(\Magento\Catalog\Ui\DataProvider\Product\ProductDataProvider $subject, callable $proceed)
{
    $subject->addField('field', 'alias'); // alias is optional
    $collection = $subject->getCollection(); // Here you have access to all public methods of collection.
    $select = $collection->getSelect(); // You can do whatever you want with Zend_DB_Select here
    return $proceed();    
}

DataProvider具有addField,而addFilter方法在内部使用Product Collection