每个人,
我的Prestashop中有一个商店界面模块由朋友开发。我有症状阻滞剂可供使用。我现在无法与朋友联系,我需要解决这个问题。
在我的模块中,我有:
- 控制器,用于所有功能(添加客户,添加购物车,将购物车转换为订单等)
- 用于所有Ajax调用的Javascript文件
当我想添加客户并验证表单时,未分配给购物车。我用Chrome开发工具查看了ajax调用,我看到了:
在createCustomer调用之后,必须调用函数assignCustomer,但不能调用。
您可以在createCustomer和assignCustomer函数下面找到:
public function ajaxProcessCreateCustomer(){
// Collecting datas form
$lastname = Tools::getValue('lastname');
$firstname = Tools::getValue('firstname');
$id_gender = Tools::getValue('gender');
$postcode = Tools::getValue('postcode');
$address1 = Tools::getValue('address1');
$address2 = Tools::getValue('address2');
$city = Tools::getValue('city');
$phone = Tools::getValue('phone');
$phone_mobile = Tools::getValue('mobile');
$email = Tools::getValue('email');
$id_country = Tools::getValue('country');
$newsletter = Tools::getValue('newsletter');
// Create new customer only if we get at least postcode
if(!empty($postcode)){
$this->create_account = true;
if(!Tools::getValue('is_new_customer', 1))
$_POST['passwd'] = md5(time()._COOKIE_KEY_);
if(empty($email)){
$email = "part.part@example.com";
}
else {
// Checked the user address in case he changed his email address
if(Validate::isEmail($email) && !empty($email))
if(Customer::customerExists($email))
Caisse::$errors[] = Tools::displayError('E-mail address already used.', false);
}
// Preparing customer
$customer = new Customer();
if(!count(Caisse::$errors)){
$customer->id_gender =(!empty($id_gender) ? $id_gender : 1);
$customer->firstname =(!empty($firstname) ? ucwords($firstname) : ' ');
$customer->lastname =(!empty($lastname) ? ucwords($lastname) : ' ');
$customer->newsletter =(!empty($newsletter) ? $newsletter : 0);
$customer->passwd = md5(time()._COOKIE_KEY_);
$customer->email = $email;
$customer->is_guest = 0;
$customer->active = 1;
if($customer->add()){
$customer->cleanGroups();
$customer->addGroups(array(3,4));
if(!empty($address1) || !empty($postcode) || !empty($phone) || !empty($phone_mobile)){
$address = new Address();
$address->id_customer =(int)$customer->id;
$address->alias = "Mon adresse";
$address->lastname =(!empty($lastname) ? $lastname : ' ');
$address->firstname =(!empty($firstname) ? $firstname : ' ');
$address->address1 =(!empty($address1) ? $address1 : ' ');
$address->address2 =(!empty($address2) ? $address2 : ' ');
$address->postcode =(!empty($postcode) ? $postcode : ' ');
$address->phone =(!empty($phone) ? $phone : ' ');
$address->phone_mobile =(!empty($phone_mobile) ? $phone_mobile : ' ');
$address->id_country = $id_country;
$address->id_state = 0;
$address->city =(!empty($city) ? $city : ' ');
if($address->id_country == Country::getByIso('US') && Configuration::get('PS_TAASC')){
include_once(_PS_TAASC_PATH_.'AddressStandardizationSolution.php');
$normalize = new AddressStandardizationSolution;
$address->address1 = $normalize->AddressLineStandardization($address->address1);
$address->address2 = $normalize->AddressLineStandardization($address->address2);
}
if(!($country = new Country($address->id_country)) || !Validate::isLoadedObject($country))
Caisse::$errors[] = Tools::displayError('Country cannot be loaded with address->id_country');
if($country->need_identification_number &&(!Tools::getValue('dni') || !Validate::isDniLite(Tools::getValue('dni'))))
Caisse::$errors[] = Tools::displayError('The identification number is incorrect or has already been used.');
elseif(!$country->need_identification_number)
$address->dni = null;
$address->save();
$_POST['id_customer'] =(int)$customer->id;
Caisse::assignCustomer($customer->firstname.' '.$customer->lastname);
}
}
else{
Caisse::$errors[] = Tools::displayError('The account creation failed.');
}
}
}
else{
Caisse::$errors[] = Tools::displayError('Please, give at least the postal code.');
}
$this->dieCaisseAjax();
}
public function ajaxProcessAssignCustomer(){
Caisse::assignCustomer();
$this->dieCaisseAjax();
}
在我的javascript中,功能如下:
.result(function(e, data, formatted) {
ajaxCall('assignCustomer', data);
});
$('#add-new-client').submit(function(e) {
$('#modal-new-client').modal('hide');
ajaxCall('createCustomer', $(this).serialize());
e.preventDefault();
});
感谢您的帮助