public function execute()
 {
     $id = waRequest::get('id', 0, waRequest::TYPE_INT);
     $collapsed = waRequest::get('collapsed', 0, waRequest::TYPE_INT);
     if ($collapsed) {
         shopCategories::setCollapsed($id);
         return;
     }
     shopCategories::setExpanded($id);
     if (waRequest::get('tree')) {
         $categories = new shopCategories($id);
         $this->view->assign('categories', $categories->getList());
     }
 }
 private function deleteList($hash)
 {
     $model = $this->getModel($hash[0]);
     if (!$model) {
         return true;
     }
     $item = null;
     if ($model = $this->getModel($hash[0])) {
         if (!$model->delete($hash[1])) {
             return false;
         }
         if ($hash[0] == 'category') {
             $this->logAction('category_delete', $hash[1]);
             if ($item['parent_id']) {
                 $count = $model->countByField('parent_id', $item['parent_id']);
                 $this->response['old_parent_category'] = array('id' => $item['parent_id'], 'children_count' => $model->countByField('parent_id', $item['parent_id']));
                 if (!$count) {
                     shopCategories::clear($item['parent_id']);
                 }
             }
         }
     }
     return true;
 }
Esempio n. 3
0
 /**
  * @return shopCategoryModel
  */
 private static function getCategoryModel()
 {
     if (!self::$category_model) {
         self::$category_model = new shopCategoryModel();
     }
     return self::$category_model;
 }
Esempio n. 4
0
 public function delete($id)
 {
     $id = (int) $id;
     $item = $this->getById($id);
     if (!$item) {
         return false;
     }
     $parent_id = (int) $item['parent_id'];
     /**
      * @event category_delete
      */
     wa()->event('category_delete', $item);
     // because all descendants will be thrown one level up
     // it's necessary to ensure uniqueness urls of descendants in new environment (new parent)
     foreach ($this->descendants($item, false)->order("`{$this->depth}`, `{$this->left}`")->query() as $child) {
         $url = $this->suggestUniqueUrl($child['url'], $child['id'], $parent_id);
         if ($url != $child['url']) {
             $this->updateById($child['id'], array('url' => $url, 'full_url' => $this->fullUrl($item['full_url'], $child['url'])));
         }
     }
     // than correct full urls of descendants taking into account full url of new parent
     if (!$parent_id) {
         $this->correctFullUrlOfDescendants($item, '');
     } else {
         $parent = $this->getById($parent_id);
         $this->correctFullUrlOfDescendants($item, $parent['full_url']);
     }
     if (!parent::delete($id)) {
         return false;
     }
     // delete related info
     $category_params_model = new shopCategoryParamsModel();
     $category_params_model->clear($id);
     $category_products_model = new shopCategoryProductsModel();
     $category_products_model->deleteByField('category_id', $id);
     $category_routes_model = new shopCategoryRoutesModel();
     $category_routes_model->deleteByField('category_id', $id);
     $product_model = new shopProductModel();
     $product_model->correctMainCategory(null, $id);
     shopCategories::clear($id);
     $this->clearCache();
     return true;
 }