3

In magento 2 admin panel, at product list grid area, i want to add one more grid with date, that date define product create date. so we get idea at which time product was created.

And i also want to add by whom it created, we have so many admin so we want to know by whom that product created.

So we need that 2 column on product grid area in admin side.

  • Explain your question a bit more as it is hard to understand your query with this minimum content – N. Karthic Kannan Dec 14 '17 at 11:41
  • @N.KarthicKannan, In magento 2 admin panel, at product list grid area, i want to add one more grid with date, that date define product create date. so we get idea at which time product was created. and i also want to add by whom it created, we have so many admin so we want to know by whom that product created. so we need that 2 column on product grid area in admin side. – JACK Dec 14 '17 at 11:45
  • @JACK can you take a screenshot? – Khoa TruongDinh Dec 15 '17 at 8:33
  • @KhoaTruongDinh which screenshot? in admin of magento 2 on product catalog list page. i want 2 column. 1)Created Date 2)Created By I don't think it need any screenshot. – JACK Dec 15 '17 at 10:22
2
+50

We can find the Create At field in table: catalog_product_entity.

So, for this field, we only need to show it:

For example:

app/code/Vendor/Catalog/view/adminhtml/ui_component/product_listing.xml

<?xml version="1.0" encoding="UTF-8"?>

<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <columns name="product_columns" class="Magento\Catalog\Ui\Component\Listing\Columns">
        <column name="created_at" component="Magento_Ui/js/grid/columns/date">
             <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="filter" xsi:type="string">dateRange</item>
                    <item name="dataType" xsi:type="string">date</item>
                    <item name="label" xsi:type="string" translate="true">Created Date</item>
                    <item name="sortOrder" xsi:type="number">71</item>
                </item>
            </argument>
        </column>
    </columns>
</listing>

Remember to create registration and module.xml.

[Note]

The create_at result will be different from database. Because

As we use default value CURRENT_TIMESTAMP for TIMESTAMP type columns we need to set GMT timezone

\Magento\Framework\DB\Adapter\Pdo\Mysql::connect()

    $this->_connection->query("SET time_zone = '+00:00'");
  • Thanks for answer @khoa, Can you guide me for Created by column? – JACK Dec 19 '17 at 6:47
  • @JACK in this case, hard for us. Because in some cases we cannot track the Created by. For example, products are created by CSV or via command line. But, I have a guide for you. We need to create a new product attribute Created By, and then add it via ui component like above. Using beforeSave plugin to get the current session for Created By. – Khoa TruongDinh Dec 19 '17 at 6:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.