function createProductUrl($params, LiveCart $application) { $product = $params['product']; $router = $application->getRouter(); // use parent product data for child variations if (isset($product['Parent'])) { $product = $product['Parent']; } $handle = createHandleString($product['name_lang']); $urlParams = array('controller' => 'product', 'action' => 'index', 'producthandle' => $handle, 'id' => $product['ID']); if (isset($params['query'])) { $urlParams['query'] = $params['query']; } if (isset($params['context'])) { $urlParams['query'] .= (!empty($urlParams['query']) ? '&' : '') . $router->createUrlParamString($params['context']); } $url = $router->createUrl($urlParams, true); if (!empty($params['full'])) { $url = $router->createFullUrl($url); } if (!empty($params['filterChainHandle'])) { $url = $router->setUrlQueryParam($url, 'filters', $params['filterChainHandle']); } if (!empty($params['category']) && $params['category']['ID'] != $product['categoryID']) { $url = $router->setUrlQueryParam($url, 'category', $params['category']['ID']); } $router->setLangReplace($handle, 'name', $product); return $url; }
protected function getKeywordsString($array) { if (isset($array['Product'])) { $array = $array['Product']; } if (empty($array['sku'])) { return null; } if (is_string($array['name'])) { $array['name_lang'] = $array['name']; } if (isset($array['DefaultImage']) && is_array($array['DefaultImage']['Product']['name']) && !empty($array['DefaultImage']['Product']['name']['en'])) { $array['name_lang'] = $array['DefaultImage']['Product']['name']['en']; } if (!empty($array['parentID']) && empty($array['Parent'])) { $array['Parent'] = Product::getInstanceByID($array['parentID'], true)->toArray(); } if (!empty($array['Parent']['name_lang']) && empty($array['name_lang'])) { $array['name_lang'] = $array['Parent']['name_lang']; } $name = isset($array['name_lang']) ? $array['name_lang'] : array_shift($array['name']); //if (!$name) { var_dump($array); exit; } $str = $name . '-' . $array['sku']; //var_dump($str); if ($str) { $str = preg_replace('/[^a-zA-Z0-9_\\-]/', '', urldecode(createHandleString($str))); } return $str && strlen($str) > 0 ? $str : null; }
public function toArray() { $array = array(); $array['name_lang'] = $this->manufacturerName; $array['handle'] = createHandleString($array['name_lang']); $array['ID'] = $this->getID(); return $array; }
private function getManufacturerFilterUrl($manufacturerArray) { static $templateUrl; if (!$templateUrl) { $templateUrl = $this->getFilterUrlTemplate(); } return strtr($templateUrl, array('#' => $manufacturerArray['ID'], '|' => createHandleString($manufacturerArray['name']))); }
public function toArray() { $array = array(); $array['name_lang'] = $this->name; $array['last_in_set_name_lang'] = $this->lastInSetName; $array['handle'] = createHandleString($this->name); $array['ID'] = $this->getID(); return $array; }
public function save($forceOperation = null) { $this->loadFile(); if (!$this->handle->get()) { $this->handle->set(createHandleString($this->getValueByLang('title'))); } parent::save($forceOperation); $this->saveFile(); }
function createNewsPostUrl($params, LiveCart $application) { $news = $params['news']; $urlParams = array('controller' => 'news', 'action' => 'view', 'handle' => createHandleString($news['title_lang']), 'id' => $news['ID']); $router = $application->getRouter(); $url = $router->createUrl($urlParams, true); if (array_key_exists('full', $params) && $params['full'] == true) { $url = $router->createFullUrl($url); } return $url; }
public function toArray() { $array = $this->specFieldValue->toArray(); $array['name_lang'] = $array['value_lang']; $array['handle'] = createHandleString($array['value_lang']); $array['ID'] = 'v' . $array['ID']; if (!isset($array['FilterGroup'])) { $array['FilterGroup']['SpecField'] = $array['SpecField']; } return $array; }
public function createUrlFromRoute($route, $isXHtml = false) { preg_match('/^([a-z]{2})\\//', $route, $match); $varSuffix = isset($match[1]) ? '_' . $match[1] : ''; foreach ($this->langReplaces as $needle => $replace) { $repl = !empty($replace['record'][$replace['field'] . $varSuffix]) ? $replace['record'][$replace['field'] . $varSuffix] : (isset($replace['record'][$replace['field']]) ? $replace['record'][$replace['field']] : ''); if ($repl) { $repl = createHandleString($repl); if ($repl != $needle) { $route = str_replace($needle, $repl, $route); } } } return parent::createUrlFromRoute($route, $isXHtml); }
function createProductUrl($params, LiveCart $application) { $product = $params['product']; // use parent product data for child variations if (isset($product['Parent'])) { $product = $product['Parent']; } //var_dump($product); $handle = !empty($product['URL']) ? createHandleString($product['URL']) : createHandleString($product['name_lang']); $urlParams = array('controller' => 'product', 'action' => 'index', 'producthandle' => $handle, 'id' => $product['ID']); $url = $application->getRouter()->createUrl($urlParams, true); if (!empty($params['full'])) { $url = $application->getRouter()->createFullUrl($url); } if (!empty($params['filterChainHandle'])) { $url = $application->getRouter()->setUrlQueryParam($url, 'filters', $params['filterChainHandle']); } $application->getRouter()->setLangReplace($handle, 'name', $product); return $url; }
function createCategoryUrl($params, LiveCart $application) { static $simpleUrlTemplate = null; // create URL template $router = $application->getRouter(); if (!$simpleUrlTemplate) { $simpleUrlTemplate = $router->createUrl(array('controller' => 'category', 'action' => 'index', 'cathandle' => '---', 'id' => 999)); $simpleUrlTemplate = strtr($simpleUrlTemplate, array(999 => '#', '---' => '|')); } $category = $params['data']; if (!isset($category['ID'])) { $category['ID'] = 1; } $handle = isset($category['name_lang']) ? createHandleString($category['name_lang']) : ''; // category names to use in other language links $router->setLangReplace($handle, 'name', $category); // no extra params, so we don't need to call the router to build the URL if (count($params) == 1) { return strtr($simpleUrlTemplate, array('#' => $category['ID'], '|' => $handle)); } $filters = array(); // remove filter (expand search) if (isset($params['removeFilter'])) { foreach ($params['filters'] as $key => $filter) { if ($filter['ID'] == $params['removeFilter']['ID']) { unset($params['filters'][$key]); } } } if (isset($params['removeFilters'])) { foreach ($params['removeFilters'] as $filter) { unset($params['filters'][$filter['ID']]); } } // get filters if (isset($params['filters'])) { foreach ($params['filters'] as $filter) { $filters[] = filterHandle($filter); } } // apply new filter (narrow search) if (!empty($params['addFilter'])) { $filters[] = filterHandle($params['addFilter']); } if (empty($handle)) { $handle = '-'; } $urlParams = array('controller' => 'category', 'action' => empty($params['action']) ? 'index' : $params['action'], 'cathandle' => $handle, 'id' => $category['ID']); if (!empty($params['query'])) { $urlParams['query'] = $params['query']; } if (!empty($params['page'])) { $urlParams['page'] = $params['page']; } if ($filters) { $urlParams['filters'] = implode(',', $filters); } if ('index' != $urlParams['action']) { unset($urlParams['cathandle']); if (isset($urlParams['filters'])) { $urlParams['query'] = 'filters=' . $urlParams['filters']; unset($urlParams['filters']); } } $url = $application->getRouter()->createUrl($urlParams, true); if (!empty($params['full'])) { $url = $application->getRouter()->createFullUrl($url); } // remove empty search query parameter return preg_replace('/[\\?&]q=$/', '', $url); }
public function index() { $this->loadLanguageFile('Category'); $product = Product::getInstanceByID($this->request->get('id'), Product::LOAD_DATA, array('ProductImage', 'Manufacturer', 'Category')); $this->product = $product; if (!$product->isEnabled->get() || $product->parent->get()) { throw new ARNotFoundException('Product', $product->getID()); } $product->loadPricing(); $this->category = $product->getCategory(); $this->categoryID = $product->getCategory()->getID(); // get category path for breadcrumb $path = $product->category->get()->getPathNodeArray(); include_once ClassLoader::getRealPath('application.helper.smarty') . '/function.categoryUrl.php'; include_once ClassLoader::getRealPath('application.helper.smarty') . '/function.productUrl.php'; foreach ($path as $nodeArray) { $url = createCategoryUrl(array('data' => $nodeArray), $this->application); if ($nodeArray['isEnabled']) { $this->addBreadCrumb($nodeArray['name_lang'], $url); } } // add filters to breadcrumb CategoryController::getAppliedFilters(); // for root category products if (!isset($nodeArray)) { $nodeArray = array(); } $params = array('data' => $nodeArray, 'filters' => array()); foreach ($this->filters as $filter) { $f = $filter->toArray(); $params['filters'][] = $f; $url = createCategoryUrl($params, $this->application); $this->addBreadCrumb($f['name_lang'], $url); } $productArray = $product->toArray(); $handle = empty($productArray['URL']) ? $productArray['name_lang'] : $productArray['URL']; $this->redirect301($this->request->get('producthandle'), createHandleString($handle)); //ProductSpecification::loadSpecificationForProductArray($productArray); // filter empty attributes foreach ($productArray['attributes'] as $key => $attr) { if (empty($attr['value']) && empty($attr['values']) && empty($attr['value_lang'])) { unset($productArray['attributes'][$key]); } } // attribute summary $productArray['listAttributes'] = array(); foreach ($productArray['attributes'] as $key => $attr) { if ($attr['SpecField']['isDisplayedInList']) { $productArray['listAttributes'][] = $attr; } if (!$attr['SpecField']['isDisplayed']) { unset($productArray['attributes'][$key]); } } // add product title to breacrumb $this->addBreadCrumb($productArray['name_lang'], createProductUrl(array('product' => $productArray), $this->application)); // manufacturer filter if ($product->manufacturer->get()) { $manFilter = new ManufacturerFilter($product->manufacturer->get()->getID(), $product->manufacturer->get()->name->get()); } // get category page route end($this->breadCrumb); $last = prev($this->breadCrumb); $catRoute = $this->router->getRouteFromUrl($last['url']); $response = new ActionResponse(); $response->set('product', $productArray); $response->set('category', $productArray['Category']); $response->set('quantity', $this->getQuantities($product)); $response->set('currency', $this->request->get('currency', $this->application->getDefaultCurrencyCode())); $response->set('catRoute', $catRoute); // ratings if ($this->config->get('ENABLE_RATINGS')) { if ($product->ratingCount->get() > 0) { // rating summaries ClassLoader::import('application.model.product.ProductRatingSummary'); $response->set('rating', ProductRatingSummary::getProductRatingsArray($product)); } ClassLoader::import('application.model.category.ProductRatingType'); $ratingTypes = ProductRatingType::getProductRatingTypeArray($product); $response->set('ratingTypes', $ratingTypes); $response->set('ratingForm', $this->buildRatingForm($ratingTypes, $product)); $response->set('isRated', $this->isRated($product)); $response->set('isLoginRequiredToRate', $this->isLoginRequiredToRate()); $response->set('isPurchaseRequiredToRate', $this->isPurchaseRequiredToRate($product)); } // add to cart form $response->set('cartForm', $this->buildAddToCartForm($this->getOptions(), $this->getVariations())); // related products $related = $this->getRelatedProducts($product); // items purchased together $together = $product->getProductsPurchasedTogether($this->config->get('NUM_PURCHASED_TOGETHER'), true); $spec = array(); foreach ($related as $key => $group) { foreach ($related[$key] as $i => &$prod) { $spec[] =& $related[$key][$i]; } } foreach ($together as &$prod) { $spec[] =& $prod; } ProductSpecification::loadSpecificationForRecordSetArray($spec); $response->set('related', $related); $response->set('together', $together); if (isset($manFilter)) { $response->set('manufacturerFilter', $manFilter); } $response->set('variations', $this->getVariations()); // reviews if ($this->config->get('ENABLE_REVIEWS') && $product->reviewCount->get() && ($numReviews = $this->config->get('NUM_REVIEWS_IN_PRODUCT_PAGE'))) { $f = new ARSelectFilter(new EqualsCond(new ARFieldHandle('ProductReview', 'isEnabled'), true)); $f->setLimit($numReviews); $reviews = $product->getRelatedRecordSetArray('ProductReview', $f); $this->pullRatingDetailsForReviewArray($reviews); $response->set('reviews', $reviews); } // bundled products if ($product->isBundle()) { $bundleData = ProductBundle::getBundledProductArray($product); $bundledProducts = array(); foreach ($bundleData as &$bundled) { $bundledProducts[] =& $bundled['RelatedProduct']; } ProductPrice::loadPricesForRecordSetArray($bundledProducts); $response->set('bundleData', $bundleData); $currency = Currency::getInstanceByID($this->getRequestCurrency()); $total = ProductBundle::getTotalBundlePrice($product, $currency); $response->set('bundleTotal', $currency->getFormattedPrice($total)); $saving = $total - $product->getPrice($currency); $response->set('bundleSavingTotal', $currency->getFormattedPrice($saving)); $response->set('bundleSavingPercent', $total ? round($saving / $total * 100) : 0); } // contact form if ($this->config->get('PRODUCT_INQUIRY_FORM')) { $response->set('contactForm', $this->buildContactForm()); } // display theme if ($theme = CategoryPresentation::getThemeByProduct($product)) { if ($theme->getTheme()) { $this->application->setTheme($theme->getTheme()); } $response->set('presentation', $theme->toFlatArray()); } // product images $images = $product->getImageArray(); if ($theme && $theme->isVariationImages->get()) { if ($variations = $this->getVariations()) { foreach ($variations['products'] as $prod) { if (!empty($prod['DefaultImage']['ID'])) { $images[] = $prod['DefaultImage']; } } } } $response->set('images', $images); // discounted pricing $response->set('quantityPricing', $product->getPricingHandler()->getDiscountPrices($this->user, $this->getRequestCurrency())); $response->set('files', $this->getPublicFiles()); // additional categories $f = new ARSelectFilter(); $f->setOrder(new ARFieldHandle('Category', 'lft')); $f->mergeCondition(new EqualsCond(new ARFieldHandle('Category', 'isEnabled'), true)); $pathC = new OrChainCondition(); $pathF = new ARSelectFilter($pathC); $categories = array(); foreach ($product->getRelatedRecordSetArray('ProductCategory', $f, array('Category')) as $cat) { $categories[] = array($cat['Category']); $cond = new OperatorCond(new ARFieldHandle('Category', 'lft'), $cat['Category']['lft'], "<"); $cond->addAND(new OperatorCond(new ARFieldHandle('Category', 'rgt'), $cat['Category']['rgt'], ">")); $pathC->addAnd($cond); } if ($categories) { $pathF->setOrder(new ARFieldHandle('Category', 'lft'), 'DESC'); $pathF->mergeCondition(new EqualsCond(new ARFieldHandle('Category', 'isEnabled'), true)); foreach (ActiveRecordModel::getRecordSetArray('Category', $pathF, array('Category')) as $parent) { if (!$parent['isEnabled']) { continue; } foreach ($categories as &$cat) { if ($cat[0]['lft'] > $parent['lft'] && $cat[0]['rgt'] < $parent['rgt'] && $parent['ID'] > Category::ROOT_ID) { $cat[] = $parent; } } } foreach ($categories as &$cat) { $cat = array_reverse($cat); } $response->set('additionalCategories', $categories); } $response->set('enlargeProductThumbnailOnMouseOver', $this->config->get('_ENLARGE_PRODUCT_THUMBNAILS_ON') == 'P_THUMB_ENLARGE_MOUSEOVER'); return $response; }
public function index() { ClassLoader::import('application.model.presentation.CategoryPresentation'); $this->getAppliedFilters(); // presentation if ($theme = CategoryPresentation::getThemeByCategory($this->getCategory())) { if ($theme->getTheme()) { $this->application->setTheme($theme->getTheme()); } if ($layout = $theme->listStyle->get()) { $this->request->set('layout', strtolower($layout)); $this->config->set('LIST_LAYOUT', $layout); $this->config->set('ALLOW_SWITCH_LAYOUT', false); } } // pagination $currentPage = $this->request->get('page', 1); $listLayout = $this->getListLayout(); $perPage = $this->getProductLimitCount($listLayout); $offsetStart = ($currentPage - 1) * $perPage + 1; $offsetEnd = $currentPage * $perPage; $selectFilter = new ARSelectFilter(); $selectFilter->setLimit($perPage, $offsetStart - 1); $this->application->processInstancePlugins('productFilter', $selectFilter); // create new search filter $query = $this->request->get('q'); if ($query) { $searchFilter = new SearchFilter($query); $this->filters[] = $searchFilter; // search by category names $f = new ARSelectFilter(); foreach (array($this->locale->getLocaleCode(), $this->application->getDefaultLanguageCode()) as $handle) { $langHandle = MultiLingualObject::getLangSearchHandle(new ARFieldHandle('Category', 'name'), $handle); $f->mergeCondition(new LikeCond($langHandle, '%' . $query . '%')); } $foundCategories = ActiveRecordModel::getRecordSet('Category', $f, Category::LOAD_REFERENCES); foreach ($foundCategories as $category) { $category->getPathNodeSet(); } $cleanedQuery = $searchFilter->getCleanedQuery($query); $this->logSearchQuery($cleanedQuery); } // root category? if ($this->getCategory()->isRoot() && !$this->filters && !$this instanceof IndexController && !$this->request->get('includeSub') && $currentPage > 1) { return new ActionRedirectResponse('index', 'index'); } // sorting $sort = array(); $opts = $this->config->get('ALLOWED_SORT_ORDER'); if ($opts) { foreach ($opts as $opt => $status) { $sort[strtolower($opt)] = $this->translate($opt); } } foreach ($this->getCategory()->getSpecificationFieldArray() as $field) { if ($field['isSortable']) { $sortName = $field['dataType'] == SpecField::DATATYPE_NUMBERS ? '_sort_num' : '_sort_text'; $sort[$field['ID'] . '-' . $field['handle'] . '_asc'] = $this->maketext($sortName . '_asc', $field['name_lang']); $sort[$field['ID'] . '-' . $field['handle'] . '_desc'] = $this->maketext($sortName . '_desc', $field['name_lang']); } } $order = $this->request->get('sort'); $defOrder = strtolower($this->config->get('SORT_ORDER')); if (!$order) { $order = $defOrder; } $this->applySortOrder($selectFilter, $order); // setup ProductFilter $productFilter = new ProductFilter($this->getCategory(), $selectFilter); if ($this->config->get('INCLUDE_SUBCATEGORY_PRODUCTS')) { $productFilter->includeSubcategories(); } $this->productFilter = $productFilter; foreach ($this->filters as $filter) { $productFilter->applyFilter($filter); if ($filter instanceof SearchFilter) { $productFilter->includeSubcategories(); $searchQuery = $filter->getKeywords(); } } if ($this->getCategory()->isRoot() && $this->filters || $this->filters || $this->request->get('includeSub')) { $productFilter->includeSubcategories(); } $products = $this->getProductsArray($productFilter); $this->hasProducts = count($products) > 0; // pagination $count = new ProductCount($this->productFilter, $this->application); $totalCount = $count->getCategoryProductCount($productFilter); $offsetEnd = min($totalCount, $offsetEnd); $this->totalCount = $totalCount; // narrow by subcategories $subCategories = $this->getCategory()->getSubCategoryArray(Category::LOAD_REFERENCES); $categoryNarrow = array(); if ((!empty($searchQuery) || $this->getCategory()->isRoot() || $this->filters) && $products) { $categoryNarrow = $this->getSubCategoriesBySearchQuery($productFilter->getSelectFilter(), $subCategories); } $categoryArray = $this->getCategory()->toArray(); if (!$this->getCategory()->isRoot()) { $this->redirect301($this->request->get('cathandle'), createHandleString($categoryArray['name_lang'])); } // if all the results come from one category, redirect to this category if (count($categoryNarrow) == 1 && count($this->filters) == 1 && empty($foundCategories)) { $canNarrow = true; foreach ($products as $product) { if ($product['Category']['ID'] == $this->getCategoryId()) { $canNarrow = false; } } if ($canNarrow) { while (count($categoryNarrow) == 1) { if ($categoryNarrow[0]['searchCount'] != $totalCount) { break; } $this->category = Category::getInstanceByID($categoryNarrow[0]['ID'], Category::LOAD_DATA); $subCategories = $this->getCategory()->getSubCategoryArray(Category::LOAD_REFERENCES); if ($subCategories) { $subCategories[] = $categoryArray; } $categoryNarrow = $this->getSubCategoriesBySearchQuery($selectFilter, $subCategories); } include_once ClassLoader::getRealPath('application.helper.smarty') . '/function.categoryUrl.php'; if (!$this->getCategory()->isRoot()) { return new RedirectResponse(createCategoryUrl(array('data' => $this->getCategory()->toArray(), 'filters' => $this->filters), $this->application)); } } } // get subcategory-subcategories if ($subCategories && $this->config->get('CAT_MENU_SUBS')) { $this->getSubSubCategories($subCategories); } // get subcategory featured products $subCatFeatured = array(); if ($subCategories && !$products || $this instanceof IndexController) { $subCatFeatured = $this->getSubCatFeaturedProducts(); } // if there were no products found, include subcategories in filter counts... except home page if (!$products || $this->getCategory()->isRoot()) { $selectFilter->removeCondition(new EqualsCond(new ARFieldHandle('Product', 'categoryID'), $this->getCategory()->getID())); $this->productFilter->includeSubcategories(); } // search redirects // no products found, but found one category name - redirect to this category if (isset($foundCategories) && 1 == $foundCategories->size() && !$products) { include_once ClassLoader::getRealPath('application.helper.smarty') . '/function.categoryUrl.php'; return new RedirectResponse(createCategoryUrl(array('data' => $foundCategories->get(0)->toArray()), $this->application)); } $filterArray = array(); foreach ($this->filters as $filter) { $filterArray[] = $filter->toArray(); } if ($this->config->get('DISPLAY_CATEGORY_FEATURED')) { $this->getFeaturedMainCategoryProducts($subCategories); $this->getFeaturedMainCategoryProducts($categoryNarrow); } $response = new ActionResponse(); $response->set('id', $this->getCategoryId()); $response->set('products', $products); $response->set('count', $totalCount); $response->set('offsetStart', $offsetStart); $response->set('offsetEnd', $offsetEnd); $response->set('perPage', $perPage); $response->set('currentPage', $currentPage); $response->set('category', $categoryArray); $response->set('subCategories', $subCategories); $response->set('currency', $this->getRequestCurrency()); $response->set('sortOptions', $sort); $response->set('sortForm', $this->buildSortForm($order)); $response->set('sortField', $order); $response->set('categoryNarrow', $categoryNarrow); $response->set('subCatFeatured', $subCatFeatured); //$response->set('allFilters', $filters); //$response->set('showAll', $showAll); $response->set('appliedFilters', $filterArray); $response->set('layout', $listLayout); $response->set('listAttributes', $this->getListAttributes()); $filterChainHandle = $this->setUpBreadCrumbAndReturnFilterChainHandle($currentPage); $response->set('url', $this->getCategoryPageUrl(array('page' => '_000_', 'filters' => $filterChainHandle))); $response->set('layoutUrl', $this->getCategoryPageUrl(array('filters' => $filterChainHandle, 'query' => array('layout' => '')))); $response->set('filterChainHandle', $filterChainHandle); if (isset($searchQuery)) { $response->set('searchQuery', $searchQuery); } if (isset($foundCategories)) { $response->set('foundCategories', $foundCategories->toArray()); } // look for manufacturer filter foreach ($this->filters as $filter) { if ($filter instanceof ManufacturerFilter) { $response->set('manufacturerFilter', $filter->toArray()); } } if (1 == $currentPage && $query) { $searchCon = new SearchController($this->application); $response->set('modelSearch', $searchCon->searchAll($cleanedQuery)); } return $response; }
public static function transformArray($array, ARSchema $schema) { $array = parent::transformArray($array, $schema); if (!empty($array['name_lang'])) { $array['handle'] = createHandleString($array['name_lang']); } return $array; }
public function getNextSpecField() { if (is_null($this->specFieldSql)) { // get all categories $this->specFieldSql = 'SELECT * FROM ' . $this->getTablePrefix() . 'product_options ORDER BY sort_order ASC'; } if (!($data = $this->loadRecord($this->specFieldSql))) { return null; } $this->attributes[] = $data; $rec = SpecField::getNewInstance(Category::getRootNode(), SpecField::DATATYPE_TEXT, SpecField::TYPE_TEXT_SIMPLE); $rec->setID($data['optionID']); $rec->handle->set(createHandleString($data['name'])); $rec->setValueByLang('name', $this->defLang, $data['name']); $rec->isDisplayed->set(true); return $rec; }