public function getProductById($catalogId, $productId)
 {
     $specialOffer = $this->specialOfferDAO->getById($catalogId, $productId);
     $product = ProductModel::getInstance()->getById($specialOffer['catalogId'], $specialOffer['productId']);
     $product['specialOfferDescription'] = $specialOffer['description'];
     return $product;
 }
 public function show($laboratoryUrl)
 {
     $currentLaboratory = DepartmentModel::getInstance()->getBaseLaboratoryByUrl($laboratoryUrl);
     if (empty($currentLaboratory)) {
         $this->redirect('404');
     }
     $products = ProductModel::getInstance()->getByDepartmentId($currentLaboratory['id']);
     $this->setViewVariable('currentLaboratory', $currentLaboratory);
     $this->setViewVariable('products', $products);
     $this->render();
 }
Esempio n. 3
0
 public function show($productUrl)
 {
     $currentProduct = ProductModel::getInstance()->getByUrl($productUrl);
     if (empty($currentProduct)) {
         $this->redirect('404');
     }
     ProductModel::getInstance()->fillFullInfoAboutProduct($currentProduct);
     $pathToProduct = ProductModel::getInstance()->getPathToProduct($currentProduct);
     $parentDepartment = ProductModel::getInstance()->getDepartment($pathToProduct);
     $productChildren = ProductModel::getInstance()->getChildren($currentProduct['id']);
     $this->setViewVariable('currentProduct', $currentProduct);
     $this->setViewVariable('pathToProduct', $pathToProduct);
     $this->setViewVariable('parentDepartment', $parentDepartment);
     $this->setViewVariable('products', $productChildren);
     $this->render();
 }
 public function show($catalogPathTokens)
 {
     $catalogUrl = !empty($catalogPathTokens) ? $catalogPathTokens[count($catalogPathTokens) - 2] : null;
     $productId = !empty($catalogPathTokens) ? $catalogPathTokens[count($catalogPathTokens) - 1] : null;
     if (!empty($catalogPathTokens) && !CatalogModel::getInstance()->catalogExistForUrl($catalogUrl)) {
         $this->redirect('404');
     }
     $pathToCatalog = CatalogModel::getInstance()->getPathToCatalogByUrl($catalogUrl);
     CatalogModel::getInstance()->calculateFullCatalogUrl($pathToCatalog);
     $currentCatalog = $pathToCatalog[count($pathToCatalog) - 1];
     $product = ProductModel::getInstance()->getById($currentCatalog['id'], $productId);
     $product['_imageExist'] = ProductModel::getInstance()->imageExist($product['catalogId'], $product['id']);
     if (empty($product)) {
         $this->redirect('404');
     }
     $this->setViewVariable('currentCatalog', $currentCatalog);
     $this->setViewVariable('pathToCatalog', $pathToCatalog);
     $this->setViewVariable('product', $product);
     $this->render();
 }
 public function show($departmentUrlList)
 {
     $currentDepartment = null;
     if (empty($departmentUrlList)) {
         $currentDepartmentId = 0;
     } else {
         $departmentUrl = $departmentUrlList[count($departmentUrlList) - 1];
         $currentDepartment = DepartmentModel::getInstance()->getDepartmentByUrl($departmentUrl);
         if (empty($currentDepartment)) {
             $this->redirect('404');
         }
         $currentDepartmentId = $currentDepartment['id'];
     }
     if (!empty($currentDepartment)) {
         $pathToDepartment = DepartmentModel::getInstance()->getPathToDepartment($currentDepartment);
         DepartmentModel::getInstance()->calculateFullPathUrl($pathToDepartment);
         $products = ProductModel::getInstance()->getByDepartmentId($currentDepartment['id']);
     } else {
         $pathToDepartment = [DepartmentModel::getInstance()->gerRootDepartment()];
     }
     $childDepartments = DepartmentModel::getInstance()->getDepartmentChildren($currentDepartmentId);
     DepartmentModel::getInstance()->calculateChildrenFullUrl($currentDepartment, $childDepartments);
     if (!empty($childDepartments)) {
         for ($i = 0; $i < count($childDepartments); $i++) {
             $children = DepartmentModel::getInstance()->getDepartmentChildren($childDepartments[$i]['id']);
             if (!empty($children)) {
                 $childDepartments[$i]['children'] = $children;
                 DepartmentModel::getInstance()->calculateChildrenFullUrl($childDepartments[$i], $childDepartments[$i]['children']);
             }
         }
     }
     $this->setViewVariable('currentDepartment', $currentDepartment);
     $this->setViewVariable('pathToDepartment', $pathToDepartment);
     $this->setViewVariable('departmentList', $childDepartments);
     $this->setViewVariable('products', isset($products) ? $products : []);
     $this->render();
 }
 public function show($catalogPathTokens)
 {
     $lastUrlPart = !empty($catalogPathTokens) ? $catalogPathTokens[count($catalogPathTokens) - 1] : null;
     if (!empty($catalogPathTokens) && !CatalogModel::getInstance()->catalogExistForUrl($lastUrlPart)) {
         $this->redirect('404');
     }
     $pathToCatalog = CatalogModel::getInstance()->getPathToCatalogByUrl($lastUrlPart);
     CatalogModel::getInstance()->calculateFullCatalogUrl($pathToCatalog);
     $currentCatalog = $pathToCatalog[count($pathToCatalog) - 1];
     $nearestChildren = CatalogModel::getInstance()->getNearestChildren($currentCatalog['id']);
     $products = ProductModel::getInstance()->get($currentCatalog['id']);
     $productPageInfo = null;
     if (!empty($products)) {
         ProductModel::getInstance()->calculateFullProductsUrl($products, $currentCatalog['fullUrl']);
         $productPageInfo = $this->getProductPageInfo($products);
         $products = array_slice($products, $productPageInfo['startIndex'], min($productPageInfo['countPerPage'], count($products) - ($productPageInfo['currentPage'] - 1) * $productPageInfo['countPerPage']));
     }
     $this->setViewVariable('currentCatalog', $currentCatalog);
     $this->setViewVariable('pathToCatalog', $pathToCatalog);
     $this->setViewVariable('nearestChildren', $nearestChildren);
     $this->setViewVariable('products', $products);
     $this->setViewVariable('productPageInfo', $productPageInfo);
     $this->render();
 }
 public function saveImage($catalogId, $productId)
 {
     if (!$this->isPostRequest()) {
         exit;
     }
     try {
         $uploadedFile = $_FILES['productImage'];
         if (empty($uploadedFile) || $uploadedFile['error'] != 0) {
             messages::add('Product_ImageNotUploaded', 1, 'error');
             $this->redirectBack();
         }
         $fileExt = FileUtil::getFileExtension($uploadedFile['name']);
         if (!in_array($fileExt, ImageUtil::getSupportedExtension())) {
             messages::add('Product_InvalidImageFormat', 1, 'error');
             $this->redirectBack();
         }
         $imgDir = ProductModel::getInstance()->getImagesDir($catalogId);
         FileUtil::createDirIfNotExist($imgDir);
         $targetFilename = $productId . '.' . $fileExt;
         move_uploaded_file($uploadedFile['tmp_name'], $imgDir . $targetFilename);
         ImageUtil::convertToJpeg($imgDir . $targetFilename);
         messages::add('Product_ImageSaved', 1, 'success');
         $this->systemRedirect('/catalog/editProducts/' . $catalogId);
     } catch (PhException $e) {
         messages::add('Product_ImageUploadError', 1, 'success');
         $this->redirectBack();
     }
 }
 public function editProducts($catalogId)
 {
     try {
         $catalog = CatalogModel::getInstance()->checkCatalogExist($catalogId);
         $this->setViewVariable("catalog", $catalog);
         if (ProductModel::getInstance()->productTableExist($catalogId)) {
             $this->setViewVariable("products", ProductModel::getInstance()->get($catalogId));
         }
         $this->render();
     } catch (PhException $e) {
         messages::addGroup('error', $e->getErrors());
         $this->redirectBack();
     }
 }