当我在管理面板中添加供应商(并单击保存按钮)时,我想在控制器中 postProcess()的方法中检索其ID
的Prestashop /控制器/管理/ AdminSuppliersController.php
以这种方式我可以将此供应商与DB中自定义表中的其他自定义信息相关联。我在代码中找不到将供应商存储到数据库中的部分(我在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();
}
}
答案 0 :(得分:0)
您可以使用挂钩actionObjectSupplierAddAfter
在将供应商对象添加到数据库后立即使用您的模块获取供应商对象:
public function hookActionObjectSupplierAddAfter($params) {
$supplier = $params['object'];
}