Post by Nadalb » Sun Aug 07, 2022 6:30 am

Hi everyone, as the title say I am trying to remove 2 products from being showed in the Latest Module from Opencart 3.0.3.2.
I understand that
\catalog\controller\extension\module\latest.php
must be modified

I think that I must add before

Code: Select all

if ($result['image']) {
a code snippet like

Code: Select all

if ($result['product_id'] = 'ProductIDNumber'){ THEN
					GOTO NEXT
				} else {
				}
This code is absolutely not working, it's just to show what I am trying to accomplish.
In c# a working code will look like this :

Code: Select all

{
    if (product_id == "15" | product_id == "16" | product_id == "17") // restricted product_id are here
    {
    }
    // here the program does nothing
    else
    {
        // ... here the program continue
    }
}
Does someone can give me the correct syntax in php? I have no big knowledge of PHP but I want to learn by little sample like this so if anybody can light this dark corner inm y mind I will really appreciate.

Thank you very much 🙏
Last edited by Nadalb on Sun Aug 07, 2022 8:03 am, edited 2 times in total.

New member

Posts

Joined
Tue Jan 04, 2022 2:12 am

Post by straightlight » Sun Aug 07, 2022 6:51 am

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 Nadalb » Sun Aug 07, 2022 7:02 am

straightlight wrote:
Sun Aug 07, 2022 6:51 am
OC version.
Thanks for your reply, my OC version is 3.0.3.2

New member

Posts

Joined
Tue Jan 04, 2022 2:12 am

Post by straightlight » Tue Aug 09, 2022 8:06 am

To simplify things, I would suggest to create an Event by comparing your product IDs by using the $setting array instead of hardcoding your own. This way, from the OC admin, you could control as many product IDs you'd want.

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 halfhope » Tue Aug 09, 2022 11:50 am

after foreach($results as $result){

Code: Select all

if ($product_id == 12 || $product_id == 14) {
    continue;
}
// or
if (in_array($product_id, [12,13])) {
    continue;
}

My extensions in marketplace. [ security | flexibility | speedup ]


User avatar
Active Member

Posts

Joined
Tue Dec 10, 2013 9:44 pm
Location - San Diego

Post by Nadalb » Wed Aug 10, 2022 3:40 am

halfhope wrote:
Tue Aug 09, 2022 11:50 am
after foreach($results as $result){

Code: Select all

if ($product_id == 12 || $product_id == 14) {
    continue;
}
// or
if (in_array($product_id, [12,13])) {
    continue;
}
Hi and thanks for your help, this is exactly what I was looking for but I did the modifications and despite that the restricted products is showing anyway.
As I read here https://www.bitbook.io/while-foreach-fo ... d%20loops.
a continue 2; would break out of 2 nested loops.
If the Continue; will break and go to the next item why it didn't work?


Thanks
Last edited by Nadalb on Wed Aug 10, 2022 3:51 am, edited 1 time in total.

New member

Posts

Joined
Tue Jan 04, 2022 2:12 am

Post by Nadalb » Wed Aug 10, 2022 3:48 am

straightlight wrote:
Tue Aug 09, 2022 8:06 am
To simplify things, I would suggest to create an Event by comparing your product IDs by using the $setting array instead of hardcoding your own. This way, from the OC admin, you could control as many product IDs you'd want.
Thanks for your reply, I would love to learn that but there is no real tutorial about programming for oc, I learn little by little in a very slow and empirical way.
I don't even know how to create an Event... Tutorials online are outdated since oc 2.x and those available are not for novices

New member

Posts

Joined
Tue Jan 04, 2022 2:12 am

Post by halfhope » Wed Aug 10, 2022 5:00 am

Nadalb wrote:
Wed Aug 10, 2022 3:40 am
If the Continue; will break and go to the next item why it didn't work?
Try to update modifications and check again. if not working, try to use Ctrl+F5 (flush browser cache) or this code to see contents of variable:

Code: Select all

var_dump($var_name);

My extensions in marketplace. [ security | flexibility | speedup ]


User avatar
Active Member

Posts

Joined
Tue Dec 10, 2013 9:44 pm
Location - San Diego

Post by Nadalb » Wed Aug 10, 2022 6:25 am

halfhope wrote:
Wed Aug 10, 2022 5:00 am
Nadalb wrote:
Wed Aug 10, 2022 3:40 am
If the Continue; will break and go to the next item why it didn't work?
Try to update modifications and check again. if not working, try to use Ctrl+F5 (flush browser cache) or this code to see contents of variable:

Code: Select all

var_dump($var_name);
Modifications was made directly in the
/modification/catalog/controller/extension/module/latest.php
foreach ($results as $result) {
if (in_array($product_id, [533,531,546])) {
continue;
}
if ($result['image']) {
$image = $this->model_tool_image->resize($result['image'], $setting['width'], $setting['height'],'product_list');
} else {
$image = $this->model_tool_image->resize('placeholder.png', $setting['width'], $setting['height']);
}

New member

Posts

Joined
Tue Jan 04, 2022 2:12 am

Post by halfhope » Wed Aug 10, 2022 7:34 am

replace $product_id to $result['product_id']

My extensions in marketplace. [ security | flexibility | speedup ]


User avatar
Active Member

Posts

Joined
Tue Dec 10, 2013 9:44 pm
Location - San Diego

Post by Nadalb » Wed Aug 10, 2022 8:41 am

halfhope wrote:
Wed Aug 10, 2022 7:34 am
replace $product_id to $result['product_id']
Now everything seems to work perfectly
If I am not too dumb, I suppose that

Code: Select all

in_array($result['product_id'],
is holding others data and not just 'product_id' maybe product_details['special'] and some others, do you know where I can found them?
I need to study how that work.

Thanks again for your help
Last edited by Nadalb on Mon Jan 09, 2023 7:23 am, edited 1 time in total.

New member

Posts

Joined
Tue Jan 04, 2022 2:12 am

Post by halfhope » Wed Aug 10, 2022 6:18 pm

Use var_dump function to see variable content. I have old post w explaining models but on Ru language https://shth.ru/%d1%82%d1%83%d1%82%d0%b ... d0%b8-652/

My extensions in marketplace. [ security | flexibility | speedup ]


User avatar
Active Member

Posts

Joined
Tue Dec 10, 2013 9:44 pm
Location - San Diego

Post by Nadalb » Thu Aug 11, 2022 6:23 am

halfhope wrote:
Wed Aug 10, 2022 6:18 pm
Use var_dump function to see variable content. I have old post w explaining models but on Ru language https://shth.ru/%d1%82%d1%83%d1%82%d0%b ... d0%b8-652/
Your website is what I am looking for, I will try to translate to english but if you can, translate some of them in english. Like this one Реализация событий в Opencart 2.3, 3.x, 4.x
Last edited by Nadalb on Mon Jan 09, 2023 7:22 am, edited 1 time in total.

New member

Posts

Joined
Tue Jan 04, 2022 2:12 am

Post by halfhope » Thu Aug 11, 2022 10:25 pm

Hi!

Posts on my site too old. Many models and libraries already changed. Post with events already translated to English.

My extensions in marketplace. [ security | flexibility | speedup ]


User avatar
Active Member

Posts

Joined
Tue Dec 10, 2013 9:44 pm
Location - San Diego
Who is online

Users browsing this forum: No registered users and 22 guests