Create a custom product data datagrid in Akeneo: Define columns & configure data source. Use Akeneo UI or YAML file in custom bundle. Integrate datagrid into Akeneo UI via custom tab or section. Using custom datagrids in Akeneo, combining the best aspects of UI and YAML configurations and PHP. A datagrid in Akeneo is a configurable UI component that displays tabular data.
Display the custom product data grid: Integrate the custom product data grid into the Akeneo UI by creating a custom tab or section within the product view page and rendering the grid there. Extend existing Akeneo views or create a custom UI extension.
Akeneo provides a REST API that allows you to connect external systems or custom applications’ product data. You can use the API to fetch product information from external sources and synchronize it with Akeneo.
DataGrid
datagrid: acme_testbundle-product-picker-grid: options: entityHint: product requireJSModules: - pim/datagrid/column-form-listener columnListener: dataField: identifier columnName: is_checked routerEnabled: false source: type: acme_testbundle_datasource_product entity: '%pim_catalog.entity.product.class%' columns: is_checked: frontend_type: boolean data_name: is_checked editable: true identifier: label: ID data_name: identifier type: field image: label: Image data_name: image frontend_type: product-and-product-model-image label: label: Label data_name: label type: field frontend_type: product-and-product-model-label properties: id: ~ technical_id: ~ document_type: ~
Add DataSource Type
parameters: acme_testbundle_datagrid.datasource.product.class: Acme\TestBundle\Datasource\ProductDatasource # Pim\Bundle\DataGridBundle\Datasource\ProductDatasource # services: acme_testbundle_datagrid.datasource.product: class: '%acme_testbundle_datagrid.datasource.product.class%' arguments: - '@pim_catalog.object_manager.product' - '@pim_enrich.query.product_and_product_model_query_builder_from_size_factory' - '@pim_datagrid_serializer' - '@pim_datagrid.event_subscriber.filter_entity_with_values_subscriber' calls: - [ setMassActionRepository, ['@pim_catalog.repository.product_mass_action'] ] tags: - { name: oro_datagrid.datasource, type: acme_testbundle_datasource_product }
DataSourceAdapterResolver
pim_datagrid.datasource.adapter_resolver:<br> class: '%pim_datagrid.datasource.adapter_resolver.class%'<br> arguments:<br> - '%pim_filter.datasource.orm_adapter.class%'<br> - '%pim_filter.datasource.product_orm_adapter.class%'<br> calls:<br> - [addProductDatasource, ['pim_datasource_product']]<br> - [addProductDatasource, ['pim_datasource_associated_product']]<br> - [addProductDatasource, ['pim_datasource_associated_product_model']]<br> - [addProductDatasource, ['pim_datasource_group_product']]<br> - [addProductDatasource, ['wk_chatgpt_datasource_product']]<br>
Format data for data grid
namespace Acme\TestBundle\Datasource; use Doctrine\Common\Persistence\ObjectManager; use Oro\Bundle\DataGridBundle\Datasource\ResultRecord; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; use Oro\Bundle\PimDataGridBundle\Datasource\ProductDatasource as BaseDataSource; use Oro\Bundle\PimDataGridBundle\EventSubscriber\FilterEntityWithValuesSubscriberConfiguration; use Akeneo\Pim\Enrichment\Component\Product\Query\ProductQueryBuilderFactoryInterface; use Akeneo\Pim\Enrichment\Component\Product\Model\EntityWithValuesInterface; use Oro\Bundle\PimDataGridBundle\EventSubscriber\FilterEntityWithValuesSubscriber; /** * Product datasource, executes elasticsearch query * */ class ProductDatasource extends BaseDataSource { /** @var ProductQueryBuilderInterface */ protected $pqb; /** @var ProductQueryBuilderFactoryInterface */ protected $factory; /** @var NormalizerInterface */ protected $normalizer; /** @var FilterEntityWithValuesSubscriber */ protected $filterEntityWithValuesSubscriber; /** * @param ObjectManager $om * @param ProductQueryBuilderFactoryInterface $factory * @param NormalizerInterface $serializer * @param FilterEntityWithValuesSubscriber $filterEntityWithValuesSubscriber */ public function __construct( ObjectManager $om, ProductQueryBuilderFactoryInterface $factory, NormalizerInterface $serializer, FilterEntityWithValuesSubscriber $filterEntityWithValuesSubscriber, ) { parent::__construct($om, $factory, $serializer, $filterEntityWithValuesSubscriber); } /** * {@inheritdoc} */ public function getResults() { $productList = []; // set product list $productModelList = [] set product model list; $rows = ['data' => []]; $entitiesWithValues = $productList->getItems(); $modelEntitiesWithValues = $productModelList->getItems(); foreach ($entitiesWithValues as $entityWithValue) { $normalizedItem = $this->normalizeEntityWithValues($entityWithValue); $rows['data'][] = new ResultRecord($normalizedItem); } foreach ($modelEntitiesWithValues as $modelEntityWithValue) { $normalizedItem = $this->normalizeEntityWithValues($modelEntityWithValue); $rows['data'][] = new ResultRecord($normalizedItem); } $rows['totalRecords'] = $productList->getCount() + $productModelList->getCount(); return $rows; } /** * Normalizes an entity with values with the complete set of fields required to show it. * * @param array $item * * @return array */ private function normalizeEntityWithValues($item): array { $productId = $this->getProductId($item); $normalizedItem = [ "identifier" => $item['identifier'] ?? $item['code'], "family" => $item['family'], "groups" => "", "enabled" => $item['enabled'], "values" => $item['value'], "created" => $item['created'], "updated" => $item['updated'], "label" => $item['identifier'] ?? $item['code'], "image" => null, "document_type" => "product", "technical_id" => $productId, "id" => $productId, "search_id" => "product_".$productId, "is_checked" => true, ] ; return $normalizedItem; } }
Please be aware that the provided code is a simplified example and it may be necessary for you to modify and extend it according to your specific requirements and the structure of your custom data source.
Remember to adjust the namespace and class names in the example to match your project’s structure.
It’s worth noting that Akeneo provides a flexible and extensible framework, allowing you to adapt and customize the data sources based on your business needs. The data source selected is determined by the unique integration needs, the type of data to be imported, and the frequency of updates.
The best fo example for Create a custom product datagrid in Akeneo https://webkul.com/blog/akeneo-shareable-product-url-generator-documenation/
Be the first to comment.