Skip to content

Product Ask Questions

This webcomponent is responsible for rendering a form that allows to send questions related to a given product. To render form fields we have to add a child element with a slot="form" attribute which contains necessary form fields.

Attributes

Attribute name Type Default Required Description
product-id string '' yes Id of the product we want to ask questions for
module-instance-id string '' yes Unique identifier commonly provided by a special module variable moduleInstance

Example

Here is an example of rendering a simple product-ask-questions form.

If using this macro inside a module we can pass a moduleInstance as the module-instance-id attribute.

To get the product id we use the getProduct() method from ObjectApi. Keep in mind that this method is only available withing a product card. If you wish to use this webcomponent for example on a product list page then the getProducts() method will be more suitable for you.

To get the necessary form fields we use the product_ask_questions_form macro.

Twig
    {% set product = ObjectApi.getProduct(product_id) %}

    <product-ask-questions
        module-instance-id="{{ moduleInstance }}"
        product-id="{{ product.id }}"
    >
        <div slot="form">
            {{ product_ask_questions_form({ instanceId: options.instanceId }) }}
        </div>
    </product-ask-questions>

Macros reference

ObjectApi methods reference