简体   繁体   中英

Sonata ecommerce custom product admin

I am using sonata e commerce bundle and I have added a couple of products. I can get them list and displayed in the admin section but when I try to create a new product I only see the basic field that all the products have.

Is there any way to create an Admin class that will allow me to see the extra fields for each kind of product class?

I finally figured out how to do this looking into the sonata sandbox example. To add the custom fields to the product in the admin I have to override the WineProductProvider class and add the following method just like an admin class.

 /**
 * {@inheritDoc}
 */
public function buildEditForm(FormMapper $formMapper, $isVariation = false)
{
    parent::buildEditForm($formMapper, $isVariation);

    $formMapper
        ->with('Bottle details')
            ->add('origin','text')
            ->add('year','integer')
            ->add('grapes','text')
            ->add('closure','text')
            ->add('food','text')
            ->add('style','text')
            ->add('size','integer');


    $formMapper->end();
}

And thats it. Hope it helps someone else.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM