Magento – Magento 2 List newly created products

magento-2.1new-products

In Magento 1.x I have used the Tridian New Arrivals code to list "New Arrivals" on my homepage.

Moving to Magento 2.1.5, I want to do the same thing, but am lost in how to achieve this?

Perhaps the easiest way to describe this is I want to display a list of products most recently created in Magento (so based on the product ID, in descending order – most recently created item being the top of the resultant list).

My products do not have the "new from" dates set in magento, so I need to use the product ID method for this task.

Can anyone point me in the right direction to achieve this?

Best Answer

Create a custom module

in block file use

 use Magento\Catalog\Model\ProductFactory;
    use Magento\Framework\View\Element\Template\Context;

    protected $_productFactory;

    public function __construct(
       Context $context, 
       ProductFactory $productFactory,
       array $data = array()       
    ) {
       $this->_productFactory   = $productFactory;
       parent::__construct($context, $data);
    }

    public function getProductCollection() {
       $productCollection =  = $this->_productFactory->create()->getCollection();
      $productCollection->setOrder('product_id','ASC');
$productCollection->setPageSize(3) // or whatwever number of product is required
       return $productCollection;
    }

And fetch this collection template file

you can also use widget for these