Post by turkkan » Wed Jun 06, 2018 9:23 pm

Hello my friends I'm using tab content in my website. I list the products with tabs but I want to add a button like "All Products In Computers". Because customers can't find the all products related with the category. I will add a banner for customers to send them the category. Who can help me ?

my website: https://www.inegolmobilyan.com

Newbie

Posts

Joined
Thu Jan 25, 2018 2:51 am


Post by scottyboyyy » Fri Jun 08, 2018 12:26 pm

Hi Turkkan,

Correct me if I am wrong but you want the product to link back to the category on the tabs from the product page?

For example:

This product (https://www.inegolmobilyan.com/oslo-orta-sehpa) would have a tab that links back to (https://www.inegolmobilyan.com/orta-sehpa).

You need to make two edits:

Catalog/view/template/product/product.tpl:

Add to your new tab or wherever you want it on this page, this is the visual side (what the customer sees)

Code: Select all

<?php if( $parentcategories ){ ?>
    <li>
        <?php foreach( $parentcategories as $parentcategory ){ ?>
    <a href="<?php echo $parentcategory['href']; ?>"><?php echo $parentcategory['name']; ?></a>&nbsp;
        <?php } ?>
    </li>
<?php } ?>
Catalog/controller/product/product.php:

This gives the information to the above code:

Go to line 270~ when I tested I put above "$this->load->model('catalog/review');"

Code: Select all

$checkparentcategories = $this->model_catalog_product->getCategories($product_id);
        $parentcategory = array();
          foreach( $checkparentcategories as $parentcategory ) {
               $parentcategory = $this->model_catalog_category->getCategory($parentcategory['category_id']);
               $parentcategorydata['id'] = $parentcategory['category_id'];
               $parentcategorydata['href'] = $this->url->link('product/category', 'path=' . $parentcategory['category_id']);
               $parentcategorydata['name'] = $parentcategory['name'];
               $parentcategories[] = $parentcategorydata;
           }
        $data['parentcategories'] = $parentcategories;
This will work for multiple categories - if a product has more than 1 parent categories / subcategories. For example iphone is linked to smartphones and desktops, etc.

This also won't cause you issues if a product has no category either.

Let me know if this works for you / if this is what you wanted. Also let me know if you need anything explained.

:-)

Active Member

Posts

Joined
Fri Apr 07, 2017 2:36 am

Post by turkkan » Sat Jun 09, 2018 5:57 pm

Firstly I want to say that I really appreciate for your reply. I want to explain what I want clearly. My english is not so good :)

There are tabs as you see ( http://prntscr.com/jsvnam ) and I list six products for a tab. Customers suppose that there are only 6 products for category. Thats why I want to add a button like "ALL PRODUCTS". I need to get the category link according to selected tab.

You can see the example:
http://prntscr.com/jsvmfb
http://prntscr.com/jsvm1l
scottyboyyy wrote:
Fri Jun 08, 2018 12:26 pm
Hi Turkkan,

Correct me if I am wrong but you want the product to link back to the category on the tabs from the product page?

For example:

This product (https://www.inegolmobilyan.com/oslo-orta-sehpa) would have a tab that links back to (https://www.inegolmobilyan.com/orta-sehpa).

You need to make two edits:

Catalog/view/template/product/product.tpl:

Add to your new tab or wherever you want it on this page, this is the visual side (what the customer sees)

Code: Select all

<?php if( $parentcategories ){ ?>
    <li>
        <?php foreach( $parentcategories as $parentcategory ){ ?>
    <a href="<?php echo $parentcategory['href']; ?>"><?php echo $parentcategory['name']; ?></a>&nbsp;
        <?php } ?>
    </li>
<?php } ?>
Catalog/controller/product/product.php:

This gives the information to the above code:

Go to line 270~ when I tested I put above "$this->load->model('catalog/review');"

Code: Select all

$checkparentcategories = $this->model_catalog_product->getCategories($product_id);
        $parentcategory = array();
          foreach( $checkparentcategories as $parentcategory ) {
               $parentcategory = $this->model_catalog_category->getCategory($parentcategory['category_id']);
               $parentcategorydata['id'] = $parentcategory['category_id'];
               $parentcategorydata['href'] = $this->url->link('product/category', 'path=' . $parentcategory['category_id']);
               $parentcategorydata['name'] = $parentcategory['name'];
               $parentcategories[] = $parentcategorydata;
           }
        $data['parentcategories'] = $parentcategories;
This will work for multiple categories - if a product has more than 1 parent categories / subcategories. For example iphone is linked to smartphones and desktops, etc.

This also won't cause you issues if a product has no category either.

Let me know if this works for you / if this is what you wanted. Also let me know if you need anything explained.

:-)

Newbie

Posts

Joined
Thu Jan 25, 2018 2:51 am


Post by scottyboyyy » Sun Jun 10, 2018 10:51 am

No problem! Your english is good - I just misunderstood, I know what you are wanting now!

If you can send me the .tpl and controller .php of this file then I can hopefully send you back a solution to link to all the products for the selected tab's category. It will be easier / quicker for me to do this if I can see these files :-).

Active Member

Posts

Joined
Fri Apr 07, 2017 2:36 am

Post by turkkan » Sun Jun 10, 2018 2:56 pm

Thank you very much for your interest. People need someone like you in this forum :)

this is "showintabs_output.tpl

Code: Select all

<div class="box products <?php echo $columns; ?>">

<?php if (count($tabs) <= 1) { ?>
   <div class="box-heading">
    <?php foreach ($tabs as $keyTab => $tab) { ?>
	<?php echo $tab['title']; ?>
	</div>
    <?php } ?>
    <?php } else { ?>
    <div class="menuacbaslik">
        <p>Kategoriler</p>
        <a href="#" id="menu-ac" class="menuac">Tüm Kategoriler</a>
        </div>
    <div class="box-heading product-tabs">
    <ul id="tabs-<?php echo $module; ?>" class="nav nav-tabs" data-tabs="tabs">
		<?php foreach ($tabs as $keyTab => $tab) { ?>
           	<?php if($keyTab == 0) { ?>
            <li class="active"><a href="#tab<?php echo $module; ?><?php echo $keyTab; ?>" data-toggle="tab"><span class="icon<?php echo $module; ?><?php echo $keyTab; ?>"><?php echo $tab['title']; ?></span></a></li>
            <?php } else { ?>
            <li><a href="#tab<?php echo $module; ?><?php echo $keyTab; ?>" data-toggle="tab" role="tab" title="Seç"><span class="icon<?php echo $module; ?><?php echo $keyTab; ?>"><?php echo $tab['title']; ?></span></a></li>
            <?php } ?>
    	<?php } ?>
	</ul>
    </div>
<?php } ?>
<div class="tab-content">
    <?php foreach ($tabs as $key => $tab) { ?>
    <div class="tab-pane <?php echo (empty($key) ? 'active' : ''); ?>" id="tab<?php echo $module; ?><?php echo $key; ?>">
    <div class="grid_holder">
    <div class="product-grid <?php echo $module; ?> <?php if ($carousel) { ?>carousel<?php } ?>">
        <?php foreach ($tab['products'] as $product) { ?><!--
        -->
        <div class="item contrast_font">
            <div class="mim-product">
            <?php if ($product['thumb']) { ?>
					<div class="image">
		<?php if ($product['jan']) { ?>
		<div class="uretim"><?php echo $product['jan']; ?></div>
	<?php } ?>
	
	<?php if ($product['upc']) { ?>
		<div class="takim"><?php echo $product['upc']; ?></div>
	<?php } ?>
        			<?php if ($product['special'] && $cosyone_percentage_sale_badge == 'enabled') { ?>
	    			<div class="sale_badge">-<?php echo $product['sales_percantage']; ?>%</div>
	    			<?php } ?>
        			<?php if ($product['thumb_hover'] && $cosyone_rollover_effect == 'enabled') { ?>
        			<div class="image_hover"><a href="<?php echo $product['href']; ?>"><img src="<?php echo $product['thumb_hover']; ?>" alt="<?php echo $product['name']; ?>" /></a></div>
        			<a href="<?php echo $product['href']; ?>"><img src="<?php echo $product['thumb']; ?>" alt="<?php echo $product['name']; ?>" /></a>
        			<?php } elseif ($product['thumb']) { ?>
        			<a href="<?php echo $product['href']; ?>"><img src="<?php echo $product['thumb']; ?>" alt="<?php echo $product['name']; ?>" /></a>
        		<?php } ?>
                                
                <?php if ($cosyone_text_ql) {?>
                <div class="main_quicklook">
                <a href="<?php echo $product['quickview']; ?>" rel="nofollow" class="button quickview"><i class="fa fa-eye"></i> <?php echo $cosyone_text_ql; ?></a>
                </div>
                <?php } ?>
        		</div><!-- image ends -->
				<?php } ?>
                <div class="information_wrapper">
				<div class="name"><a href="<?php echo $product['href']; ?>"><?php echo $product['name']; ?></a></div>
                <br>
                <div class="mim-catbox">
               <?php if ($product['price']) { ?>
				   <div class="price">
				   <?php if (!$product['special']) { ?>
				   <?php echo $product['price']; ?>
				   <?php } else { ?>
				   <span class="price-old"><?php echo $product['price']; ?></span> <span class="price-new"><?php echo $product['special']; ?></span>
				   <?php } ?>
				   </div>
				<?php } ?>
                <div class="cart"><button type="submit" class="button contrast" onclick="cart.add('<?php echo $product['product_id']; ?>');" ><i class="fa fa-shopping-cart"></i> <?php echo $button_cart; ?></button></div>
                <div class="clearfix"></div>
                
                </div>
        </div><!-- informtion wrapper ends -->
		</div>
        </div><!--
        --><?php } ?>
    </div>
    </div> 
    </div>
    <?php } ?>
</div>
</div>

<script type="text/javascript">
$('#menu-ac').click( function() {
    $(".vertical-wrapper").toggleClass("so-vertical-active");
} );
</script>

<script src="//itemslide.github.io/dist/itemslide.min.js"></script>
<script type="text/javascript"><!--
if ($(window).width() < 768) {
    var carousel;
    $(document).ready(function () {
        carousel = $(".ico-slider ul");
        carousel.itemslide({
            left_sided: true
        });

        $(window).resize(function () {
            carousel.reload();
        });
    });
}
--></script>
<script type="text/javascript">
$('[data-toggle="tab"]').tooltip({
    trigger: 'hover',
    placement: 'top',
    animate: true,
    delay: 0,
    container: 'body'
});
    
</script>

<?php if ($carousel) { ?>
<script type="text/javascript"><!--
$(document).ready(function() {
var grid5 = 5;
var grid4 = 4;
var grid3 = 3;
var grid1 = 1;
$('.product-grid.<?php echo $module; ?>').owlCarousel({
itemsCustom: [ [0, 1], [350, 1], [550, 2], [1025, <?php echo $columns; ?>]],
pagination: false,
navigation:true,
slideSpeed:500,
scrollPerPage:false,
navigationText: [
"<div class='slide_arrow_prev'><i class='fa fa-angle-left'></i></div>",
"<div class='slide_arrow_next'><i class='fa fa-angle-right'></i></div>"
]
}); 
});	
//--></script>
<?php } ?>
and this is showintabs_output.php

Code: Select all

<?php  
class ControllerModuleShowintabsoutput extends Controller {
	public function index($setting) {
    	$this->load->language('module/showintabs');
    	$this->load->model('catalog/product');
  		
		$data['text_tax'] = $this->language->get('text_tax');
		$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['cosyone_category_per_row'] = $this->config->get('cosyone_category_per_row');
		$data['cosyone_rollover_effect'] = $this->config->get('cosyone_rollover_effect');
		$data['cosyone_percentage_sale_badge'] = $this->config->get('cosyone_percentage_sale_badge');
		
		$cosyone_quicklook = $this->config->get('cosyone_text_ql');
		
		if(empty($cosyone_quicklook[$this->language->get('code')])) {
			$data['cosyone_text_ql'] = false;
		} else if (isset($cosyone_quicklook[$this->language->get('code')])) {
			$data['cosyone_text_ql'] = html_entity_decode($cosyone_quicklook[$this->language->get('code')], ENT_QUOTES, 'UTF-8');
		}
		
		$data['cosyone_brand'] = $this->config->get('cosyone_brand');
		
		$data['carousel'] = $setting['carousel'];
		$data['columns'] = $setting['columns'];
		
		static $module = 0;
		
		$data['tabs'] = array();

		$this->load->model('tool/image');
		
		$tabs = $this->config->get('showintabs_tab');
		
		$tabs = isset($tabs) ? $tabs : array();

    	foreach ($tabs as $key => $tab) {
			if(in_array($key, $setting['selected_tabs']['tabs'])) {
				if (!empty($tab['title'][$this->config->get('config_language_id')])) {
					$title = $tab['title'][$this->config->get('config_language_id')];
				}else{
					$title = $this->language->get('heading_default');
				}	
	
				$products = array();
	
				switch ($tab['data_source']) {
					case 'SP': //Select Products
						$results = $this->getSelectProducts($tab,$setting['limit']);
						break;
					case 'PG': //Product Group
						$results = $this->getProductGroups($tab,$setting['limit']);
						break;
					case 'CQ': //Custom Query
						$results = $this->getCustomQuery($tab,$setting['limit']);
						break;
					default:
						$this->log->write('SHOW_IN_TAB::ERROR: The tab don\'t have product configured.');
						break;
				}
				
	
				//Preparo la info de cada producto
				foreach ($results as $result) {
					if ($result['image']) {
						$image = $this->model_tool_image->resize($result['image'], $setting['image_width'], $setting['image_height']);
					} else {
						$image = $this->model_tool_image->resize('placeholder.png', $setting['image_width'], $setting['image_height']);
					}
					
					
					
					$images = $this->model_catalog_product->getProductImages($result['product_id']);
					if(isset($images[0]['image']) && !empty($images[0]['image'])){
					$images =$images[0]['image'];
				   	} else {
					$images = 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')));
					} else {
						$special = false;
					}
					
					if ((float)$result['special']) {
					$sales_percantage = ((($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')))-($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax'))))/(($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')))/100));
					} else {
					$sales_percantage = false;
					}
					
					if ((float)$result['special']) {
    				$special_info = $this->model_catalog_product->getSpecialPriceEnd($result['product_id']);
        			$special_date_end = strtotime($special_info['date_end']) - time();
    				} else {
        			$special_date_end = false;
    				}
					
					if ($this->config->get('config_tax')) {
					$tax = $this->currency->format((float)$result['special'] ? $result['special'] : $result['price']);
					} else {
						$tax = false;
					}	
					
					if ($this->config->get('config_review_status')) {
						$rating = $result['rating'];
					} else {
						$rating = false;
					}
					
									
					$products[] = array(
						'product_id' => $result['product_id'],
						'thumb'   	 => $image,
						'name'    	 => $result['name'],
						'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('config_product_description_length')) . '..',
						'price'   	 => $price,
						'special' 	 => $special,
						'tax'         => $tax,
						'rating'     => $rating,
						'reviews'    => sprintf($this->language->get('text_reviews'), (int)$result['reviews']),
						'href'    	 => $this->url->link('product/product', 'product_id=' . $result['product_id']),
						'quickview'  => $this->url->link('product/quickview', 'product_id=' . $result['product_id'], '', 'SSL'),
						'jan' => $result['jan'], 
						'upc' => $result['upc'],
						'sales_percantage' => number_format($sales_percantage, 0, ',', '.'),
						'special_date_end' => $special_date_end,
						'brand_name'		=> $result['manufacturer'],
						'thumb_hover'  => $this->model_tool_image->resize($images, $setting['image_width'], $setting['image_height'])
					);
				}	

				$data['tabs'][] = array(
					'title' => $title,
					'products' => $products
				);
			}
    	}
		
	    
    	$data['button_cart'] = $this->language->get('button_cart');
		
		$data['module'] = $module++;

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

  	// Obtiene los productos de los grupos predefinidos de opencart
  	private function getProductGroups( $tabInfo , $limit ){
  		$results = array();

  		//Obtengo listado de productos en funcion del criterio
  		switch ( $tabInfo['product_group'] ) {
  			case 'BS':
  				$results = $this->model_catalog_product->getBestSellerProducts($limit);
  				break;
  			case 'LA':
  				$results = $this->model_catalog_product->getLatestProducts($limit);
  				break;
  			case 'SP':
  				$results = $this->model_catalog_product->getProductSpecials(array('start' => 0,'limit' => $limit));
  				break;
  			case 'PP':
  				$results = $this->model_catalog_product->getPopularProducts($limit);
  				break;
  		}

  		return $results;
  	}

	// Obtiene los productos seleccionados por el user con toda la info necesaria
  	private function getSelectProducts( $tabInfo , $limit ){
  		$results = array();

  		if(isset($tabInfo['products'])){
  			$limit_count = 0;
			foreach ( $tabInfo['products'] as $product ) {
				if ($limit_count++ == $limit) break;
				$results[$product['product_id']] = $this->model_catalog_product->getProduct($product['product_id']);
			}
		}

		return $results;
  	}

  	//Obtiene los productos segun los datos del custom query
  	private function getCustomQuery( $tabInfo , $limit){
  		$results = array();

  		if ( $tabInfo['sort'] == 'rating' || $tabInfo['sort'] == 'p.date_added') {
  			$order = 'DESC';
  		}else{
  			$order = 'ASC';
  		}

  		$data = array(
  			'filter_category_id' => $tabInfo['filter_category']=='ALL' ? '' : $tabInfo['filter_category'], 
  			'filter_manufacturer_id' => $tabInfo['filter_manufacturer']=='ALL' ? '' : $tabInfo['filter_manufacturer'], 
  			'sort' => $tabInfo['sort'], 
  			'order' => $order,
  			'start' => 0,
  			'limit' => $limit
  		);

  		$results = $this->model_catalog_product->getProducts($data);

		return $results;
  	}

}
scottyboyyy wrote:
Sun Jun 10, 2018 10:51 am
No problem! Your english is good - I just misunderstood, I know what you are wanting now!

If you can send me the .tpl and controller .php of this file then I can hopefully send you back a solution to link to all the products for the selected tab's category. It will be easier / quicker for me to do this if I can see these files :-).

Newbie

Posts

Joined
Thu Jan 25, 2018 2:51 am


Post by scottyboyyy » Mon Jun 11, 2018 1:17 am

I don't have time to set it up locally and test today but from a quick look, you could do something simple like this:

<?php echo $module; ?><?php echo $key; ?>. These are giving unique numbers for each tab, so we can use them to give specific numbers for each of our buttons, so that the button matches the tab that it is inside.

Add button here:

Code: Select all

<div class="tab-content">
    <?php foreach ($tabs as $key => $tab) { ?>
    <div class="tab-pane <?php echo (empty($key) ? 'active' : ''); ?>" id="tab<?php echo $module; ?><?php echo $key; ?>">
<!-- Add button here !-->
<button id="button<?php echo $module; ?><?php echo $key; ?>"> View more </button>
<!-- button end !-->
So we know these <?php echo $module; ?><?php echo $key; ?> are giving 001, 002, 003, etc so that means our button's id ("button<?php echo $module; ?><?php echo $key; ?>") will give ids like button001, button002, button003, etc.

We can then do this:

Code: Select all

<script>
$('#button001').click(function() {
   window.location = "www.example.com/1";
});
$('#button002').click(function() {
   window.location = "www.example.com/2";
});
....
</script>
You just need to find which category is 001 and add the link instead of example.

Not the neatest solution but hope this works for you!

Active Member

Posts

Joined
Fri Apr 07, 2017 2:36 am

Post by turkkan » Mon Jun 11, 2018 11:28 pm

It works fine. Thank you very much!
scottyboyyy wrote:
Mon Jun 11, 2018 1:17 am
I don't have time to set it up locally and test today but from a quick look, you could do something simple like this:

<?php echo $module; ?><?php echo $key; ?>. These are giving unique numbers for each tab, so we can use them to give specific numbers for each of our buttons, so that the button matches the tab that it is inside.

Add button here:

Code: Select all

<div class="tab-content">
    <?php foreach ($tabs as $key => $tab) { ?>
    <div class="tab-pane <?php echo (empty($key) ? 'active' : ''); ?>" id="tab<?php echo $module; ?><?php echo $key; ?>">
<!-- Add button here !-->
<button id="button<?php echo $module; ?><?php echo $key; ?>"> View more </button>
<!-- button end !-->
So we know these <?php echo $module; ?><?php echo $key; ?> are giving 001, 002, 003, etc so that means our button's id ("button<?php echo $module; ?><?php echo $key; ?>") will give ids like button001, button002, button003, etc.

We can then do this:

Code: Select all

<script>
$('#button001').click(function() {
   window.location = "www.example.com/1";
});
$('#button002').click(function() {
   window.location = "www.example.com/2";
});
....
</script>
You just need to find which category is 001 and add the link instead of example.

Not the neatest solution but hope this works for you!

Newbie

Posts

Joined
Thu Jan 25, 2018 2:51 am

Who is online

Users browsing this forum: Baidu [Spider] and 47 guests