Jump to content
minanj12

Customer Error: Property Address->id_country is empty. at line 944 in file classes/ObjectModel.php

Recommended Posts

Hello,

 

When a customers tries to checkout they get an error after they type the address. It seems like it's throwing this error because the customer isn't entering a country. The problem is it doesn't ask for a country. It just asks for a state, zip code etc. I sell only for U.S. customers so I don't really care if they enter the country or not.

Regardless I want this to work. Can you someone help? Thanks in advance.

 

 

 

[PrestaShopException]

Property Address->id_country is empty.
at line 944 in file classes/ObjectModel.php

939. }
940.
941. $message = $this->validateField($field, $this->$field);
942. if ($message !== true) {
943. if ($die) {
944. throw new PrestaShopException($message);
945. }
946. return $error_return ? $message : false;
947. }
948. }
949.

 

Share this post


Link to post
Share on other sites

What version of Prestashop?  Be specific

Are you using the standard theme included with Prestashop, or a custom theme?  If you are using a custom theme, then contact your theme provider for support

 

If you are using the standard theme, did you make changes to it?  The standard theme will always ask for the address Country, as it is a required field.

Share this post


Link to post
Share on other sites

Hello,

 

I have a similary problem with a customer on prestashop 1.7.2.2., have you got a solution to this problem?

 

Thanks for your help Yoan.

Are you using the standard theme included with Prestashop, or a custom theme?

Share this post


Link to post
Share on other sites

Hello, 

 

My client uses a theme that he has customized himself and how to see if he has spawned an error. For my part I am an integrator and not a developer so I lose a lot of time since Monday on this worry.

 

I just did a test with the shopping cart of a customer who did not order, it marks that the address can not be delivered, while his country and zone are correct, but I think that again is due to the address that does not pass.

 

There is currently this error message as well.

 

 

Frontcontroller::init - Cart cannot be loaded or an order has already been placed using this cart Frontcontroller::init - Cart cannot be loaded or an order has already been placed using this cart

Share this post


Link to post
Share on other sites

That message is just a warning, doesn't actually cause an issue

 

Well, it would seem that your client likely broke something in the theme, by not properly capturing the country for the address.  Not really an issue that can be solved in a forum post, someone is going to have to dive into the code and see what was removed

Share this post


Link to post
Share on other sites

Hello,

 

Many thanks for your return.

 

My client has apparently changed the addresses.tpl file, this can be the source of the problem.
 
Comparing the two files the only differences are at this level:
 
In the "cakelicious theme" there is a hook more ...
 
      {hook h = "displayCartRuleAddress"} {if $ use_same_address &&! $ cart.is_virtual}
Classic Version
      {if $ use_same_address &&! $ cart.is_virtual}
 
 
For the position of the button, nothing serious here, o)
 
The class of the last button is different. Here the version "theme cakelicious"
 
      {if! $ form_has_continue_button}
        <div class = "clearfix">
          <button type = "submit" class = "btn btn-primary continue pull-xs-right" name = "confirm-addresses" value = "1">
              {l s = 'Continue' d = 'Shop.Theme.Actions'}
          </ Button>
        </ Div>
      {/ If}
 
The class of the last button is different. Here the version "Classic"
 
      {if! $ form_has_continue_button}
        <div class = "clearfix">
          <button type = "submit" class = "btn-primary continuous float-xs-right" name = "confirm-addresses" value = "1">
              {l s = 'Continue' d = 'Shop.Theme.Actions'}
          </ Button>
        </ Div>
      {/ If}
 
If an developer can give me a helping hand because I admit to rowing for 5 days on this problem and do not know how to get out, I can transmit ftp, mysql and backoffice access in mp if necessary to access the site test in order to look at this.
 
In thanking you in advance, most cordially, Yoan.

Share this post


Link to post
Share on other sites

For starters, I would suggest installing a free theme and activate it.  If the issue was caused by the client changing the theme, then installing a new theme should fix the issue.

 

If it doesn't fix the issue, then you would need to start going through the server side code looking for changes, which can include changes to modules, or perhaps the addition of a custom module that is interfering with customer/address creation

Share this post


Link to post
Share on other sites
Hello,

 

Sorry for my late return, so the problem is random and does not happen every time, that's what let me think more of a coding error in the modifications of the theme, than a module problem.

 

Is there a tool to analyze the files of a theme see if there are no code errors in it?

 

Regards,

Share this post


Link to post
Share on other sites
On 18/4/2018 at 11:28 AM, ITIS-Commerce.com said:

Hi,

This a bug from prestashop.

Change the file  \classes\form\CustomerAddressPersister.php  by the one attached

CustomerAddressPersister.zip

 

Thank you sooo much! That worked for me!

 

Share this post


Link to post
Share on other sites

Hi,

I am getting same error after upgrading to php 7.

I am using prestashop version 1.6.

in 1.6 version there is no such class as form\CustomerAddressPersister.php

thanks,

husein

Edited by husein522 (see edit history)

Share this post


Link to post
Share on other sites

this is the error

 

[PrestaShopException]

Property Address->id_country is empty
at line 909 in file classes/ObjectModel.php

904. } 905. 906. $message = $this->validateField($field, $this->$field); 907. if ($message !== true) { 908. if ($die) { 909. throw new PrestaShopException($message); 910. } 911. return $error_return ? $message : false; 912. } 913. } 914.

ObjectModelCore->validateFields - [line 246 - classes/ObjectModel.php]

241. * @return array All object fields 242. * @throws PrestaShopException 243. */ 244. public function getFields() 245. { 246. $this->validateFields(); 247. $fields = $this->formatFields(self::FORMAT_COMMON); 248. 249. // For retro compatibility 250. if (Shop::isTableAssociated($this->def['table'])) { 251. $fields = array_merge($fields, $this->getFieldsShop());

ObjectModelCore->getFields - [line 487 - classes/ObjectModel.php]

482. 483. // Database insertion 484. if (Shop::checkIdShopDefault($this->def['table'])) { 485. $this->id_shop_default = (in_array(Configuration::get('PS_SHOP_DEFAULT'), $id_shop_list) == true) ? Configuration::get('PS_SHOP_DEFAULT') : min($id_shop_list); 486. } 487. if (!$result = Db::getInstance()->insert($this->def['table'], $this->getFields(), $null_values)) { 488. return false; 489. } 490. 491. // Get object id in database 492. $this->id = Db::getInstance()->Insert_ID();

ObjectModelCore->add - [line 173 - classes/Address.php] - [2 Arguments]

168. /** 169. * @see ObjectModel::add() 170. */ 171. public function add($autodate = true, $null_values = false) 172. { 173. if (!parent::add($autodate, $null_values)) { 174. return false; 175. } 176. 177. if (Validate::isUnsignedId($this->id_customer)) { 178. Customer::resetAddressCache($this->id_customer, $this->id);

AddressCore->add - [line 445 - classes/ObjectModel.php] - [2 Arguments]

440. * @return bool Insertion result 441. * @throws PrestaShopException 442. */ 443. public function save($null_values = false, $auto_date = true) 444. { 445. return (int)$this->id > 0 ? $this->update($null_values) : $this->add($auto_date, $null_values); 446. } 447. 448. /** 449. * Adds current object to the database 450. *

ObjectModelCore->save - [line 212 - controllers/front/AddressController.php]

207. $this->ajaxDie(Tools::jsonEncode($return)); 208. } 209. } 210. 211. // Save address 212. if ($result = $address->save()) { 213. // Update id address of the current cart if necessary 214. if (isset($address_old) && $address_old->isUsed()) { 215. $this->context->cart->updateAddressId($address_old->id, $address->id); 216. } else { // Update cart address 217. $this->context->cart->autosetProductAddress();

AddressControllerCore->processSubmitAddress - [line 107 - controllers/front/AddressController.php]

102. * @see FrontController::postProcess() 103. */ 104. public function postProcess() 105. { 106. if (Tools::isSubmit('submitAddress')) { 107. $this->processSubmitAddress(); 108. } elseif (!Validate::isLoadedObject($this->_address) && Validate::isLoadedObject($this->context->customer)) { 109. $_POST['firstname'] = $this->context->customer->firstname; 110. $_POST['lastname'] = $this->context->customer->lastname; 111. $_POST['company'] = $this->context->customer->company; 112. }

AddressControllerCore->postProcess - [line 178 - classes/controller/Controller.php]

173. if (!$this->content_only && ($this->display_header || (isset($this->className) && $this->className))) { 174. $this->setMedia(); 175. } 176. 177. // postProcess handles ajaxProcess 178. $this->postProcess(); 179. 180. if (!empty($this->redirect_after)) { 181. $this->redirect(); 182. } 183.

ControllerCore->run - [line 367 - classes/Dispatcher.php]

362. if (isset($params_hook_action_dispatcher)) { 363. Hook::exec('actionDispatcher', $params_hook_action_dispatcher); 364. } 365. 366. // Running controller 367. $controller->run(); 368. } catch (PrestaShopException $e) { 369. $e->displayMessage(); 370. } 371. } 372.

DispatcherCore->dispatch - [line 28 - index.php]

23. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) 24. * International Registered Trademark & Property of PrestaShop SA 25. */ 26. 27. require(dirname(__FILE__).'/config/config.inc.php'); 28. Dispatcher::getInstance()->dispatch();

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More