JEEGuy Posted December 11, 2012 Share Posted December 11, 2012 Hy I try to use PrestaShops core functionality from within my own PHP Script. Lets say for example i want to check if "foo@bar.com" is an already registered customer, then i would like to call the Customers core class method the following way: Customer::customerExists("foo@bar.com"); Now if i do so the following error occurs: Fatal error: Class 'ObjectModel' not found in C:\xampp\htdocs\prestashop\classes\Customer.php According to the PrestaShop forum i included the PrestaShop config file to solve this error. I did this the following way: include('config_mod.inc.php'); Good news is: Above error is solved! My Problem: My PHP code doesent even run but the PrestaShop index page gets displayed in the browser. Any suggestions what i am doing wrong? Regards Jan Link to comment Share on other sites More sharing options...
sharif854 Posted December 11, 2012 Share Posted December 11, 2012 your own php file is working for front office? 1.you use require_once instead of include 2.you can you write there that your file location? like this prestashop/modules/mymodules/front/myphpscript.php you write that i know where is your file location to require config Link to comment Share on other sites More sharing options...
JEEGuy Posted December 11, 2012 Author Share Posted December 11, 2012 Hy and many thanks for your fast reply. I use require_once now with the same effect that my code wont run but i get directly redirected to the index page of PrestaShop. My PHP Script is based in prestashop/modules/aaiAuth/aaiReturnHandler I also tried to place it in the override/classes folder as well as inside the prestashop/classes folder. Was anyone even able to use a Core class the way i try to? Regards Jan Background information: I implemented a third party authentification service (Switch AAI) to authenticate students. The reason why i need to call PrestaShop core classes from within a own script is because this third party service delivers SAML2 protected information about the successfully authenticated student to my script. After that return i want to register this student and load it to the PrestaShop Context (or in case of a second successful AAI Login just load it to the context). A workaround would mean to copy hundreds of lines of PrestaShop code to my own script context which i belive is not the way to go. Link to comment Share on other sites More sharing options...
sharif854 Posted December 12, 2012 Share Posted December 12, 2012 ok i assume your direction file is: prestashop/modules/folder1/yourscript.php and you want to use it in front so 1.used this code to require config.php require_once(dirname(__FILE__).'/../../../config/config.inc.php'); and you use FrontController class for your script if you don't know what used this you see 3 file in prestashop 1.contactform.php in root 2.contactController.php in controllers 3.contactForm.tpl in themes you know what is working and you use like this if you use like this everthing is ok if your script not working you konw you have mistake more attention your codes you find your mistake if your problem is not solved in private message send me your code i fix to you if i can regards DMT ! development team Link to comment Share on other sites More sharing options...
JEEGuy Posted December 13, 2012 Author Share Posted December 13, 2012 Hy & again thanks for your reply. Well i will study the mentioned PHP files but lets assume this very easy example, wonder if you can get it to run. I call the Script unter https://localhost/prestashop/modules/aaiauth/Test.php First example: <?php //NOTE THE BELOW LINE IS COMMENTED YET! //require_once(dirname(__FILE__).'/../../config/config.inc.php'); if (Customer::customerExists("foo@bar.com")){ echo("Customer exists"); }else{ echo("Customer doesn't exist"); } echo("Reached end"); ?> My result is the following error: Fatal error: Class 'Customer' not found in C:\xampp\htdocs\prestashop\modules\aaiauth\Test.php on line 5 Now we uncomment the line with the PrestaShop config and load the config: Second example: <?php require_once(dirname(__FILE__).'/../../config/config.inc.php'); if (Customer::customerExists("foo@bar.com")){ echo("Customer exists"); }else{ echo("Customer doesn't exist"); } echo("Reached end"); ?> Now there we go again in my case. I get directly relocated to the index page of PrestaShop and the following code wont run. (I know this from debuging). I would love to hear from you if you were able to run this simple example to echo something instead of only redirect to the index page of PrestaShop. Regards Jan Further information: I will debug deeper into the PrestaShop config. As faar as i have seen till now, the following line of code is the last one executed in the config file and thats why we never reach the own code: Context::getContext()->shop = Shop::initialize(); Link to comment Share on other sites More sharing options...
sharif854 Posted December 14, 2012 Share Posted December 14, 2012 A test this code you write in my system this is location: http://localhost/presta/modules/aaiauth/Test.php so this code is work fine and the result is the pictures your code is working and not have bug but i don't know what do you need if you don't have result you reinstall the prestashop but you sure your code is fine and for develop the prestashop you change line 29 and 30 on and true that prestacomplier is run to help you best regards Link to comment Share on other sites More sharing options...
pernambuco Posted March 13, 2013 Share Posted March 13, 2013 global $smarty; if (!$cookie->isLogged()) { $message = "registrate"; $smarty->assign('message',$message); } else { $message = "Buenos días"; $smarty->assign('message',$message); } Link to comment Share on other sites More sharing options...
twenty5media Posted March 21, 2013 Share Posted March 21, 2013 Hi, I know this is a bit of an old topic but did you manage to find a fix for this? Thanks in advance Link to comment Share on other sites More sharing options...
ghoose Posted October 9, 2014 Share Posted October 9, 2014 Hi! I know this is a prehistoric post, but I still have the same problem... I need to call : Category::regenerateEntireNtree(); from classes/Category.php but I can´t. I´ve this: <?php echo 'open'; require_once(dirname(__FILE__).'/../classes/Category.php'); echo 'reading'; Category::regenerateEntireNtree(); echo 'end'; ?> Someone can give me a hand ?? I´m only a graphic designer, 0 knowledge in PHP. Thnx everybody ! Link to comment Share on other sites More sharing options...
tomerg3 Posted October 9, 2014 Share Posted October 9, 2014 ghoose: Next time, start a new thread rather that revive an 18 month old thread. You can't just include a class, you need to include the PrestaShop config files, which will in turn load all the required classes. It depends on where you are placing this php file, my example is calling it from a module folder (you will need to adjust the path). It should look like <?php //call module include(dirname(__FILE__).'/../../config/config.inc.php'); include(dirname(__FILE__) . '/../../init.php'); Category::regenerateEntireNtree(); echo 'end'; ?> Link to comment Share on other sites More sharing options...
ghoose Posted October 15, 2014 Share Posted October 15, 2014 Sorry tomerg3, next time I´ll do it! Thnx a lot for the answer, I didn´t get notification in my email inbox. I´ll quickly try this and post here the results. THNX!!! Link to comment Share on other sites More sharing options...
ghoose Posted November 5, 2014 Share Posted November 5, 2014 Hi! This work fine for me... but only if I call it manually from the browser. I´m trying to configurate a CRON job but It don´t works. :S I tried with absolute paths etc etc but can´t find the solution... ...any idea about that??? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now