/** * delete a number of product * * @return array status */ function Products_adminProductsDelete() { $ids_to_check = $_REQUEST['ids']; if (!count($ids_to_check)) { return array('error' => 'no ids'); } $ids = array(); foreach ($ids_to_check as $id) { $ids[] = (int) $id; } dbQuery('delete from products where id in (' . join(', ', $ids) . ')'); ProductsCategoriesProducts::deleteByProductId($ids); dbQuery('delete from products_relations where from_id in (' . join(', ', $ids) . ')' . ' or to_id in (' . join(', ', $ids) . ')'); dbQuery('delete from products_reviews where product_id in (' . join(', ', $ids) . ')'); Products_categoriesRecount($ids); Core_cacheClear('products_reviews,products_relations,products'); return array('ok' => 1); }
/** * get the relative URL of a page for showing this product * * @return string URL of the product's page */ function getRelativeUrl() { global $PAGEDATA; if (isset($this->relativeUrl) && $this->relativeUrl) { return $this->relativeUrl; } // { if this product is disabled, then it can only be shown on special pages if ($this->vals['enabled'] == '0') { $pid = dbOne('select page_id from page_vars' . ' where name="products_filter_by_status" and value in (1, 2)', 'page_id'); $page = Page::getInstance($pid); if (!$page) { return '/'; } return $page->getRelativeUrl() . '/' . $this->id . '-' . preg_replace('/[^a-zA-Z0-9]/', '-', $this->link); } // } // { Does the product have a page assigned to display the product? $pageID = dbOne('select page_id from page_vars where name="products_product_to_show" ' . 'and value=' . $this->id . ' limit 1', 'page_id', 'page_vars'); if ($pageID) { $this->relativeUrl = Page::getInstance($pageID)->getRelativeUrl(); return $this->relativeUrl; } // } // { Is there a page intended to display its category? $productCats = ProductsCategoriesProducts::getByProductId($this->id); $productCats[] = $this->default_category; $pcats = array(); foreach ($productCats as $cid) { $cat = ProductCategory::getInstance($cid); if ($cat) { $url = $cat->getRelativeUrl(); return $url . '/' . $this->id . '-' . preg_replace('/[^a-zA-Z0-9]/', '-', $this->link); } } // } $cat = 0; if (@$_REQUEST['product_cid']) { $cat = (int) $_REQUEST['product_cid']; } if ($cat) { $category = ProductCategory::getInstance($cat); if ($category) { $catdir = $category->getRelativeUrl(); } else { $catdir = '/missing-category-' . $cat; $pids = ProductsCategoriesProducts::getByCategoryId($cat); ProductsCategoriesProducts::deleteByCategoryId($cat); Products_categoriesRecount($pids); return $this->getRelativeUrl(); } return $catdir . '/' . $this->id . '-' . preg_replace('/[^a-zA-Z0-9]/', '-', $this->link); } if (preg_match('/^products(\\||$)/', $PAGEDATA->type)) { return $PAGEDATA->getRelativeUrl() . '/' . $this->id . '-' . preg_replace('/[^a-zA-Z0-9]/', '-', $this->link); } $this->relativeUrl = '/_r?type=products&product_id=' . $this->id; return $this->relativeUrl; }