magento2-functional-testing-framework icon indicating copy to clipboard operation
magento2-functional-testing-framework copied to clipboard

Set custom product attributes

Open snez opened this issue 3 years ago • 2 comments

There seems to be no documentation on how to set custom product attributes through entity data. I searched through the example tests and tried a few things to no avail.

Preconditions

  1. MFTF v3

Steps to reproduce

  1. Create custom attribute entity
    <entity name="SubscriptionIsEnabled" type="custom_attribute">
        <data key="attribute_code">sub_enabled</data>
        <data key="value">1</data>
    </entity>
  1. Create a product entity
    <entity name="SubscriptionProduct" extends="SimpleProduct">
        <data key="name">Simple Subscription</data>
        <data key="sku" unique="suffix">simple-trial-2</data>
        <data key="urlKey" unique="suffix">simple-trial-2</data>
        <requiredEntity type="custom_attribute">SubscriptionIsEnabled</requiredEntity>
    </entity>
  1. Create the product in a <before> block of a Suite
    <createData entity="SubscriptionProduct" stepKey="createSubscriptionProduct">
        <requiredEntity createDataKey="createCategory"/>
    </createData>

Expected result

  1. The product's sub_enabled custom attribute should be set

Actual result

  1. The attribute is not set

snez avatar Jun 10 '21 13:06 snez

Hi @snez. Thank you for your report. To help us process this issue please make sure that you provided sufficient information.

Please, add a comment to assign the issue: @magento I am working on this


m2-assistant[bot] avatar Jun 10 '21 13:06 m2-assistant[bot]

@snez Ran into this as well trying to set product custom attribute on product test entity. Using custom_attribute_array instead of custom_attribute for type worked in my case for a "yes/no" custom attribute

    <entity name="SubscriptionProduct" extends="SimpleProduct">
        <data key="name">Simple Subscription</data>
        <data key="sku" unique="suffix">simple-trial-2</data>
        <data key="urlKey" unique="suffix">simple-trial-2</data>
-        <requiredEntity type="custom_attribute">SubscriptionIsEnabled</requiredEntity>
+        <requiredEntity type="custom_attribute_array">SubscriptionIsEnabled</requiredEntity>
    </entity>

sdaugherty-af avatar Jan 23 '24 17:01 sdaugherty-af