Sylius: Customizing a Modal

Created on 10 Jul 2018  ·  6Comments  ·  Source: Sylius/Sylius

Sylius version affected: 1.2.2

Description
I can’t update a dabasebase before overriding Country Modal a system returned this error

In MappingException.php line 340:

Class “AppBundle\Entity\Country” sub class of “Sylius\Component\Addressing
Model\Country” is not a valid entity or mapped super class.

i was defined a Country.orm.yml

note: it is a same exemple in the doc

http://docs.sylius.com/en/1.2/customization/model.html1

Most helpful comment

I have run into the same problem, and backtraced it to the missing ORM annotations. The Country in the Customization guide could be updated to include the ORM annotations like this:

<?php

namespace AppBundle\Entity;

use Sylius\Component\Addressing\Model\Country as BaseCountry;
use Sylius\Component\Addressing\Model\CountryInterface;
use Doctrine\ORM\Mapping as ORM;

/**
 * Class Country
 * @package AppBundle\Entity
 * @ORM\Table(name="sylius_country")
 * @ORM\Entity
 */
class Country extends BaseCountry implements CountryInterface {
    /**
     * @var bool
     * @ORM\Column(name="flag", type="boolean")
     */
    private $flag;

    /**
     * @return bool|null
     */
    public function getFlag(): ?bool {
        return $this->flag;
    }

    /**
     * @param bool $flag
     */
    public function setFlag(bool $flag): void {
        $this->flag = $flag;
    }
}

All 6 comments

Hello @ChafikHadjAbdouRazack and welcome to the community! Sylius issues should be used to report bugs, propose new features, discuss new functionalities. For everything else, please, use our Slack (preferred) or forum ;) We have a very active, developed community, I'm sure someone will be able to help you with your problem. With this problem, I guess you're missing the sylius_resource configuration, but it's just a blink shot. Good luck :)

I have run into the same problem, and backtraced it to the missing ORM annotations. The Country in the Customization guide could be updated to include the ORM annotations like this:

<?php

namespace AppBundle\Entity;

use Sylius\Component\Addressing\Model\Country as BaseCountry;
use Sylius\Component\Addressing\Model\CountryInterface;
use Doctrine\ORM\Mapping as ORM;

/**
 * Class Country
 * @package AppBundle\Entity
 * @ORM\Table(name="sylius_country")
 * @ORM\Entity
 */
class Country extends BaseCountry implements CountryInterface {
    /**
     * @var bool
     * @ORM\Column(name="flag", type="boolean")
     */
    private $flag;

    /**
     * @return bool|null
     */
    public function getFlag(): ?bool {
        return $this->flag;
    }

    /**
     * @param bool $flag
     */
    public function setFlag(bool $flag): void {
        $this->flag = $flag;
    }
}

Using annotation by default would make all the project lighter and easer to extend and understand.
Also is pretty strange that the doc suggest for yml file orm, but the default one are in xml!
This make it a bit harder to work with.

Also:
Symfony docs say that yml have the same speed of xml, but also symfony docs say to use annotation if possible in the latest best practice pdf for symfony 4.

I faced with the same issue but in version 1.3.4, but when I use annotation method everything works. Issue is only when I use .orm.yml file.
Please provide the solution for this issue.

Documentation (https://docs.sylius.com/en/1.3/customization/model.html?highlight=mapped%2520superclass) uses different locations , for example:
1) App/Resources/config/doctrine/Country.orm.yml
2) src/Resources/config/doctrine/ShippingMethodTranslation.orm.yml

As you can see App and src!!!
Where is the mistake?

Documentation (https://docs.sylius.com/en/1.3/customization/model.html?highlight=mapped%2520superclass) uses different locations , for example:

  1. App/Resources/config/doctrine/Country.orm.yml
  2. src/Resources/config/doctrine/ShippingMethodTranslation.orm.yml

As you can see App and src!!!
Where is the mistake?

Should be:
/src/Resources/config/doctrine/Country.orm.yml

On 1.2 version or earlier, it uses yml by default. But on 1.3, it uses annotation instead.
Since I need to upgrade from 1.2 to 1.3, I have changed the settings of:
\config\packages\doctrine.yaml
on type and dir:

    orm:
        auto_generate_proxy_classes: '%kernel.debug%'
        auto_mapping: true
        mappings:
            App:
                is_bundle: false
                #type: annotation
                type: yml
                #dir: '%kernel.project_dir%/src/Entity'
                dir: '%kernel.project_dir%/src/Resources/config/doctrine'
                prefix: 'App\Entity'
                alias: App

Without adding annotation, there would be warning message instead of error message.

Migration file generated correctly.

But if using annotation is the best practice of Symfony 4, I'll add back the annotation.

Strongly suggest Sylius team to update 1.3 doc with annotation sample.

Was this page helpful?
0 / 5 - 0 ratings