public function execute() { $this->setLayout(new shopFrontendLayout()); $product_model = new shopProductModel(); $product = $product_model->getByField('url', waRequest::param('product_url')); if (!$product) { throw new waException('Product not found', 404); } $product = new shopProduct($product); $this->getBreadcrumbs($product, true); $reviews_model = new shopProductReviewsModel(); $reviews = $reviews_model->getFullTree($product['id'], 0, null, 'datetime DESC', array('escape' => true)); $config = wa()->getConfig(); $this->view->assign(array('product' => $product, 'reviews' => $reviews, 'reviews_count' => $reviews_model->count($product['id']), 'reply_allowed' => true, 'auth_adapters' => $adapters = wa()->getAuthAdapters(), 'request_captcha' => $config->getGeneralSettings('require_captcha'), 'require_authorization' => $config->getGeneralSettings('require_authorization'))); $storage = wa()->getStorage(); $current_auth = $storage->read('auth_user_data'); $current_auth_source = $current_auth ? $current_auth['source'] : shopProductReviewsModel::AUTH_GUEST; $this->view->assign('current_auth_source', $current_auth_source); $this->view->assign('current_auth', $current_auth, true); /** * @event frontend_product * @param shopProduct $product * @return array[string][string]string $return[%plugin_id%]['menu'] html output * @return array[string][string]string $return[%plugin_id%]['cart'] html output * @return array[string][string]string $return[%plugin_id%]['block_aux'] html output * @return array[string][string]string $return[%plugin_id%]['block'] html output */ $this->view->assign('frontend_product', wa()->event('frontend_product', $product, array('menu', 'cart', 'block_aux', 'block'))); $this->setThemeTemplate('reviews.html'); }
public function execute() { $id = waRequest::get('id', null, waRequest::TYPE_INT); $product_model = new shopProductModel(); $product = $product_model->getById($id); if (!$product) { throw new waException(_w("Unkown product")); } $offset = waRequest::get('offset', 0, waRequest::TYPE_INT); $total_count = waRequest::get('total_count', null, waRequest::TYPE_INT); $lazy = waRequest::get('lazy'); $order = waRequest::get('order', 'default', waRequest::TYPE_STRING_TRIM); $order = isset($this->orders[$order]) ? $order : 'default'; $product_reviews_model = new shopProductReviewsModel(); $reviews = $product_reviews_model->getFullTree($id, $offset, $this->getConfig()->getOption('reviews_per_page_product'), $this->orders[$order], array('is_new' => true)); $this->view->assign(array('product' => $product, 'reviews' => $reviews, 'offset' => $offset, 'total_count' => $total_count ? $total_count : $product_reviews_model->count($id), 'reply_allowed' => true, 'lazy' => $lazy, 'current_author' => shopProductReviewsModel::getAuthorInfo(wa()->getUser()->getId()), 'count' => count($reviews), 'id' => $id, 'order' => $order, 'sidebar_counters' => array('new' => $product_reviews_model->countNew()))); }
public function execute() { if (!$this->getUser()->isAdmin('shop') && !wa()->getUser()->getRights('shop', 'type.%')) { throw new waRightsException('Access denied'); } $this->setLayout(new shopBackendLayout()); $this->getResponse()->setTitle(_w('Products')); $this->view->assign('categories', new shopCategories()); $tag_model = new shopTagModel(); $this->view->assign('cloud', $tag_model->getCloud()); $set_model = new shopSetModel(); $this->view->assign('sets', $set_model->getAll()); $collapse_types = wa()->getUser()->getSettings('shop', 'collapse_types'); if (empty($collapse_types)) { $type_model = new shopTypeModel(); $this->view->assign('types', $type_model->getTypes()); } else { $this->view->assign('types', false); } $product_model = new shopProductModel(); $this->view->assign('count_all', $product_model->countAll()); $review_model = new shopProductReviewsModel(); $this->view->assign('count_reviews', array('all' => $review_model->count(null, false), 'new' => $review_model->countNew(true))); $product_services = new shopServiceModel(); $this->view->assign('count_services', $product_services->countAll()); $config = $this->getConfig(); $this->view->assign('default_view', $config->getOption('products_default_view')); /* * @event backend_products * @return array[string]array $return[%plugin_id%] array of html output * @return array[string][string]string $return[%plugin_id%]['sidebar_top_li'] html output * @return array[string][string]string $return[%plugin_id%]['sidebar_section'] html output */ $this->view->assign('backend_products', wa()->event('backend_products')); $this->view->assign('sidebar_width', $config->getSidebarWidth()); $this->view->assign('lang', substr(wa()->getLocale(), 0, 2)); }
protected function getReviewsTotalCount($product_id) { return $this->reviews_model->count($product_id, 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()); }