Ejemplo n.º 1
0
 /**
  * Set cookie currency from POST or default currency
  *
  * @param $cookie
  * @return JeproshopCurrencyModelCurrency object
  */
 public static function setCurrency($cookie)
 {
     $app = JFactory::getApplication();
     if ($app->input->get('SubmitCurrency')) {
         if (isset($_POST['currency_id']) && is_numeric($_POST['currency_id'])) {
             $currency = JeproshopCurrencyModelCurrency::getCurrencyInstance($_POST['currency_id']);
             if (is_object($currency, 'currency_id') && $currency->currency_id && !$currency->deleted && $currency->isAssociatedToShop()) {
                 $cookie->currency_id = (int) $currency->currency_id;
             }
         }
     }
     $currency = null;
     if ((int) $cookie->currency_id) {
         $currency = JeproshopCurrencyModelCurrency::getCurrencyInstance((int) $cookie->currency_id);
     }
     if (!JeproshopTools::isLoadedObject($currency, 'currency_id') || (bool) $currency->deleted || !(bool) $currency->published) {
         $currency = JeproshopCurrencyModelCurrency::getCurrencyInstance(JeproshopSettingModelSetting::getValue('default_currency'));
     }
     $cookie->currency_id = (int) $currency->currency_id;
     if ($currency->isAssociatedToShop()) {
         return $currency;
     } else {
         // get currency from context
         $currency = JeproshopShopModelShop::getEntityIds('currency', JeproshopContext::getContext()->shop->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;
 }