Jump to content

Edit History

caovillanueva

caovillanueva

Its works for me:

Override Tools.php

\override\classes\Tools.php

With this i can use CAD only in frontend and USD for backend.

Used in Prestashop 1.7.7.4

Not conflict detected. Just need replace 2 lines. In my case i used 1 as id currency for CAD

 

<?php

class Tools extends ToolsCore
{

    /**
     * Set cookie currency from POST or default currency.
     *
     * @return Currency object
     */
    public static function setCurrency($cookie)
    {
        if (Tools::isSubmit('SubmitCurrency') && ($id_currency = Tools::getValue('id_currency'))) {
            /** @var Currency $currency */
            $currency = Currency::getCurrencyInstance((int) $id_currency);
            if (is_object($currency) && $currency->id && !$currency->deleted && $currency->isAssociatedToShop()) {
                $cookie->id_currency = (int) $currency->id;
            }
        }

        $currency = null;
        if ((int) $cookie->id_currency) {
            //$currency = Currency::getCurrencyInstance((int) $cookie->id_currency);//befoore
            $currency = Currency::getCurrencyInstance(1);//Force CAD for frontend.
        }
        if (!Validate::isLoadedObject($currency) || (bool) $currency->deleted || !(bool) $currency->active) {
            //$currency = Currency::getCurrencyInstance(Configuration::get('PS_CURRENCY_DEFAULT'));//before
            $currency = Currency::getCurrencyInstance(1);//Force CAD for frontend.
        }

        $cookie->id_currency = (int) $currency->id;
        if ($currency->isAssociatedToShop()) {
            return $currency;
        } else {
            // get currency from context
            $currency = Shop::getEntityIds('currency', Context::getContext()->shop->id, true, true);
            if (isset($currency[0]) && $currency[0]['id_currency']) {
                $cookie->id_currency = $currency[0]['id_currency'];

                return Currency::getCurrencyInstance((int) $cookie->id_currency);
            }
        }

        return $currency;
    }
}

 

caovillanueva

caovillanueva

Its works for me:

Override Tools.php

\override\classes\Tools.php

With this i can use CAD only in frontend and USD for backend.

Used in Prestashop 1.7.7.4

Not conflict detected. Just need replace 2 lines.

 

<?php

class Tools extends ToolsCore
{

    /**
     * Set cookie currency from POST or default currency.
     *
     * @return Currency object
     */
    public static function setCurrency($cookie)
    {
        if (Tools::isSubmit('SubmitCurrency') && ($id_currency = Tools::getValue('id_currency'))) {
            /** @var Currency $currency */
            $currency = Currency::getCurrencyInstance((int) $id_currency);
            if (is_object($currency) && $currency->id && !$currency->deleted && $currency->isAssociatedToShop()) {
                $cookie->id_currency = (int) $currency->id;
            }
        }

        $currency = null;
        if ((int) $cookie->id_currency) {
            //$currency = Currency::getCurrencyInstance((int) $cookie->id_currency);//befoore
            $currency = Currency::getCurrencyInstance(1);//Force CAD for frontend.
        }
        if (!Validate::isLoadedObject($currency) || (bool) $currency->deleted || !(bool) $currency->active) {
            //$currency = Currency::getCurrencyInstance(Configuration::get('PS_CURRENCY_DEFAULT'));//before
            $currency = Currency::getCurrencyInstance(1);//Force CAD for frontend.
        }

        $cookie->id_currency = (int) $currency->id;
        if ($currency->isAssociatedToShop()) {
            return $currency;
        } else {
            // get currency from context
            $currency = Shop::getEntityIds('currency', Context::getContext()->shop->id, true, true);
            if (isset($currency[0]) && $currency[0]['id_currency']) {
                $cookie->id_currency = $currency[0]['id_currency'];

                return Currency::getCurrencyInstance((int) $cookie->id_currency);
            }
        }

        return $currency;
    }
}

 

×
×
  • Create New...