1

I have a field named 'soldout_date' in product form. If it has null value then i don't want to show the field in the form. But if it has some value then how to show?? I am using productmodifiers.

public function getSoldOutDate(array $options = [])
    {
        return array_replace_recursive(
            [
                'arguments' => [
                    'data' => [
                        'config' => [
                            'label' => __('SoldOut Date'),
                            'componentType' => Field::NAME,
                            'formElement' => Date::NAME,
                            'dataScope' => 'soldout_date',
                            'dataType' => Text::NAME,
                            'sortOrder' => 10,
                            'disabled' => true,
                        ],
                    ],
                ],
            ],
            $options
        );
    }

form field: https://i.stack.imgur.com/2IJGj.png

1 Answer 1

1

Try the below code:

public function getSoldOutDate(array $options = [])
{
    $product = $this->locator->getProduct();

    $disabled =  ($product->getSoldOutDate()) ? false : true;
    return array_replace_recursive(
        [
            'arguments' => [
                'data' => [
                    'config' => [
                        'label' => __('SoldOut Date'),
                        'componentType' => Field::NAME,
                        'formElement' => Date::NAME,
                        'dataScope' => 'soldout_date',
                        'dataType' => Text::NAME,
                        'sortOrder' => 10,
                        'disabled' => $disabled,
                    ],
                ],
            ],
        ],
        $options
    );
}

If your class does not have $this->locator yet, declare it by:

public function __construct(
    ...
    \Magento\Catalog\Model\Locator\LocatorInterface $locator
    ...
)
{
    $this->locator = $locator;
}
2
  • 1
    If this does not work for you, please add the full content of your productmodifiers class, and I'll continue helping you.
    – Tu Van
    Oct 28, 2022 at 12:33
  • Thank you its worked.
    – Alshihab
    Oct 31, 2022 at 4:15

Your Answer

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

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