0

Within a node template I can retrieve the status of the published flag by calling the code: node.isPublished()

How do I retrieve the status of the published flag within a commerce product...

I've tried:

product.isPublished()
product.status
product.published

But I can't seem to get it to print. I've tried to look through the core code where status seems to be the key, but no luck, plus api.drupalcommerce.org is down.

Any advice?

Thanks in advance

3
  • IIRC product is the content render array, you probably want to look at elements['#commerce_product'].status
    – Clive
    Feb 20 '18 at 14:23
  • @Clive how would I access that from the product variable, product.elements['#commerce_product'].status?
    – cwiggo
    Feb 20 '18 at 14:28
  • Assuming you're in theme_commerce_product (standard entity view for commerce product) it's just elements['#commerce_product'].status
    – Clive
    Feb 20 '18 at 14:31
0

{% if product_entity.status.value == 0 %} {% set classes = [ 'is-unpublished' ] %} {% endif %} <article{{ attributes.addClass(classes) }}> .. </article>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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