/** * @see ObjectModel::delete() */ public function delete() { $res = parent::delete(); if ($res && $this->id_product_attribute == 0) { $items = ProductSupplier::getSupplierCollection($this->id_product, false); foreach ($items as $item) { if ($item->id_product_attribute > 0) { $item->delete(); } } } return $res; }
public function initFormSuppliers($obj) { $data = $this->createTemplate($this->tpl_form); if ($obj->id) { if ($this->product_exists_in_shop) { // Get all id_product_attribute $attributes = $obj->getAttributesResume($this->context->language->id); if (empty($attributes)) { $attributes[] = array('id_product' => $obj->id, 'id_product_attribute' => 0, 'attribute_designation' => ''); } $product_designation = array(); foreach ($attributes as $attribute) { $product_designation[$attribute['id_product_attribute']] = rtrim($obj->name[$this->context->language->id] . ' - ' . $attribute['attribute_designation'], ' - '); } // Get all available suppliers $suppliers = Supplier::getSuppliers(); // Get already associated suppliers $associated_suppliers = ProductSupplier::getSupplierCollection($obj->id); // Get already associated suppliers and force to retreive product declinaisons $product_supplier_collection = ProductSupplier::getSupplierCollection($obj->id, false); $default_supplier = 0; foreach ($suppliers as &$supplier) { $supplier['is_selected'] = false; $supplier['is_default'] = false; foreach ($associated_suppliers as $associated_supplier) { if ($associated_supplier->id_supplier == $supplier['id_supplier']) { $associated_supplier->name = $supplier['name']; $supplier['is_selected'] = true; if ($obj->id_supplier == $supplier['id_supplier']) { $supplier['is_default'] = true; $default_supplier = $supplier['id_supplier']; } } } } $data->assign(array('attributes' => $attributes, 'suppliers' => $suppliers, 'default_supplier' => $default_supplier, 'associated_suppliers' => $associated_suppliers, 'associated_suppliers_collection' => $product_supplier_collection, 'product_designation' => $product_designation, 'currencies' => Currency::getCurrencies(), 'product' => $obj, 'link' => $this->context->link, 'token' => $this->token, 'id_default_currency' => Configuration::get('PS_CURRENCY_DEFAULT'))); } else { $this->displayWarning($this->l('You must save the product in this shop before managing suppliers.')); } } else { $this->displayWarning($this->l('You must save this product before managing suppliers.')); } $this->tpl_form_vars['custom_form'] = $data->fetch(); }