Jump to content

[SOLVED] "ContextErrorException Notice: Undefined index: cookie" after manually changing currency in classes/controllers/FrontController.php (PS 1.7.5.0)


Recommended Posts

Greetings PS community,
I'm a relatively new PHP dev with zero experience in Prestashop, I've only been using it for a week.

With my project, I'm trying to add a few currencies, modifying the currency's displayName & symbol to something else in translations/cldr/main--en-US--currencies, then allow users to choose which currency in the Front Office except for the default currency, which is USD.

The error that I encountered (as in the attachment), was after I've modified the classes/controllers/FrontController.php file.
I've changed the original code on line 350 in the file from this :

$currency = Tools::setCurrency($this->context->cookie);

to this :

$currency = Currency::getCurrencyInstance(i);

* the "i" represents number from 1 - 6, which were the id for the currencies I've added.


The error occurs after I switched the code back to the original code & have multiple currencies enabled.
I really have no clue how to get it to work as it were before.

If you can tell what went wrong or if you need more information, please let me know.
Thank you for taking your time to read this.
 

ContextErrorException.JPG

 

UPDATE :
The ContectErrorException no longer shows when Debug Mode is disabled but I am still unable to change currency & I would get Error 502.

change_currency_error_502.thumb.JPG.28bcbbed5dcb333cb84daf5fad72428d.JPG

 

I'd also get this in the nginx error log :

2019/01/17 15:49:16 [error] 697#697: *3693 FastCGI sent in stderr: "PHP message: PHP Notice:  Undefined index: current in /var/www/html/sinegy_store/var/cache/prod/smarty/compile/b9/77/56/b97756c07f8c7dd53da6530f78f67ddd242f77c9_2.module.pscurrencyselectorpscurre.php on line 38
PHP message: PHP Notice:  Undefined index: url in /var/www/html/sinegy_store/var/cache/prod/smarty/compile/b9/77/56/b97756c07f8c7dd53da6530f78f67ddd242f77c9_2.module.pscurrencyselectorpscurre.php on line 40
PHP message: PHP Notice:  Undefined index: cookie in /var/www/html/sinegy_store/var/cache/prod/smarty/compile/b9/77/56/b97756c07f8c7dd53da6530f78f67ddd242f77c9_2.module.pscurrencyselectorpscurre.php on line 71
PHP message: PHP Notice:  Trying to get property 'value' of non-object in /var/www/html/sinegy_store/var/cache/prod/smarty/compile/b9/77/56/b97756c07f8c7dd53da6530f78f67ddd242f77c9_2.module.pscurrencyselectorpscurre.php on line 71
PHP message: PHP Notice:  Trying to get property 'id_currency' of non-object in /var/www/html/sinegy_store/var/cache/prod/smarty/compile/b9/77/56/b97756c07f8c7dd53da6530f78f67ddd242f77c9_2.module.pscurrencyselectorpscurre.php on line 71
PHP message: PHP Notice:  Undefined index: cookie in /var/www/html/sinegy_store/var/cache/prod/smarty/compile/b9/77/56/b97756c07f8c7dd53da6530f78f67ddd242f77c9_2.module.pscurrencyselectorpscurre.php on line 77
PHP message: PHP Notice:  Trying to get property 'value' of non-object in /var/www/html/sinegy_store/var/cache/prod/smarty/compile/b9/77/56/b97756c07f8c7dd53da6530f78f67ddd242f77c9_2.module.pscurrencyselectorpscurre.php on line 77
PHP message: PHP Notice:  Trying to get property 'id_currency' of non-object in /var/www/html/sinegy_store/var/cache/prod/smarty/compile/b9/77/56/b97756c07f8c7dd53da6530f78f67ddd242f77c9_2.module.pscurrencyselectorpscurre.php on line 77
PHP message: PHP Notice:  Undefined index: cookie in /var/www/html/sinegy_store/var/cache/prod/smarty/compile/b9/77/56/b97756c07f8c7dd53da6530f78f67ddd242f77c9_2.module.pscurrencyselectorpscurre.php on lin
2019/01/17 15:49:16 [error] 697#697: *3693 upstream sent too big header while reading response header from upstream, client: xxx.xxx.xxx.xx, server: store.sinegy.com, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.2-fpm.sock:", host: "store.sinegy.com"
2019/01/17 15:49:18 [error] 697#697: *3695 FastCGI sent in stderr: "PHP message: PHP Notice:  Undefined index: current in /var/www/html/sinegy_store/var/cache/prod/smarty/compile/b9/77/56/b97756c07f8c7dd53da6530f78f67ddd242f77c9_2.module.pscurrencyselectorpscurre.php on line 38
PHP message: PHP Notice:  Undefined index: url in /var/www/html/sinegy_store/var/cache/prod/smarty/compile/b9/77/56/b97756c07f8c7dd53da6530f78f67ddd242f77c9_2.module.pscurrencyselectorpscurre.php on line 40
PHP message: PHP Notice:  Undefined index: cookie in /var/www/html/sinegy_store/var/cache/prod/smarty/compile/b9/77/56/b97756c07f8c7dd53da6530f78f67ddd242f77c9_2.module.pscurrencyselectorpscurre.php on line 71
PHP message: PHP Notice:  Trying to get property 'value' of non-object in /var/www/html/sinegy_store/var/cache/prod/smarty/compile/b9/77/56/b97756c07f8c7dd53da6530f78f67ddd242f77c9_2.module.pscurrencyselectorpscurre.php on line 71
PHP message: PHP Notice:  Trying to get property 'id_currency' of non-object in /var/www/html/sinegy_store/var/cache/prod/smarty/compile/b9/77/56/b97756c07f8c7dd53da6530f78f67ddd242f77c9_2.module.pscurrencyselectorpscurre.php on line 71
PHP message: PHP Notice:  Undefined index: cookie in /var/www/html/sinegy_store/var/cache/prod/smarty/compile/b9/77/56/b97756c07f8c7dd53da6530f78f67ddd242f77c9_2.module.pscurrencyselectorpscurre.php on line 77
PHP message: PHP Notice:  Trying to get property 'value' of non-object in /var/www/html/sinegy_store/var/cache/prod/smarty/compile/b9/77/56/b97756c07f8c7dd53da6530f78f67ddd242f77c9_2.module.pscurrencyselectorpscurre.php on line 77
PHP message: PHP Notice:  Trying to get property 'id_currency' of non-object in /var/www/html/sinegy_store/var/cache/prod/smarty/compile/b9/77/56/b97756c07f8c7dd53da6530f78f67ddd242f77c9_2.module.pscurrencyselectorpscurre.php on line 77
PHP message: PHP Notice:  Undefined index: cookie in /var/www/html/sinegy_store/var/cache/prod/smarty/compile/b9/77/56/b97756c07f8c7dd53da6530f78f67ddd242f77c9_2.module.pscurrencyselectorpscurre.php on lin
2019/01/17 15:49:18 [error] 697#697: *3695 upstream sent too big header while reading response header from upstream, client: xxx.xxx.xxx.xx, server: store.sinegy.com, request: "GET /index.php?id_lang=1&SubmitCurrency=1&id_currency=7 HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.2-fpm.sock:", host: "store.sinegy.com", referrer: "https://store.sinegy.com/index.php"
2019/01/17 15:49:20 [error] 697#697: *3693 FastCGI sent in stderr: "PHP message: PHP Notice:  Undefined index: current in /var/www/html/sinegy_store/var/cache/prod/smarty/compile/b9/77/56/b97756c07f8c7dd53da6530f78f67ddd242f77c9_2.module.pscurrencyselectorpscurre.php on line 38
PHP message: PHP Notice:  Undefined index: url in /var/www/html/sinegy_store/var/cache/prod/smarty/compile/b9/77/56/b97756c07f8c7dd53da6530f78f67ddd242f77c9_2.module.pscurrencyselectorpscurre.php on line 40
PHP message: PHP Notice:  Undefined index: cookie in /var/www/html/sinegy_store/var/cache/prod/smarty/compile/b9/77/56/b97756c07f8c7dd53da6530f78f67ddd242f77c9_2.module.pscurrencyselectorpscurre.php on line 71
PHP message: PHP Notice:  Trying to get property 'value' of non-object in /var/www/html/sinegy_store/var/cache/prod/smarty/compile/b9/77/56/b97756c07f8c7dd53da6530f78f67ddd242f77c9_2.module.pscurrencyselectorpscurre.php on line 71
PHP message: PHP Notice:  Trying to get property 'id_currency' of non-object in /var/www/html/sinegy_store/var/cache/prod/smarty/compile/b9/77/56/b97756c07f8c7dd53da6530f78f67ddd242f77c9_2.module.pscurrencyselectorpscurre.php on line 71
PHP message: PHP Notice:  Undefined index: cookie in /var/www/html/sinegy_store/var/cache/prod/smarty/compile/b9/77/56/b97756c07f8c7dd53da6530f78f67ddd242f77c9_2.module.pscurrencyselectorpscurre.php on line 77
PHP message: PHP Notice:  Trying to get property 'value' of non-object in /var/www/html/sinegy_store/var/cache/prod/smarty/compile/b9/77/56/b97756c07f8c7dd53da6530f78f67ddd242f77c9_2.module.pscurrencyselectorpscurre.php on line 77
PHP message: PHP Notice:  Trying to get property 'id_currency' of non-object in /var/www/html/sinegy_store/var/cache/prod/smarty/compile/b9/77/56/b97756c07f8c7dd53da6530f78f67ddd242f77c9_2.module.pscurrencyselectorpscurre.php on line 77
PHP message: PHP Notice:  Undefined index: cookie in /var/www/html/sinegy_store/var/cache/prod/smarty/compile/b9/77/56/b97756c07f8c7dd53da6530f78f67ddd242f77c9_2.module.pscurrencyselectorpscurre.php on lin
2019/01/17 15:49:22 [error] 697#697: *3698 open() "/var/www/html/sinegy_store/themes/core.js.map" failed (2: No such file or directory), client: xxx.xxx.xxx.xx, server: store.sinegy.com, request: "GET /themes/core.js.map HTTP/1.1", host: "store.sinegy.com"
2019/01/17 15:49:24 [error] 697#697: *3693 FastCGI sent in stderr: "PHP message: PHP Notice:  Undefined index: current in /var/www/html/sinegy_store/var/cache/prod/smarty/compile/b9/77/56/b97756c07f8c7dd53da6530f78f67ddd242f77c9_2.module.pscurrencyselectorpscurre.php on line 38
PHP message: PHP Notice:  Undefined index: url in /var/www/html/sinegy_store/var/cache/prod/smarty/compile/b9/77/56/b97756c07f8c7dd53da6530f78f67ddd242f77c9_2.module.pscurrencyselectorpscurre.php on line 40
PHP message: PHP Notice:  Undefined index: cookie in /var/www/html/sinegy_store/var/cache/prod/smarty/compile/b9/77/56/b97756c07f8c7dd53da6530f78f67ddd242f77c9_2.module.pscurrencyselectorpscurre.php on line 71
PHP message: PHP Notice:  Trying to get property 'value' of non-object in /var/www/html/sinegy_store/var/cache/prod/smarty/compile/b9/77/56/b97756c07f8c7dd53da6530f78f67ddd242f77c9_2.module.pscurrencyselectorpscurre.php on line 71
PHP message: PHP Notice:  Trying to get property 'id_currency' of non-object in /var/www/html/sinegy_store/var/cache/prod/smarty/compile/b9/77/56/b97756c07f8c7dd53da6530f78f67ddd242f77c9_2.module.pscurrencyselectorpscurre.php on line 71
PHP message: PHP Notice:  Undefined index: cookie in /var/www/html/sinegy_store/var/cache/prod/smarty/compile/b9/77/56/b97756c07f8c7dd53da6530f78f67ddd242f77c9_2.module.pscurrencyselectorpscurre.php on line 77
PHP message: PHP Notice:  Trying to get property 'value' of non-object in /var/www/html/sinegy_store/var/cache/prod/smarty/compile/b9/77/56/b97756c07f8c7dd53da6530f78f67ddd242f77c9_2.module.pscurrencyselectorpscurre.php on line 77
PHP message: PHP Notice:  Trying to get property 'id_currency' of non-object in /var/www/html/sinegy_store/var/cache/prod/smarty/compile/b9/77/56/b97756c07f8c7dd53da6530f78f67ddd242f77c9_2.module.pscurrencyselectorpscurre.php on line 77
PHP message: PHP Notice:  Undefined index: cookie in /var/www/html/sinegy_store/var/cache/prod/smarty/compile/b9/77/56/b97756c07f8c7dd53da6530f78f67ddd242f77c9_2.module.pscurrencyselectorpscurre.php on lin
2019/01/17 15:49:25 [error] 697#697: *3700 open() "/var/www/html/sinegy_store/themes/core.js.map" failed (2: No such file or directory), client: xxx.xxx.xxx.xx, server: store.sinegy.com, request: "GET /themes/core.js.map HTTP/1.1", host: "store.sinegy.com"
2019/01/17 15:49:28 [error] 697#697: *3693 FastCGI sent in stderr: "PHP message: PHP Notice:  Undefined index: current in /var/www/html/sinegy_store/var/cache/prod/smarty/compile/b9/77/56/b97756c07f8c7dd53da6530f78f67ddd242f77c9_2.module.pscurrencyselectorpscurre.php on line 38
PHP message: PHP Notice:  Undefined index: url in /var/www/html/sinegy_store/var/cache/prod/smarty/compile/b9/77/56/b97756c07f8c7dd53da6530f78f67ddd242f77c9_2.module.pscurrencyselectorpscurre.php on line 40
PHP message: PHP Notice:  Undefined index: cookie in /var/www/html/sinegy_store/var/cache/prod/smarty/compile/b9/77/56/b97756c07f8c7dd53da6530f78f67ddd242f77c9_2.module.pscurrencyselectorpscurre.php on line 71
PHP message: PHP Notice:  Trying to get property 'value' of non-object in /var/www/html/sinegy_store/var/cache/prod/smarty/compile/b9/77/56/b97756c07f8c7dd53da6530f78f67ddd242f77c9_2.module.pscurrencyselectorpscurre.php on line 71
PHP message: PHP Notice:  Trying to get property 'id_currency' of non-object in /var/www/html/sinegy_store/var/cache/prod/smarty/compile/b9/77/56/b97756c07f8c7dd53da6530f78f67ddd242f77c9_2.module.pscurrencyselectorpscurre.php on line 71
PHP message: PHP Notice:  Undefined index: cookie in /var/www/html/sinegy_store/var/cache/prod/smarty/compile/b9/77/56/b97756c07f8c7dd53da6530f78f67ddd242f77c9_2.module.pscurrencyselectorpscurre.php on line 77
PHP message: PHP Notice:  Trying to get property 'value' of non-object in /var/www/html/sinegy_store/var/cache/prod/smarty/compile/b9/77/56/b97756c07f8c7dd53da6530f78f67ddd242f77c9_2.module.pscurrencyselectorpscurre.php on line 77
PHP message: PHP Notice:  Trying to get property 'id_currency' of non-object in /var/www/html/sinegy_store/var/cache/prod/smarty/compile/b9/77/56/b97756c07f8c7dd53da6530f78f67ddd242f77c9_2.module.pscurrencyselectorpscurre.php on line 77
PHP message: PHP Notice:  Undefined index: cookie in /var/www/html/sinegy_store/var/cache/prod/smarty/compile/b9/77/56/b97756c07f8c7dd53da6530f78f67ddd242f77c9_2.module.pscurrencyselectorpscurre.php on lin
2019/01/17 15:49:28 [error] 697#697: *3693 upstream sent too big header while reading response header from upstream, client: xxx.xxx.xxx.xx, server: store.sinegy.com, request: "GET /index.php?id_lang=1&SubmitCurrency=1&id_currency=7 HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.2-fpm.sock:", host: "store.sinegy.com", referrer: "https://store.sinegy.com/index.php"
Edited by Limerin555
Question solved (see edit history)
Link to comment
Share on other sites

14 hours ago, JBW said:

Looking at your code the i is not a PHP variable - they always start with a $. So either i is a type or you miss to explain how this is filled.

JBW, the "i" was filled in directly in the FrontController,  it is not a variable, it is an integer from 1 - 6.

The reason why I did it was because I wanted to see which currency id belongs to which currency, after I've got what I wanted to know I switched the code back to :

$currency = Tools::setCurrency($this->context->cookie);


This is when the "cookie" error showed up when I try to load the front office  with multiple currencies enabled. 
It's as if the cookie was still stuck at a different currency or is empty, therefore unable to load the "ps_currencyselector.tpl" file in "themes/theme_name/modules/".

This is what's in the "ps_currencyselector.tpl" :
 

<div id="_desktop_currency_selector">
  <div class="currency-selector dropdown js-dropdown">
    <span id="currency-selector-label">{l s='Currency:' d='Shop.Theme.Global'}</span>
    <button data-target="#" data-toggle="dropdown" class="hidden-sm-down btn-unstyle" aria-haspopup="true" aria-expanded="false" aria-label="{l s='Currency dropdown' d='Shop.Theme.Global'}">
        <span id="currency_dropdown" class="expand-more _gray-darker">{$current_currency.name}</span>
        <i class="fas fa-chevron-down expand-more"></i>
    </button>

    <form id="setCurrency" action="{$request_uri}" method="post">
        <input id="current_id" type="hidden" value="{$current_currency.name}">
        <input type="hidden" name="id_currency" id="id_currency" value=""/>
        <input type="hidden" name="SubmitCurrency" value="" />

        <ul class="dropdown-menu hidden-sm-down" aria-labelledby="currency-selector-label">
            <li {if $cookie->id_currency == 2}class="selected"{/if}>
                <a title="Bitcoin" rel="nofollow" href="#" class="dropdown-item" onclick="setCurrency(2)">
                    <img class="crypto_icons" src="{$urls.img_ps_url}/crypto_icons/BTC_icon.png"> BTC
                </a>
            </li>
            <li {if $cookie->id_currency == 3}class="selected"{/if}>
                <a title="Ethereum" rel="nofollow" href="#" class="dropdown-item" onclick="setCurrency(3)">
                    <img class="crypto_icons" src="{$urls.img_ps_url}/crypto_icons/ETH_icon.png"> ETH
                </a>
            </li>
            <li {if $cookie->id_currency == 4}class="selected"{/if}>
                <a title="Bitcoin Cash" rel="nofollow" href="#" class="dropdown-item" onclick="setCurrency(4)">
                    <img class="crypto_icons" src="{$urls.img_ps_url}/crypto_icons/BCH_icon.png"> BCH
                </a>
            </li>
            <li {if $cookie->id_currency == 5}class="selected"{/if}>
                <a title="Litecoin" rel="nofollow" href="#" class="dropdown-item" onclick="setCurrency(5)">
                    <img class="crypto_icons" src="{$urls.img_ps_url}/crypto_icons/LTC_icon.png"> LTC
                </a>
            </li>
            <li {if $cookie->id_currency == 6}class="selected"{/if}>
                <a title="Ripple" rel="nofollow" href="#" class="dropdown-item" onclick="setCurrency(6)">
                    <img class="crypto_icons" src="{$urls.img_ps_url}/crypto_icons/XRP_icon.png"> XRP
                </a>
            </li>
        </ul>
    </form>
    <select class="link hidden-md-up" aria-labelledby="currency-selector-label">
      {foreach from=$currencies item=currency}
        <option value="{$currency.url}"{if $currency.current} selected="selected"{/if}>{$currency.iso_code} {$currency.sign}</option>
      {/foreach}
    </select>
  </div>
</div>


I did everything exactly the same on localhost but this error did not happen on localhost.

Edited by Limerin555 (see edit history)
Link to comment
Share on other sites

  • 1 year later...

EDIT: Problem was solved by enabling second language :D

 

(1/1) ContextErrorException

Notice: Undefined index: reduction_without_tax

in Cart.php line 792

at CartCore->getProducts(true)in CartPresenter.php line 319

at CartPresenter->present(object(Cart))in FrontController.php line 490

at FrontControllerCore->assignGeneralPurposeVariables()in FrontController.php line 548

at FrontControllerCore->initContent()in IndexController.php line 37

at IndexControllerCore->initContent()in Controller.php line 292

at ControllerCore->run()in Dispatcher.php line 515

at DispatcherCore->dispatch()in index.php line 28

 

Prestasho 1.7.6.4 

Php 7.2.29

Does anyone have a clue or lead how to solve it? When i hit add to cart button nothing happens if i reafresh page i get this error. 

 I have custom theme and modul that allow clients to use decimal values and overwrites prices and quantities. With developer of modul we are trying to solve from 2 weeks but with no success. 

Edited by prus (see edit history)
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...