【发布时间】:2015-12-19 14:13:16
【问题描述】:
当我在管理面板中添加供应商(并单击保存按钮)时,我想在控制器中的 postProcess() 方法中检索其 ID
prestashop/controllers/admin/AdminSuppliersController.php
以这样一种方式,我可以将数据库中自定义表中的其他自定义信息与此供应商相关联。将供应商存储到数据库时,我无法在代码中找到该部分(当它在 ps_address 表中插入相对于供应商的地址时,我只找到该部分)。
这里默认的postProcess()方法:
public function postProcess()
{
// checks access
if (Tools::isSubmit('submitAdd'.$this->table) && !($this->tabAccess['add'] === '1')) {
$this->errors[] = Tools::displayError('You do not have permission to add suppliers.');
return parent::postProcess();
}
if (Tools::isSubmit('submitAdd'.$this->table)) {
if (Tools::isSubmit('id_supplier') && !($obj = $this->loadObject(true))) {
return;
}
// updates/creates address if it does not exist
if (Tools::isSubmit('id_address') && (int)Tools::getValue('id_address') > 0) {
$address = new Address((int)Tools::getValue('id_address'));
} // updates address
else {
$address = new Address();
} // creates address
$address->alias = Tools::getValue('name', null);
$address->lastname = 'supplier'; // skip problem with numeric characters in supplier name
$address->firstname = 'supplier'; // skip problem with numeric characters in supplier name
$address->address1 = Tools::getValue('address', null);
$address->address2 = Tools::getValue('address2', null);
$address->postcode = Tools::getValue('postcode', null);
$address->phone = Tools::getValue('phone', null);
$address->phone_mobile = Tools::getValue('phone_mobile', null);
$address->id_country = Tools::getValue('id_country', null);
$address->id_state = Tools::getValue('id_state', null);
$address->city = Tools::getValue('city', null);
$validation = $address->validateController();
// checks address validity
if (count($validation) > 0) {
foreach ($validation as $item) {
$this->errors[] = $item;
}
$this->errors[] = Tools::displayError('The address is not correct. Please make sure all of the required fields are completed.');
} else {
if (Tools::isSubmit('id_address') && Tools::getValue('id_address') > 0) {
$address->update();
} else {
$address->save();
// here I want to get the ID of the inserted supplier
$_POST['id_address'] = $address->id;
}
}
return parent::postProcess();
} elseif (Tools::isSubmit('delete'.$this->table)) {
if (!($obj = $this->loadObject(true))) {
return;
} elseif (SupplyOrder::supplierHasPendingOrders($obj->id)) {
$this->errors[] = $this->l('It is not possible to delete a supplier if there are pending supplier orders.');
} else {
//delete all product_supplier linked to this supplier
Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'product_supplier` WHERE `id_supplier`='.(int)$obj->id);
$id_address = Address::getAddressIdBySupplierId($obj->id);
$address = new Address($id_address);
if (Validate::isLoadedObject($address)) {
$address->deleted = 1;
$address->save();
}
return parent::postProcess();
}
} else {
return parent::postProcess();
}
}
【问题讨论】:
标签: php content-management-system prestashop prestashop-1.6