Setono / SyliusMailchimpPlugin

Mailchimp integration plugin for Sylius
MIT License
11 stars 14 forks source link

[BUG] Set $mailchimpState field as nullable #91

Open lamasfoker opened 1 year ago

lamasfoker commented 1 year ago

I think that \Setono\SyliusMailchimpPlugin\Model\MailchimpAwareTrait::$mailchimpState should be nullable and defined as below:

    /**
     * @var string
     *
     * @ORM\Column(type="string", nullable=true)
     */
    protected $mailchimpState = self::MAILCHIMP_STATE_PENDING;

In this way, this field of the entities (order and customer) already present on the DB will be null. It has to be null and not an empty string as is right now and I have explained the reason here.

getMailchimpState() and setMailchimpState() should be changed accordingly.

lamasfoker commented 1 year ago

This bug causes an error on the registration page. During the installation of the plugin, in the sylius_customer table will be added the mailchimpState column with the value empty string. If this customer tries to register after the installation and flags also the newsletter subscription checkbox an error will be present on the page. See the attached image.

screencapture-127-0-0-1-8000-it-IT-register-2023-01-25-16_45_33

lamasfoker commented 1 year ago

Another solution is to put these queries in the migration files:

UPDATE sylius_order SET mailchimpState = 'pending' WHERE mailchimpState = '';
UPDATE sylius_customer SET mailchimpState = 'pending' WHERE mailchimpState = '';

This way, the previous orders and customers can conform to the plugin workflow.