Post by andriypolik » Fri Oct 16, 2020 10:25 pm

Hello everyone) Thank you for attention to my issue!
I have the next problem: I've edited menu php and twig files for showing list of categories as dropdown in top menu, but my code(category_mob.category_id != 57) isn't excluding this category. Below i'm adding code
menu.php

Code: Select all

class ControllerCommonMenu extends Controller {
	public function index() {
		$this->load->language('common/menu');

	  // Menu
		$this->load->model('catalog/category');

		$this->load->model('catalog/product');

		
		$data['categoriestop'] = array();
		$data['categoriesmob'] = array();

		
		// MY CODE
		$categoriesmob = $this->model_catalog_category->getCategories(0);
		$categoriestop = $this->model_catalog_category->getCategories(0);
		// END

		
		// My INSERT Information 

		foreach ($categoriesmob as $category_mob) {
			
			$children_data = array();

			if ($category_mob['category_id'] == $data['category_id']) {
				$children = $this->model_catalog_category->getCategories($category_mob['category_id']);

				foreach($children as $child) {
					$filter_data = array('filter_category_id' => $child['category_id'], 'filter_sub_category' => true);

					$children_data[] = array(
						'category_id' => $child['category_id'],
						'name' => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
						'href' => $this->url->link('product/category', 'path=' . $category_mob['category_id'] . '_' . $child['category_id'])
					);
				}
			
			}

			$filter_data = array(
				'filter_category_id'  => $category_mob['category_id'],
				'filter_sub_category' => true
			);
      $data['categoriesmob'][] = array(
				'category_id' => $category_mob['category_id'],
				'name_mob'        => $category_mob['name'],
				'children'    => $children_data,
				'href_mob'        => $this->url->link('product/category', 'path=' . $category_mob['category_id'])
			);
			
		}

   foreach ($categoriestop as $category_top) {
			

				// Level 1
			$children_data = array();

			if ($category_top['category_id'] == $data['category_id']) {
				$children = $this->model_catalog_category->getCategories($category_top['category_id']);

				foreach($children as $child) {
					$filter_data = array('filter_category_id' => $child['category_id'], 'filter_sub_category' => true);

					$children_data[] = array(
						'category_id' => $child['category_id'],
						'name' => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
						'href' => $this->url->link('product/category', 'path=' . $category_top['category_id'] . '_' . $child['category_id'])
					);
				}
			}

			$filter_data = array(
				'filter_category_id'  => $category_top['category_id'],
				'filter_sub_category' => true
			);

			$data['categoriestop'][] = array(
				
				'name_top'        => $category_top['name'],
				
				'href_top'        => $this->url->link('product/category', 'path=' . $category_top['category_id'])
			);

			
		}
			$data['cart'] = $this->load->controller('common/cart');
 
		return $this->load->view('common/menu', $data);
	}
}

my MENU TWIG

Code: Select all

	{% if categoriestop %}
		{% if categoriesmob %}
  <div class="top-blue">  
<div class="container">
  <div class="row"> 
  <nav id="menu" class="col-xl-8 col-lg-8 col-md-8 navbar">
    <div class="navbar-header">
      <button type="button" class="btn btn-navbar navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse"><i class="fa fa-bars"></i></button>
    </div>
    <div class="menu-top">
      <ul class="navgtn">
        <li><a href="{{ home }}">Главная</a></li>
        <li class="about-com"><a href=" ">O компании</a>
         <div class="sub-menu"> 
           <div class="content">  
               <div class="row">  
                  <div class="col-sm-12 sub-menu2"> 
                        <ul>  
                              <li>  
                                  <a href=" "> О нас</a>

                              </li>
                              <li>  
                                  <a href=" "> Контакты</a>

                              </li>

                        </ul>
                     
                  </div>

               </div>

           </div>

         </div>

        </li>
        <li class="class-cat catalog"><a class='hreff'>Каталог</a>

          <div class="sub-men">  
            <div class="content"> 
                <div class="row"> 
                  
                    <div class="col-sm-12 sub-me">  
                           
                                   
                        <ul>  
                          {% for category_top in categoriestop %}
                       {% if category_top.category_id != 57 %}
                	 {% if category_top.category_id == category_id %}
                	  
        <li class="dropdown"><a href="{{ category_top.href_top }}">{{ category_top.name_top }}</a>
       </li>
       
                 {% endif %}
                {% endif %}
        {% endfor %}
                        </ul>  
                                   
                         
                                   

                    </div>

                    
                </div>

            </div>

          </div>
          
          
          
          


        </li>
        {% for category_mob in categoriesmob %}
        	    {% if category_mob.category_id != 57 %}
                	 {% if category_mob.category_id == category_id %}
             
        <li class="dropdown-tog"><a href="{{ category_mob.href_mob }}">{{ category_mob.name_mob }}</a>
       </li>
         
           {% endif %}
                {% endif %}
        {% endfor %}
        <li><a href="{{ home }}">Статьи</a></li>
        



    
      </ul>
      
    </div>
  </nav>
     <div class="basket-menu col-xl-3 col-lg-3 col-md-3">{{ cart }}</div>
  </div>
  
</div>
</div>
{% endif %} 
{% endif %}
Thanks in advance

Newbie

Posts

Joined
Fri Feb 21, 2020 5:29 am

Post by IP_CAM » Sat Oct 17, 2020 8:04 am

You may find some answers on this here:
https://www.google.com/search?q=Exclude ... 8&oe=utf-8

My Github OC Site: https://github.com/IP-CAM
5'200 + FREE OC Extensions, on the World's largest private Github OC Repository Archive Site.


User avatar
Legendary Member

Posts

Joined
Tue Mar 04, 2014 1:37 am
Location - Switzerland

Post by sw!tch » Sat Oct 17, 2020 9:09 am

There are better ways to do the above.

Offhand looks like you are missing category_id for categoriestop

ex:

Code: Select all

$data['categoriestop'][] = array(
	'category_id'     => $category_top['category_id'],  // category_id needed. 
	'name_top'        => $category_top['name'],
	'href_top'        => $this->url->link('product/category', 'path=' . $category_top['category_id'])
);
You can always just print your $data array - Easier to see what's being passed and if something is missing.

Full Stack Web Developer :: Send a PM for Custom Work.
Backup and learn how to recover before you make any changes!


Active Member

Posts

Joined
Sat Apr 28, 2012 2:32 pm

Post by andriypolik » Tue Oct 20, 2020 3:58 am

Thanks, early i've been searching many websites , but couldn't find anything that help me. How to print open data array?

Newbie

Posts

Joined
Fri Feb 21, 2020 5:29 am

Post by sw!tch » Tue Oct 20, 2020 4:15 am

If development (e.g not public facing). you can just output to screen and view the page source to see it cleanly formatted.

Code: Select all

print_r($data); 
if production it's better to write to a log. You don't want to be dumping variables on a public website.

Code: Select all

 $this->log->write(print_r($data, true)); 
In both cases you would put before the view output.

Full Stack Web Developer :: Send a PM for Custom Work.
Backup and learn how to recover before you make any changes!


Active Member

Posts

Joined
Sat Apr 28, 2012 2:32 pm

Post by by mona » Tue Oct 20, 2020 4:38 am

andriypolik wrote:
Fri Oct 16, 2020 10:25 pm
but my code(category_mob.category_id != 57) isn't excluding
No it isn’t because twig is twig and that is half twig and half php
In twig ! is not

https://twig.symfony.com/doc/3.x/tags/if.html

DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.


https://www.youtube.com/watch?v=zXIxDoCRc84


User avatar
Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am

Post by andriypolik » Tue Oct 20, 2020 5:51 am

by mona wrote:
Tue Oct 20, 2020 4:38 am
andriypolik wrote:
Fri Oct 16, 2020 10:25 pm
but my code(category_mob.category_id != 57) isn't excluding
No it isn’t because twig is twig and that is half twig and half php
In twig ! is not

https://twig.symfony.com/doc/3.x/tags/if.html
Hi! != working in twig as well. I've tried with not - the same result

Newbie

Posts

Joined
Fri Feb 21, 2020 5:29 am

Post by by mona » Tue Oct 20, 2020 6:05 am

try the opposite then

Code: Select all

{% if category_top.category_id == '57' %}
{% else %}
..

DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.


https://www.youtube.com/watch?v=zXIxDoCRc84


User avatar
Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am

Post by andriypolik » Tue Oct 20, 2020 6:25 am

sw!tch wrote:
Tue Oct 20, 2020 4:15 am
If development (e.g not public facing). you can just output to screen and view the page source to see it cleanly formatted.

Code: Select all

print_r($data); 
Sorry for stupid question, how i have to do this. At first add print_r($data) to menu php and then display through {{ }} in twig? Thanks in advence

Newbie

Posts

Joined
Fri Feb 21, 2020 5:29 am

Post by sw!tch » Tue Oct 20, 2020 7:52 am

andriypolik wrote:
Tue Oct 20, 2020 6:25 am
sw!tch wrote:
Tue Oct 20, 2020 4:15 am
If development (e.g not public facing). you can just output to screen and view the page source to see it cleanly formatted.

Code: Select all

print_r($data); 
Sorry for stupid question, how i have to do this. At first add print_r($data) to menu php and then display through {{ }} in twig? Thanks in advence
You add it in your controller before:

Code: Select all

return $this->load->view('common/menu', $data);
All print_r($data); does is dump your $data array so you can see what's being passed to the view. You can view source to see it formatted or wrap it in pre tags.

Full Stack Web Developer :: Send a PM for Custom Work.
Backup and learn how to recover before you make any changes!


Active Member

Posts

Joined
Sat Apr 28, 2012 2:32 pm

Post by andriypolik » Wed Oct 21, 2020 2:59 am

You add it in your controller before:

Code: Select all

return $this->load->view('common/menu', $data);
All print_r($data); does is dump your $data array so you can see what's being passed to the view. You can view source to see it formatted or wrap it in pre tags.
So I add print_r($data) before return $this->load->view('common/menu', $data), but how it will be displayed? Maybe I must to write

Code: Select all

 $data['array'] = print_r($data); 
and than add {{ array }} in twig?
Sorry, if i'm wrong with it, and thanks for help

Newbie

Posts

Joined
Fri Feb 21, 2020 5:29 am

Post by by mona » Wed Oct 21, 2020 3:11 am

you just write

Code: Select all

print_r($data);
in the controller before

Code: Select all

return $this->load->view('common/menu', $data);
that is it and that gives you the dumped data

Attachments

Screen-Shot-2020-10-20-at-20.09.13.jpg

Screen-Shot-2020-10-20-at-20.09.13.jpg (89.88 KiB) Viewed 23533 times


DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.


https://www.youtube.com/watch?v=zXIxDoCRc84


User avatar
Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am

Post by straightlight » Wed Oct 21, 2020 4:05 am

Take note you can also use the events debug to output the $args .

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by andriypolik » Wed Oct 21, 2020 4:21 am

by mona wrote:
Wed Oct 21, 2020 3:11 am
you just write

Code: Select all

print_r($data);
in the controller before

Code: Select all

return $this->load->view('common/menu', $data);
that is it and that gives you the dumped data
Thank you a lot. I'm desparate and can't realize what's the problem. It doesn't show any array, but I've try it with another opencart site on localhost - and it displayed.

Maybe thats because of duplicated categories in controller - categoriestop and categoriesmob?

Newbie

Posts

Joined
Fri Feb 21, 2020 5:29 am

Post by sw!tch » Wed Oct 21, 2020 6:04 am

If you have modifications writing to that file then you need to also refresh you modification cache.

Post your controller code in full if you still have trouble.

Full Stack Web Developer :: Send a PM for Custom Work.
Backup and learn how to recover before you make any changes!


Active Member

Posts

Joined
Sat Apr 28, 2012 2:32 pm

Post by straightlight » Wed Oct 21, 2020 7:48 pm

andriypolik wrote:
Wed Oct 21, 2020 4:21 am
by mona wrote:
Wed Oct 21, 2020 3:11 am
you just write

Code: Select all

print_r($data);
in the controller before

Code: Select all

return $this->load->view('common/menu', $data);
that is it and that gives you the dumped data
Thank you a lot. I'm desparate and can't realize what's the problem. It doesn't show any array, but I've try it with another opencart site on localhost - and it displayed.

Maybe thats because of duplicated categories in controller - categoriestop and categoriesmob?
FAQ: viewtopic.php?f=134&t=215776#p718325 .

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by andriypolik » Sat Oct 24, 2020 6:48 pm

Thank you. Sure i've made refresh every time after changing code . Ok, thank you, i will search another decision for this issue

Newbie

Posts

Joined
Fri Feb 21, 2020 5:29 am
Who is online

Users browsing this forum: No registered users and 403 guests