Exemplo n.º 1
0
 /**
  * @param int $product_id
  * @return bool
  */
 public function deleteProduct($product_id)
 {
     if (!(int) $product_id) {
         return false;
     }
     $rm = new AResourceManager();
     $this->db->query("DELETE FROM " . $this->db->table("products") . " WHERE product_id = '" . (int) $product_id . "'");
     $this->db->query("DELETE FROM " . $this->db->table("product_descriptions") . " WHERE product_id = '" . (int) $product_id . "'");
     $resources = $rm->getResourcesList(array('object_name' => 'products', 'object_id' => (int) $product_id));
     foreach ($resources as $r) {
         $rm->unmapResource('products', $product_id, $r['resource_id']);
         //if resource become orphan - delete it
         if (!$rm->isMapped($r['resource_id'])) {
             $rm->deleteResource($r['resource_id']);
         }
     }
     //delete product's downloads
     $this->load->model('catalog/download');
     $downloads = $this->model_catalog_download->getProductDownloadsDetails($product_id, array('subsql_filter' => 'AND d.shared<>1'));
     foreach ($downloads as $d) {
         $this->model_catalog_download->deleteDownload($d['download_id']);
     }
     $this->db->query("DELETE FROM " . $this->db->table("product_options") . " WHERE product_id = '" . (int) $product_id . "'");
     $this->db->query("DELETE FROM " . $this->db->table("product_option_descriptions") . " WHERE product_id = '" . (int) $product_id . "'");
     $sql = "SELECT product_option_value_id FROM " . $this->db->table("product_option_values") . " WHERE product_id = '" . (int) $product_id . "'";
     $result = $this->db->query($sql);
     foreach ($result->rows as $row) {
         $pd_opt_val_id = $row['product_option_value_id'];
         $resources = $rm->getResourcesList(array('object_name' => 'product_option_value', 'object_id' => (int) $pd_opt_val_id));
         foreach ($resources as $r) {
             $rm->unmapResource('product_option_value', $pd_opt_val_id, $r['resource_id']);
         }
     }
     $this->db->query("DELETE FROM " . $this->db->table("product_option_values") . " WHERE product_id = '" . (int) $product_id . "'");
     $this->db->query("DELETE FROM " . $this->db->table("product_option_value_descriptions") . " WHERE product_id = '" . (int) $product_id . "'");
     $this->db->query("DELETE FROM " . $this->db->table("product_discounts") . " WHERE product_id = '" . (int) $product_id . "'");
     $this->db->query("DELETE FROM " . $this->db->table("products_related") . " WHERE product_id = '" . (int) $product_id . "'");
     $this->db->query("DELETE FROM " . $this->db->table("products_to_downloads") . " WHERE product_id = '" . (int) $product_id . "'");
     $this->db->query("DELETE FROM " . $this->db->table("products_to_categories") . " WHERE product_id = '" . (int) $product_id . "'");
     $this->db->query("DELETE FROM " . $this->db->table("reviews") . " WHERE product_id = '" . (int) $product_id . "'");
     $this->db->query("DELETE FROM " . $this->db->table("products_to_stores") . " WHERE product_id = '" . (int) $product_id . "'");
     $this->db->query("DELETE FROM " . $this->db->table("url_aliases") . " WHERE query = 'product_id=" . (int) $product_id . "'");
     $this->db->query("DELETE FROM " . $this->db->table("product_tags") . " WHERE product_id='" . (int) $product_id . "'");
     $lm = new ALayoutManager();
     $lm->deletePageLayout('pages/product/product', 'product_id', (int) $product_id);
     $this->cache->remove('product');
     return true;
 }
 /**
  * @throws AException
  */
 public function list_library()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $language_id = $this->language->getContentLanguageID();
     $this->data['sort'] = $this->request->get['sort'];
     $this->data['order'] = $this->request->get['order'];
     $rm = new AResourceManager();
     $rm->setType($this->data['type']);
     //Build request URI and filter params
     $uri = '&object_name=' . $this->data['object_name'] . '&object_id=' . $this->data['object_id'];
     $uri .= '&type=' . $this->data['type'] . '&mode=' . $this->data['mode'] . '&language_id=' . $language_id . '&action=' . $this->data['action'];
     $filter_data = array('type_id' => $rm->getTypeId(), 'language_id' => $language_id, 'limit' => 12);
     if (!empty($this->request->get['keyword'])) {
         $filter_data['keyword'] = $this->request->get['keyword'];
         $uri .= '&keyword=' . $this->request->get['keyword'];
     }
     if (!empty($this->data['object_name']) && $this->data['action'] == 'list_object') {
         $filter_data['object_name'] = $this->data['object_name'];
     }
     if (!empty($this->data['object_id']) && $this->data['action'] == 'list_object') {
         $filter_data['object_id'] = $this->data['object_id'];
     }
     if ($this->data['sort']) {
         $filter_data['sort'] = $this->data['sort'];
     }
     if ($this->data['order']) {
         $filter_data['order'] = $this->data['order'];
     } elseif (!$this->data['sort'] && $this->data['action'] == 'list_object') {
         $filter_data['sort'] = 'sort_order';
     } else {
         $filter_data['sort'] = 'date_added';
         $filter_data['order'] = 'DESC';
     }
     if (isset($this->request->get['page'])) {
         $page = $this->request->get['page'];
         if ((int) $page < 1) {
             $page = 1;
         }
         $filter_data['start'] = ($page - 1) * $filter_data['limit'];
     }
     $resources_total = $rm->getTotalResources($filter_data);
     $result = $rm->getResourcesList($filter_data);
     foreach ($result as $key => $item) {
         if ($item['date_added']) {
             $result[$key]['date_added'] = dateISO2Display($item['date_added']);
         }
         $result[$key]['thumbnail_url'] = $rm->getResourceThumb($item['resource_id'], $this->thumb_sizes['width'], $this->thumb_sizes['height'], $language_id);
         $result[$key]['url'] = $rm->buildResourceURL($item['resource_path'], 'full');
         $result[$key]['relative_url'] = $rm->buildResourceURL($item['resource_path'], 'relative');
         $result[$key]['mapped_to_current'] = $rm->isMapped($item['resource_id'], $this->data['object_name'], $this->data['object_id']);
     }
     $sort_order = '&sort=' . $this->data['sort'] . '&order=' . $this->data['order'];
     $this->data['current_url'] = $this->html->getSecureURL('common/resource_library', $uri . $sort_order . '&page={page}', '&encode');
     $this->data['no_sort_url'] = $this->html->getSecureURL('common/resource_library', $uri, '&encode');
     if ($resources_total > 12) {
         $this->data['pagination_bootstrap'] = HtmlElementFactory::create(array('type' => 'Pagination', 'name' => 'pagination', 'text' => $this->language->get('text_pagination'), 'text_limit' => $this->language->get('text_per_page'), 'total' => $resources_total, 'page' => $page, 'limit' => 12, 'url' => $this->data['current_url'], 'size_class' => 'sm', 'no_perpage' => true, 'style' => 'pagination'));
     }
     $this->data['rls'] = $result;
     $this->view->assign('form_language_switch', $this->html->getContentLanguageSwitcher());
     $this->view->assign('help_url', $this->gen_help_url('resource_library'));
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
     $this->view->batchAssign($this->data);
     $this->processTemplate('responses/common/resource_library.tpl');
 }
Exemplo n.º 3
0
 /**
  * @param int $manufacturer_id
  */
 public function deleteManufacturer($manufacturer_id)
 {
     $this->db->query("DELETE FROM " . $this->db->table("manufacturers") . " WHERE manufacturer_id = '" . (int) $manufacturer_id . "'");
     $this->db->query("DELETE FROM " . $this->db->table("manufacturers_to_stores") . " WHERE manufacturer_id = '" . (int) $manufacturer_id . "'");
     $this->db->query("DELETE FROM " . $this->db->table("url_aliases") . " WHERE query = 'manufacturer_id=" . (int) $manufacturer_id . "'");
     $lm = new ALayoutManager();
     $lm->deletePageLayout('pages/product/manufacturer', 'manufacturer_id', (int) $manufacturer_id);
     //delete resources
     $rm = new AResourceManager();
     $resources = $rm->getResourcesList(array('object_name' => 'manufacturers', 'object_id' => (int) $manufacturer_id));
     foreach ($resources as $r) {
         $rm->unmapResource('manufacturers', $manufacturer_id, $r['resource_id']);
         //if resource became orphan - delete it
         if (!$rm->isMapped($r['resource_id'])) {
             $rm->deleteResource($r['resource_id']);
         }
     }
     $this->cache->remove('manufacturer');
 }
Exemplo n.º 4
0
 /**
  * @param int $download_id
  * @return null
  */
 public function deleteDownload($download_id)
 {
     $download_id = (int) $download_id;
     if (!$download_id) {
         return null;
     }
     $download = $this->getDownload($download_id);
     if (!$download) {
         return null;
     }
     $rm = new AResourceManager();
     $rm->setType('download');
     $path = ltrim($download['filename'], 'download/');
     $rl_id = $rm->getIdFromHexPath($path);
     if ($rl_id && !$rm->isMapped($rl_id)) {
         $rm->deleteResource($rl_id);
     }
     $this->db->query("DELETE FROM " . $this->db->table("downloads") . " WHERE download_id = '" . (int) $download_id . "'");
     $this->db->query("DELETE FROM " . $this->db->table("download_descriptions") . " WHERE download_id = '" . (int) $download_id . "'");
     $this->db->query("DELETE FROM " . $this->db->table("download_attribute_values") . " WHERE download_id = '" . (int) $download_id . "'");
     $this->db->query("DELETE FROM " . $this->db->table("products_to_downloads") . " WHERE download_id = '" . (int) $download_id . "'");
 }
Exemplo n.º 5
0
 /**
  * @param int $category_id
  */
 public function deleteCategory($category_id)
 {
     $this->db->query("DELETE FROM " . $this->db->table("categories") . " WHERE category_id = '" . (int) $category_id . "'");
     $this->db->query("DELETE FROM " . $this->db->table("category_descriptions") . " WHERE category_id = '" . (int) $category_id . "'");
     $this->db->query("DELETE FROM " . $this->db->table("categories_to_stores") . " WHERE category_id = '" . (int) $category_id . "'");
     $this->db->query("DELETE FROM " . $this->db->table("url_aliases") . " WHERE query = 'category_id=" . (int) $category_id . "'");
     $this->db->query("DELETE FROM " . $this->db->table("products_to_categories") . " WHERE category_id = '" . (int) $category_id . "'");
     //delete resources
     $rm = new AResourceManager();
     $resources = $rm->getResourcesList(array('object_name' => 'categories', 'object_id' => (int) $category_id));
     foreach ($resources as $r) {
         $rm->unmapResource('products', $category_id, $r['resource_id']);
         //if resource became orphan - delete it
         if (!$rm->isMapped($r['resource_id'])) {
             $rm->deleteResource($r['resource_id']);
         }
     }
     //remove layout
     $lm = new ALayoutManager();
     $lm->deletePageLayout('pages/product/category', 'path', $category_id);
     //delete children categories
     $query = $this->db->query("SELECT category_id\n\t\t\t\t\t\t\t\t\tFROM " . $this->db->table("categories") . "\n\t\t\t\t\t\t\t\t\tWHERE parent_id = '" . (int) $category_id . "'");
     foreach ($query->rows as $result) {
         $this->deleteCategory($result['category_id']);
     }
     $this->cache->remove('category');
 }