Kom ihåg mig?
Home Menu

Menu


php hjälp. if & else..

Ämnesverktyg Visningsalternativ
Oläst 2014-05-13, 14:34 #1
xciso xciso är inte uppkopplad
Mycket flitig postare
 
Reg.datum: Jul 2006
Inlägg: 569
xciso xciso är inte uppkopplad
Mycket flitig postare
 
Reg.datum: Jul 2006
Inlägg: 569
Standard php hjälp. if & else..

Tjena.
Jag håller på med ett filter i en webshop och tyvärr så störs jag väldigt mycket på en sak.

I filtret så sätter man en filter kategori. Tex Färg.
Under kategorin så lägger jag in färgerna. Tex Svart, Röd, Grön.

I produkterna lägger jag sedan in färgen Röd om den produkten nu är röd.

Men..I filtret vill jag inte visa checkbox i text.
Idag ser det ut så här:
-----------
Färg
¤Röd
¤Svart
¤Grön

Istället för det vill jag ha tre olika bilder, som jag döper till red.jpg, black.jpg osv.

Men hur gör jag om denna kod så den visar bilder istället för text.
Bilderna ska alltså fungera som checkbox, men istället för att skriva ut en checkbox och text efter så ska det enbart visas bild.

Koden är skriven i två filer.
filter.php under /controller/module/
Kod:
<?php  
class ControllerModuleFilter extends Controller {
	protected function index($setting) {
		if (isset($this->request->get['path'])) {
			$parts = explode('_', (string)$this->request->get['path']);
		} else {
			$parts = array();
		}
		
		$category_id = end($parts);
		
		$this->load->model('catalog/category');
		
		$category_info = $this->model_catalog_category->getCategory($category_id);
		
		if ($category_info) {
			$this->language->load('module/filter');
		
			$this->data['heading_title'] = $this->language->get('heading_title');
			
			$this->data['button_filter'] = $this->language->get('button_filter');
			
			$url = '';
			
			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['limit'])) {
				$url .= '&limit=' . $this->request->get['limit'];
			}
									
			$this->data['action'] = str_replace('&amp;', '&', $this->url->link('product/category', 'path=' . $this->request->get['path'] . $url));
			
			if (isset($this->request->get['filter'])) {
				$this->data['filter_category'] = explode(',', $this->request->get['filter']);
			} else {
				$this->data['filter_category'] = array();
			}
			
			$this->load->model('catalog/product');

			$this->data['filter_groups'] = array();
			
			$filter_groups = $this->model_catalog_category->getCategoryFilters($category_id);
			
			if ($filter_groups) {
				foreach ($filter_groups as $filter_group) {
					$filter_data = array();
					
					foreach ($filter_group['filter'] as $filter) {
						$data = array(
							'filter_category_id' => $category_id,
							'filter_filter'      => $filter['filter_id']
						);	
						
						$filter_data[] = array(
							'filter_id' => $filter['filter_id'],
							'name'      => $filter['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($data) . ')' : '')
						);
					}
					
					$this->data['filter_groups'][] = array(
						'filter_group_id' => $filter_group['filter_group_id'],
						'name'            => $filter_group['name'],
						'filter'          => $filter_data
					);
				} 
			
				if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/filter.tpl')) {
					$this->template = $this->config->get('config_template') . '/template/module/filter.tpl';
				} else {
					$this->template = 'default/template/module/filter.tpl';
				}
				
				$this->render();
			}
		}
	}
}
?>
Och sedan har vi filen filter.tpl under /template/module/
Kod:
<div class="box">
  <div class="box-heading"><?php echo $heading_title; ?></div>
  <div class="box-content">
    <ul class="box-filter">
      <?php foreach ($filter_groups as $filter_group) { ?>
      <li><span id="filter-group<?php echo $filter_group['filter_group_id']; ?>"><?php echo $filter_group['name']; ?></span>
        <ul>
          <?php foreach ($filter_group['filter'] as $filter) { ?>
          <?php if (in_array($filter['filter_id'], $filter_category)) { ?>
          <li>
            <input type="checkbox" value="<?php echo $filter['filter_id']; ?>" id="filter<?php echo $filter['filter_id']; ?>" checked="checked" />
            <label for="filter<?php echo $filter['filter_id']; ?>"><?php echo $filter['name']; ?></label>
          </li>
          <?php } else { ?>
          <li>
            <input type="checkbox" value="<?php echo $filter['filter_id']; ?>" id="filter<?php echo $filter['filter_id']; ?>" />
            <label for="filter<?php echo $filter['filter_id']; ?>"><?php echo $filter['name']; ?></label>
          </li>
          <?php } ?>
          <?php } ?>
        </ul>
      </li>
      <?php } ?>
    </ul>
    <a id="button-filter" class="button"><?php echo $button_filter; ?></a>
  </div>
</div>
<script type="text/javascript"><!--
$('#button-filter').bind('click', function() {
	filter = [];
	
	$('.box-filter input[type=\'checkbox\']:checked').each(function(element) {
		filter.push(this.value);
	});
	
	location = '<?php echo $action; ?>&filter=' + filter.join(',');
});
//--></script>
Snälla. Är det någon som kan??
Stort tack på förhand

Senast redigerad av xciso den 2014-05-13 klockan 14:37
xciso är inte uppkopplad   Svara med citatSvara med citat
Oläst 2014-05-13, 15:16 #2
ANttila ANttila är inte uppkopplad
Medlem
 
Reg.datum: Aug 2013
Inlägg: 81
ANttila ANttila är inte uppkopplad
Medlem
 
Reg.datum: Aug 2013
Inlägg: 81
Citat:
Ursprungligen postat av xciso Visa inlägg
Tjena.
Jag håller på med ett filter i en webshop och tyvärr så störs jag väldigt mycket på en sak.

I filtret så sätter man en filter kategori. Tex Färg.
Under kategorin så lägger jag in färgerna. Tex Svart, Röd, Grön.

I produkterna lägger jag sedan in färgen Röd om den produkten nu är röd.

Men..I filtret vill jag inte visa checkbox i text.
Idag ser det ut så här:
-----------
Färg
¤Röd
¤Svart
¤Grön

Istället för det vill jag ha tre olika bilder, som jag döper till red.jpg, black.jpg osv.

Men hur gör jag om denna kod så den visar bilder istället för text.
Bilderna ska alltså fungera som checkbox, men istället för att skriva ut en checkbox och text efter så ska det enbart visas bild.

Koden är skriven i två filer.
filter.php under /controller/module/
Kod:
<?php  
class ControllerModuleFilter extends Controller {
	protected function index($setting) {
		if (isset($this->request->get['path'])) {
			$parts = explode('_', (string)$this->request->get['path']);
		} else {
			$parts = array();
		}
		
		$category_id = end($parts);
		
		$this->load->model('catalog/category');
		
		$category_info = $this->model_catalog_category->getCategory($category_id);
		
		if ($category_info) {
			$this->language->load('module/filter');
		
			$this->data['heading_title'] = $this->language->get('heading_title');
			
			$this->data['button_filter'] = $this->language->get('button_filter');
			
			$url = '';
			
			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['limit'])) {
				$url .= '&limit=' . $this->request->get['limit'];
			}
									
			$this->data['action'] = str_replace('&amp;', '&', $this->url->link('product/category', 'path=' . $this->request->get['path'] . $url));
			
			if (isset($this->request->get['filter'])) {
				$this->data['filter_category'] = explode(',', $this->request->get['filter']);
			} else {
				$this->data['filter_category'] = array();
			}
			
			$this->load->model('catalog/product');

			$this->data['filter_groups'] = array();
			
			$filter_groups = $this->model_catalog_category->getCategoryFilters($category_id);
			
			if ($filter_groups) {
				foreach ($filter_groups as $filter_group) {
					$filter_data = array();
					
					foreach ($filter_group['filter'] as $filter) {
						$data = array(
							'filter_category_id' => $category_id,
							'filter_filter'      => $filter['filter_id']
						);	
						
						$filter_data[] = array(
							'filter_id' => $filter['filter_id'],
							'name'      => $filter['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($data) . ')' : '')
						);
					}
					
					$this->data['filter_groups'][] = array(
						'filter_group_id' => $filter_group['filter_group_id'],
						'name'            => $filter_group['name'],
						'filter'          => $filter_data
					);
				} 
			
				if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/filter.tpl')) {
					$this->template = $this->config->get('config_template') . '/template/module/filter.tpl';
				} else {
					$this->template = 'default/template/module/filter.tpl';
				}
				
				$this->render();
			}
		}
	}
}
?>
Och sedan har vi filen filter.tpl under /template/module/
Kod:
<div class="box">
  <div class="box-heading"><?php echo $heading_title; ?></div>
  <div class="box-content">
    <ul class="box-filter">
      <?php foreach ($filter_groups as $filter_group) { ?>
      <li><span id="filter-group<?php echo $filter_group['filter_group_id']; ?>"><?php echo $filter_group['name']; ?></span>
        <ul>
          <?php foreach ($filter_group['filter'] as $filter) { ?>
          <?php if (in_array($filter['filter_id'], $filter_category)) { ?>
          <li>
            <input type="checkbox" value="<?php echo $filter['filter_id']; ?>" id="filter<?php echo $filter['filter_id']; ?>" checked="checked" />
            <label for="filter<?php echo $filter['filter_id']; ?>"><?php echo $filter['name']; ?></label>
          </li>
          <?php } else { ?>
          <li>
            <input type="checkbox" value="<?php echo $filter['filter_id']; ?>" id="filter<?php echo $filter['filter_id']; ?>" />
            <label for="filter<?php echo $filter['filter_id']; ?>"><?php echo $filter['name']; ?></label>
          </li>
          <?php } ?>
          <?php } ?>
        </ul>
      </li>
      <?php } ?>
    </ul>
    <a id="button-filter" class="button"><?php echo $button_filter; ?></a>
  </div>
</div>
<script type="text/javascript"><!--
$('#button-filter').bind('click', function() {
	filter = [];
	
	$('.box-filter input[type=\'checkbox\']:checked').each(function(element) {
		filter.push(this.value);
	});
	
	location = '<?php echo $action; ?>&filter=' + filter.join(',');
});
//--></script>
Snälla. Är det någon som kan??
Stort tack på förhand
Du gör såhär:
HTML-kod:
<label for="blue"><img src="blue.jpg"></label>
<input type="checkbox" id="blue" name="color" value="blue">
Dock skulle jag rekommendera att visa färger med CSS:ade div:ar istället för bilder:
HTML-kod:
<label for="blue"><div class="checkbox blue"></div></label>
<input type="checkbox" id="blue" name="color" value="blue">
ANttila är inte uppkopplad   Svara med citatSvara med citat
Oläst 2014-05-17, 19:29 #3
xciso xciso är inte uppkopplad
Mycket flitig postare
 
Reg.datum: Jul 2006
Inlägg: 569
xciso xciso är inte uppkopplad
Mycket flitig postare
 
Reg.datum: Jul 2006
Inlägg: 569
Tack för svar.
Tyvärr förstår jag inte riktigt hur jag ska få till det i min fil.
xciso är inte uppkopplad   Svara med citatSvara med citat
Svara


Aktiva användare som för närvarande tittar på det här ämnet: 1 (0 medlemmar och 1 gäster)
 

Regler för att posta
Du får inte posta nya ämnen
Du får inte posta svar
Du får inte posta bifogade filer
Du får inte redigera dina inlägg

BB-kod är
Smilies är
[IMG]-kod är
HTML-kod är av

Forumhopp


Alla tider är GMT +2. Klockan är nu 22:06.

Programvara från: vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Svensk översättning av: Anders Pettersson
 
Copyright © 2017