function step2(){
$checkout = &JModel::getInstance('checkout', 'jshop');
$checkout->checkStep(2);
JPluginHelper::importPlugin('jshoppingcheckout');
$dispatcher =& JDispatcher::getInstance();
$dispatcher->trigger('onLoadCheckoutStep2', array() );
$session =& JFactory::getSession();
$user = &JFactory::getUser();
$jshopConfig = &JSFactory::getConfig();
$country = &JTable::getInstance('country', 'jshop');
$checkLogin = JRequest::getInt('check_login');
if ($checkLogin){
$session->set("show_pay_without_reg", 1);
checkUserLogin();
}
appendPathWay(_JSHOP_CHECKOUT_ADDRESS);
$seo = &JTable::getInstance("seo", "jshop");
$seodata = $seo->loadData("checkout-address");
if ($seodata->title==""){
$seodata->title = _JSHOP_CHECKOUT_ADDRESS;
}
setMetaData($seodata->title, $seodata->keyword, $seodata->description);
$this->_showCheckoutNavigation(2);
if ($jshopConfig->show_cart_all_step_checkout){
$this->_showSmallCart(2);
}
$cart = &JModel::getInstance('cart', 'jshop');
$cart->load();
$cart->getSum();
if ($user->id){
$adv_user = &JSFactory::getUserShop();
}else{
$adv_user = &JSFactory::getUserShopGuest();
}
$tmp_fields = $jshopConfig->getListFieldsRegister();
$config_fields = $tmp_fields['address'];
$count_filed_delivery = 0;
foreach($config_fields as $k=>$v){
if (substr($k, 0, 2)=="d_" && $v['display']==1) $count_filed_delivery++;
}
$view_name = "checkout";
$view_config = array("template_path"=>JPATH_COMPONENT."/templates/".$jshopConfig->template."/".$view_name);
$view = &$this->getView($view_name, getDocumentType(), '', $view_config);
$view->setLayout("adress");
$view->assign('select', $jshopConfig->arr['title']);
//Payments
$paymentmethod = &JTable::getInstance('paymentmethod', 'jshop');
$all_payment_methods = jshopPaymentMethod::getAllPaymentMethods();
$i = 0;
$paym = array();
foreach ($all_payment_methods as $pm) {
if (file_exists($jshopConfig->path . 'payments/'.$pm->payment_class."/".$pm->payment_class.'.php')){
require_once ($jshopConfig->path . 'payments/'.$pm->payment_class."/".$pm->payment_class.'.php');
$paym[$i]->existentcheckform = 1;
}else{
$paym[$i]->existentcheckform = 0;
}
$paym[$i]->name = $pm->name;
$paym[$i]->payment_id = $pm->payment_id;
$paym[$i]->payment_class = $pm->payment_class;
$paym[$i]->payment_description = $pm->description;
$paym[$i]->price_type = $pm->price_type;
$paym[$i]->image = $pm->image;
if ($pm->price_type==2){
$paym[$i]->calculeprice = $pm->price;
}else{
$paym[$i]->calculeprice = getPriceCalcParamsTax($pm->price * $jshopConfig->currency_value, $pm->tax_id);
}
$s_payment_method_id = $cart->getPaymentId();
if ($s_payment_method_id == $pm->payment_id){
$params = $cart->getPaymentParams();
}else{
$params = array();
}
$parseString = new parseString($pm->payment_params);
$pmconfig = $parseString->parseStringToParams();
if ($paym[$i]->existentcheckform){
ob_start();
call_user_func(array($pm->payment_class, 'showPaymentForm'), $params, $pmconfig);
$paym[$i]->form = ob_get_contents();
ob_get_clean();
}else{
$paym[$i]->form = "";
}
$i++;
}
$s_payment_method_id = $cart->getPaymentId();
$active_payment = intval($s_payment_method_id);
if (!$active_payment){
$list_payment_id = array();
foreach($paym as $v){
$list_payment_id[] = $v->payment_id;
}
if (in_array($adv_user->payment_id, $list_payment_id)) $active_payment = $adv_user->payment_id;
}
if (!$active_payment){
if (isset($paym[0])){
$active_payment = $paym[0]->payment_id;
}
}
$view->assign('payment_methods', $paym);
$view->assign('active_payment', $active_payment);
//end payments
if (!$adv_user->country) $adv_user->country = $jshopConfig->default_country;
if (!$adv_user->d_country) $adv_user->d_country = $jshopConfig->default_country;
$option_country[] = JHTML::_('select.option', '0', _JSHOP_REG_SELECT, 'country_id', 'name' );
$option_countryes = array_merge($option_country, jshopCountry::getAllCountries());
$select_countries = JHTML::_('select.genericlist', $option_countryes, 'country', 'class = "inputbox" size = "1"','country_id', 'name', $adv_user->country );
$select_d_countries = JHTML::_('select.genericlist', $option_countryes, 'd_country', 'class = "inputbox" size = "1"','country_id', 'name', $adv_user->d_country);
foreach ($jshopConfig->arr['title'] as $key => $value) {
$option_title[] = JHTML::_('select.option', $key, $value, 'title_id', 'title_name');
}
$select_titles = JHTML::_('select.genericlist', $option_title, 'title', 'class = "inputbox"','title_id', 'title_name', $adv_user->title);
$select_d_titles = JHTML::_('select.genericlist', $option_title, 'd_title', 'class = "inputbox"','title_id', 'title_name', $adv_user->d_title);
$client_types = array();
foreach ($jshopConfig->user_field_client_type as $key => $value) {
$client_types[] = JHTML::_('select.option', $key, $value, 'id', 'name' );
}
$select_client_types = JHTML::_('select.genericlist', $client_types,'client_type','class = "inputbox" onchange="showHideFieldFirm(this.value)"','id','name', $adv_user->client_type);
filterHTMLSafe( $adv_user, ENT_QUOTES);
$view->assign('select_countries', $select_countries);
$view->assign('select_d_countries', $select_d_countries);
$view->assign('select_titles', $select_titles);
$view->assign('select_d_titles', $select_d_titles);
$view->assign('select_client_types', $select_client_types);
$view->assign('live_path', JURI::base());
$view->assign('config_fields', $config_fields);
$view->assign('count_filed_delivery', $count_filed_delivery);
$view->assign('user', $adv_user);
$view->assign('delivery_adress', $adv_user->delivery_adress);
$view->assign('action', SEFLink('index.php?option=com_jshopping&controller=checkout&task=step2save', 0, 0, $jshopConfig->use_ssl));
$dispatcher->trigger('onBeforeDisplayCheckoutStep2View', array(&$view));
$view->display();
}
function step2save(){
$checkout = &JModel::getInstance('checkout', 'jshop');
$checkout->checkStep(2);
JPluginHelper::importPlugin('jshoppingcheckout');
$dispatcher =& JDispatcher::getInstance();
$dispatcher->trigger('onLoadCheckoutStep2save', array());
$cart = &JModel::getInstance('cart', 'jshop');
$cart->load();
$session =& JFactory::getSession();
$jshopConfig = &JSFactory::getConfig();
$post = JRequest::get('post');
if (!count($post)){
JError::raiseWarning("",_JSHOP_ERROR_DATA);
$this->setRedirect(SEFLink('index.php?option=com_jshopping&controller=checkout&task=step2',0,1, $jshopConfig->use_ssl));
return 0;
}
unset($post['user_id']);
unset($post['usergroup_id']);
$user = &JFactory::getUser();
if ($user->id){
$adv_user = &JTable::getInstance('userShop', 'jshop');
$adv_user->load($user->id);
}else{
$adv_user = &JSFactory::getUserShopGuest();
}
$adv_user->bind($post);
if(!$adv_user->check("address")){
JError::raiseWarning("",$adv_user->getError());
$this->setRedirect(SEFLink('index.php?option=com_jshopping&controller=checkout&task=step2',0,1, $jshopConfig->use_ssl));
return 0;
}
$dispatcher->trigger( 'onBeforeSaveCheckoutStep2', array(&$adv_user, &$user, &$cart) );
if(!$adv_user->store()){
JError::raiseWarning(500,_JSHOP_REGWARN_ERROR_DATABASE);
$this->setRedirect(SEFLink('index.php?option=com_jshopping&controller=checkout&task=step2',0,1, $jshopConfig->use_ssl));
return 0;
}
if ($user->id){
$user = clone(JFactory::getUser());
$user->email = $adv_user->email;
$user->name = $adv_user->f_name;
$user->save();
}
setNextUpdatePrices();
$dispatcher->trigger( 'onAfterSaveCheckoutStep2', array(&$adv_user, &$user, &$cart) );
//Payments
$payment_method = JRequest::getVar('payment_method'); //class payment method
$params = JRequest::getVar('params');
$params_pm = $params[$payment_method];
$paym_method = &JTable::getInstance('paymentmethod', 'jshop');
$paym_method->class = $payment_method;
$payment_method_id = $paym_method->getId();
$paym_method->load($payment_method_id);
$pmconfigs = $paym_method->getConfigs();
if (!file_exists($jshopConfig->path . 'payments/'.$payment_method."/".$payment_method.'.php')) {
$existentcheckform = 0;
}else{
$existentcheckform = 1;
include_once($jshopConfig->path . 'payments/'.$payment_method."/".$payment_method.'.php');
if (!class_exists($payment_method)) {
$cart->setPaymentParams('');
JError::raiseWarning(500, _JSHOP_ERROR_PAYMENT);
$this->setRedirect(SEFLink('index.php?option=com_jshopping&controller=checkout&task=step3',0,1,$jshopConfig->use_ssl));
return 0;
}
$payment_system = new $payment_method();
if (!$payment_system->checkPaymentInfo($params_pm, $pmconfigs)){
$cart->setPaymentParams('');
JError::raiseWarning("", $payment_system->getErrorMessage());
$this->setRedirect(SEFLink('index.php?option=com_jshopping&controller=checkout&task=step3',0,1,$jshopConfig->use_ssl));
return 0;
}
}
$paym_method->setCart($cart);
$cart->setPaymentId($payment_method_id);
$cart->setPaymentPrice($paym_method->getPrice());
$cart->setPaymentTax($paym_method->calculateTax());
$cart->setPaymentTaxPercent($paym_method->getTax());
if (isset($params[$payment_method])) {
$cart->setPaymentParams($params_pm);
} else {
$cart->setPaymentParams('');
}
$adv_user->saveTypePayment($payment_method_id);
$dispatcher->trigger( 'onAfterSaveCheckoutStep3save', array(&$adv_user, &$paym_method, &$cart) );
//End payments
if ($jshopConfig->without_shipping && $jshopConfig->without_payment) {
$checkout->setMaxStep(5);
$cart->setShippingId(0);
$cart->setShippingPrId(0);
$cart->setShippingPrice(0);
$cart->setPaymentId(0);
$cart->setPaymentParams("");
$cart->setPaymentPrice(0);
$this->setRedirect(SEFLink('index.php?option=com_jshopping&controller=checkout&task=step5',0,1, $jshopConfig->use_ssl));
return 0;
}
if ($jshopConfig->without_payment){
$checkout->setMaxStep(4);
$cart->setPaymentId(0);
$cart->setPaymentParams("");
$cart->setPaymentPrice(0);
$this->setRedirect(SEFLink('index.php?option=com_jshopping&controller=checkout&task=step4',0,1,$jshopConfig->use_ssl));
return 0;
}
$checkout->setMaxStep(4);
$this->setRedirect(SEFLink('index.php?option=com_jshopping&controller=checkout&task=step4',0,1,$jshopConfig->use_ssl));
}