Jump to content

Cart form page 2 adress manditory field not correct PS 1.7.8.11


Frevab

Recommended Posts

I recently upgrade to 1.7.8.11 but discovered after a few complaints from customers that the required/optional fields are not show correctly.

In debug mode I get this error in Front office:

[PrestaShopException]

Property Address->phone is empty.
at line 1046 in file classes/ObjectModel.php

1041.             }
1042.
1043.             $message = $this->validateField($field, $this->$field);
1044.             if ($message !== true) {
1045.                 if ($die) {
1046.                     throw new PrestaShopException($message);
1047.                 }
1048.
1049.                 return $error_return ? $message : false;
1050.             }
1051.         }

    ObjectModelCore->validateFields - [line 293 - classes/ObjectModel.php]
    ObjectModelCore->getFields - [line 578 - classes/ObjectModel.php]
    ObjectModelCore->add - [line 192 - classes/Address.php] - [2 Arguments]
    AddressCore->add - [line 535 - classes/ObjectModel.php] - [2 Arguments]
    ObjectModelCore->save - [line 71 - classes/form/CustomerAddressPersister.php]
    CustomerAddressPersisterCore->save - [line 158 - classes/form/CustomerAddressForm.php] - [2 Arguments]
    CustomerAddressFormCore->submit - [line 90 - classes/checkout/CheckoutAddressesStep.php]
    CheckoutAddressesStepCore->handleRequest - [line 76 - classes/checkout/CheckoutProcess.php] - [1 Arguments]
    CheckoutProcessCore->handleRequest - [line 229 - controllers/front/OrderController.php] - [1 Arguments]
    OrderControllerCore->initContent - [line 306 - classes/controller/Controller.php]
    ControllerCore->run - [line 525 - classes/Dispatcher.php]
    DispatcherCore->dispatch - [line 28 - index.php]


In my cart page 2 only the fields Company, Address2 Line and Phone are shows with text "Optional" but apparantly Phone should be filled. If not customer gets server 500 error (which is not goods for business!).

In previous version of PS you could set which fields are mandatory and which not.
How can I fix this ?


Small addition: as customer sometime forget to leave their house number, I changed the text of 2nd address line to "house number"and made it mandatory to force them to leave their house number. Saves a lot of extra communications with customer.

I found this in classes/Address.php

    /**
     * @see ObjectModel::$definition
     */

    // when you override this class, do not create a field with allow_null=>true
    // because it will give you exception on checkout address step
    public static $definition = [
        'table' => 'address',
        'primary' => 'id_address',
        'fields' => [
            'id_customer' => ['type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_post' => false],
            'id_manufacturer' => ['type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_post' => false],
            'id_supplier' => ['type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_post' => false],
            'id_warehouse' => ['type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_post' => false],
            'id_country' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true],
            'id_state' => ['type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId'],
            'alias' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true, 'size' => 32],
            'company' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 255],
            'lastname' => ['type' => self::TYPE_STRING, 'validate' => 'isName', 'required' => true, 'size' => 255],
            'firstname' => ['type' => self::TYPE_STRING, 'validate' => 'isName', 'required' => true, 'size' => 255],
            'vat_number' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName'],
            'address1' => ['type' => self::TYPE_STRING, 'validate' => 'isAddress', 'required' => true, 'size' => 128],
            'address2' => ['type' => self::TYPE_STRING, 'validate' => 'isAddress', 'size' => 128],
            'postcode' => ['type' => self::TYPE_STRING, 'validate' => 'isPostCode', 'size' => 12],
            'city' => ['type' => self::TYPE_STRING, 'validate' => 'isCityName', 'required' => true, 'size' => 64],
            'other' => ['type' => self::TYPE_STRING, 'validate' => 'isMessage', 'size' => 300],
            'phone' => ['type' => self::TYPE_STRING, 'validate' => 'isPhoneNumber', 'size' => 32],
              'phone_mobile' => ['type' => self::TYPE_STRING, 'validate' => 'isPhoneNumber', 'size' => 32],

            'dni' => ['type' => self::TYPE_STRING, 'validate' => 'isDniLite', 'size' => 16],
            'deleted' => ['type' => self::TYPE_BOOL, 'validate' => 'isBool', 'copy_post' => false],
            'date_add' => ['type' => self::TYPE_DATE, 'validate' => 'isDate', 'copy_post' => false],
            'date_upd' => ['type' => self::TYPE_DATE, 'validate' => 'isDate', 'copy_post' => false],
        ],
    ];

But the lines of interest do not mention 'required' => true.

Any help is much appreciated.

Link to comment
Share on other sites

On 5/13/2025 at 3:08 PM, Frevab said:

Thank your reply but none of these are ticked in my backoffice but still get the server error because phone is empty.

You can check your overrides. It might be possible that any module is overriding the Address class definition.

Link to comment
Share on other sites

  • 2 weeks later...

I do not see any overrides. In the overrides folder are only index.php files. Only one override for contactform for reCAPTCHA

modules/contactform/contactform.php and
classes/controller/FrontController.php

 

Now I discover I cannot open the orders in the back office and I do not get any email alerts of new orders.

I get this error

Level     Channel     Message
INFO 01:18:44     request     Matched route "admin_addresses_edit".
DEBUG 01:18:44     security     Read existing security token from the session.
DEBUG 01:18:44     security     User was reloaded from a user provider.
INFO 01:18:44     php     User Deprecated: Not specifying the optional ShopConstraint parameter is deprecated since version 1.7.8.0
INFO 01:18:44     php     User Deprecated: Not specifying the optional ShopConstraint parameter is deprecated since version 1.7.8.0
INFO 01:18:44     php     User Deprecated: Not specifying the optional ShopConstraint parameter is deprecated since version 1.7.8.0
INFO 01:18:44     php     User Deprecated: Not specifying the optional ShopConstraint parameter is deprecated since version 1.7.8.0
INFO 01:18:44     php     User Deprecated: Not specifying the optional ShopConstraint parameter is deprecated since version 1.7.8.0
INFO 01:18:44     php     User Deprecated: Creating Doctrine\ORM\Mapping\UnderscoreNamingStrategy without making it number aware is deprecated and will be removed in Doctrine ORM 3.0.
INFO 01:18:44     php     User Deprecated: Not specifying the optional ShopConstraint parameter is deprecated since version 1.7.8.0
CRITICAL 01:18:44     php     Type error: Argument 11 passed to PrestaShop\PrestaShop\Core\Domain\Address\QueryResult\EditableCustomerAddress::__construct() must be of the type string, null given, called in /var/www/vhosts/xxxxxx.nl/httpdocs/xxxxxx.nl/src/Adapter/Address/QueryHandler/GetCustomerAddressForEditingHandler.php on line 95
INFO 01:18:44     php     User Deprecated: Implementing "Symfony\Component\HttpKernel\DataCollector\DataCollectorInterface" without the "reset()" method is deprecated since Symfony 3.4 and will be unsupported in 4.0 for class "Csa\Bundle\GuzzleBundle\DataCollector\GuzzleCollector".
CRITICAL 01:18:44     request     Uncaught PHP Exception Symfony\Component\Debug\Exception\FatalThrowableError: "Type error: Argument 11 passed to PrestaShop\PrestaShop\Core\Domain\Address\QueryResult\EditableCustomerAddress::__construct() must be of the type string, null given, called in /var/www/vhosts/zzzzzz.nl/httpdocs/zzzzzz.nl/src/Adapter/Address/QueryHandler/GetCustomerAddressForEditingHandler.php on line 95" at /var/www/vhosts/zzzzzz.nl/httpdocs/zzzzzz.nl/src/Core/Domain/Address/QueryResult/EditableCustomerAddress.php line 155

 

which looks like again a problem with the address fields that are mandatory to be filled and which not.

In the back office at customer addresses I have only ticked postcode and phone. The others listed are not ticked.

When I go into the database ps_address table and unselect the fields that are not filled but are ticked I can access the order in the b/o again.

Where is this problem coming from. Never had this in the 10+ years I am using PS.

Since the last upgrade to 1.7.8.11 this has changed (running on PHP-version: 7.4.33 and MySQL version: 10.11.11-MariaDB-cll-lve

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...