Jump to content

Whats wrong with these modification to a plugin


sanjar12345

Recommended Posts

Hello,

 


 

I saw that it already had an auto updated (currency exchange) for BTC and DOGE so I decided to see if I could update it to also allow "Stellar" to be auto updated.

 

I looked over this code twice and don't think there is anything wrong with it yet I get the following errors in prestashop.

 

2 errors 
cryptocurrency (parse error in /modules/cryptocurrency/cryptocurrency.php)
cryptocurrency (class missing in /modules/cryptocurrency/cryptocurrency.php)

 

Here is my cryptocurrency.php

 


 

Thank you for all your help

Link to comment
Share on other sites

        //update btc conversion rate if the user loads a page and has btc as current currency
        public function hookHeader($params){
                if(Configuration::get('CRYPTO_CURRENCY_UPDATE_STELLAR')){
                        $stellar_code = 'STELLAR';
                        $cart_currency = $this->context->cart->id_currency;
                       
                        $stellar_currency_id = Db::getInstance()->executeS('
                                SELECT `id_currency`
                                FROM `'._DB_PREFIX_.'currency`
                                WHERE `iso_code`=\''.$stellar_code.'\'');
                       
                        if($stellar_currency_id && $stellar_currency_id[0]['id_currency']==$cart_currency){
                                //some code snippets taken from bitcointicker module
                                $default_currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT'));
                                $response = file_get_contents('http://coinmarketcap-nexuist.rhcloud.com/api/str');
                                $object = json_decode($response);
                               
                                if(is_object($object)){
                                        $curr = strtolower($default_currency->iso_code);//'USD';
                                        //$rate = $object->$curr->{'last'};
                                        $rate = $object->{'price'}->$curr;
                                        $rate_default = 1.0/floatval($rate);
                                        $rate_default_str = trim(sprintf("%.6f", $rate_default));
                                       
                                        //update conversion_rate on currency table
                                        $query='UPDATE IGNORE `'._DB_PREFIX_.'currency`
                                                SET `conversion_rate` = \''.$rate_default_str.'\'
                                                WHERE `iso_code` = \''.$stellar_code.'\'';
                                       
                                        //print_r($query);
                                        $return = Db::getInstance()->Execute($query);
                                       
                                        //update conversion_rate in currency_shop table too
                                        $curr_id = strval($stellar_currency_id[0]['id_currency']);
                                        $query2='UPDATE IGNORE `'._DB_PREFIX_.'currency_shop`
                                                SET `conversion_rate` = \''.$rate_default_str.'\'
                                                WHERE `id_currency`=\''.$curr_id.'\'';
                                               
                                        $return = Db::getInstance()->Execute($query2);
                                }
                        }
                }

this code is out of class brackets

Link to comment
Share on other sites

        //update btc conversion rate if the user loads a page and has btc as current currency
        public function hookHeader($params){
                if(Configuration::get('CRYPTO_CURRENCY_UPDATE_STELLAR')){
                        $stellar_code = 'STELLAR';
                        $cart_currency = $this->context->cart->id_currency;
                       
                        $stellar_currency_id = Db::getInstance()->executeS('
                                SELECT `id_currency`
                                FROM `'._DB_PREFIX_.'currency`
                                WHERE `iso_code`=\''.$stellar_code.'\'');
                       
                        if($stellar_currency_id && $stellar_currency_id[0]['id_currency']==$cart_currency){
                                //some code snippets taken from bitcointicker module
                                $default_currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT'));
                                $response = file_get_contents('http://coinmarketcap-nexuist.rhcloud.com/api/str');
                                $object = json_decode($response);
                               
                                if(is_object($object)){
                                        $curr = strtolower($default_currency->iso_code);//'USD';
                                        //$rate = $object->$curr->{'last'};
                                        $rate = $object->{'price'}->$curr;
                                        $rate_default = 1.0/floatval($rate);
                                        $rate_default_str = trim(sprintf("%.6f", $rate_default));
                                       
                                        //update conversion_rate on currency table
                                        $query='UPDATE IGNORE `'._DB_PREFIX_.'currency`
                                                SET `conversion_rate` = \''.$rate_default_str.'\'
                                                WHERE `iso_code` = \''.$stellar_code.'\'';
                                       
                                        //print_r($query);
                                        $return = Db::getInstance()->Execute($query);
                                       
                                        //update conversion_rate in currency_shop table too
                                        $curr_id = strval($stellar_currency_id[0]['id_currency']);
                                        $query2='UPDATE IGNORE `'._DB_PREFIX_.'currency_shop`
                                                SET `conversion_rate` = \''.$rate_default_str.'\'
                                                WHERE `id_currency`=\''.$curr_id.'\'';
                                               
                                        $return = Db::getInstance()->Execute($query2);
                                }
                        }
                }

this code is out of class brackets

 

 

Sorry, what do you mean with "class brackets"

Link to comment
Share on other sites

structure of well coded module looks like:

class ModuleName extends Module {
  // code of module
  public function doSomething(){
  }
}

your code looks like:
 

class ModuleName extends Module {
  // code of module
}

  public function doSomething(){
  }

as you can see public function doSomething() is outside

 

class ModuleName extends Module {

}

 

 

all module functions must be inside class, not outside

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...