function smarty_function_currency($params, $smarty)
{
    if (isset($params['get'])) {
        switch ($params['get']) {
            case 'ind':
                if (!empty($params['id']) and (int) $params['id']) {
                    return model_corecatalog_currcalc::getCurrencyByID($params['id']);
                } else {
                    return model_corecatalog_currcalc::currInd();
                }
                break;
            case 'shortname':
                return model_corecatalog_currcalc::currShortName();
                break;
            case 'name':
                return model_corecatalog_currcalc::currName();
                break;
            default:
                throw new rad_exception("currency: wrong argument for 'get' parameter", E_USER_WARNING);
                break;
        }
    }
    if (!isset($params['cost'])) {
        throw new rad_exception("currency: missing 'cost' parameter", E_USER_WARNING);
    }
    if (!isset($params['curid'])) {
        throw new rad_exception("currency: missing 'curid' parameter", E_USER_WARNING);
    }
    $cost = empty($params['noconvert']) ? model_corecatalog_currcalc::calcCours($params['cost'], (int) $params['curid']) : $params['cost'];
    return empty($params['noformat']) ? model_corecatalog_currcalc::formatCost($cost, empty($params['noconvert']) ? null : (int) $params['curid']) : $cost;
}
Example #2
0
 function __construct()
 {
     if ($this->getParamsObject()) {
         $params = $this->getParamsObject();
         $this->_itemsperpage = $params->_get('itemsperpage', $this->_itemsperpage);
         $this->setVar('params', $params);
         if ($params->_get('type_show', false)) {
             //last products and other onmain
             $model = rad_instances::get('model_corecatalog_catalog')->setState('active', 1)->setState('lang', $this->getCurrentLangID())->setState('join.mainimage', true)->setState('only.withimages', true)->setState('lang', $this->getCurrentLangID());
             switch ($params->_get('type_show')) {
                 case 'last':
                     $model->setState('order by', 'cat_datecreated DESC');
                     break;
                 case 'showed':
                     $model->setState('order by', 'cat_showed DESC');
                     break;
             }
             $this->setVar('items', $model->getItems($this->_itemsperpage));
         } else {
             //special offers for menu
             $model = rad_instances::get('model_corecatalog_catalog')->setState('special_offer', $params->cs_type)->setState('limit', $params->itemsperpage)->setState('where_condition', ' 1 ')->setState('lang', $this->getCurrentLangID());
             if ($params->ordering !== 0) {
                 $model->setState('order by', $params->ordering);
             }
             $items = $model->getProductsList();
             model_corecatalog_currcalc::init();
             $curCurrency = model_corecatalog_currcalc::$_curcours;
             foreach ($items as &$item) {
                 if ($item->cat_currency_id != $curCurrency->cur_id) {
                     $item->cat_cost = model_corecatalog_currcalc::calcCours($item->cat_cost, $item->cat_currency_id);
                     $item->currency_indicate = $curCurrency->cur_ind;
                 }
             }
             $this->setVar('products', $items);
         }
     }
 }
Example #3
0
 /**
  * ReCalc referal order sum
  * @param integer $order
  * @return boolean
  */
 function recalcOrderSum($order)
 {
     $orderPositions = array();
     rad_instances::get('model_corecatalog_order')->assignPositions($orderPositions, $order);
     $orderSum = 0;
     if (!empty($orderPositions)) {
         foreach ($orderPositions as $id) {
             $orderSum += model_corecatalog_currcalc::calcCours($id->orp_cost, $id->orp_curid) * $id->orp_count;
         }
     }
     $this->query('UPDATE ' . RAD . 'referals_orders SET rro_order_sum=:order_sum WHERE rro_order_id=:order_id', array('order_sum' => $orderSum, 'order_id' => (int) $order));
     return true;
 }
Example #4
0
 /**
  * Final order!
  * return HTML to AJAX
  */
 function order()
 {
     $isNewUser = false;
     $item = new struct_corecatalog_orders();
     $item->order_userid = ($user = $this->getCurrentUser()) ? $user->u_id : 0;
     if ($this->_showCaptcha or $this->_OrderScheme[self::ORDER_REG]) {
         $captcha = new model_coresession_captcha(SITE_ALIAS);
         if (!$captcha->check($this->request('captcha_text'))) {
             $this->setVar('message', $this->lang('wrongcaptcha.session.error'));
             $this->startPage();
             $this->setVar('wrong_capcha', true);
             return;
         }
     }
     $item->order_address = $this->request('address', '');
     $item->order_comments = $this->request('order_comment');
     $item->order_email = $this->getCurrentUser()->u_email ?: $this->request('email');
     $item->order_fio = $this->request('fio');
     $item->order_phone = $this->request('contact_phone');
     $item->order_langid = $this->getCurrentLangID();
     if ($this->request('delivery')) {
         $item->order_delivery = (int) $this->request('delivery');
     }
     if ($item->order_userid === 0) {
         //type of the order - 3 is the quick order
         $item->order_type = 3;
         $isNewUser = true;
     } else {
         if ($this->_OrderScheme[self::ORDER_FAST_REG]) {
             //type of the order - 2 is the quick & registration
             $item->order_type = 2;
         } else {
             //type of the order - 1 is the registration
             $item->order_type = 1;
         }
     }
     $item->order_dt = now();
     $item->order_num = date("ymdHis");
     $item->order_num .= $this->getCurrentUser() ? 'u' . $this->getCurrentUser()->u_id : 's';
     $item->order_sessid = $this->getCurrentSessID();
     //Link to the tree_id
     $item->order_status = $this->_defStatus;
     //calc the order summ
     $model_bin = rad_instances::get('model_corecatalog_bin');
     $ct_showing = $this->getParamsObject() ? $this->getParamsObject()->ct_showing : NULL;
     $items = $model_bin->getCartProducts(NULL, NULL, $ct_showing);
     $bin_pos = $model_bin->getItemsCart();
     $counts = array();
     $bin_ids = array();
     $total_count = 0;
     $total_costs = 0;
     if (count($bin_pos)) {
         foreach ($bin_pos as $id) {
             $counts[$id->bp_catid] = $id->bp_count;
             $bin_ids[$id->bp_catid] = $id->bp_id;
         }
     }
     for ($i = 0; $i < count($items); $i++) {
         $items[$i]->cat_cost = model_corecatalog_currcalc::calcCours($items[$i]->cat_cost, $items[$i]->cat_currency_id);
         $items[$i]->cat_count = $counts[$items[$i]->cat_id];
         $total_count += $items[$i]->cat_count;
         $total_costs += $items[$i]->cat_cost * $items[$i]->cat_count;
         $items[$i]->bp_id = $bin_ids[$items[$i]->cat_id];
     }
     if ($this->_showDelivery and $this->request('delivery')) {
         $delivery = new struct_corecatalog_delivery(array('rdl_id' => (int) $this->request('delivery')));
         $delivery->load();
         $totalCostsWithoutDelivery = $total_costs;
         $total_costs += model_corecatalog_currcalc::calcCours($delivery->rdl_cost, $delivery->rdl_currency);
         $item->delivery = $delivery;
     }
     $item->order_summ = $total_costs;
     $item->order_currency = model_corecatalog_currcalc::$_curcours->cur_ind;
     $item->order_curid = model_corecatalog_currcalc::$_curcours->cur_id;
     if ($isNewUser && $this->_addtoclients) {
         //try, maybe user already exists
         $modelUsers = rad_instances::get('model_core_users');
         $exUser = $modelUsers->setState('u_email', $item->order_email)->getItem();
         if (!empty($exUser->u_id)) {
             $item->order_userid = (int) $exUser->u_id;
             $isNewUser = false;
         } else {
             $user = new struct_core_users(array('u_group' => $this->_clientsPID, 'u_login' => $item->order_email, 'u_email' => $item->order_email, 'u_fio' => $item->order_fio, 'u_phone' => $item->order_phone, 'u_address' => $item->order_address, 'u_isadmin' => 0));
             $modelUsers->register($user, $this->config('registration.class') != 'registerphpbb');
             $item->order_userid = $user->u_id;
         }
     }
     $model = rad_instances::get('model_corecatalog_order');
     if ($rows = $model->insertItem($item)) {
         $item->order_id = $rows;
         $item->order_num .= $item->order_id;
         $item->save();
         rad_instances::get('model_corecatalog_bin')->clearItemsCart();
         /*assign to the referals*/
         if ($this->config('referals.on') and class_exists('struct_coresession_referals_orders')) {
             //TODO Учесть что пользователь до этого уже приведен был другим партнером и взять с user_id
             if ($this->cookie($this->config('referals.cookieName')) or !empty($item->order_userid)) {
                 if ($item->order_userid !== 0) {
                     $refUser = rad_instances::get('model_coresession_referals')->getUserPartner($item->order_userid);
                 }
                 if (!empty($refUser->u_id)) {
                     $referalId = $refUser->rru_referal_id;
                 } elseif ($referal = rad_instances::get('model_coresession_referals')->setState('cookie', $this->cookie($this->config('referals.cookieName')))->getItem()) {
                     $referalId = $referal->rrf_id;
                 }
                 if (!empty($referalId)) {
                     $percent = rad_instances::get('model_coresession_referals')->getParntnerPercent($referalId);
                     $orderSum = isset($totalCostsWithoutDelivery) ? $totalCostsWithoutDelivery : $item->order_summ;
                     $refOfder = new struct_coresession_referals_orders(array('rro_referals_id' => $referalId, 'rro_order_id' => $item->order_id, 'rro_percent' => $percent, 'rro_currency_id' => $item->order_curid, 'rro_order_sum' => $orderSum));
                     rad_instances::get('model_coresession_referals')->insertOrder($refOfder);
                 }
             }
         }
     }
     $item->order_positions = $bin_pos;
     if ($isNewUser) {
         $this->_sendMail($item, 'order_new');
     } else {
         $this->_sendMail($item, 'order_new_auth');
     }
     $this->redirect($this->makeURL('action=success'));
 }
Example #5
0
 /**
  * Shows the edit order form of just a view
  *
  */
 function showEdit()
 {
     $order_id = (int) $this->request('oid');
     if ($order_id) {
         $this->setVar('order_id', $order_id);
         $model = rad_instances::get('model_corecatalog_order');
         $order = $model->getItem($order_id, true);
         if ($order->order_delivery) {
             $order->delivery = new struct_corecatalog_delivery(array('rdl_id' => $order->order_delivery));
             $order->delivery->load();
         }
         $this->setVar('order', $order);
         $this->addBC('cur_order_num', $order->order_num);
         $total_count = 0;
         $total_cost = 0;
         if (count($order->order_positions)) {
             foreach ($order->order_positions as $id) {
                 $total_count += $id->orp_count;
                 $total_cost += $id->orp_count * model_corecatalog_currcalc::calcCours($id->orp_cost, $id->orp_curid);
             }
             //foreach
         }
         //if count
         $this->setVar('total_cost', $total_cost);
         $this->setVar('total_count', $total_count);
         $this->setVar('currency', model_corecatalog_currcalc::$_curcours);
         $this->assignTypes();
     } else {
         $this->securityHoleAlert(__FILE__, __LINE__, $this->getClassName());
     }
 }
Example #6
0
 function changePositionCount($order_id, $cat_id, $count)
 {
     $order = $this->getItem($order_id, true);
     if (!empty($order->order_positions)) {
         $pos_id = 0;
         foreach ($order->order_positions as $orpos) {
             $orpos->orp_catid = (int) $orpos->orp_catid;
             if ($orpos->orp_catid === $cat_id) {
                 $pos_id = (int) $orpos->orp_id;
                 break;
             }
         }
         if ($pos_id > 0) {
             $position = new struct_corecatalog_order_positions(array('orp_id' => $pos_id));
             $position->load();
             if ((double) $position->orp_count != $count) {
                 $model_catalog = rad_instances::get('model_corecatalog_catalog');
                 $model_catalog->setState('with_vv', true);
                 $product = $model_catalog->getItem($cat_id);
                 $pos_summ = (double) $position->orp_count * (double) $position->orp_cost;
                 $new_pos_summ = $count * (double) $product->cat_cost;
                 $new_pos_summ = model_corecatalog_currcalc::calcCours($new_pos_summ, $order->order_curid);
                 $order->order_summ = $order->order_summ - ($pos_summ - $new_pos_summ);
                 $position->orp_count = '' . $count;
                 $this->updateItem($order);
                 return $position->save();
             }
         }
     }
     return 0;
 }
Example #7
0
 /**
  * Shows a bin window at goods addition
  *
  */
 function showBinWindow()
 {
     model_corecatalog_currcalc::init();
     $this->setVar('curr', model_corecatalog_currcalc::$_curcours);
     $model = rad_instances::get('model_corecatalog_bin');
     $ct_showing = $this->getParamsObject() ? $this->getParamsObject()->ct_showing : NULL;
     $items = $model->getCartProducts(NULL, NULL, $ct_showing);
     $bin_pos = $model->getItemsCart();
     $counts = array();
     $bin_ids = array();
     $total_count = 0;
     $total_costs = 0;
     if (count($bin_pos)) {
         foreach ($bin_pos as $id) {
             $counts[$id->bp_catid] = $id->bp_count;
             $bin_ids[$id->bp_catid] = $id->bp_id;
         }
     }
     for ($i = 0; $i < count($items); $i++) {
         $items[$i]->cost = $items[$i]->cat_cost;
         $items[$i]->cat_cost = model_corecatalog_currcalc::calcCours($items[$i]->cat_cost, $items[$i]->cat_currency_id);
         $items[$i]->cat_count = $counts[$items[$i]->cat_id];
         $total_count += $items[$i]->cat_count;
         $total_costs += $items[$i]->cat_cost * $items[$i]->cat_count;
         $items[$i]->bp_id = $bin_ids[$items[$i]->cat_id];
     }
     $this->setVar('items', $items);
     $this->setVar('total_count', $total_count);
     $this->setVar('total_costs', $total_costs);
 }