PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, June 29, 2022

[FIXED] How check if new function is working on prestashop

 June 29, 2022     php, prestashop     No comments   

Issue

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 ?


Solution

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;
}


Answered By - Léa Gris
Answer Checked By - Clifford M. (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing