/** * get data fields in <option> format * * @return null */ function Products_adminDatafieldsList() { $fields = array(); $filter = ''; $arr = array('_name' => 'Name', '_activates_on' => 'Publish date', '_expires_on' => 'Expiry date', '_os_base_price' => 'Price'); if ($_REQUEST['other_GET_params']) { if (is_numeric($_REQUEST['other_GET_params'])) { // product type $filter = ' where id=' . (int) $_REQUEST['other_GET_params']; } elseif (strpos($_REQUEST['other_GET_params'], 'c') === 0) { $cat = (int) str_replace('c', '', $_REQUEST['other_GET_params']); if ($cat == 0) { $rs = dbAll('select distinct product_type_id from products'); } else { $arr2 = ProductsCategoriesProducts::getByCategoryId($cat); if (!count($arr2)) { return $arr; } $sql = 'select distinct product_type_id from products where id in (' . join(',', $arr2) . ')'; $rs = dbAll($sql, false, 'products'); } $arr2 = array(); foreach ($rs as $r) { $arr2[] = $r['product_type_id']; } if (!count($arr2)) { return $arr; } $filter = ' where id in (' . join(',', $arr2) . ')'; } } $rs = dbAll('select data_fields from products_types' . $filter); foreach ($rs as $r) { $fs = json_decode($r['data_fields']); foreach ($fs as $f) { $fields[] = $f->n; } } $fields = array_unique($fields); asort($fields); foreach ($fields as $field) { $arr[$field] = $field; } return $arr; }
/** * 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; }