How Check If New Function Is Working On Prestashop

- 1 answer

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:

if (!defined('_PS_VERSION_')) {

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();

Normally at this point, at the adresse https:/.../modules/sdevmanomano/classes/MyClass.php i have to see my dump, but didn' happen. Why ?



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/';

// Then you have access to _PS_VERSION_
if (!defined('_PS_VERSION_')) {