Post by rick998 » Thu Feb 04, 2016 7:45 am

In catalog/controller/product/featured.php I have copied the code:

Code: Select all

if ($data['products']) {
			//added
			
			if (isset($this->request->get['page'])) {
		             $page = $this->request->get['page'];

		          } else {
		             $page = 1;
		          }

		          $this->data['pagination'] = '';
		          if (isset($this->request->get['product_id'])) {      
		             $pagination = new Pagination();
		             $pagination->total = sizeof($this->data['products']);
		             $pagination->page = $page;
		             $pagination->limit = $this->config->get('config_catalog_limit');
		             $pagination->text = $this->language->get('text_pagination');
		             $pagination->url = $this->url->link('module/featured', 'product_id=' . $this->request->get['product_id'] . '&page={page}');

		             $this->data['pagination'] = $pagination->render();
		          }
		    
			
			//added end
			if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/featured.tpl')) {
				return $this->load->view($this->config->get('config_template') . '/template/module/featured.tpl', $data);
			} else {
				return $this->load->view('default/template/module/featured.tpl', $data);
			}
.../template/module/featured.tpl

Code: Select all

</div>
		<div class="pagination"><?php echo $pagination; ?></div>
	</div>
</div>
I have added these 2 lines of code in order to try to add pagination to the 'featured' module but I get the error Notice: Undefined variable: pagination in .../template/module/featured.tpl when I open the page.

Any idea of why that happens?
Any help appreciated

Newbie

Posts

Joined
Thu Feb 04, 2016 7:33 am

Post by rick998 » Sat Feb 06, 2016 2:29 am

I actually feel like nothing of what I change in controllers do reflect:

for example, if I change the line:
$data['heading_title'] = $this->language->get('heading_title');
To
$data['heading_title'] = 'test';

The title of my module does not change either.
I am not sure where does the issue comes from. The file is updated correctly on the FTP and I have also tried locally in MAMP and am getting the exact same issue.\

Any help would be appreciated.

Newbie

Posts

Joined
Thu Feb 04, 2016 7:33 am

Post by artcore » Sat Feb 06, 2016 3:45 am

Did you refresh the modification cache?

If I may say so, I'm not sure if it's an improvement that customers would enjoy, the page will reload at every pagination change. Just to have another 4(?) products change in that featured module while the rest stays the same...
I would either use a javascript slider like carouFredsel for this or js based pagination like listjs.com which is real easy to use and doesn't require any php changes.
That way visitors can flip in comfort and way quicker ;D

Attn: I no longer provide OpenCart extensions, nor future support - this includes forum posts.
Reason: I moved on to Laravel ;D

Thanks!


User avatar
Active Member

Posts

Joined
Tue Jul 09, 2013 4:13 am
Location - The Netherlands

Post by rick998 » Sat Feb 06, 2016 4:33 am

Thank you!
Refreshing the modification cache helps solving the
$data['heading_title'] = $this->language->get('heading_title');
issue and also another issue that I had with AddStyle.

However, the pagination issue seems to remain even after that ???

Using javascript would imply I would need to load all my products and then paginate with javascript which might be quite heavy, but I'll look into this if I can solve how to make it work with php.

Newbie

Posts

Joined
Thu Feb 04, 2016 7:33 am

Post by artcore » Sat Feb 06, 2016 5:50 am

Just cache the results so you're not taxing the db every time. And as another tip, have the container to be paginated set with a max height so visitors don't see the full list before js is ready to slice it down. Works like a charm, I like letting the browser do the work, not the server :)

You're using $this->data['pagination'] while passing $data to the view. That's why it's undefined.
Also I don't get the url inside the pagination. It should be the page the module is on, not a link to itself especially as it's a module, not the actual page

e.g.
$pagination->url = $this->url->link('common/home', 'page={page}');
Or in stead of common/home a variable $this->request->get['route'] so it works on other pages the module is on.

With some error checking and initialization of course.

But I still feel it's weird to do it this way ;D

Attn: I no longer provide OpenCart extensions, nor future support - this includes forum posts.
Reason: I moved on to Laravel ;D

Thanks!


User avatar
Active Member

Posts

Joined
Tue Jul 09, 2013 4:13 am
Location - The Netherlands

Post by rick998 » Sat Feb 06, 2016 6:05 am

Thank you.

So what should I use instead of $this->data['pagination'] in the controller? Should I use $pagination=$pagination->render(); or should I echo $this->data['pagination'] in the view instead? Sorry if the question is silly, I am new to this.

Newbie

Posts

Joined
Thu Feb 04, 2016 7:33 am

Post by artcore » Sat Feb 06, 2016 4:01 pm

$data['pagination'] = $pagination->render();
I commend you for trying yourself, but you urgently need to take some basic courses if you plan on doing more changes in the future. I'm gladly helping, this is meant for your own protection ;D

Let me know if you got it working,

Cheers

Attn: I no longer provide OpenCart extensions, nor future support - this includes forum posts.
Reason: I moved on to Laravel ;D

Thanks!


User avatar
Active Member

Posts

Joined
Tue Jul 09, 2013 4:13 am
Location - The Netherlands

Post by rick998 » Sun Feb 07, 2016 11:07 pm

Thank you for your help.
It helped me a lot understanding those errors and also I learned about the cache, which solved another of my issue.

The error has disappeared after I change the code $this->data to $data
However, I did not figure out how to figure the number of items per page and other settings for pagination on this module.

As you said before, as this is not user-friendly, especially as this is on the home page. I just used some javascript instead and it is working. :) I was still very curious to understand the issue with the php code for future references.
I did not understand which object $this was referring to in this case, but I'll look into some basics on the internet, thank you again.

Newbie

Posts

Joined
Thu Feb 04, 2016 7:33 am

Post by artcore » Mon Feb 08, 2016 12:36 am

You're welcome, happy to help especially someone willing to learn instead of looking for ready code :)

The page limits are in the filter_array which in turn tells the db how many records to retreive from which starting point.
$this will become clear over time, just use it for now as it won't affect the thought process.
$this->data is available across class methods where as $data is an array in the local scope (the function it's in)

Even in OC2 I still tend to use $this->data for convenience.
Cheers

Attn: I no longer provide OpenCart extensions, nor future support - this includes forum posts.
Reason: I moved on to Laravel ;D

Thanks!


User avatar
Active Member

Posts

Joined
Tue Jul 09, 2013 4:13 am
Location - The Netherlands

Post by simis » Wed Apr 25, 2018 5:42 pm

rick998 wrote:
Sun Feb 07, 2016 11:07 pm

As you said before, as this is not user-friendly, especially as this is on the home page. I just used some javascript instead and it is working. :) I was still very curious to understand the issue with the php code for future references.
Hi to all,

I need exactly the same thing for fetaured products and i can't understand how to do it with javascript. I checked the sites mentioned above but I can't understand how to do it (newbie). Could you provide me some help?

Newbie

Posts

Joined
Wed Jan 31, 2018 6:47 pm
Who is online

Users browsing this forum: labeshops and 17 guests