public function execute() { $type_model = new shopTypeModel(); $types = $type_model->getAll('id'); $category_model = new shopCategoryModel(); $categories = $category_model->getFullTree('id, name, depth', true); $features_model = new shopFeatureModel(); $features = $features_model->getAll('id'); $data = array(); $type_values = array(); foreach ($types as $type_id => $type) { $type_values[] = array($type_id, $type['name']); $data[$type_id]['price'] = array('feature' => 'price'); $data[$type_id]['type_id'] = array('feature' => 'type_id'); $data[$type_id]['tag'] = array('feature' => 'tag'); } $type_features_model = new shopTypeFeaturesModel(); $rows = $type_features_model->getAll(); foreach ($rows as $row) { if (isset($features[$row['feature_id']])) { $code = $features[$row['feature_id']]['code']; $data[$row['type_id']][$code] = array('feature' => $code, 'feature_id' => $row['feature_id']); } } $type_upselling_model = new shopTypeUpsellingModel(); $rows = $type_upselling_model->getAll(); foreach ($rows as $row) { $data[$row['type_id']][$row['feature']] = array('feature_id' => $row['feature_id'], 'feature' => $row['feature'], 'cond' => $row['cond'], 'value' => $row['value']); } foreach ($data as &$row) { $row = array_values($row); } unset($row); foreach ($types as &$type) { if ($type['upselling']) { $type['upselling_html'] = self::getConditionHTML($data[$type['id']], $features); } } unset($type); $fids = array(); foreach ($features as $f_key => $f) { $features[$f_key]['selectable'] = (int) $f['selectable']; $features[$f_key]['multiple'] = (int) $f['multiple']; if ($f['selectable']) { $fids[$f['id']] = $f; } } if ($fids) { $fids = $features_model->getValues($fids); foreach ($fids as $feature_id => $f) { foreach ($f['values'] as $value_id => $value) { $features[$feature_id]['values'][] = array($value_id, $value); } } unset($fids); } $features['type_id'] = array('name' => _w('Type'), 'type' => 'varchar', 'selectable' => 1, 'values' => $type_values); $this->view->assign(array('types' => $types, 'categories' => $categories, 'features' => $features, 'data' => $data)); }
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 execute() { $category_model = new shopCategoryModel(); $this->view->assign('categories', $category_model->getFullTree('', true)); }
public function execute() { $product = new shopProduct(waRequest::get('id', 0, waRequest::TYPE_INT)); if (!$product->id) { if (waRequest::get('id') == 'new') { $product->name = ''; $product->id = 'new'; $product->status = 1; } else { throw new waException("Product not found", 404); } } $counters = array('reviews' => 0, 'images' => 0, 'pages' => 0, 'services' => 0); $sidebar_counters = array(); $config = $this->getConfig(); /** * @var shopConfig $config */ #load product types $type_model = new shopTypeModel(); $product_types = $type_model->getTypes(true); $product_types_count = count($product_types); if (intval($product->id)) { # 1 fill extra product data # 1.1 fill product reviews $product_reviews_model = new shopProductReviewsModel(); $product['reviews'] = $product_reviews_model->getReviews($product->id, 0, $config->getOption('reviews_per_page_product'), 'datetime DESC', array('is_new' => true)); $counters['reviews'] = $product_reviews_model->count($product->id); $sidebar_counters['reviews'] = array('new' => $product_reviews_model->countNew()); $counters['images'] = count($product['images']); $product_pages_model = new shopProductPagesModel(); $counters['pages'] = $product_pages_model->count($product->id); $product_services_model = new shopProductServicesModel(); $counters['services'] = $product_services_model->countServices($product->id); $product_stocks_log_model = new shopProductStocksLogModel(); $counters['stocks_log'] = $product_stocks_log_model->countByField('product_id', $product->id); $this->view->assign('edit_rights', $product->checkRights()); } else { $counters += array_fill_keys(array('images', 'services', 'pages', 'reviews'), 0); $product['images'] = array(); reset($product_types); $product->type_id = 0; if ($product_types_count) { if (!$product_types) { throw new waRightsException(_w("Access denied")); } else { reset($product_types); $product->type_id = key($product_types); } } elseif (!$product->checkRights()) { throw new waRightsException(_w("Access denied")); } $this->view->assign('edit_rights', true); $product['skus'] = array('-1' => array('id' => -1, 'sku' => '', 'available' => 1, 'name' => '', 'price' => 0.0, 'purchase_price' => 0.0, 'count' => null, 'stock' => array(), 'virtual' => 0)); $product->currency = $config->getCurrency(); } $this->assignReportsData($product); $stock_model = new shopStockModel(); $taxes_mode = new shopTaxModel(); $this->view->assign('stocks', $stock_model->getAll('id')); $this->view->assign(array('use_product_currency' => wa()->getSetting('use_product_currency'), 'currencies' => $this->getCurrencies(), 'primary_currency' => $config->getCurrency(), 'taxes' => $taxes_mode->getAll())); $category_model = new shopCategoryModel(); $categories = $category_model->getFullTree('id, name, depth, url, full_url, parent_id', true); $frontend_urls = array(); if (intval($product->id)) { $routing = wa()->getRouting(); $domain_routes = $routing->getByApp($this->getAppId()); foreach ($domain_routes as $domain => $routes) { foreach ($routes as $r) { if (!empty($r['private'])) { continue; } if (empty($r['type_id']) || in_array($product->type_id, (array) $r['type_id'])) { $routing->setRoute($r, $domain); $params = array('product_url' => $product->url); if ($product->category_id && isset($categories[$product->category_id])) { if (!empty($r['url_type']) && $r['url_type'] == 1) { $params['category_url'] = $categories[$product->category_id]['url']; } else { $params['category_url'] = $categories[$product->category_id]['full_url']; } } $frontend_url = $routing->getUrl('/frontend/product', $params, true); $frontend_urls[] = array('url' => $frontend_url); } } } } else { $frontend_urls[] = array('url' => wa()->getRouteUrl('/frontend/product', array('product_url' => '%product_url%'), true)); } $stuff = intval($product->id) ? $product->url : '%product_url%'; foreach ($frontend_urls as &$frontend_url) { $pos = strrpos($frontend_url['url'], $stuff); $frontend_url['base'] = $pos !== false ? rtrim(substr($frontend_url['url'], 0, $pos), '/') . '/' : $frontend_url['url']; } unset($frontend_url); $product_model = new shopProductModel(); $this->view->assign('storefront_map', $product_model->getStorefrontMap($product->id)); /** * Backend product profile page * UI hook allow extends product profile page * @event backend_product * @param shopProduct $entry * @return array[string][string]string $return[%plugin_id%]['title_suffix'] html output * @return array[string][string]string $return[%plugin_id%]['action_button'] html output * @return array[string][string]string $return[%plugin_id%]['toolbar_section'] html output * @return array[string][string]string $return[%plugin_id%]['image_li'] html output */ $this->view->assign('backend_product', wa()->event('backend_product', $product)); /** * @event backend_product_edit */ $this->view->assign('backend_product_edit', wa()->event('backend_product_edit', $product)); $this->view->assign('categories', $categories); $this->view->assign('counters', $counters); $this->view->assign('product', $product); $this->view->assign('current_author', shopProductReviewsModel::getAuthorInfo(wa()->getUser()->getId())); $this->view->assign('reply_allowed', true); $this->view->assign('review_allowed', true); $this->view->assign('sidebar_counters', $sidebar_counters); $this->view->assign('lang', substr(wa()->getLocale(), 0, 2)); $this->view->assign('frontend_urls', $frontend_urls); $tag_model = new shopTagModel(); $this->view->assign('popular_tags', $tag_model->popularTags()); $counts = array(); // Selectable features $features_selectable = $product->features_selectable; if (is_array($features_selectable)) { foreach ($features_selectable as $f) { if ($f['selected']) { $counts[] = $f['selected']; } } } $feature_model = new shopTypeFeaturesModel(); $features_selectable_types = $feature_model->getSkuTypeSelectableTypes(); foreach ($product_types as $type_id => &$type) { $type['sku_type'] = empty($features_selectable_types[$type_id]) ? shopProductModel::SKU_TYPE_FLAT : shopProductModel::SKU_TYPE_SELECTABLE; } $this->view->assign('features', $features_selectable); $this->view->assign('duble', '???'); $this->view->assign('features_counts', $counts); #load product types $this->view->assign('product_types', $product_types); $this->view->assign('sidebar_width', $config->getSidebarWidth()); }