0

I want get product by sku, name, price.I do not know how to get it. Please help me. i get it by sku is success but name or price isn't success.

1 Answer 1

1

you can get product by name or price by using this code

namespace Abdus\Test\Helper;



class HelperData extends \Magento\Framework\App\Helper\AbstractHelper
{
    protected $_productsFactory;

    public function __construct(

        \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productFactory

    )
    {

        $this->_productsFactory = $productFactory;

    }

    public function getProductCollection($productId)
    {
          $price = 500;
          $name = 'little shirt';

        $productCollection = $this->_productsFactory->create()
                        ->addFieldToFilter('price', $price)
                        ->addFieldToFilter('name', $name)
                        ->addAttributeToSelect('*');
        return $productCollection;
    }

}

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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