private function stepExportCategory(&$current_stage, &$count, &$processed)
 {
     static $categories;
     if (!$categories) {
         $model = new shopCategoryModel();
         if (preg_match('@^category/(\\d+)$@', $this->data['hash'], $matches)) {
             $categories = array_reverse($model->getPath($matches[1]));
             if ($category = $model->getById($matches[1])) {
                 $categories[$matches[1]] = $category;
             }
         } else {
             $categories = $model->getFullTree('*', true);
         }
         if (count($categories) != $this->data['count'][self::STAGE_CATEGORY]) {
             throw new waException(sprintf('Invalid category count. Expected %d but get %d', $this->data['count'][self::STAGE_CATEGORY], count($categories)));
         }
         if ($current_stage) {
             $categories = array_slice($categories, $current_stage[self::STAGE_CATEGORY]);
         }
     }
     if ($category = reset($categories)) {
         $category['name'] = str_repeat('!', $category['depth']) . $category['name'];
         $this->writer->write($category);
         array_shift($categories);
         ++$current_stage[self::STAGE_CATEGORY];
         ++$processed[self::STAGE_CATEGORY];
         $this->data['map'][self::STAGE_CATEGORY] = intval($category['id']);
         $this->data['map'][self::STAGE_PRODUCT] = $current_stage[self::STAGE_PRODUCT];
         $count[self::STAGE_PRODUCT] += $this->getCollection()->count();
     }
     return $current_stage[self::STAGE_CATEGORY] < $count[self::STAGE_CATEGORY];
 }
 public function getBreadcrumbs(shopProduct $product, $product_link = false)
 {
     if ($product['category_id']) {
         $category_model = new shopCategoryModel();
         $category = $category_model->getById($product['category_id']);
         $product['category_url'] = waRequest::param('url_type') == 1 ? $category['url'] : $category['full_url'];
         if (waRequest::param('url_type') == 2 && !waRequest::param('category_url')) {
             $this->redirect(wa()->getRouteUrl('/frontend/product', array('product_url' => $product['url'], 'category_url' => $product['category_url'])), 301);
         }
         $breadcrumbs = array();
         $path = $category_model->getPath($category['id']);
         $path = array_reverse($path);
         $root_category_id = $category['id'];
         if ($path) {
             $temp = reset($path);
             $root_category_id = $temp['id'];
         }
         foreach ($path as $row) {
             $breadcrumbs[] = array('url' => wa()->getRouteUrl('/frontend/category', array('category_url' => waRequest::param('url_type') == 1 ? $row['url'] : $row['full_url'])), 'name' => $row['name']);
         }
         $breadcrumbs[] = array('url' => wa()->getRouteUrl('/frontend/category', array('category_url' => waRequest::param('url_type') == 1 ? $category['url'] : $category['full_url'])), 'name' => $category['name']);
         if ($product_link) {
             $breadcrumbs[] = array('url' => wa()->getRouteUrl('/frontend/product', array('product_url' => $product['url'], 'category_url' => $product['category_url'])), 'name' => $product['name']);
         }
         if ($breadcrumbs) {
             $this->view->assign('breadcrumbs', $breadcrumbs);
         }
     } else {
         $root_category_id = null;
     }
     $this->view->assign('root_category_id', $root_category_id);
 }
 public function execute()
 {
     $id = $this->get('id', true);
     $category_model = new shopCategoryModel();
     $category = $category_model->getById((int) $id);
     if ($category) {
         if ($category['parent_id']) {
             $parents = $category_model->getPath($category['id']);
             if (waRequest::get('reverse')) {
                 $parents = array_reverse($parents);
             }
             $this->response = array_values($parents);
             $this->response['_element'] = 'category';
         } else {
             $this->response = array();
         }
     } else {
         throw new waAPIException('invalid_request', 'Category not found', 404);
     }
 }