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
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;
}
}