title: Get Magento 2 collection based on final_price
body: <p>I have the following code to get a Magento 2 product collection:</p>
  
  <pre><code>&lt;?php namespace Qxs\Related\Block;
  
  class Related extends \Magento\Framework\View\Element\Template
  {
    public function __construct(
      \Magento\Backend\Block\Template\Context $context,
      \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,
      \Magento\Catalog\Model\Product\Attribute\Source\Status $productStatus,
      \Magento\Catalog\Model\Product\Visibility $productVisibility,
      \Magento\Framework\Registry $registry,
      array $data = []
    )
    {
      $this-&gt;_productCollectionFactory = $productCollectionFactory;
      $this-&gt;productStatus = $productStatus;
      $this-&gt;productVisibility = $productVisibility;
      $this-&gt;_registry = $registry;
      parent::__construct($context, $data);
    }
  
    public function getProductCollection()
    {
      try {
  
        $product = $this-&gt;_registry-&gt;registry('current_product');
  
        $range_percentage = 35;
        $price_temp = round($product-&gt;getFinalPrice() / 100 * $range_percentage);
        $price_from = $product-&gt;getFinalPrice() - $price_temp;
        $price_to = $product-&gt;getFinalPrice() + $price_temp;
  
        $categories = $product-&gt;getCategoryIds();
  
        $collection = $this-&gt;_productCollectionFactory-&gt;create();
        $collection-&gt;addAttributeToSelect('*')
          -&gt;addCategoriesFilter(['in' =&gt; $categories])
          -&gt;addPriceDataFieldFilter('%s &gt;= %s', ['min_price', $price_from])
          -&gt;addPriceDataFieldFilter('%s &lt;= %s', ['min_price', $price_to])
          -&gt;addMinimalPrice()
          -&gt;addAttributeToFilter('entity_id', ['neq' =&gt; $product-&gt;getId()])
          -&gt;addAttributeToFilter('status', ['in' =&gt; $this-&gt;productStatus-&gt;getVisibleStatusIds()])
          -&gt;setVisibility($this-&gt;productVisibility-&gt;getVisibleInSiteIds())
          -&gt;setPageSize(5);
  
        return $collection;
  
      } catch (\Exception $e) {
  
        var_dump($e-&gt;getMessage());
      }
    }
  }
  </code></pre>
  
  <p><strong>Code above is updated with a working example</strong></p>
  
  <p>It will return a result with addtofieldfilter 'price' but it does not work with final_price attribute. I need to sort based on final_price because configurable products don't have a price. The code returns: invalid attribute name.</p>
  
  <p>How can I filter on price range in final_price attribute?</p>
  
  <p>Thanks,</p>