I have written an extremely complex pricing function which I am using to display the price in product.php. In addition to the customer viewing these prices throughout the catalog, I also want them to pay the same price in the cart system.
I would ideally want to access this routine inside of admin too since there will be a page for admin to add orders and enter quotes, although this isn't as important.
Ideally, I don't want to create this code 3 times for obvious reasons.
Ideas and have tried and results:
idea) create code in an include file
result) doesn't work because you cannot include a file inside a class
idea) create code inside a model file
result) doesn't work because you cannot access a catalog model from cart.php
idea) create 3 versions of the code
result) don't want potential of price displayed not being the same as the price paid!
idea) create code inside a model file in catalog and create a controller with localhost IP address security and use curl to get results outside of catalog
result) would work but would only use if no other option
idea supplied in another post was to use the events system. I don't understand how that could help me.
I would be grateful if anyone has any other ideas.
Thanks in advance
Laurence
Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com
So could I create a custom library which could access the DB and contain functions which could be accessed from all areas of the system (catalog pages, cart, admin).
Is there a document on this that I could view or basic skeleton somewhere please?
Many thanks
Just reading....

Notice: Undefined property: Cart\Cart::$mytest ....
I have added the following code to catalog/controller/startup/startup.php
$this->registry->set('mytest', new Mytest($this->registry));
and I access using this code:
$str = $this->mytest->myfunction();
How do I make it accessable from inside the system/library/cart/cart.php
Many thanks
Laurence
Code: Select all
$this->load->library('mytest');
Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig
Hi, thanks for the reply.JNeuhoff wrote: ↑Sat Feb 27, 2021 8:36 pmI would use this:
Code: Select all
$this->load->library('mytest');
If I put that code in cart.php I get the following error:
Notice: Undefined property: Cart\Cart::$load in /home/ezec/storage_topsoil2/modification/system/library/cart/cart.php on line 34
Code: Select all
$this->load = $registry->get('load');
Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig
That stops the new error but back to the original one:JNeuhoff wrote: ↑Sat Feb 27, 2021 9:33 pmAdd this to the system/library/cart/cart.php __construct:
Code: Select all
$this->load = $registry->get('load');
Notice: Undefined property: Cart\Cart::$mytest
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Please explain how I can use an event to facilitate my performing the same code in the catalog and the cart? I don't understand what you are telling me to do.
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
It is the cart, so there is no route or controller.straightlight wrote: ↑Sat Feb 27, 2021 11:00 pmWhat is your route and controller name? Also, to state the admin or catalog path in front.
Can anyone provide an example of how I can instanciate a system library file in the cart please? I am hoping someone knows!
You could always create a new service request in the Commercial Support section of the forum to get this done as a custom job.Lozza2 wrote: ↑Sat Feb 27, 2021 11:09 pmIt is the cart, so there is no route or controller.straightlight wrote: ↑Sat Feb 27, 2021 11:00 pmWhat is your route and controller name? Also, to state the admin or catalog path in front.
Can anyone provide an example of how I can instanciate a system library file in the cart please? I am hoping someone knows!
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Users browsing this forum: No registered users and 9 guests