Example #1
0
 function getShipping(&$ref, &$cart, $ajax = false)
 {
     if (empty($cart)) {
         if (!empty($ref->cart)) {
             $cart =& $ref->cart;
         } else {
             $cart = VirtueMartCart::getCart(false, false);
         }
     }
     include JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'config' . DS . 'onepage.cfg.php';
     $cmd = JRequest::getVar('cmd', false);
     //$methods = OPCloader::getPluginMethods();
     if (!$ajax) {
         if (!class_exists('vmPSPlugin')) {
             require JPATH_VM_PLUGINS . DS . 'vmpsplugin.php';
         }
         JPluginHelper::importPlugin('vmpayment');
         $dispatcher = JDispatcher::getInstance();
         if (!isset($cart)) {
             $cart = VirtueMartCart::getCart();
         }
         $plugins = array();
         $html = '';
         $results = $dispatcher->trigger('loadPluginJavascriptOPC', array(&$cart, &$plugins, &$html));
         //include(JPATH_SITE.DS.'components'.DS.'com_onepage'.DS.'helpers'.DS.'third_party'.DS.'third_party_shipping_javascript.php');
         if (!empty($html)) {
             OPCloader::$extrahtml .= $html;
         }
         unset($html);
         // so we don't update the address twice
         require_once JPATH_SITE . DS . 'components' . DS . 'com_onepage' . DS . 'controllers' . DS . 'opc.php';
         $c = new VirtueMartControllerOpc();
         $c->setAddress($cart, true, false, true);
     }
     if ($cmd != 'customershipping' && $cmd != 'runpay') {
         if (!empty($op_customer_shipping)) {
             $onclick = 'onclick="javascript: return Onepage.op_runSS(null, false, true, \'customershipping\');" ';
             $html = $this->fetch($ref, 'customer_shipping', array('onclick' => $onclick));
             if (empty($html)) {
                 $html = '<a href="#" ' . $onclick . '  >' . OPClang::_('COM_ONEPAGE_CLICK_HERE_TO_DISPLAY_SHIPPING') . '</a>';
             }
             $html .= '<input type="hidden" name="invalid_country" id="invalid_country" value="invalid_country" /><input type="hidden" name="virtuemart_shipmentmethod_id" checked="checked" id="shipment_id_0" value="choose_shipping" />';
             $shipping_choose_html = '<div id="customer_shipping_wrapper">' . $html . '</div>';
             $shipping_choose_html_a = array();
             $shipping_choose_html_a[] = $shipping_choose_html;
         }
     }
     require_once JPATH_SITE . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'ajaxhelper.php';
     $bhelper = new basketHelper();
     if (!isset($shipping_choose_html_a)) {
         $sh = $bhelper->getShippingArrayHtml($ref, $cart, $ajax);
     } else {
         $sh = $shipping_choose_html_a;
     }
     if (empty($cart) || empty($cart->products)) {
         $op_disable_shipping = OPCloader::getShippingEnabled($cart);
         if (empty($op_disable_shipping)) {
             $html = '<input type="hidden" name="invalid_country" id="invalid_country" value="invalid_country" /><input type="hidden" name="virtuemart_shipmentmethod_id" checked="checked" id="shipment_id_0" value="choose_shipping" />';
         }
         $html .= '<div style="color: red; font-weight: bold;">' . OPCLang::_('COM_VIRTUEMART_EMPTY_CART') . '</div>';
         $sh = array($html);
     }
     if (!empty($disable_payment_per_shipping)) {
         $session = JFactory::getSession();
         $dpps = array();
         require_once JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'transform.php';
         foreach ($sh as $k => $cs) {
             foreach ($dpps_search as $key => $val) {
                 // if we find the need in the shipping, let's associate it with an id
                 $val = urldecode($val);
                 if (strpos($cs, $val) !== false) {
                     //if (!empty($dpps[$key])) continue;
                     $id = OPCTransform::getFT($cs, 'input', 'virtuemart_shipmentmethod_id', 'name', 'virtuemart_shipmentmethod_id', '>', 'value');
                     if (is_array($id)) {
                         $id = reset($id);
                     }
                     if (empty($dpps[$key])) {
                         $dpps[$key] = array();
                     }
                     $dpps[$key][] = $id;
                 }
             }
         }
         $session->set('dpps', $dpps);
     }
     if ($cart->pricesUnformatted['billTotal'] && empty($cart->pricesUnformatted['billTotal'])) {
         $ph = array();
     } else {
         $ph = $bhelper->getPaymentArray();
     }
     $bhelper->createDefaultAddress($ref, $cart);
     $html = $bhelper->getPaymentArrayHtml($ref->cart, $ph, $sh);
     self::$totals_html = basketHelper::$totals_html;
     $bhelper->restoreDefaultAddress($ref, $cart);
     //$ret = implode('<br />', $sh);
     $ret = '';
     $ret .= $html;
     return $ret;
 }