/** * @return $this * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ protected function _prepareColumns() { $this->addColumn('entity_id', ['header' => __('ID'), 'type' => 'number', 'index' => 'entity_id', 'header_css_class' => 'col-id', 'column_css_class' => 'col-id']); $this->addColumn('name', ['header' => __('Name'), 'index' => 'name', 'class' => 'xxx']); $store = $this->_getStore(); if ($store->getId()) { $this->addColumn('custom_name', ['header' => __('Name in %1', $store->getName()), 'index' => 'custom_name', 'header_css_class' => 'col-name', 'column_css_class' => 'col-name']); } $this->addColumn('type', ['header' => __('Type'), 'index' => 'type_id', 'type' => 'options', 'options' => $this->_type->getOptionArray()]); $sets = $this->_setsFactory->create()->setEntityTypeFilter($this->_productFactory->create()->getResource()->getTypeId())->load()->toOptionHash(); $this->addColumn('set_name', ['header' => __('Attribute Set'), 'index' => 'attribute_set_id', 'type' => 'options', 'options' => $sets, 'header_css_class' => 'col-attr-name', 'column_css_class' => 'col-attr-name']); $this->addColumn('sku', ['header' => __('SKU'), 'index' => 'sku']); $store = $this->_getStore(); $this->addColumn('price', ['header' => __('Price'), 'type' => 'price', 'currency_code' => $store->getBaseCurrency()->getCode(), 'index' => 'price', 'header_css_class' => 'col-price', 'column_css_class' => 'col-price']); if ($this->moduleManager->isEnabled('Magento_CatalogInventory')) { $this->addColumn('qty', ['header' => __('Quantity'), 'type' => 'number', 'index' => 'qty']); } $this->addColumn('visibility', ['header' => __('Visibility'), 'index' => 'visibility', 'type' => 'options', 'options' => $this->_visibility->getOptionArray(), 'header_css_class' => 'col-visibility', 'column_css_class' => 'col-visibility']); $this->addColumn('status', ['header' => __('Status'), 'index' => 'status', 'type' => 'options', 'options' => $this->_status->getOptionArray()]); if (!$this->_storeManager->isSingleStoreMode()) { $this->addColumn('websites', ['header' => __('Websites'), 'sortable' => false, 'index' => 'websites', 'type' => 'options', 'options' => $this->_websiteFactory->create()->getCollection()->toOptionHash(), 'header_css_class' => 'col-websites', 'column_css_class' => 'col-websites']); } $this->addColumn('edit', ['header' => __('Edit'), 'type' => 'action', 'getter' => 'getId', 'actions' => [['caption' => __('Edit'), 'url' => ['base' => '*/*/edit', 'params' => ['store' => $this->getRequest()->getParam('store')]], 'field' => 'id']], 'filter' => false, 'sortable' => false, 'index' => 'stores', 'header_css_class' => 'col-action', 'column_css_class' => 'col-action']); $block = $this->getLayout()->getBlock('grid.bottom.links'); if ($block) { $this->setChild('grid.bottom.links', $block); } return parent::_prepareColumns(); }
/** * Add columns to grid * * @return $this * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ protected function _prepareColumns() { if (!$this->isReadonly()) { $this->addColumn('in_products', ['type' => 'checkbox', 'name' => 'in_products', 'values' => $this->_getSelectedProducts(), 'align' => 'center', 'index' => 'entity_id', 'header_css_class' => 'col-select', 'column_css_class' => 'col-select']); } $this->addColumn('entity_id', ['header' => __('ID'), 'sortable' => true, 'index' => 'entity_id', 'header_css_class' => 'col-id', 'column_css_class' => 'col-id']); $this->addColumn('name', ['header' => __('Name'), 'index' => 'name', 'header_css_class' => 'col-name', 'column_css_class' => 'col-name']); $this->addColumn('type', ['header' => __('Type'), 'index' => 'type_id', 'type' => 'options', 'options' => $this->_type->getOptionArray(), 'header_css_class' => 'col-type', 'column_css_class' => 'col-type']); $sets = $this->_setsFactory->create()->setEntityTypeFilter($this->_productFactory->create()->getResource()->getTypeId())->load()->toOptionHash(); $this->addColumn('set_name', ['header' => __('Attribute Set'), 'index' => 'attribute_set_id', 'type' => 'options', 'options' => $sets, 'header_css_class' => 'col-attr-name', 'column_css_class' => 'col-attr-name']); $this->addColumn('status', ['header' => __('Status'), 'index' => 'status', 'type' => 'options', 'options' => $this->_status->getOptionArray(), 'header_css_class' => 'col-status', 'column_css_class' => 'col-status']); $this->addColumn('visibility', ['header' => __('Visibility'), 'index' => 'visibility', 'type' => 'options', 'options' => $this->_visibility->getOptionArray(), 'header_css_class' => 'col-visibility', 'column_css_class' => 'col-visibility']); $this->addColumn('sku', ['header' => __('SKU'), 'index' => 'sku', 'header_css_class' => 'col-sku', 'column_css_class' => 'col-sku']); $this->addColumn('price', ['header' => __('Price'), 'type' => 'currency', 'currency_code' => (string) $this->_scopeConfig->getValue(\Magento\Directory\Model\Currency::XML_PATH_CURRENCY_BASE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE), 'index' => 'price', 'header_css_class' => 'col-price', 'column_css_class' => 'col-price']); $this->addColumn('position', ['header' => __('Position'), 'name' => 'position', 'type' => 'number', 'validate_class' => 'validate-number', 'index' => 'position', 'editable' => !$this->getProduct()->getRelatedReadonly(), 'edit_only' => !$this->getProduct()->getId(), 'header_css_class' => 'col-position', 'column_css_class' => 'col-position']); return parent::_prepareColumns(); }