Esempio n. 1
0
/**
 * delete a category
 *
 * @return null
 */
function Products_adminCategoryDelete()
{
    if (!isset($_REQUEST['id']) || !is_numeric($_REQUEST['id'])) {
        Core_quit();
    }
    $id = (int) $_REQUEST['id'];
    if ($id == 1) {
        return array('status' => 0);
    }
    $parent = ProductCategory::getInstance($id)->vals['parent_id'];
    dbQuery('update products_categories set parent_id=' . $parent . ' where parent=' . $id);
    $pids = ProductsCategoriesProducts::getByCategoryId($id);
    ProductsCategoriesProducts::deleteByCategoryId($id);
    Products_categoriesRecount($pids);
    dbQuery('delete from products_categories where id=' . $id);
    Core_cacheClear('products_categories');
    return array('status' => 1);
}
Esempio n. 2
0
 /**
  * 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;
 }