Exemplo n.º 1
0
 public static function renderNamed(&$BTaddressNamed, $adr1, &$cart, $OPCloader, $virtuemart_userinfo_id, $returnHtml = false)
 {
     $uid = JFactory::getUser()->get('id');
     // will load all the shipping addresses
     $ada = array();
     foreach ($adr1 as $k => $v) {
         $ada[$k] = $v;
         $ada['shipto_' . $k] = $v;
     }
     $cart->ST = $ada;
     //do_dump($ref->cart->ST); echo '<br /><br />';
     $adr1->edit_link = '#" onclick="return Onepage.op_showEditST(' . $adr1->virtuemart_userinfo_id . ')';
     $i = 2;
     $adr1 = $OPCloader->setCountryAndState($adr1);
     $arr = array('ST' => $adr1, 'bt_user_info_id' => $virtuemart_userinfo_id, 'BTaddress' => $BTaddressNamed, 'uid' => $uid, 'cart' => $cart, 'i' => $i);
     $html2_1 = $OPCloader->fetch($OPCloader, 'get_shipping_address_v2.tpl', $arr);
     if (empty($html2_1)) {
         // theme file not found, please create or copy /overrides/get_shipping_address_v2.tpl.php
         /// ************** start of customer info / shipping address
         foreach ($BTaddressNamed as $key => $val) {
             if (!empty($adr1->{$key})) {
                 $BTaddressNamed[$key]['value'] = $adr1->{$key};
             } else {
                 unset($BTaddressNamed[$key]);
             }
         }
         $vars = array('BTaddress' => $BTaddressNamed, 'edit_link' => $adr1->edit_link);
         $html2_1 = $OPCloader->fetch($OPCloader, 'customer_info.tpl', $vars);
         $edit_label = OPCLang::_('JACTION_EDIT');
         if ($edit_label == 'JACTION_EDIT') {
             $edit_label = OPCLang::_('EDIT');
         }
         $html2_1 = str_replace(OPCLang::_('COM_VIRTUEMART_USER_FORM_EDIT_BILLTO_LBL'), $edit_label, $html2_1);
         /// ************** end of customer info
     }
     if (!empty($cart->ST['virtuemart_country_id'])) {
         $dc = $cart->ST['virtuemart_country_id'];
     } else {
         $dc = OPCloader::getDefaultCountry($cart, true);
     }
     $hasmissing = $OPCloader->hasMissingFieldsST($cart->ST);
     $html2_id = '<div ';
     if (empty($hasmissing)) {
         $html2_id .= ' style="display: none;" ';
     }
     $html2_id .= ' id="opc_stedit_' . $adr1->virtuemart_userinfo_id . '">';
     $html2_id .= ' <input type="hidden" name="st_complete_list" value="' . $adr1->virtuemart_userinfo_id . '" />';
     $gf = $OPCloader->getSTfields($OPCloader, true, true, $dc);
     //do_dump($gf); echo '<br /><br />';
     $html2_id .= $gf;
     $html2_id .= '</div>';
     $html2_id = str_replace('id="', 'id="REPLACE' . $adr1->virtuemart_userinfo_id . 'REPLACE', $html2_id);
     $html2_id = str_replace('name="', 'name="REPLACE' . $adr1->virtuemart_userinfo_id . 'REPLACE', $html2_id);
     $html2 = '<input type="hidden" id="opc_st_changed_' . $adr1->virtuemart_userinfo_id . '" name="opc_st_changed_' . $adr1->virtuemart_userinfo_id . '" value="';
     if (!empty($hasmissing)) {
         $html2 .= '1';
     } else {
         $html2 .= '0';
     }
     $html2 .= '" />';
     $html2 .= '<div ';
     if (!empty($hasmissing)) {
         $html2 .= ' style="display: none;" ';
     }
     $html2 .= ' id="opc_st_' . $adr1->virtuemart_userinfo_id . '">' . $html2_1 . '</div>' . $html2_id;
     if ($i == 1) {
         $i++;
     } elseif ($i == 2) {
         $i--;
     }
     if (!empty($STaddressList)) {
         $html2 .= '<input type="hidden" name="shipto_logged" value="' . $adr1->virtuemart_userinfo_id . '" />';
     } else {
         $html2 .= '<input type="hidden" name="shipto_logged" value="new" />';
     }
     $html2 = '<div id="hidden_st_' . $adr1->virtuemart_userinfo_id . '" style="display: none;">' . $html2 . '</div>';
     if ($returnHtml) {
         return $html2;
     }
     if (!isset(OPCloader::$extrahtml)) {
         OPCloader::$extrahtml = '';
     }
     OPCloader::$extrahtml .= $html2;
     return $html2;
 }
Exemplo n.º 2
0
 function getBTfields(&$obj, $unlg = false, $no_wrapper = false)
 {
     include JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'config' . DS . 'onepage.cfg.php';
     $default_shipping_country = OPCloader::getDefaultCountry($cart);
     // $default_shipping_country
     $islogged = OPCloader::logged($obj->cart);
     if ($islogged && empty($unlg)) {
         return $this->getUserInfoBT($obj);
     } else {
         if (!class_exists('VirtueMartCart')) {
             require JPATH_VM_SITE . DS . 'helpers' . DS . 'cart.php';
         }
         if (!empty($obj->cart)) {
             $cart =& $obj->cart;
         } else {
             $cart = VirtueMartCart::getCart();
         }
         $type = 'BT';
         $this->address_type = 'BT';
         // for unlogged
         $virtuemart_userinfo_id = 0;
         $this->virtuemart_userinfo_id = 0;
         $new = 1;
         if (!empty($unlg)) {
             $new = false;
         }
         $fieldtype = $type . 'address';
         if (empty($cart->BT)) {
             $cart->BT = array();
         }
         $user = JFactory::getUser();
         $uid = $user->get('id');
         // PPL Express address:
         $moveBT = false;
         $count = 0;
         if (!empty($cart->savedST)) {
             if (!$islogged) {
                 foreach ($cart->savedST as $key => $val) {
                     if ($key == 'virtuemart_country_id') {
                         continue;
                     }
                     if ($key == 'virtuemart_state_id') {
                         continue;
                     }
                     if (substr($key, 0, 7) === 'shipto_') {
                         continue;
                     }
                     if (empty($cart->BT[$key]) && !empty($val)) {
                         $count++;
                     } else {
                         if (!empty($cart->BT[$key]) && $val != $cart->BT[$key]) {
                             $count--;
                         }
                     }
                 }
                 if ($count > 0) {
                     if ($cart->savedST['virtuemart_country_id'] != $cart->BT['virtuemart_country_id']) {
                         $cart->BT['virtuemart_state_id'] = 0;
                     }
                     foreach ($cart->savedST as $key => $val) {
                         if (!empty($val)) {
                             $cart->BT[$key] = $val;
                         }
                     }
                 }
             }
         }
         if (empty($cart->BT['virtuemart_country_id'])) {
             if (!empty($default_shipping_country) && is_numeric($default_shipping_country)) {
                 $cart->BT['virtuemart_country_id'] = $default_shipping_country;
             } else {
                 // let's set a default country
                 $vendor = $this->getVendorInfo($cart);
                 $cart->BT['virtuemart_country_id'] = $vendor['virtuemart_country_id'];
             }
         }
         /*
         if (!empty($cart->BT) && (count($cart->BT)>2)) $new = false;    
         if (empty($cart->BT)) $new = true; 
         */
         $type = 'BT';
         require_once JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'userfields.php';
         OPCUserFields::populateCart($cart, $type, true);
         OPCloader::setRegType();
         $op_disable_shipto = OPCloader::getShiptoEnabled($cart);
         if (!class_exists('VirtuemartModelUserfields')) {
             require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'userfields.php';
         }
         $corefields = VirtueMartModelUserfields::getCoreFields();
         $userFields = $cart->{$fieldtype};
         if (isset($cart->BTaddress) && isset($cart->BTaddress['fields']) && isset($cart->BTaddress['fields']['virtuemart_country_id']) && !empty($cart->BTaddress['fields']['virtuemart_country_id']['value'])) {
             if (is_numeric($cart->BTaddress['fields']['virtuemart_country_id']['value'])) {
                 $cart->BT['virtuemart_country_id'] = $cart->BTaddress['fields']['virtuemart_country_id']['value'];
             }
         }
         // unset corefields
         $onlyf = array();
         if (empty($bt_fields_from)) {
             $q = 'select name from #__virtuemart_userfields where published=1 and registration = 1';
             $db = JFactory::getDBO();
             $db->setQuery($q);
             $onlyf2 = $db->loadAssocList();
             foreach ($onlyf2 as $k => $v) {
                 $onlyf[] = $v['name'];
             }
         }
         if (!empty($userFields['fields'])) {
             foreach ($userFields['fields'] as $key => $uf) {
                 // disable fields that are not marked for registration
                 if (!empty($onlyf)) {
                     if (!in_array($uf['name'], $onlyf)) {
                         unset($userFields['fields'][$key]);
                         continue;
                     }
                 }
                 $userFields['fields'][$key]['formcode'] = str_replace('vm-chzn-select', '', $userFields['fields'][$key]['formcode']);
                 OPCloader::$fields_names[$key] = $userFields['fields'][$key]['title'];
                 if ($userFields['fields'][$key]['type'] == 'delimiter') {
                     unset($userFields['fields'][$key]);
                     continue;
                 }
                 foreach ($corefields as $f) {
                     if ($f == $uf['name']) {
                         // will move the email to bt section
                         if (empty($no_login_in_template) || $unlg) {
                             if ($f == 'email') {
                                 if (empty($opc_email_in_bt)) {
                                     if (!$this->isNoLogin()) {
                                         unset($userFields['fields'][$key]);
                                     }
                                 }
                             } else {
                                 unset($userFields['fields'][$key]);
                             }
                             continue;
                         }
                     }
                 }
                 if (empty($custom_rendering_fields)) {
                     $custom_rendering_fields = array();
                 }
                 if (!empty($custom_rendering_fields)) {
                     if (in_array($uf['name'], $custom_rendering_fields)) {
                         unset($userFields['fields'][$key]);
                         continue;
                     }
                 }
                 if ($key == 'name') {
                     if (!empty($op_no_display_name)) {
                         if (!empty($userFields['fields']['name'])) {
                             unset($userFields['fields']['name']);
                         }
                     }
                 }
             }
         }
         // end of for each
         require_once JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'userfields.php';
         $skipreorder = array('email');
         OPCUserFields::getUserFields($userFields, $this, $cart, array(), array(), $skipreorder);
         // logic reversed, if email is not in BT, remove it
         if (!((!empty($opc_email_in_bt) || $this->isNoLogin()) && !empty($double_email))) {
             unset($userFields['fields']['email2']);
             // email is in BT, let's check for double mail
         }
         $skipreorder = array();
         if (!empty($opc_email_in_bt) || $this->isNoLogin()) {
             $skipreorder[] = 'email';
             if (!empty($opc_check_email)) {
                 if (!OPCloader::logged($cart) && empty($uid)) {
                     if (!empty($userFields['fields']['email'])) {
                         $un = $userFields['fields']['email']['formcode'];
                         if (stripos($un, 'id="email_already_exists"') === false) {
                             //if (!$double_email)
                             $un = str_replace('id=', ' onblur="javascript: Onepage.email_check(this);" id=', $un);
                             $un .= '<span class="email_already_exist" style="display: none; position: relative; color: red; font-size: 10px; background: none; border: none; padding: 0; margin: 0;" id="email_already_exists">';
                             $un .= OPCLang::sprintf('COM_ONEPAGE_EMAIL_ALREADY_EXISTS', OPCLang::_('COM_VIRTUEMART_USER_FORM_EMAIL'));
                             $un .= '</span>';
                             $userFields['fields']['email']['formcode'] = $un;
                         }
                     }
                 }
             }
         }
         require_once JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'userfields.php';
         OPCUserFields::reorderFields($userFields, $skipreorder);
         require_once JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'mini.php';
         $this->_model = OPCmini::getModel('user');
         //new VirtuemartModelUser();
         $layout = 'default';
         $hidden = array();
         $hidden_html = '';
         if (!empty($userFields['fields'])) {
             foreach ($userFields['fields'] as $key => $val) {
                 if (!empty($val['hidden'])) {
                     $hidden[] = $val;
                     $hidden_html .= $val['formcode'];
                     unset($userFields['fields'][$key]);
                 }
             }
         }
         $vars = array('rowFields' => $userFields, 'cart' => $obj, 'is_logged' => $unlg);
         $html = $this->fetch($this, 'list_user_fields.tpl', $vars);
         $hidden_html = str_replace('"required"', '""', $hidden_html);
         $html .= $hidden_html;
         $html = $this->addListeners($html);
         if (empty($custom_rendering_fields)) {
             $custom_rendering_fields = array();
         }
         if (in_array('virtuemart_country_id', $custom_rendering_fields)) {
             $html .= '<input type="hidden" id="virtuemart_country_id" name="virtuemart_country_id" value="' . $default_shipping_country . '" />';
         }
         if (in_array('virtuemart_state_id', $custom_rendering_fields)) {
             $html .= '<input type="hidden" id="virtuemart_state_id" name="virtuemart_state_id" value="0" />';
         }
         return $html;
     }
 }
Exemplo n.º 3
0
 public static function createDefaultAddress(&$ref, &$cart)
 {
     include JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'config' . DS . 'onepage.cfg.php';
     require_once JPATH_SITE . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'loader.php';
     $vendor = OPCloader::getVendorInfo($cart);
     if (empty($cart->BT)) {
         $cart->BT = array();
         $GLOBALS['opc_cart_empty'] = true;
     }
     if (empty($cart->BT['zip'])) {
         $GLOBALS['opc_zip_empty'] = true;
         if (!empty($op_default_zip)) {
             $cart->BT['zip'] = $op_default_zip;
         } else {
             if ($op_default_zip === 0) {
                 $cart->BT['zip'] = '';
             } else {
                 $cart->BT['zip'] = $vendor['zip'];
             }
         }
     }
     if (empty($cart->BT['virtuemart_country_id'])) {
         $GLOBALS['opc_country_empty'] = true;
         // ok, here we decide on default country:
         $default_shipping_country = OPCloader::getDefaultCountry($cart);
         if (!empty($default_shipping_country)) {
             $cart->BT['virtuemart_country_id'] = $default_shipping_country;
         } else {
             $cart->BT['virtuemart_country_id'] = $vendor['virtuemart_country_id'];
         }
     }
     if (empty($cart->BT['virtuemart_state_id'])) {
         $GLOBALS['opc_state_empty'] = true;
         // this will set taxes to zero:
         if (!empty($opc_usmode)) {
             $cart->BT['virtuemart_state_id'] = ' ';
         }
     }
     // we need to check the ST address as well
     if (!empty($cart->ST)) {
         if (empty($cart->ST['zip'])) {
             $GLOBALS['st_opc_zip_empty'] = true;
             if (!empty($op_default_zip)) {
                 $cart->ST['zip'] = $op_default_zip;
             } else {
                 if ($op_default_zip === 0) {
                     $cart->ST['zip'] = '';
                 } else {
                     $cart->ST['zip'] = $vendor['zip'];
                 }
             }
         }
         if (empty($cart->ST['virtuemart_country_id'])) {
             $GLOBALS['st_opc_country_empty'] = true;
             // ok, here we decide on default country:
             $default_shipping_country = OPCloader::getDefaultCountry($cart);
             if (!empty($default_shipping_country)) {
                 $cart->ST['virtuemart_country_id'] = $default_shipping_country;
             } else {
                 $cart->ST['virtuemart_country_id'] = $vendor['virtuemart_country_id'];
             }
         }
         // we will not do the state for now
         if (empty($cart->ST['virtuemart_state_id'])) {
             $GLOBALS['st_opc_state_empty'] = true;
             if (!empty($opc_usmode)) {
                 $cart->ST['virtuemart_state_id'] = ' ';
             }
         }
     }
 }