Sylius: Extend CartItemType from CoreBundle (v1.0.0-alpha)

Created on 4 Nov 2016  路  8Comments  路  Source: Sylius/Sylius

Hi (again), I'd like to extend the CartItemType to add some fields to it.

Before, I had to override the sylius_cart config, but it's not available anymore since v1.0.0-alpha. Do I have to use the CompilerPass to override the CoreBundle's services ? Or is there an option that I missed ?

Shouldn't this be possible under the sylius_order config ?

DX Documentation Feature Stale

Most helpful comment

@TheMadeleine configuration is no longer exposed for sylius_cart*, due to the merge of Order & Cart bundles. We should absolutely make these configurable again. :/

All 8 comments

As far as I understand your question, you want to override OrderItem :

sylius_order:
    resources:
        order_item:
            classes:
                model: My\WebBundle\Entity\OrderItem
                form:
                    default: My\WebBundle\Form\Type\OrderItemType

Thanks for taking the time to answer.

At first I tried to override the OrderItemType but then I realized that it's not this one that is rendered in the product view. It's the CartItemType (see SyliusShopBundle/Resources/config/routing/cart.yml).

This form comes from SyliusCoreBundle/Form/Type/Order/CartItemType.
And it's registered in SyliusCoreBundle/Resources/config/services/form.xml.

For now, I had to override it via a CompilerPass like this :

public function process(ContainerBuilder $container)
{
    $definition = $container->getDefinition('sylius.form.type.cart_item');
    $definition->setClass('AppBundle\Form\Type\CartItemType');
}

Doesn't it work that way istead of using a Compiler Pass?

@TheMadeleine configuration is no longer exposed for sylius_cart*, due to the merge of Order & Cart bundles. We should absolutely make these configurable again. :/

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in a week if no further activity occurs. Thank you for your contributions.

I believe this was never fixed.

@teohhanhui can't it be done with form type extension?

Yes, form type extensions work just fine. But otherwise if you want to replace the form type, I guess one could just replace the sylius.form.type.cart_item service? Haha...

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mezoni picture mezoni  路  3Comments

mikemix picture mikemix  路  3Comments

inssein picture inssein  路  3Comments

bnd170 picture bnd170  路  3Comments

javiereguiluz picture javiereguiluz  路  3Comments