Post by kodomoyeh » Tue May 16, 2023 12:15 pm

Did any one try running composer in OC 4.0 ?
https://code.tutsplus.com/tutorials/int ... -cms-27874
This article did composer with OC3.x successfully
I noticed that after OC4.0
There is no require_once(DIR_STORAGE . 'vendor/autoload.php'); in system/startup.php
and there is a new file system/vendor.php
I could do composer require , but i cannot use class in Controller Layer
either I add related autoload code in system/vendor.php or not .

It shows Class "xxxxxxxxxxxxxxxxxx" not found

Newbie

Posts

Joined
Fri Feb 26, 2016 9:06 am

Post by kodomoyeh » Fri May 19, 2023 4:08 pm

OK . Acturally it works.
Just remomber to edit system/vendor.php

Newbie

Posts

Joined
Fri Feb 26, 2016 9:06 am

Post by chongshengdz » Tue May 23, 2023 4:11 am

Class "xxxxxxxxxxxxxxxxxx" not found
means you need to install the not-found php component on your server via ssh and after install the php component, you need to restart php or your server.
the errors means something wrong with your server.

https://www.ectransistors.com/
https://www.transistormosfet.com/


Active Member

Posts

Joined
Sat Apr 12, 2014 10:18 pm


Post by haydent » Fri Jun 30, 2023 1:43 pm

thanks for this, id found the composer vendor folder in storage and wondered if i could use it, installed my library with require , added use lines to the class but class not found when trying to new() in .... thank you thankyou , just edit system/vendor maybe oc should just autoload ?? (chongshengdz you are way off, delete your post)

User avatar
Active Member

Posts

Joined
Wed Nov 09, 2011 9:50 am
Location - Sydney, Australia

Post by JNeuhoff » Fri Jun 30, 2023 7:45 pm

haydent wrote:
Fri Jun 30, 2023 1:43 pm
thanks for this, id found the composer vendor folder in storage and wondered if i could use it, installed my library with require , added use lines to the class but class not found when trying to new() in .... thank you thankyou , just edit system/vendor maybe oc should just autoload ?? (chongshengdz you are way off, delete your post)
Go to your system/storage folder, where you will find the 'composer.json' file, which can be edited, to add your needed package. Then run a 'composer update' from your command prompt.

Having said that, it might be better to leave this alone, and create your own OpenCart 4 extension, e.g. something like this, all wrapped up in an .ocmod.zip archive:

myext/system/library/mymod/vendor/*
myext/system/library/mymod/composer.json
myext/system/library/mymod/composer.lock

And then use it in your OpenCart extension via PHP's require or include.

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member
Online

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by haydent » Sat Jul 01, 2023 4:40 am

I did that (update composer.json or use require command) but you still have to edit vendor.php which is a pain and seems pointless when there is a perfectly good autoloader available, plus its not just the lib you want, its all its dependencies, plus their functions....

I tried creating a 2nd vendor/composer install but this doesnt work as common dependency libraries will conflict, ie you cant run 2 copies of guzzle...

User avatar
Active Member

Posts

Joined
Wed Nov 09, 2011 9:50 am
Location - Sydney, Australia

Post by JNeuhoff » Sat Jul 01, 2023 5:14 pm

You need to include the vendor/autoload.php. E.g. this is how I did it for the Export/Import tool:

Code: Select all

....
// enable auto_load from system/library/export_import
require( DIR_EXTENSION.'export_import/system/library/export_import/vendor/autoload.php' );

// Use the PhoOffice/PhpSpreadsheet package from https://github.com/PHPOffice/PhpSpreadsheet
$workbook = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
....

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member
Online

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by haydent » Sat Jul 01, 2023 6:41 pm

extension_id=17 , wow you've had that a while :)
ill have to try that, thanks ! I downloaded your extension to see how you did it.

User avatar
Active Member

Posts

Joined
Wed Nov 09, 2011 9:50 am
Location - Sydney, Australia

Post by haydent » Sat Jul 01, 2023 6:50 pm

actually this is how ive done it in the past, so no big deal, what i was talking about is using the system composer install, but i think it retrospect its likely best to run my own composer install.

User avatar
Active Member

Posts

Joined
Wed Nov 09, 2011 9:50 am
Location - Sydney, Australia

Post by treii28 » Wed Feb 21, 2024 1:36 am

Yeah - ugh - that vendor.php is ugly and the composer.json is broken in v4 (running composer update in the storage directory on a vanilla install fails due to a conflict between phpdocumentor and twig and guzzlehttp/promises changes in >v3 and no longer includes the functions_include.php file)

I found a solution for the phpdocumentor problem by changing the require line to load the shim instead. But the rest of that file is just janky. I found if you comment out all the references to vendor and just use the composer autoloader (require_once) it seems to work just fine. vendor.php might still be useful for loading non composer / packagist libraries, but is there some reason they do it this way? That's just bleh!

Read more about here: viewtopic.php?p=867361#p867361

Newbie

Posts

Joined
Wed Jan 31, 2024 5:48 am
Who is online

Users browsing this forum: No registered users and 4 guests