/** * @param int $parent_id * @param int[] $productCategoryIds * @return string */ private function getCategoriesParent($parent_id, $productCategoryIds) { $categories = CategoryDAO::getInstance()->getCategoriesByParentId($parent_id); $output = '<ul id="tree1">'; foreach ($categories as $category) { $children = CategoryDAO::getInstance()->getCategoriesByParentId($category->getId()); if (empty($children)) { $output .= '<li>'; if (in_array($category->getId(), $productCategoryIds)) { $output .= '<input type="checkbox" name="product_category[]" value="' . $category->getId() . '" checked="checked" />'; } else { $output .= '<input type="checkbox" name="product_category[]" value="' . $category->getId() . '" />'; } $output .= $category->getDescription()->getName(); $output .= '</li>'; } else { $output .= '<li>'; if (in_array($category->getId(), $productCategoryIds)) { $output .= '<input type="checkbox" name="product_category[]" value="' . $category->getId() . '" checked="checked" />'; } else { $output .= '<input type="checkbox" name="product_category[]" value="' . $category->getId() . '" />'; } $output .= $category->getDescription()->getName(); $output .= $this->getCategoriesParent($category->getId(), $productCategoryIds); $output .= '</li>'; } } $output .= '</ul>'; return $output; }
public function getProductsM($data = array()) { // $this->log->write(print_r($data, true)); if ($this->getCurrentCustomer()->isLogged()) { $customer_group_id = $this->getCurrentCustomer()->getCustomerGroupId(); } else { $customer_group_id = $this->getConfig()->get('config_customer_group_id'); } $cache = md5(http_build_query($data)); if (isset($data['nocache'])) { $product_data = 0; } else { $product_data = $this->getCache()->get('product.' . (int) $this->getConfig()->get('config_language_id') . '.' . (int) $this->getConfig()->get('config_store_id') . '.' . (int) $customer_group_id . '.' . $cache); } if (!$product_data) { $sql = "\n\t\t\t SELECT\n\t\t\t p.product_id,\n\t\t\t (\n\t\t\t SELECT AVG(rating) AS total\n\t\t\t FROM review r1\n\t\t\t WHERE r1.product_id = p.product_id AND r1.status = '1'\n\t\t\t GROUP BY r1.product_id\n ) AS rating\n FROM\n product p\n LEFT JOIN product_description pd ON (p.product_id = pd.product_id)\n LEFT JOIN product_to_store p2s ON (p.product_id = p2s.product_id)\n "; if (!empty($data['filter_tag'])) { $sql .= " LEFT JOIN product_tag pt ON (p.product_id = pt.product_id)"; } if (!empty($data['filter_category_id'])) { $sql .= " LEFT JOIN product_to_category p2c ON (p.product_id = p2c.product_id)"; } $sql .= "\n\t\t\t WHERE\n\t\t\t pd.language_id = '" . (int) $this->getConfig()->get('config_language_id') . "'\n\t\t\t AND p.status = '1'\n\t\t\t AND p.date_available <= '" . date('Y-m-d H:00:00') . "'\n\t\t\t AND p2s.store_id = '" . (int) $this->getConfig()->get('config_store_id') . "\n '"; if (!empty($data['filter_name']) || !empty($data['filter_tag'])) { $sql .= " AND ("; if (!empty($data['filter_name'])) { $implode = array(); $words = explode(' ', $data['filter_name']); foreach ($words as $word) { if (!empty($data['filter_description'])) { $implode[] = "LCASE(pd.name) LIKE '%" . $this->getDb()->escape(utf8_strtolower($word)) . "%' OR LCASE(pd.description) LIKE '%" . $this->getDb()->escape(utf8_strtolower($word)) . "%'" . "OR LCASE(p.model) LIKE '%" . $this->getDb()->escape(utf8_strtolower($word)) . "%' OR LCASE(pd.description) LIKE '%" . $this->getDb()->escape(utf8_strtolower($word)) . "%'"; } else { $implode[] = "LCASE(pd.name) LIKE '%" . $this->getDb()->escape(utf8_strtolower($word)) . "%'" . "OR LCASE(p.model) LIKE '%" . $this->getDb()->escape(utf8_strtolower($word)) . "%'"; } } if ($implode) { $sql .= " " . implode(" OR ", $implode) . ""; } } if (!empty($data['filter_name']) && !empty($data['filter_tag'])) { $sql .= " OR "; } if (!empty($data['filter_tag'])) { $implode = array(); $words = explode(' ', $data['filter_tag']); foreach ($words as $word) { $implode[] = "LCASE(pt.tag) LIKE '%" . $this->getDb()->escape(utf8_strtolower($word)) . "%' AND pt.language_id = '" . (int) $this->getConfig()->get('config_language_id') . "'"; } if ($implode) { $sql .= " " . implode(" OR ", $implode) . ""; } } $sql .= ")"; } if (!empty($data['filter_category_id'])) { if (!empty($data['filter_sub_category'])) { $implode_data = array(); $implode_data[] = "p2c.category_id = '" . (int) $data['filter_category_id'] . "'"; $categories = CategoryDAO::getInstance()->getCategoriesByParentId($data['filter_category_id']); foreach ($categories as $category) { $implode_data[] = "p2c.category_id = '" . (int) $category->getId() . "'"; } $sql .= " AND (" . implode(' OR ', $implode_data) . ")"; } else { $sql .= " AND p2c.category_id = '" . (int) $data['filter_category_id'] . "'"; } } if (!empty($data['filter_manufacturer_id'])) { $sql .= " AND p.manufacturer_id = '" . (int) $data['filter_manufacturer_id'] . "'"; } $sql .= " GROUP BY p.product_id"; $sort_data = array('pd.name', 'p.model', 'p.quantity', 'p.price', 'rating', 'p.sort_order', 'p.date_added'); if (isset($data['sort']) && in_array($data['sort'], $sort_data)) { if ($data['sort'] == 'pd.name' || $data['sort'] == 'p.model') { $sql .= " ORDER BY LCASE(" . $data['sort'] . ")"; } else { $sql .= " ORDER BY " . $data['sort']; } } else { $sql .= " ORDER BY p.sort_order"; } if (isset($data['order']) && $data['order'] == 'DESC') { $sql .= " DESC"; } else { $sql .= " ASC"; } if (isset($data['start']) || isset($data['limit'])) { if ($data['start'] < 0) { $data['start'] = 0; } if ($data['limit'] < 1) { $data['limit'] = 20; } // $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit']; } $product_data = array(); //print_r($sql);exit(); $query = $this->getDb()->query($sql); foreach ($query->rows as $result) { $product_data[$result['product_id']] = $this->getProduct($result['product_id']); } $this->getCache()->set('product.' . (int) $this->getConfig()->get('config_language_id') . '.' . (int) $this->getConfig()->get('config_store_id') . '.' . (int) $customer_group_id . '.' . $cache, $product_data); } return $product_data; }
/** * */ public function index() { $this->language->load('product/product'); if (isset($this->request->get['path'])) { $path = ''; foreach (explode('_', $this->request->get['path']) as $path_id) { if (!$path) { $path = $path_id; } else { $path .= '_' . $path_id; } $category = CategoryDAO::getInstance()->getCategory($path_id); if ($category) { #kabantejay synonymizer start $razdel = $category->getDescription()->getName(); #kabantejay synonymizer end $this->setBreadcrumbs([['text' => $category->getDescription()->getName(), 'route' => 'product/category&path=' . $path]]); } } } if (isset($this->request->get['manufacturer_id'])) { $this->data['breadcrumbs'][] = array('text' => $this->language->get('text_brand'), 'href' => $this->getUrl()->link('product/manufacturer'), 'separator' => $this->language->get('text_separator')); $manufacturer_info = ManufacturerDAO::getInstance()->getManufacturer($this->request->get['manufacturer_id']); if ($manufacturer_info) { $this->data['breadcrumbs'][] = array('text' => $manufacturer_info['name'], 'href' => $this->getUrl()->link('product/manufacturer/product', 'manufacturer_id=' . $this->request->get['manufacturer_id']), 'separator' => $this->language->get('text_separator')); } } if (isset($this->request->get['filter_name']) || isset($this->request->get['filter_tag'])) { $url = ''; if (isset($this->request->get['filter_name'])) { $url .= '&filter_name=' . $this->request->get['filter_name']; } if (isset($this->request->get['filter_tag'])) { $url .= '&filter_tag=' . $this->request->get['filter_tag']; } if (isset($this->request->get['filter_description'])) { $url .= '&filter_description=' . $this->request->get['filter_description']; } if (isset($this->request->get['filter_category_id'])) { $url .= '&filter_category_id=' . $this->request->get['filter_category_id']; } $this->data['breadcrumbs'][] = array('text' => $this->language->get('text_search'), 'href' => $this->getUrl()->link('product/search', $url), 'separator' => $this->language->get('text_separator')); } if (isset($this->request->get['product_id'])) { $productId = $this->request->get['product_id']; } else { $productId = 0; } try { $product = ProductDAO::getInstance()->getProduct($productId, false, true); $description = is_null($product->getDescription($this->getLanguage()->getId())) ? new \model\localization\Description($this->getLanguage()->getId(), '') : $product->getDescription($this->getLanguage()->getId()); $this->data['product_info'] = $product; //print_r($product_info);exit; $url = ''; if (isset($this->request->get['path'])) { $url .= '&path=' . $this->request->get['path']; } if (isset($this->request->get['manufacturer_id'])) { $url .= '&manufacturer_id=' . $this->request->get['manufacturer_id']; } if (isset($this->request->get['filter_name'])) { $url .= '&filter_name=' . $this->request->get['filter_name']; } if (isset($this->request->get['filter_tag'])) { $url .= '&filter_tag=' . $this->request->get['filter_tag']; } if (isset($this->request->get['filter_description'])) { $url .= '&filter_description=' . $this->request->get['filter_description']; } if (isset($this->request->get['filter_category_id'])) { $url .= '&filter_category_id=' . $this->request->get['filter_category_id']; } $this->data['breadcrumbs'][] = array('text' => $product->getName(), 'href' => $this->getUrl()->link('product/product', $url . '&product_id=' . $this->request->get['product_id']), 'separator' => $this->language->get('text_separator')); if (!empty($description->getSeoTitle())) { $this->document->setTitle($description->getSeoTitle()); } else { $this->document->setTitle($product->getName()); } $this->document->setDescription($description->getMetaDescription()); $this->document->setKeywords($description->getMetaKeyword()); //$this->document->addLink($this->getUrl()->link('product/product', 'product_id=' . $this->request->get['product_id']), 'canonical'); $this->data['seo_h1'] = $description->getSeoH1(); $this->data['heading_title'] = $product->getName(); $this->data['text_minimum'] = sprintf($this->language->get('text_minimum'), $product->getMinimum()); $this->getLoader()->model('catalog/review'); $this->data['tab_review'] = sprintf($this->language->get('tab_review'), $this->model_catalog_review->getTotalReviewsByProductId($this->request->get['product_id'])); $this->data['product_id'] = $product->getId(); $this->data['manufacturer'] = $product->getManufacturer()->getName(); $this->data['manufacturers'] = $this->getUrl()->link('product/manufacturer/product', 'manufacturer_id=' . $product->getManufacturer()->getId()); $this->data['model'] = $product->getModel(); $this->data['reward'] = $product->getRewards(); $this->data['points'] = $product->getPoints(); if ($product->getQuantity() <= 0) { $this->data['stock'] = $product->getStockStatusId(); } elseif ($this->getConfig()->get('config_stock_display')) { $this->data['stock'] = $product->getQuantity(); } else { $this->data['stock'] = $this->language->get('text_instock'); } if ($product->getImagePath()) { $this->data['popup'] = ImageService::getInstance()->resize($product->getImagePath(), $this->getConfig()->get('config_image_popup_width'), $this->getConfig()->get('config_image_popup_height')); } else { $this->data['popup'] = ''; } $results = ProductDAO::getInstance()->getProductImages($this->request->get['product_id']); if ($results) { $this->data['thumb'] = ImageService::getInstance()->resize($results[0]->getImagePath(), $this->getConfig()->get('config_image_thumb_width'), $this->getConfig()->get('config_image_thumb_height')); } else { if ($product->getImagePath()) { $this->data['thumb'] = ImageService::getInstance()->resize($product->getImagePath(), $this->getConfig()->get('config_image_thumb_width'), $this->getConfig()->get('config_image_thumb_height')); } else { $this->data['thumb'] = ''; } } $this->data['images'] = array(); foreach ($results as $tag) { $this->data['images'][] = array('popup' => ImageService::getInstance()->resize($tag->getImagePath(), $this->getConfig()->get('config_image_popup_width'), $this->getConfig()->get('config_image_popup_height')), 'thumb' => ImageService::getInstance()->resize($tag->getImagePath(), $this->getConfig()->get('config_image_additional_width'), $this->getConfig()->get('config_image_additional_height'))); } if ($this->getConfig()->get('config_customer_price') && $this->customer->isLogged() || !$this->getConfig()->get('config_customer_price')) { $this->data['price'] = $this->getCurrentCurrency()->format($product->getPrice()); } else { $this->data['price'] = false; } if ((double) $product->getSpecialPrice($this->getCurrentCustomer()->getCustomerGroupId())) { $this->data['special'] = $this->getCurrentCurrency()->format($product->getSpecialPrice($this->getCurrentCustomer()->getCustomerGroupId())); } else { $this->data['special'] = false; } // if ($this->getConfig()->get('config_tax')) { // $this->data['tax'] = $this->getCurrentCurrency()->format((float)$product_info->getSpecial'] ? $product_info['special'] : $product_info['price()); // } else { // $this->data['tax'] = false; // } $discounts = ProductDAO::getInstance()->getProductDiscounts($product->getId()); $this->data['discounts'] = array(); foreach ($discounts as $discount) { $this->data['discounts'][] = array('quantity' => $discount['quantity'], 'price' => $this->getCurrentCurrency()->format($discount['price'])); } $this->data['options'] = array(); foreach (ProductDAO::getInstance()->getProductOptions($this->request->get['product_id']) as $productOption) { if ($productOption->getOption()->isMultiValueType()) { $option_value_data = array(); foreach ($productOption->getValue() as $option_value) { if (is_null($option_value->getOptionValue())) { continue; } if (!$option_value->getSubtract() || $option_value->getQuantity() > 0) { $option_value_data[] = array('product_option_value_id' => $option_value->getId(), 'option_value_id' => $option_value->getOptionValue()->getId(), 'name' => $option_value->getOptionValue()->getName(), 'image' => ImageService::getInstance()->resize($option_value->getOptionValue()->getImage(), 50, 50), 'price' => (double) $option_value->getPrice() ? $this->getCurrentCurrency()->format($option_value->getPrice()) : false, 'price_prefix' => $option_value->getPrice() < 0 ? '-' : '+'); } } $this->data['options'][] = array('product_option_id' => $productOption->getId(), 'option_id' => $productOption->getOption()->getId(), 'name' => $productOption->getOption()->getName(), 'type' => $productOption->getType(), 'option_value' => $option_value_data, 'required' => $productOption->isRequired()); } elseif ($productOption->getOption()->isSingleValueType()) { $this->data['options'][] = array('product_option_id' => $productOption->getId(), 'option_id' => $productOption->getOption()->getId(), 'name' => $productOption->getOption()->getName(), 'type' => $productOption->getType(), 'option_value' => $productOption->getValue(), 'required' => $productOption->isRequired()); } } if ($product->getMinimum()) { $this->data['minimum'] = $product->getMinimum(); } else { $this->data['minimum'] = 1; } $date_added = getdate(strtotime($product->getDateAdded())); $date_added = mktime(0, 0, 0, $date_added['mon'], $date_added['mday'], $date_added['year']); $this->data['review_status'] = $this->getConfig()->get('config_review_status'); $this->data['reviews'] = sprintf($this->language->get('text_reviews'), (int) $product->getReviewsCount()); $this->data['rating'] = (int) $product->getRating(); $this->data['description'] = html_entity_decode($description->getDescription(), ENT_QUOTES, 'UTF-8'); $this->data['image_description'] = html_entity_decode($product->getImageDescription(), ENT_QUOTES, 'UTF-8'); $this->data['attribute_groups'] = $product->getAttributes(); $this->data['hot'] = $date_added + 86400 * $this->getConfig()->get('config_product_hotness_age') > time(); $this->data['weight'] = $this->weight->format($product->getWeight()->getWeight(), $product->getWeight()->getUnit()->getId()); $this->data['products'] = array(); #kabantejay synonymizer start if (!is_null($product->getManufacturer())) { $brand = ''; } else { $brand = $product->getManufacturer(); } if (!isset($razdel)) { $razdel = ''; } if (!isset($category)) { $syncat = ''; } else { $syncat = $category->getDescription()->getName(); } if (!is_null($product->getModel())) { $synmod = ''; } else { $synmod = $product->getModel(); } if ($this->data['special'] == false) { $synprice = $this->data['price']; } else { $synprice = $this->data['special']; } $syntext = array(array("%H1%", $product->getName()), array("%BRAND%", $brand), array("%RAZDEL%", $razdel), array("%CATEGORY%", $syncat), array("%MODEL%", $synmod), array("%PRICE%", $synprice)); for ($it = 0; $it < 6; $it++) { $this->data['description'] = str_replace($syntext[$it][0], $syntext[$it][1], $this->data['description']); } $this->data['description'] = preg_replace_callback('/\\{ (.*?) \\}/xs', function ($m) { $ar = explode("|", $m[1]); return $ar[array_rand($ar, 1)]; }, $this->data['description']); #kabantejay synonymizer end // $results = $this->model_catalog_product->getProductRelated($this->request->get['product_id']); // $results = $product_info->getRelated(); foreach ($product->getRelated() as $tag) { if ($tag->getImagePath()) { $image = ImageService::getInstance()->resize($tag->getImagePath(), $this->getConfig()->get('config_image_related_width'), $this->getConfig()->get('config_image_related_height')); } else { $image = false; } if ($this->getConfig()->get('config_customer_price') && $this->customer->isLogged() || !$this->getConfig()->get('config_customer_price')) { $price = $this->getCurrentCurrency()->format($tag->getPrice()); } else { $price = false; } if ((double) $tag->getSpecialPrice($this->getCurrentCustomer()->getCustomerGroupId())) { $special = $this->getCurrentCurrency()->format($tag->getSpecialPrice($this->getCurrentCustomer()->getCustomerGroupId())); } else { $special = false; } if ($this->getConfig()->get('config_review_status')) { $rating = (int) $tag->getRating(); } else { $rating = false; } $this->data['products'][] = array('product_id' => $tag->getId(), 'thumb' => $image, 'name' => $tag->getName(), 'price' => $price, 'special' => $special, 'rating' => $rating, 'reviews' => sprintf($this->language->get('text_reviews'), (int) $tag->getReviewsCount()), 'href' => $this->getUrl()->link('product/product', 'product_id=' . $tag->getId())); } $this->data['tags'] = array(); // $results = $this->model_catalog_product->getProductTags($this->request->get['product_id']); foreach ($product->getTags() as $tag) { $this->data['tags'][] = array('tag' => $tag, 'href' => $this->getUrl()->link('product/search', 'filter_tag=' . $tag)); } ProductDAO::getInstance()->updateViewed($product->getId()); $this->setBreadcrumbs(); $this->children = array('common/header', 'common/column_left', 'common/column_right', 'common/content_top', 'common/content_bottom', 'common/footer'); $templateFile = '/template/product/product.tpl'; $templateDir = file_exists(DIR_TEMPLATE . $this->getConfig()->get('config_template') . $templateFile) ? $this->getConfig()->get('config_template') : 'default'; $this->getResponse()->setOutput($this->render($templateDir . $templateFile)); } catch (InvalidArgumentException $exc) { $url = ''; if (isset($this->request->get['path'])) { $url .= '&path=' . $this->request->get['path']; } if (isset($this->request->get['manufacturer_id'])) { $url .= '&manufacturer_id=' . $this->request->get['manufacturer_id']; } if (isset($this->request->get['filter_name'])) { $url .= '&filter_name=' . $this->request->get['filter_name']; } if (isset($this->request->get['filter_tag'])) { $url .= '&filter_tag=' . $this->request->get['filter_tag']; } if (isset($this->request->get['filter_description'])) { $url .= '&filter_description=' . $this->request->get['filter_description']; } if (isset($this->request->get['filter_category_id'])) { $url .= '&filter_category_id=' . $this->request->get['filter_category_id']; } $this->data['breadcrumbs'][] = array('text' => $this->language->get('text_error'), 'href' => $this->getUrl()->link('product/product', $url . '&product_id=' . $productId), 'separator' => $this->language->get('text_separator')); $this->document->setTitle($this->language->get('text_error')); $this->data['heading_title'] = $this->language->get('text_error'); $this->data['text_error'] = $this->language->get('text_error'); $this->data['button_continue'] = $this->language->get('button_continue'); $this->data['continue'] = $this->getUrl()->link('common/home'); $this->children = array('common/header', 'common/column_left', 'common/column_right', 'common/content_top', 'common/content_bottom', 'common/footer'); $this->getResponse()->setOutput($this->render($this->getConfig()->get('config_template') . '/template/error/not_found.tpl')); } }
public function index() { // $this->log->write(print_r($this->request, true)); $this->getLanguage()->load('product/search'); if (isset($this->request->get['filter_name'])) { $filter_name = $this->request->get['filter_name']; } else { $filter_name = ''; } // // if (isset($this->request->get['filter_description'])) { // $filter_description = $this->request->get['filter_description']; // } else { // $filter_description = ''; // } if (isset($this->request->get['filter_category_id'])) { $filter_category_id = $this->request->get['filter_category_id']; } else { $filter_category_id = 0; } if (isset($this->request->get['filter_sub_category'])) { $filter_sub_category = $this->request->get['filter_sub_category']; } else { $filter_sub_category = ''; } if (isset($this->request->get['sort'])) { $sort = $this->request->get['sort']; } else { $sort = null; } if (isset($this->request->get['order'])) { $order = $this->request->get['order']; } else { $order = 'ASC'; } if (isset($this->request->get['page'])) { $page = $this->request->get['page']; } else { $page = 1; } if (isset($this->request->get['limit'])) { $limit = $this->request->get['limit']; } else { $limit = $this->getConfig()->get('config_catalog_limit'); } if (isset($this->request->get['keyword'])) { $this->document->setTitle($this->getLanguage()->get('heading_title') . ' - ' . $this->request->get['keyword']); } else { $this->document->setTitle($this->getLanguage()->get('heading_title')); } $url = ''; if (isset($this->request->get['filter_name'])) { $url .= '&filter_name=' . $this->request->get['filter_name']; } if (isset($this->request->get['filter_tag'])) { $url .= '&filter_tag=' . $this->request->get['filter_tag']; } if (isset($this->request->get['filter_description'])) { $url .= '&filter_description=' . $this->request->get['filter_description']; } if (isset($this->request->get['filter_category_id'])) { $url .= '&filter_category_id=' . $this->request->get['filter_category_id']; } if (isset($this->request->get['filter_sub_category'])) { $url .= '&filter_sub_category=' . $this->request->get['filter_sub_category']; } if (isset($this->request->get['sort'])) { $url .= '&sort=' . $this->request->get['sort']; } if (isset($this->request->get['order'])) { $url .= '&order=' . $this->request->get['order']; } if (isset($this->request->get['page'])) { $url .= '&page=' . $this->request->get['page']; } if (isset($this->request->get['limit'])) { $url .= '&limit=' . $this->request->get['limit']; } $this->data['text_compare'] = sprintf($this->getLanguage()->get('text_compare'), isset($this->session->data['compare']) ? count($this->session->data['compare']) : 0); $this->data['compare'] = $this->getUrl()->link('product/compare'); // 3 Level Category Search $this->data['categories'] = array(); $categories_1 = CategoryDAO::getInstance()->getCategoriesByParentId(0); foreach ($categories_1 as $category_1) { $level_2_data = array(); $categories_2 = CategoryDAO::getInstance()->getCategoriesByParentId($category_1->getId()); foreach ($categories_2 as $category_2) { $level_3_data = array(); $categories_3 = CategoryDAO::getInstance()->getCategoriesByParentId($category_2->getId()); foreach ($categories_3 as $category_3) { $level_3_data[] = array('category_id' => $category_3->getId(), 'name' => $category_3->getDescription()->getName()); } $level_2_data[] = array('category_id' => $category_2->getId(), 'name' => $category_2->getDescription()->getName(), 'children' => $level_3_data); } $this->data['categories'][] = array('category_id' => $category_1->getId(), 'name' => $category_1->getDescription()->getName(), 'children' => $level_2_data); } #kabantejay synonymizer start $result['description'] = null; /// Expression below makes no sense as it refers to non-initialized variable // $result['description'] = preg_replace_callback( // '/\{ (.*?) \}/xs', // function ($m) { // $ar = explode("|", $m[1]); // return $ar[array_rand($ar, 1)]; // }, // $result['description'] // ); #kabantejay synonymizer end $this->data['products'] = array(); if (isset($this->request->get['filter_name']) || isset($this->request->get['filter_tag'])) { $filter = new FilterTree(['filterEnabled' => true, 'filterCategoryId' => $filter_category_id, 'filterSubCategories' => $filter_sub_category], 'AND', new FilterTree(['filterName' => $filter_name], 'OR', new FilterTree(['filterModel' => $filter_name], 'OR', new FilterTree(['filterTag' => $filter_name]))), true); $data = array('filterEnabled' => true, 'filterName' => $filter_name, 'filterCategoryId' => $filter_category_id, 'filterSubCategories' => $filter_sub_category, 'sort' => $sort, 'order' => $order, 'start' => ($page - 1) * $limit, 'limit' => $limit); $product_total = ProductDAO::getInstance()->getProductsCount($filter); $results = ProductDAO::getInstance()->getProducts($filter, $sort, $order, ($page - 1) * $limit, $limit); if ($sort == null) { $results = $this->sortByRelevance($results, $filter_name); } foreach ($results as $product) { if ($product->getImagePath()) { $image = ImageService::getInstance()->resize($product->getImagePath(), $this->getConfig()->get('config_image_product_width'), $this->getConfig()->get('config_image_product_height')); } else { $image = false; } if ($this->getConfig()->get('config_customer_price') && $this->customer->isLogged() || !$this->getConfig()->get('config_customer_price')) { $price = $this->getCurrency()->format($product->getPrice()); } else { $price = false; } if ((double) $product->getSpecialPrice($this->getCurrentCustomer()->getCustomerGroupId())) { $special = $this->getCurrency()->format($product->getSpecialPrice($this->getCurrentCustomer()->getCustomerGroupId())); } else { $special = false; } // // if ($this->getConfig()->get('config_review_status')) { // $rating = (int)$product->getRating(); // } else { // $rating = false; // } $this->data['products'][] = array('product_id' => $product->getId(), 'thumb' => $image, 'name' => $product->getName(), 'description' => !is_null($product->getDescriptions()->getDescription($this->getLanguage()->getId())) ? utf8_truncate(strip_tags(html_entity_decode($product->getDescriptions()->getDescription($this->getLanguage()->getId())->getDescription(), ENT_QUOTES, 'UTF-8')), 400, ' …', true) : '', 'price' => $price, 'special' => $special, 'rating' => $product->getRating(), 'reviews' => sprintf($this->getLanguage()->get('text_reviews'), (int) $product->getReviewsCount()), 'href' => $this->getUrl()->link('product/product', $url . '&product_id=' . $product->getId())); } $url = ''; if (isset($this->request->get['filter_name'])) { $url .= '&filter_name=' . $this->request->get['filter_name']; } if (isset($this->request->get['filter_tag'])) { $url .= '&filter_tag=' . $this->request->get['filter_tag']; } if (isset($this->request->get['filter_description'])) { $url .= '&filter_description=' . $this->request->get['filter_description']; } if (isset($this->request->get['filter_category_id'])) { $url .= '&filter_category_id=' . $this->request->get['filter_category_id']; } if (isset($this->request->get['filter_sub_category'])) { $url .= '&filter_sub_category=' . $this->request->get['filter_sub_category']; } $this->data['sorts'] = array(); // $this->data['sorts'][] = array( // 'text' => $this->getLanguage()->get('text_default'), // 'value' => 'p.sort_order-ASC', // 'href' => $this->getUrl()->link('product/search', 'sort=p.sort_order&order=ASC' . $url) // ); $this->data['sorts'][] = array('text' => $this->getLanguage()->get('RELEVANCE'), 'value' => null, 'href' => $this->getUrl()->link('product/search', '' . $url)); $this->data['sorts'][] = array('text' => $this->getLanguage()->get('text_name_asc'), 'value' => 'pd.name-ASC', 'href' => $this->getUrl()->link('product/search', 'sort=pd.name&order=ASC' . $url)); $this->data['sorts'][] = array('text' => $this->getLanguage()->get('text_name_desc'), 'value' => 'pd.name-DESC', 'href' => $this->getUrl()->link('product/search', 'sort=pd.name&order=DESC' . $url)); $this->data['sorts'][] = array('text' => $this->getLanguage()->get('text_price_asc'), 'value' => 'p.price-ASC', 'href' => $this->getUrl()->link('product/search', 'sort=p.price&order=ASC' . $url)); $this->data['sorts'][] = array('text' => $this->getLanguage()->get('text_price_desc'), 'value' => 'p.price-DESC', 'href' => $this->getUrl()->link('product/search', 'sort=p.price&order=DESC' . $url)); $this->data['sorts'][] = array('text' => $this->getLanguage()->get('text_rating_desc'), 'value' => 'rating-DESC', 'href' => $this->getUrl()->link('product/search', 'sort=rating&order=DESC' . $url)); $this->data['sorts'][] = array('text' => $this->getLanguage()->get('text_rating_asc'), 'value' => 'rating-ASC', 'href' => $this->getUrl()->link('product/search', 'sort=rating&order=ASC' . $url)); $this->data['sorts'][] = array('text' => $this->getLanguage()->get('text_model_asc'), 'value' => 'p.model-ASC', 'href' => $this->getUrl()->link('product/search', 'sort=p.model&order=ASC' . $url)); $this->data['sorts'][] = array('text' => $this->getLanguage()->get('text_model_desc'), 'value' => 'p.model-DESC', 'href' => $this->getUrl()->link('product/search', 'sort=p.model&order=DESC' . $url)); $this->data['limits'] = array(); $this->data['limits'][] = array('text' => $this->getConfig()->get('config_catalog_limit'), 'value' => $this->getConfig()->get('config_catalog_limit'), 'href' => $this->getUrl()->link('product/search', $url . '&limit=' . $this->getConfig()->get('config_catalog_limit'))); $this->data['limits'][] = array('text' => 25, 'value' => 25, 'href' => $this->getUrl()->link('product/search', $url . '&limit=25')); $this->data['limits'][] = array('text' => 50, 'value' => 50, 'href' => $this->getUrl()->link('product/search', $url . '&limit=50')); $this->data['limits'][] = array('text' => 75, 'value' => 75, 'href' => $this->getUrl()->link('product/search', $url . '&limit=75')); $this->data['limits'][] = array('text' => 100, 'value' => 100, 'href' => $this->getUrl()->link('product/search', $url . '&limit=100')); $pagination = new Pagination(); $pagination->total = $product_total; $pagination->page = $page; $pagination->limit = $limit; $pagination->text = $this->getLanguage()->get('text_pagination'); $pagination->url = $this->getUrl()->link('product/search', $url . '&page={page}'); $this->data['pagination'] = $pagination->render(); } $this->data['filter_name'] = $filter_name; // $this->data['filter_description'] = $filter_description; $this->data['filter_category_id'] = $filter_category_id; $this->data['filter_sub_category'] = $filter_sub_category; $this->data['sort'] = $sort; $this->data['order'] = $order; $this->data['limit'] = $limit; $this->setBreadcrumbs(); $this->children = array('common/column_left', 'common/column_right', 'common/content_top', 'common/content_bottom', 'common/footer', 'common/header'); $templateFile = '/template/product/search.tpl.php'; $templateDir = file_exists(DIR_TEMPLATE . $this->getConfig()->get('config_template') . $templateFile) ? $this->getConfig()->get('config_template') : ($templateDir = 'default'); $this->getResponse()->setOutput($this->render($templateDir . $templateFile)); }