i want to get product details (sku,name,id) using rest api this is my code in model(is collection code is correct )

magento.stackexchange https://magento.stackexchange.com/questions/333641

Question

<?php
namespace Ameex\Restapi\Model;

use Ameex\Restapi\Api\PostManagementInterface;
use Magento\Store\Model\StoreManagerInterface;

class PostManagement implements PostManagementInterface
{
    

      /**
     * @var \Magento\Framework\ObjectManagerInterface
     */
    protected $objectManager;

     /**
     * @var StoreManagerInterface
     */
    protected $storeManager;

    protected $_productCollectionFactory;   



    /**
     * Product constructor.
     *
     * @param StoreManagerInterface $storeManager
     
     */
    public function __construct(
        StoreManagerInterface $storeManager,
        \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory

    ) {
         $this->storeManager       = $storeManager;
        $this->_productCollectionFactory = $productCollectionFactory;   
    }

    public function getProductCollection()
    {
        $collection = $this->_productCollectionFactory->create();
        $collection->addAttributeToSelect('*')->load();
        $collection->setPageSize(10); // fetching only 10 products
        return $collection;
    }

   
    public function getStoreId()
    {

        return $this->storeManager->getStore()->getId();
    }
    
    public function get_Sku()
    {
        return $this->getProductCollection()->getSku();
    }
    
    public function get_Name()
    {
        return $this->getProductCollection()->getName();
    }


}

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top