Skip to content

[Question] Overwrite CartStockAvailabilityValidator #2419

@lukadschaak

Description

@lukadschaak
Q A
Bug report? no
Feature request? no
BC Break report? no
RFC? no
Question yes

Moin!
We are currently working on overriding some validators for the checkout. For various reasons. In one case we have a sort of sub items whose stock we also want to validate. So we would like to override the CartStockAvailabilityValidator.

What is the best way to do this? In the checkout steps, the order is validated in its entirety, and the contraints for this are configured here.

# src/CoreShop/Bundle/CoreBundle/Resources/config/validation/Order.yml
CoreShop\Component\Core\Model\Order:
    constraints:
        - \CoreShop\Bundle\CoreBundle\Validator\Constraints\CartStockAvailability: { groups: ['coreshop'] }
        - \CoreShop\Bundle\CoreBundle\Validator\Constraints\CartMinimumQuantity: { messageBelowMinimum: 'coreshop.cart_item.quantity_below_min_limit', groups: ['coreshop'] }
        - \CoreShop\Bundle\CoreBundle\Validator\Constraints\CartMaximumQuantity: { messageAboveMaximum: 'coreshop.cart_item.quantity_above_max_limit', groups: ['coreshop'] }

Unfortunately, we cannot replace validators. The configuration can only be extended, but not overwritten. Do we have to decorate the class now or what would be the best practice?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions