public function index() { $this->setViewVariable('currentCatalog', CatalogModel::getInstance()->getRootCatalog()); $this->setViewVariable('nearestChildren', CatalogModel::getInstance()->getNearestChildren(0)); $this->setViewVariable('specialOfferProducts', $this->splitByRows(SpecialOfferModel::getInstance()->getProducts())); $this->render(['layout' => 'index']); }
public function show($catalogPathTokens) { $lastUrlPart = !empty($catalogPathTokens) ? $catalogPathTokens[count($catalogPathTokens) - 1] : null; $catalogPathToCatalog = CatalogModel::getInstance()->getPathToCatalogByUrl($lastUrlPart); $this->setViewVariable('catalogPathToCatalog', $catalogPathToCatalog); $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 uploadImage($catalogId, $productId) { try { ProductModel::getInstance()->checkProductExist($catalogId, $productId); $catalog = CatalogModel::getInstance()->getById($catalogId); $product = ProductModel::getInstance()->getById($catalogId, $productId); $this->setViewVariable('catalog', $catalog); $this->setViewVariable('product', $product); if (ProductModel::getInstance()->imageExist($catalogId, $productId)) { $this->setViewVariable('currentImagePath', ProductModel::getInstance()->getImagePath($catalogId, $productId)); } $this->setViewVariable('maxImageSizeMb', ProductModel::getInstance()->getMaxImageSizeToUpload() / 1024 / 1024); $this->render(); } catch (PhException $e) { messages::addGroup('error', $e->getErrors()); $this->systemRedirect('/catalog/editProducts/' . $catalogId); } }
public function getById($catalogId, $productId) { $catalog = CatalogModel::getInstance()->getById($catalogId); $this->redirect('/product/' . $catalog['url'] . '/' . $productId); }
private function getCatalogExistenceValidationErrors($product) { $errors = []; if (!CatalogModel::getInstance()->catalogExist($product['catalogId'])) { $errors['Catalog_IdNotFound'] = 1; return $errors; } if (!$this->productTableExist($product['catalogId'])) { $errors['Product_TableNotFound'] = 1; return $errors; } return $errors; }
public function saveImage($catalogId) { if (!$this->isPostRequest()) { exit; } try { $uploadedFile = $_FILES['catalogImage']; if (empty($uploadedFile) || $uploadedFile['error'] != 0) { messages::add('Catalog_ImageNotUploaded', 1, 'error'); $this->redirectBack(); } $fileExt = FileUtil::getFileExtension($uploadedFile['name']); if (!in_array($fileExt, ImageUtil::getSupportedExtension())) { messages::add('Catalog_InvalidImageFormat', 1, 'error'); $this->redirectBack(); } $imgDir = CatalogModel::getInstance()->getImagesDir(); FileUtil::createDirIfNotExist($imgDir); $targetFilename = $catalogId . '.' . $fileExt; move_uploaded_file($uploadedFile['tmp_name'], $imgDir . $targetFilename); ImageUtil::convertToJpeg($imgDir . $targetFilename); messages::add('Catalog_ImageSaved', 1, 'success'); $this->redirectBack(); } catch (\Exception $e) { messages::add('Catalog_ImageUploadError', 1, 'success'); $this->redirectBack(); } }
public function index() { $catalogs = CatalogModel::getInstance()->getNearestChildren(0); $this->setViewVariable('catalogs', $catalogs); $this->render(['layout' => 'index']); }
<?php $ph->include_css('children-catalog.css'); ?> <div class="container marketing"> <div class="row"> <?php foreach ($nearestChildren as $catalog) { ?> <div class="col-lg-4 catalog-container"> <?php $ph->link_open($currentCatalog['fullUrl'] . '/' . $catalog['url'], ['class' => 'image-container']); if (\application\models\CatalogModel::getInstance()->imageExist($catalog['id'])) { $ph->image('catalog/' . $catalog['id'] . '.jpeg', ['class' => 'img-circle image', 'data-src' => 'holder.js/140x140']); } else { $ph->image('no-photo.jpg', ['class' => 'img-circle image', 'data-src' => 'holder.js/140x140']); } $ph->link_close(); $ph->link_open($currentCatalog['fullUrl'] . '/' . $catalog['url'])->tag('h4', $catalog['name'], ['class' => 'catalog-name'])->tag_close('a'); ?> <p class="catalog-short-description"> <?php if (!empty($catalog['description'])) { $ph->cut_text($catalog['description'], 65)->text('...'); } ?> </p> <p> <?php $ph->link_open($currentCatalog['fullUrl'] . '/' . $catalog['url'], ['class' => 'btn btn-default'])->tag('span', null, ['class' => 'glyphicon glyphicon-list'])->text(' Посмотреть')->link_close('a');