sql - Updating customer's address works in Observer.php, fails in custom PHP file -


i've connected ajax call event on changing customer's address in checkout. supposed update 1 field in customer's address.

require('../../../../mage.php'); umask(0); mage::app();  $newcontactologyclientid = $_post['contactologyclientid'];  $customerdefaultaddressid = mage::getsingleton('customer/session')->getcustomer()->getdefaultshipping(); $customeraddress = mage::getmodel('customer/address'); $customeraddress = $customeraddress->load($customerdefaultaddressid);   $_new_address = array (     'contactology_client_id' => "$newcontactologyclientid"     );  $customeraddress->adddata($_new_address); $customeraddress->implodestreetaddress()->save(); 

on javascript side ok, won't include here. posted code responsible database update works when fired in module's observer.php on magento event (sales_quote_save_after), when run via ajax error:

uncaught exception 'pdoexception' message 'sqlstate[23000]:  integrity constraint violation: 1452 cannot add or update child row:  foreign key constraint fails (`mag6`.`customer_address_entity`,  constraint `fk_customer_address_entity_parent_id_customer_entity_entity_id`  foreign key (`parent_id`) references `customer_entity` (`entity_id`)  on delete cas)' in c:\(...)\pdo.php:228 

the line causes error last 1 naturally:

$customeraddress->implodestreetaddress()->save(); 

so reckon if database operation works in observer.php , doesn't in custom oncheckoutaddressedit.php, because including mage:app() not enough , need require additional classes, no idea one.

i missing:

mage::run($mageruncode, $mageruntype); 

looking @ code, looks $customerdefaultaddressid returns null, customer session must not instatiated properly.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -