0
votes

I'm trying to set Sonata Bundles Ecommerce on Symfony 2.3.

I followed install steps mentionned here but I'm getting an error when trying to load my page requesting app_dev.php.

Here is the error

FatalErrorException: Compile Error: Declaration of Sonata\ProductBundle\Entity\BaseProduct::validateOneMainCategory() must be compatible with Sonata\Component\Product\ProductInterface::validateOneMainCategory(Symfony\Component\Validator\Context\LegacyExecutionContext $context) in /xxx/xx/xx/xxxx/vendor/sonata-project/ecommerce/src/ProductBundle/Entity/BaseProduct.php line 28

Can anyone help me to solve this ?

2

2 Answers

0
votes

I get this error message before using sonata admin bundle i think that you shoold pay attention for the uses statement at the top of the your file.You neeed to add the appropriate use statement.Look on the ProductInterface you will find the right file to use.

0
votes

I have this in ProductInterface

    use Symfony\Component\Validator\Context\LegacyExecutionContext;

/**
     * Validates if product has one main category
     *
     * @param LegacyExecutionContext $context
     *
     * @return void
     */
    public function validateOneMainCategory(LegacyExecutionContext $context);

And in BaseProduct.php

use Symfony\Component\Validator\ExecutionContext;

   /**
     * {@inheritdoc}
     */
    public function validateOneMainCategory(LegacyExecutionContext $context)
    {
        if ($this->getCategories()->count() == 0) {
            return;
        }

        if (!$this->hasOneMainCategory()) {
            $context->addViolation('sonata.product.must_have_one_main_category');
        }
    }