OFFLINE-GmbH / oc-mall-plugin

:convenience_store: E-commerce solution for October CMS
https://offline-gmbh.github.io/oc-mall-plugin
MIT License
169 stars 114 forks source link

Is there A Way to Extend the Variants Form Fields? #755

Closed artistro08 closed 3 years ago

artistro08 commented 3 years ago

So I'm able to extend the products field into a new tab, but I am not able to dot the same for the variants.

Is there some sort of relation I'm missing? I couldn't find out how and my code is pretty standard.

My code

        VariantsController::extendFormFields(function ($form, $model, $context) {

            if (!$model instanceof VariantModel)
                return;

            $form->addTabFields([
                'printful_variant_id' => [
                    'label' => 'Printful Variant',
                    'tab' => 'Printful Variant',
                    'type' => 'text',
                    'span' => 'left'

                ],
                'printful_variant_placement' => [
                    'label' => 'Print Files',
                    'tab' => 'Printful Variant',
                    'type' => 'text',
                    'span' => 'right'

                ],
                'printful_variant_color' => [
                    'label' => 'Option ID',
                    'tab' => 'Printful Variant',
                    'type' => 'textarea',
                    'span' => 'left'
                ],
            ]);
        });
tobias-kuendig commented 3 years ago

The Variants form is loaded in a popup in the Products form, so you might have better luck extending the ProductsController.

artistro08 commented 3 years ago

I thought so, but wasn't entirely sure. If you could could you show me where to hook into the popup? I'm having trouble finding the documentation for it.

tobias-kuendig commented 3 years ago

Changing

-         VariantsController::extendFormFields(function ($form, $model, $context) {
+         ProductsController::extendFormFields(function ($form, $model, $context) {

should already do the trick. See if this method gets called with a Variant $model

artistro08 commented 3 years ago

It did. Thank you!