Jump to content

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


minanj12

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.

 

Link to comment
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.

Link to comment
Share on other sites

  • 2 weeks later...

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
Link to comment
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

Link to comment
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.
Link to comment
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

Link to comment
Share on other sites

  • 6 months later...
  • 2 weeks later...
  • 3 months later...
  • 1 month later...
  • 9 months later...

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();

Link to comment
Share on other sites

  • 9 months later...
On 4/18/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

I had the same problem and this file has solved it for me. Thank you.

The only thing to change is on line 73 and 74

What do you think of this other modification?
https://github.com/PrestaShop/PrestaShop/pull/10373/files

Just adding $ address-> save ();

I have not tried this but would it be correct?

Thank you.

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...