php - How to get current category id - OpenCart 2.0 -
i have code product tpl witch need condition if category id=12 echo.. code below works on opencart 1.5.6.4 on 2.0 doesn't generate anything.
<?php if(isset($this->request->get['path'])) { $path = $this->request->get['path']; $cats = explode('_', $path); $cat_id = $cats[count($cats) - 1]; } ?> <?php if (isset($cat_id) && $cat_id == '108') { ?> <div style="text-align: right;"><a href = "javascript:void(0)" onclick ="document.getelementbyid('fade').style.display='block'" style=" color: rgb(221, 0, 23);">mesurments table</a></div> <div id="fade" class="black_overlay"><a class="close" href = "javascript:void(0)" onclick = "document.getelementbyid('fade').style.display='none'"></a><img src="/image/data/misc/blugi.jpg"style=" width: 100%;"></div> ?php } ?>
the reason no longer works because in 2.0> templates rendered via loader object, not controller object.
you'll need declare $cat_id
variable inside product controller data variable.
so let's clean , make bit more usable.
in catalog/controller/product/product.php
add:
if (isset ($this->request->get['path'])) { $path = $this->request->get['path']; $cats = explode('_', $path); $data['cat_id'] = $cats[count($cats) - 1]; }
then in template can access $cat_id
like.
in product.tpl
file, in javascript area @ bottom add:
<script type="text/javascript"><!-- $('#fade-link').css({ color: rgb(221, 0, 23) }).on('click', function() { $('#fade').show(); }); $('#fade a.close').on('click', function(){ $('#fade').hide(); }); //--></script>
then replace existing code with:
<?php if ($cat_id && $cat_id == '108') { ?> <div style="text-align: right;"> <a id="fade-link">measurements table</a></div> <div id="fade" class="black_overlay"> <a class="close"></a> <img src="/image/data/misc/blugi.jpg" style="width: 100%;"> </div> <?php } ?>
this should there, or @ least pretty close, didn't test it, may need adjust js.
Comments
Post a Comment