cancel
Showing results for 
Search instead for 
Did you mean: 

Showing only products in special price

Showing only products in special price

I'm trying to show a product list in a block with this condition:
show only products that currently are in "special price"!
Can I do it programmatically? how to filter the product list?
For example, maybe I need to read two product information: the "original price" and the "final price" and if they differ then show the product!?.. but I'm newbe in magento 2 and I don't know how to made it.
Thanks in advance

10 REPLIES

Re: Showing only products in special price

Hi @girtri,

 

Could a widget work for your requirment?

 

--
If you've found one of my answers useful, please give "Kudos" or "Accept as Solution"

Re: Showing only products in special price

yes but how can I do it via widget?

a product list? but I didn't understand how to filter records

Re: Showing only products in special price

@girtri,

 

I didn't tried but maybe you can check this idea:

 

Edit your CMS page:

 

Área de trabajo 1_001.png

 

And insert a new widget.

Now you'll see a widget selection page.

 

Área de trabajo 1_002.png

 

Select the "Catalog Product List" widget.

These will be the options for this widget:

 

Área de trabajo 1_003.png

 

At the end you can set conditions. There you'll be able to set products with special price grather than or another types of rules.

Maybe you can use this feature to avoid the need of coding a new/custom widget type.

 

 

--
If you've found one of my answers useful, please give "Kudos" or "Accept as Solution"

Re: Showing only products in special price

thank you, I had looked at this possibility .. In fact my problem is how to set the rule:

what kind of condition can I set?

there are "placeholder / global variables" that can be inserted in the rule?

I'd like to use this rule (but I do not know if possible):

"Special price" is less than "regular price" (and obviously different from zero)

Re: Showing only products in special price

@girtri,

 

Maybe (as I said I didn't tried) you can set "where special price is grather than 1".

This should get allproducts with special price greater than value. If a product hasn't special price shouldn't be included (i guess).

Can you try that idea?

--
If you've found one of my answers useful, please give "Kudos" or "Accept as Solution"

Re: Showing only products in special price

We had a similar request recently. You can create the product collection as follows:

/** @var ProductCollection $productCollection */
$productCollection = $this->productCollectionFactory->create();

$productCollection
    ->setVisibility($this->catalogProductVisibility->getVisibleInCatalogIds())
    ->addMinimalPrice()
    ->addFinalPrice()
    ->addTaxPercents()
    ->addAttributeToSelect($this->catalogConfig->getProductAttributes())
    ->addUrlRewrite();
    ->addStoreFilter()
    ->addAttributeToSort(
        'minimal_price',
        'asc'
    );

$productCollection->getSelect()->where(
    'price_index.final_price < price_index.price'
);

If you want to support prices for children products, i.e. of grouped products, more work may be necessary. With this answer, I assume you know how to create a Block and use a Factory.

Andreas von Studnitz, Trainer, Consultant, Developer and CEO of integer_net, Germany.

Re: Showing only products in special price

Re: Showing only products in special price

Hi Damian.. " special price is grather than 1" it works.

It seems that solutions doesn't work with "Marketing\Catalog Price Rule" active but just if I edit a product and insert a special price.

Unfortunatly, because this way I have to edit edit every single product (with a rule I have not)

Re: Showing only products in special price

Thanks avstudnitz, your code works (like a condition "special price greater than 1" using a widget).

Does not work with a "catalog price rule" active. I can't understand this behavior in magento:

I can see products that correspond to the rule with a discounted price but in $productCollection they have the "price" and the "final_price" with the same value!

but it's not true! cause the price showed on the screen, resulting from the application of the rule, it's lower than regular price.

Is it possible that the collection also reads the discounted prices falling in a "catalog price rule"?