1

Is there a way in disabling a product by checking its custom attribute?

example scenario: 'date_expiration' if date_expiration < today the product status will be disabled.

I have tried creating a custom front_end template for Magento_Catalog, that checks attribute date_expiration when expiration met it will redirect to homepage. I know this is not good solution because it will appear on catalog list.

2 Answers 2

1

You can write a event for this in your module config.xml :

    <frontend>
    <event>
        <catalog_product_is_salable_after>
            <observer>
                <any_name>
                    <class>yourmodule/observer</class>
                    <method>yourMethodName</method>
                </any_name>
            </observer>
        </catalog_product_is_salable_after>
    </event>
</frontend>

and in module observer file you have to write your method

    public function yourMethodName($observer)
    {
    $product = $observer->getProduct();
    $salable = $observer->getSalable(); 
    $date_expiration = $product->getDateExpiration()
    if( your logic for stop showing product)
    {
        $salable->setIsSalable(false);
    }
    return $this;
    }
0

Yes, you need to override product listing block and filter the collection with your custom attribute value.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.