Jump to content
Sign in to follow this  
latoshinserg

Вывести ссылку на категорию в модуле

Recommended Posts

Есть модуль, типа слайдера - отображает товары из категории и название этой категории, а ссылку на категорию нет.

Хочу, чтоб при клике по названию переходило в эту категорию. Никак не могу придумать, как это сделать. Помогите, как реализовать??

 

controller

<?php

class ControllerModuleCategoryProductSlider extends Controller {
	
	public function index($setting) {
	

		static $module = 0;

		$this->load->language('module/category_product_slider');
		
		$this->load->model('catalog/product');
		
		$this->load->model('tool/image');
		
	
		//category wise Products
		$data['categorywise_products1'] = array();
		
		if (empty($setting['limit'])) {
			$setting['limit'] = 5;
		}

		$data = array('filter_category_id' => $setting['category_name'],'limit'=> $setting['limit'],'sort'  => 'p.date_added','order' => 'DESC','start'=>'0');
		
		$results = $this->model_catalog_product->getProducts($data);
		
		foreach ($results as $result) {
			if ($result['image']) {
				$image = $this->model_tool_image->resize($result['image'], $setting['width'], $setting['height']);
			} else {
				$image = false;
			}
						
			if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
				$price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')));
			} else {
				$price = false;
			}
					
				if ((float)$result['special']) {
					$special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')));
					$skidka = round(100-($result['special']/($result['price']/100)));
				} else {
					$special = false;
					$skidka = false;
				}
			
			if ($this->config->get('config_review_status')) {
				$rating = $result['rating'];
			} else {
				$rating = false;
			}
			
			$data['categorywise_products'][] = array(
			
				'product_id' => $result['product_id'],
				'thumb'   	 => $image,
				'name'    	 => $result['name'],
				'price'   	 => $price,
				'special' 	 => $special,
				'rating'     => $rating,
				'skidka' 	 => $skidka,
				'reviews'    => sprintf($this->language->get('text_reviews'), (int)$result['reviews']),
				'href'    	 => $this->url->link('product/product', 'product_id=' . $result['product_id']),
			);
		}


		//get name of category
		$this->load->model('catalog/category');
		
		$category_result = $this->model_catalog_category->getCategory($setting['category_name']);
		$data['category_name'] = NULL;
		$data['category_name'] = $category_result['name'];
		$data['heading_title'] = $this->language->get('heading_title');
		$data['button_cart'] = $this->language->get('button_cart');
		$data['button_wishlist'] = $this->language->get('button_wishlist');
		$data['button_compare'] = $this->language->get('button_compare');
		$data['no_product_found'] = $this->language->get('no_product_found');

		$data['module'] = $module++;


		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/category_product_slider.tpl')) {
				return $this->load->view($this->config->get('config_template') . '/template/module/category_product_slider.tpl', $data);
			} else {
				return $this->load->view('default/template/module/category_product_slider.tpl', $data);
			}

		/*$this->render();*/
	}
}

?>

 

template

<?php global $config; ?>
<div class="middle-slider container">
<div class="row">
<div class="col-md-12">
<div class="bag-product-slider small-pr-slider wow bounceInLeft animated">
<div class="slider-items-products">
<div class="new_title center"><h2><?php echo $category_name; ?></h2></div>
<div id="bag-seller-slider" class="product-flexslider hidden-buttons">
  <?php if(isset($categorywise_products)){ ?>
   <div class="slider-items slider-width-col3"> 
     <?php  foreach ($categorywise_products as $product) { ?>
                  <div class="item">
                  <div class="product-block">
                  <?php if ($product['thumb']) { ?>
                  <div class="product-image">
                  <a href="<?php echo $product['href']; ?>">
                  <figure class="product-display">
                  <?php if($config->get('magikmicra_sale_label')==1) { 
                  if ($product['price'] && $product['special']) { ?>
                  <div class="sale-label sale-top-right"><div class="procent">-<?php echo $product['skidka']; ?> %</div></div>
                  <?php } }?>
                  <img style="display: block;" alt="<?php echo $product['name']; ?>" class="lazyOwl product-mainpic img-responsive" src="<?php echo $product['thumb']; ?>"> 
                  <img width="258" src="<?php echo $product['thumb']; ?>" alt="<?php echo $product['name']; ?>" class="product-secondpic img-responsive"> 
                  </figure>
                  </a> 
                  </div><!-- product-image -->    
                  <div class="product-meta">
                  <div class="product-action">
                  <a class="addcart" onclick="cart.add('<?php echo $product['product_id']; ?>');" title="Купить"><i class="icon-shopping-cart"> </i><?php //echo $button_cart; ?></a>
                  <?php if($config->get('magikmicra_quickview_button') == 1) { ?>
                  <a data-fancybox-type="ajax" onclick="callQuickView('index.php?route=product/quickview&amp;product_id=<?php echo $product['product_id']; ?>');" title="Просмотр" type="button" class="quickview"><i class="icon-zoom"> </i></a>
                  <?php } ?> 
                  </div>
                  </div><!-- product-meta -->
                  <?php } ?>
                  </div><!-- product-block -->


                  <div class="item-info">
                  <div class="info-inner">
                  <div class="item-title"> <a title="<?php echo $product['name']; ?>" href="<?php echo $product['href']; ?>"><?php echo $product['name']; ?></a> 
                  </div>
                  <div class="item-content">
                  <?php if ($product['price']) { ?>
                  <div class="item-price">
                  <div class="price-box"> 
                  <?php if (!$product['special']) { ?>
                  <span class="regular-price"><span class="price"><?php echo $product['price']; ?></span></span> 
                  <?php } else { ?>
                  <span class="old-price"><span class="price"><?php echo $product['price']; ?></span></span> 
                  <span class="special-price"><span class="price"><?php echo $product['special']; ?></span></span>
                  <?php } ?>
                  <?php /* if ($product['tax']) { ?>
                  <span class="price-tax"><?php echo $text_tax; ?> <?php echo $product['tax']; ?></span>
                  <?php } */?>
                  </div>
                  </div>
                  <?php } ?>
                  <?php //if ($product['rating']) { ?>
                  <div class="rating">
                  <div class="ratings">
                  <div class="rating-box">
                  <?php for ($i = 1; $i <= 5; $i++) { ?>
                  <?php if ($product['rating'] < $i) { ?>
                  <span class="fa fa-stack"><i class="fa fa-star-o fa-stack-2x"></i></span>
                  <?php } else { ?>
                  <span class="fa fa-stack"><i class="fa fa-star fa-stack-2x"></i><i class="fa fa-star-o fa-stack-2x"></i></span>
                  <?php } ?>
                  <?php } ?>
                  </div>
                  </div>
                  </div><!-- rating -->
                  <?php // }?>
                  <?php /* ?> <div class="actions">
                  <a style="cursor:pointer" class="link-wishlist" onclick="wishlist.add('<?php echo $product['product_id']; ?>');" title="<?php echo $button_wishlist; ?>"><?php //echo $button_wishlist; ?></a>
                  <div class="add_cart">
                  <button class="button btn-cart" type="button" onclick="cart.add('<?php echo $product['product_id']; ?>');"><span><?php echo $button_cart; ?></span></button>
                  </div>
                  <a style="cursor:pointer" class="link-compare" title="<?php echo $button_compare; ?>" onclick="compare.add('<?php echo $product['product_id']; ?>');"><?php //echo $button_compare; ?></a> 
                  </div><!-- action -->
                  <?php */ ?>  
                  </div><!-- item-content -->
                  </div><!-- info-inner -->
                  </div><!-- item-info -->


              </div><!-- item -->
     <?php } ?>
   </div>
  <?php } else { ?>
  <?php echo $no_product_found;?>
  <?php } ?>
</div><!-- bag-seller-slider -->
</div>
</div>
</div>
</div>
</div>

 

category_product_slider.php category_product_slider.tpl

Share this post


Link to post
Share on other sites

Увы, но решение так и не найдено.

Но.... Если мы имеем ссылку на товар из этой категории 

$product['href'];

можно ли из нее как-то убрать последнюю часть с id товара, чтоб осталась только категория.

 т.е. получаем ссылку на любой товар из этой катеогрии http://site1.ru/category1/tovar1.html

убираем tovar1.html - и показываем ссылку на категорию этого товара?

 

На странице самого товара предлагали решение такое

 

<?php
$real_url = $_SERVER['REQUEST_URI'];                //получаем адрес текущей страницы
$cut_url = rtrim( dirname( $real_url ), "/" )."/";  //отрезаем текущий товар и получаем адрес директории
?>
<div class="box">
   <a class="button"  target="_top" href="<?php echo $cut_url; ?>"> Перейти в раздел </a>
</div>
 
я попробовал переделать под свои нужды - не работает, ошибка 500 ((
 
 
<?php  foreach ($categorywise_products as $product) { ?>
<?php $real_url = echo $product['href']; ?> 
<?php $cut_url = rtrim( dirname( $real_url ), "/" )."/"; ?>
<a href="<?php echo $cut_url; ?>">
<?php } ?> 
<?php echo $category_name; ?>
</a>

 

Share this post


Link to post
Share on other sites

Таки добил я эту "гребаную" ссылку, может кому-то понадобится решение

 

<?php  foreach ($categorywise_products as $product) { ?>
<?php 
$link = $product['href']; 
$url = rtrim( dirname( $link ), "/" )."/";
?>
<a href="<?php echo $url; ?>">
<?php } ?> 
<?php echo $category_name; ?>
</a>

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.