Post by talentive » Sun May 22, 2022 6:17 pm

I need to show preorder tag on related products under any given product. I have found following code in product.tpl

Code: Select all

<?php if ($product['quantity']==0) { ?>
          <span class="preorder-label">Pre Order</span>
          <?php } ?>
It uses $product['quantity']==0 to check if it should apply the preorder tag or not.

Now I want same in related products under any product page. The issue is that generates undefined index when the above code is used in product.tpl.
I know variables are defines in product.php so I have tried this on top of product.php to import preorder.php

Code: Select all

$this->load->controller('product/preorder');
Addition of this code breaks the page.

In short, I need to be able to check if product quantity is zero and then apply relevant class in product.tpl`
Last edited by talentive on Sun May 22, 2022 8:26 pm, edited 1 time in total.

New member

Posts

Joined
Tue Nov 10, 2020 2:04 am

Post by by mona » Mon May 23, 2022 7:18 am

is there a controller preorder or did you just make that up?
quantity is already in the product controller

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 talentive » Mon May 23, 2022 7:53 am

I did not make it up, preorder.php file is present in catalog -> controller -> product

New member

Posts

Joined
Tue Nov 10, 2020 2:04 am

Post by by mona » Mon May 23, 2022 8:37 am

Sorry but I still don’t get it
why are you not using what already exists in the product controller?

presumably you have defined it?

Code: Select all

$data['preorder'] = $this->load->controller('product/preorder’); 
and not just

Code: Select all

$this->load->controller('product/preorder'); 
error logs?

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 talentive » Mon May 23, 2022 10:14 am

Okay, I just need to be able to check product quantity in product.tpl. If the functionality is already available in product.php controller, please guide how to check quantity in product.tpl.

New member

Posts

Joined
Tue Nov 10, 2020 2:04 am

Post by straightlight » Mon May 23, 2022 10:28 am

talentive wrote:
Mon May 23, 2022 10:14 am
Okay, I just need to be able to check product quantity in product.tpl. If the functionality is already available in product.php controller, please guide how to check quantity in product.tpl.
OC version.

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 by mona » Mon May 23, 2022 10:40 am

controller
product
after

Code: Select all

$data['points'] = $product_info['points'];
add

Code: Select all

$data['quantity'] = $product_info['quantity'];
related
after

Code: Select all

'name'        => $result['name'],
add

Code: Select all

'quantity' 	  => $result['quantity’],

then tpl use
product

Code: Select all

$quantity
related

Code: Select all

$product['quantity']

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 talentive » Mon May 23, 2022 11:50 am

That worked like a charm. Thank you so much for your help. If possible, can you please suggest some good online article/tutorial which can explain the working of these files so that I can make such edits myself in future.

New member

Posts

Joined
Tue Nov 10, 2020 2:04 am

Post by by mona » Mon May 23, 2022 8:19 pm

You are most welcome

Google is usually a good option, we all started somewhere.
Like anything, it is time knowledge and skill - this is what people get paid for.

Opencart is a simle structure
http://docs.opencart.com/en-gb/developer/module/

If you keep trying you will get it.

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
Who is online

Users browsing this forum: No registered users and 47 guests