How Check If New Function Is Working On Prestashop
I'm new in prestashop and there is a thing that i don't understand.
I need to add a function that get a file CSV and stock all in a array. This function will be added in a exixsting Class in this path "/modules/sdevmanomano/classes/MyClass.php" Now i have to test the new function, and it the end of the class (out of the {}), i did a var_dump of my object.method(). When i go at the adress of file in my browser, i get nothing. (i m in the correct path). Why? Exemple:
/modules/sdevmanomano/classes/MyClass.php
if (!defined('_PS_VERSION_')) {
exit;
}
include_once(dirname(__FILE__) . '/OtherClass.php');
class MyClass
{
...
//Before execute the code i want check if he has open correctly the CSV in tmpName
private function getDeliveryPrices(){
$tmpName = fopen(dirname(dirname(__FILE__)) . '/prices/prezzi_spedizione_francia.csv', 'r');
if ($tmpName){
$csvAsArray = 'ok';
} else {
$csvAsArray = 'errore';
}
return $csvAsArray;
}
}
// end of class
$test = new MyClass();
$res = $test->getDeliveryPrice();
var_dump($res);
Normally at this point, at the adresse https:/.../modules/sdevmanomano/classes/MyClass.php i have to see my dump, but didn' happen. Why ?
Answer
Assuming you would want to use your php script outside a PrestaShop session within the module context, here is how you could require the PrestaShop configuration when on a stand-alone php script:
// /modules/sdevmanomano/classes/MyClass.php
/*
* Require the PrestaShop configuration
* relative to the location of this script
*/
reqire_once(dirname(__FILE__) . '../../../config/config.inc.php';
// Then you have access to _PS_VERSION_
if (!defined('_PS_VERSION_')) {
exit;
}
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?