/** * The function that holds the code for deleting * one product from the database and all related tables * plus deleting files related to the product * * @param int $product_id * @param array $d The input vars * @return boolean True on success, false on error */ function delete_product($product_id, &$d) { global $vmLogger, $VM_LANG; $db = new ps_DB(); if (!$this->validate_delete($product_id, $d)) { return false; } /* If is Product */ if ($this->is_product($product_id)) { /* Delete all items first */ $q = "SELECT product_id FROM #__{vm}_product WHERE product_parent_id='{$product_id}'"; $db->setQuery($q); $db->query(); while ($db->next_record()) { $d2["product_id"] = $db->f("product_id"); if (!$this->delete($d2)) { return false; } } /* Delete attributes */ $q = "DELETE FROM #__{vm}_product_attribute_sku WHERE product_id='{$product_id}' "; $db->setQuery($q); $db->query(); /* Delete categories xref */ $q = "DELETE FROM #__{vm}_product_category_xref WHERE product_id = '{$product_id}' "; $db->setQuery($q); $db->query(); } else { /* Delete attribute values */ $q = "DELETE FROM #__{vm}_product_attribute WHERE product_id='{$product_id}'"; $db->setQuery($q); $db->query(); } /* For both Product and Item */ /* Delete product - manufacturer xref */ $q = "DELETE FROM #__{vm}_product_mf_xref WHERE product_id='{$product_id}'"; $db->setQuery($q); $db->query(); /* Delete Product - ProductType Relations */ $q = "DELETE FROM `#__{vm}_product_product_type_xref` WHERE `product_id`={$product_id}"; $db->setQuery($q); $db->query(); /* Delete product votes */ $q = "DELETE FROM #__{vm}_product_votes WHERE product_id='{$product_id}'"; $db->setQuery($q); $db->query(); /* Delete product reviews */ $q = "DELETE FROM #__{vm}_product_reviews WHERE product_id='{$product_id}'"; $db->setQuery($q); $db->query(); /* Delete Image files */ if (!vmImageTools::process_images($d)) { return false; } /* Delete other Files and Images files */ require_once CLASSPATH . 'ps_product_files.php'; $ps_product_files = new ps_product_files(); $db->query("SELECT file_id FROM #__{vm}_product_files WHERE file_product_id='{$product_id}'"); while ($db->next_record()) { $d["file_id"] = $db->f("file_id"); $ps_product_files->delete($d); } /* Delete Product Relations */ $q = "DELETE FROM #__{vm}_product_relations WHERE product_id = '{$product_id}'"; $db->setQuery($q); $db->query(); /* Delete Prices */ $q = "DELETE FROM #__{vm}_product_price WHERE product_id = '{$product_id}'"; $db->setQuery($q); $db->query(); /* Delete entry FROM #__{vm}_product table */ $q = "DELETE FROM #__{vm}_product WHERE product_id = '{$product_id}'"; $db->setQuery($q); $db->query(); /* If only deleting an item, go to the parent product page after ** the deletion. This had to be done here because the product id ** of the item to be deleted had to be passed as product_id */ if (!empty($d["product_parent_id"])) { $d["product_id"] = $d["product_parent_id"]; $d["product_parent_id"] = ""; } $vmLogger->info(str_replace('{product_id}', $product_id, $VM_LANG->_('VM_PRODUCT_DELETED', false))); return true; }
/** * Deletes one Record. */ function delete_record($record_id, &$d) { global $db; if (!$this->validate_delete($record_id, $d)) { return False; } /* Delete Image files */ if (!vmImageTools::process_images($d)) { return false; } $q = "DELETE FROM #__{vm}_vendor where vendor_id='{$record_id}'"; $db->query($q); return True; }
/** * Deletes one Record. */ function delete_record($record_id, &$d) { global $ps_product, $db, $vmLogger, $VM_LANG; if (!$this->validate_delete($record_id, $d)) { return False; } // Delete all products from that category // We must filter out those products that are in more than one category! // Case 1: Products are assigned to more than on category // so let's only delete the __{vm}_product_category_xref entry $q = "CREATE TEMPORARY TABLE IF NOT EXISTS `#__tmp_prod` AS\n (SELECT * FROM `#__{vm}_product_category_xref` \n WHERE `category_id`='{$record_id}');"; $db->query($q); $q = "SELECT #__{vm}_product_category_xref.product_id\n FROM `#__{vm}_product_category_xref`, `#__tmp_prod` \n WHERE #__{vm}_product_category_xref.product_id=#__tmp_prod.product_id \n AND #__{vm}_product_category_xref.category_id!='{$record_id}';"; $db->query($q); if ($db->num_rows() > 0) { $i = 0; $q = "DELETE FROM #__{vm}_product_category_xref WHERE product_id IN ("; while ($db->next_record()) { $q .= "'" . $db->f("product_id") . "'"; if ($i++ < $db->num_rows() - 1) { $q .= ","; } } $q .= ") AND category_id='{$record_id}'"; $db->query($q); } else { // Case 2: Products are assigned to this category only $q = "SELECT product_id FROM `#__{vm}_product_category_xref` WHERE `category_id`='{$record_id}';"; $db->query($q); $d['product_id'] = array(); while ($db->next_record()) { $d['product_id'][] = $db->f("product_id"); } $ps_product->delete($d); } $q = "DELETE FROM #__{vm}_category WHERE category_id='{$record_id}'"; $db->setQuery($q); $db->query(); $q = "DELETE FROM #__{vm}_category_xref WHERE category_child_id='{$record_id}'"; $db->setQuery($q); $db->query(); // Delete Image files if (!vmImageTools::process_images($d)) { return false; } $vmLogger->info($VM_LANG->_('VM_PRODUCT_CATEGORY_DELETED') . ": {$record_id}."); return True; }