public function execute() { $id = waRequest::get('id', null, waRequest::TYPE_INT); $service_model = new shopServiceModel(); $service = array(); $services = $service_model->getAll('id'); if ($id !== 0) { if (!empty($services)) { if ($id && isset($services[$id])) { $service = $services[$id]; } else { $service = current($services); } } } // blank area for adding new service if (!$service) { $services[] = $this->getEmptyService(); $type_model = new shopTypeModel(); $this->assign(array('services' => $services, 'types' => $type_model->getAll(), 'count' => $service_model->countAll(), 'taxes' => $this->getTaxes())); return; } $service_variants_model = new shopServiceVariantsModel(); $variants = $service_variants_model->get($service['id']); $type_services_model = new shopTypeServicesModel(); $types = $type_services_model->getTypes($service['id']); $products_count = 0; $selected_types = array(); foreach ($types as $type) { if ($type['type_id']) { $selected_types[] = $type['type_id']; } } if (!empty($selected_types)) { $product_model = new shopProductModel(); $products_count = $product_model->countByField(array('type_id' => $selected_types)); } $product_services_model = new shopProductServicesModel(); $this->assign(array('services' => $services, 'service' => $service, 'products' => $product_services_model->getProducts($service['id']), 'types' => $types, 'products_count' => $products_count, 'variants' => $variants, 'count' => $service_model->countAll(), 'taxes' => $this->getTaxes())); }
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)); }