public static function getPayment(&$ref, &$OPCloader, &$num, $ajax = false, $isexpress = false)
    {
        if ($isexpress) {
            $reta = array();
            $reta['html'] = '<input type="hidden" name="virtuemart_paymentmethod_id" value="' . $ref->cart->virtuemart_paymentmethod_id . '" />';
            $reta['extra'] = '';
            return $reta;
        }
        include JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'config' . DS . 'onepage.cfg.php';
        $payment_not_found_text = '';
        $payments_payment_rates = array();
        if (!class_exists('OPCrenderer')) {
            require JPATH_SITE . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'renderer.php';
        }
        $renderer = OPCrenderer::getInstance();
        if (!$renderer->checkPaymentMethodsConfigured()) {
            if (method_exists($renderer, 'assignRef')) {
                $renderer->assignRef('paymentplugins_payments', $payments_payment_rates);
                $renderer->assignRef('found_payment_method', $found_payment_method);
            }
        }
        $p = JRequest::getVar('payment_method_id', $payment_default);
        if (empty($p)) {
            $selectedPayment = empty($ref->cart->virtuemart_paymentmethod_id) ? 0 : $ref->cart->virtuemart_paymentmethod_id;
        } else {
            $selectedPayment = $p;
        }
        // set missing fields for klarna
        OPCloader::prepareBT($ref->cart);
        $dpps = array();
        $shipping = JRequest::getVar('shipping_rate_id', '');
        //if ($ajax)
        if (!empty($shipping)) {
            if (!empty($disable_payment_per_shipping)) {
                $session = JFactory::getSession();
                $dpps = $session->get('dpps', null);
                if (empty($dpps)) {
                    $OPCloader->getShipping($ref, $ref->cart, true);
                }
                $dpps = $session->get('dpps', null);
                if (!empty($dpps)) {
                }
            }
        }
        //
        if (!empty($shipping)) {
            if (!empty($shipping)) {
                $ref->cart->virtuemart_shipmentmethod_id = $shipping;
            }
            $vm2015 = false;
            $ref->cart->prices = $ref->cart->pricesUnformatted = OPCloader::getCheckoutPrices($ref->cart, false, $vm2015, 'opc');
        }
        $paymentplugins_payments = array();
        if ($p === 'none') {
            $p = 0;
        }
        if ($payment_default === 'none') {
            $paymentplugins = array();
            $psel = '<input onclick="javascript: Onepage.runPay(\'\',\'\',op_textinclship, op_currency, 0)" type="radio" name="virtuemart_paymentmethod_id" id="payment_id_0"   value="0" not_a_valid_payment="not_a_valid_payment" ';
            if (empty($p) || $p === 'none') {
                $psel .= ' selected="selected" ';
                $payment_default = 0;
            }
            $psel .= ' />
<label for="payment_id_0"><span class="vmpayment"><span class="vmpayment_name">-' . OPCLang::_('COM_VIRTUEMART_CART_EDIT_PAYMENT') . '- </span></span></label>';
            $paymentplugins[] = $psel;
        }
        if (!class_exists('vmPSPlugin')) {
            require JPATH_VM_PLUGINS . DS . 'vmpsplugin.php';
        }
        JPluginHelper::importPlugin('vmpayment');
        $dispatcher = JDispatcher::getInstance();
        require_once JPATH_SITE . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'ajaxhelper.php';
        $bhelper = new basketHelper();
        //$bhelper->createDefaultAddress($ref, $ref->cart);
        //old: 2.0.208 and prior: $returnValues = $dispatcher->trigger('plgVmDisplayListFEPayment', array($ref->cart, $selectedPayment, &$paymentplugins_payments));
        //plgVmDisplayListFEPaymentOPCNocache
        $returnValues = $dispatcher->trigger('plgVmDisplayListFEPaymentOPCNocache', array(&$ref->cart, $selectedPayment, &$paymentplugins_payments));
        if (empty($returnValues)) {
            $returnValues = $dispatcher->trigger('plgVmDisplayListFEPayment', array($ref->cart, $selectedPayment, &$paymentplugins_payments));
        }
        // if no payment defined
        $found_payment_method = false;
        $n = 0;
        $debug = '';
        foreach ($paymentplugins_payments as $p1) {
            if (is_array($p1)) {
                $n += count($p1);
            }
        }
        if ($n > 0) {
            $found_payment_method = true;
        }
        $num = $n;
        if (!$found_payment_method) {
            $link = '';
            // todo
            $payment_not_found_text = OPCLang::sprintf('COM_VIRTUEMART_CART_NO_PAYMENT_METHOD_PUBLIC', '<a href="' . $link . '">' . $link . '</a>');
        }
        require_once JPATH_SITE . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'ajaxhelper.php';
        $bhelper = new basketHelper();
        require_once JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'transform.php';
        $ret = array();
        if ($found_payment_method) {
            if (!empty($payment_inside)) {
                $ret2 = OPCTransform::paymentToSelect($paymentplugins_payments, $shipping, $dpps);
                if (!empty($ret2)) {
                    $ret = array($ret2['select']);
                    $extra = $ret2['extra'];
                    /*
                    		  foreach ($ret['extra'] as $key=>$val)
                    {
                      $extra[$key] = $val; 
                    }
                    */
                }
            }
            if (empty($payment_inside) || empty($ret)) {
                $sorted = array();
                $unknown = array();
                foreach ($paymentplugins_payments as $paymentplugin_payments) {
                    if (is_array($paymentplugin_payments)) {
                        foreach ($paymentplugin_payments as $paymentplugin_payment) {
                            $id = OPCTransform::getFT($paymentplugin_payment, 'input', 'virtuemart_paymentmethod_id', 'name', 'virtuemart_paymentmethod_id', '>', 'value');
                            if (is_array($id)) {
                                $id = reset($id);
                            }
                            $paymentplugin_payment = str_replace('class="vmpayment_description"', 'class="vmpayment_description vmpayment_description_' . $id . '"', $paymentplugin_payment);
                            //vmpayment_cardinfo
                            $paymentplugin_payment = str_replace('class="vmpayment_cardinfo"', 'class="vmpayment_cardinfo vmpayment_cardinfo_' . $id . '"', $paymentplugin_payment);
                            //ccDetails
                            $paymentplugin_payment = str_replace('class="ccDetails"', 'class="ccDetails ccDetails_' . $id . '"', $paymentplugin_payment);
                            OPCloader::opcDebug('checking shipping ' . $shipping);
                            OPCloader::opcDebug('dpps:');
                            OPCloader::opcDebug($dpps);
                            OPCloader::opcDebug('dpps_disable:');
                            OPCloader::opcDebug($dpps_disable);
                            if (!empty($shipping)) {
                                if (!empty($dpps)) {
                                    if (!empty($disable_payment_per_shipping)) {
                                        foreach ($dpps_disable as $k => $v) {
                                            if (!empty($dpps[$k])) {
                                                foreach ($dpps[$k] as $y => $try) {
                                                    if ((int) $dpps[$k][$y] == (int) $shipping) {
                                                        if ($dpps_disable[$k] == $id) {
                                                            OPCloader::opcDebug('disabling payment id ' . $id . ' for shipping id ' . $shipping);
                                                            $paymentplugin_payment = '';
                                                            continue 3;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            // PPL Pro fix
                            $paymentplugin_payment = str_replace('<br/><a href="' . JRoute::_('index.php?option=com_virtuemart&view=cart&task=editpayment&Itemid=' . JRequest::getInt('Itemid'), false) . '">' . JText::_('VMPAYMENT_PAYPAL_CC_ENTER_INFO') . '</a>', '', $paymentplugin_payment);
                            $paymentplugin_payment = str_replace('name="virtuemart_paymentmethod_id"', 'name="virtuemart_paymentmethod_id" onclick="javascript: Onepage.runPay(\'\',\'\',op_textinclship, op_currency, 0)" ', $paymentplugin_payment);
                            $ret[] = $paymentplugin_payment;
                            if ($n === 1 && !empty($hide_payment_if_one)) {
                                $paymentplugin_payment = str_replace('type="radio"', 'type="hidden"', $paymentplugin_payment);
                            }
                            if (is_numeric($id)) {
                                $ind = (int) $id;
                                if (empty($sorted[$ind])) {
                                    $sorted[$ind] = $paymentplugin_payment;
                                } else {
                                    $unknown[] = $paymentplugin_payment;
                                }
                            } else {
                                if (is_numeric($id[0])) {
                                    $ind = (int) $id[0];
                                    if (empty($sorted[$ind])) {
                                        $sorted[$ind] = $paymentplugin_payment;
                                    } else {
                                        $unknown[] = $paymentplugin_payment;
                                    }
                                } else {
                                    $unknown[] = $paymentplugin_payment;
                                }
                            }
                        }
                    }
                }
                if (!empty($sorted)) {
                    $dbj = JFactory::getDBO();
                    $dbj->setQuery("select * from #__virtuemart_paymentmethods where published = '1' order by ordering asc limit 999");
                    $list = $dbj->loadAssocList();
                    $msg = $dbj->getErrorMsg();
                    if (!empty($msg)) {
                        echo $msg;
                    }
                    $sortedfinal = array();
                    if (!empty($list)) {
                        foreach ($list as $pme) {
                            if (!empty($sorted[$pme['virtuemart_paymentmethod_id']])) {
                                $sortedfinal[] = $sorted[$pme['virtuemart_paymentmethod_id']];
                            }
                        }
                        if (empty($unknown)) {
                            $unknown = array();
                        }
                        if (!empty($sortedfinal)) {
                            $ret = array_merge($sortedfinal, $unknown);
                        }
                    }
                }
            }
        } else {
            $ret[] = $payment_not_found_text . '<input type="hidden" name="virtuemart_paymentmethod_id" id="opc_missing_payment" value="0" />';
        }
        if (empty($payment_inside)) {
            if (!empty($ret)) {
                if (!empty($paymentplugins)) {
                    $ret = array_merge($paymentplugins, $ret);
                }
            }
        }
        $vars = array('payments' => $ret, 'cart' => $ref->cart);
        $html = $OPCloader->fetch($OPCloader, 'list_payment_methods.tpl', $vars);
        $pid = JRequest::getVar('payment_method_id', '');
        if (!empty($pid) && is_numeric($pid)) {
            if (strpos($html, 'value="' . $pid . '"') !== false) {
                $html = str_replace('checked="checked"', '', $html);
                $html = str_replace(' checked', ' ', $html);
                $html = str_replace('value="' . $pid . '"', 'value="' . $pid . '" checked="checked" ', $html);
            }
        } else {
            if (strpos($html, 'value="' . $payment_default . '"') !== false) {
                $html = str_replace('checked="checked"', '', $html);
                $html = str_replace(' checked', ' ', $html);
                $html = str_replace('value="' . $payment_default . '"', 'value="' . $payment_default . '" checked="checked" ', $html);
            }
        }
        $html = str_replace('"radio"', '"radio" autocomplete="off" ', $html);
        if (!$payment_inside) {
            if (strpos($html, 'checked') === false) {
                $x1 = strpos($html, 'name="virtuemart_paymentmethod_id"');
                if ($x1 !== false) {
                    $html = substr($html, 0, $x1) . ' checked="checked" ' . substr($html, $x1);
                } else {
                    // we've got no method here !
                }
            }
        }
        // klarna compatibility
        $count = 0;
        $html = str_replace('name="klarna_paymentmethod"', 'name="klarna_paymentmethod_opc"', $html, $count);
        $html .= '<input type="hidden" name="opc_payment_method_id" id="opc_payment_method_id" value="" />';
        if ($count > 0) {
            if (!defined('klarna_opc_id')) {
                $html .= '<input type="hidden" name="klarna_opc_method" id="klarna_opc_method" value="" />';
                define('klarna_opc_id', 1);
            }
        }
        $reta = array();
        $reta['html'] = $html;
        if (!empty($extra)) {
            $reta['extra'] = $extra;
        } else {
            $reta['extra'] = '';
        }
        return $reta;
    }
Exemple #2
0
 /**
  * Check if a minimum purchase value for this order has been set, and if so, if the current
  * value is equal or hight than that value.
  * @author Oscar van Eijk
  * @return An error message when a minimum value was set that was not eached, null otherwise
  */
 public static function checkPurchaseValue($cart)
 {
     $s = $cart->virtuemart_shipmentmethod_id;
     $p = $cart->virtuemart_paymentmethod_id;
     $cart->virtuemart_shipmentmethod_id = 0;
     $cart->virtuemart_paymentmethod_id = 0;
     $ret = '';
     require_once JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'mini.php';
     $vendor = OPCmini::getModel('vendor');
     if (empty($vendor)) {
         return;
     }
     $vendor->setId($cart->vendorId);
     $store = $vendor->getVendor();
     if ($store->vendor_min_pov > 0) {
         $vm2015 = true;
         $prices = OPCloader::getCheckoutPrices($cart, false, $vm2015, null);
         if (!empty($prices['couponValue']) || !empty($prices['salesPriceCoupon'])) {
             $ret = '';
         } else {
             if ($prices['salesPrice'] < $store->vendor_min_pov) {
                 if (!class_exists('CurrencyDisplay')) {
                     require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'currencydisplay.php';
                 }
                 $currency = CurrencyDisplay::getInstance();
                 $ret = JText::sprintf('COM_VIRTUEMART_CART_MIN_PURCHASE', $currency->priceDisplay($store->vendor_min_pov));
             }
         }
     }
     $cart->virtuemart_shipmentmethod_id = $s;
     $cart->virtuemart_paymentmethod_id = $p;
     return $ret;
 }
 function checkoutData($redirect = true)
 {
     $cart =& self::$current_cart;
     $this->_redirect = false;
     $this->_inCheckOut = true;
     include JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'config' . DS . 'onepage.cfg.php';
     $cart->_inCheckOut = true;
     if (!isset($cart->tosAccepted)) {
         $cart->tosAccepted = 1;
     }
     $cart->tosAccepted = JRequest::getInt('tosAccepted', $cart->tosAccepted);
     if (!isset($cart->customer_comment)) {
         $cart->customer_comment = '';
     }
     $cart->customer_comment = JRequest::getVar('customer_comment', $cart->customer_comment);
     if (empty($cart->customer_comment)) {
         $cart->customer_comment = JRequest::getVar('customer_note', $cart->customer_comment);
     }
     $op_disable_shipto = OPCloader::getShiptoEnabled($cart);
     if (empty($op_disable_shipto)) {
         $shipto = JRequest::getVar('shipto', null);
         if ($shipto != 'new') {
             if (($cart->selected_shipto = $shipto) !== null) {
                 //JModel::addIncludePath(JPATH_VM_ADMINISTRATOR . DS . 'models');
                 require_once JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'mini.php';
                 $userModel = OPCmini::getModel('user');
                 //JModel::getInstance('user', 'VirtueMartModel');
                 $stData = $userModel->getUserAddressList(0, 'ST', $cart->selected_shipto);
                 if (isset($stData[0])) {
                     $this->validateUserData('ST', $stData[0], $cart);
                 }
             }
         }
     } else {
         $cart->STsameAsBT = 1;
         $cart->ST = $cart->BT;
     }
     $cart->setCartIntoSession();
     $mainframe = JFactory::getApplication();
     if (isset($cart->cartProductsData)) {
         $count = count($cart->cartProductsData);
     } else {
         $count = count($cart->products);
     }
     if ($count == 0) {
         $mainframe->redirect(JRoute::_('index.php?option=com_virtuemart', false), JText::_('COM_VIRTUEMART_CART_NO_PRODUCT'));
     } else {
         foreach ($cart->products as $product) {
             $redirectMsg = $this->checkForQuantities($product, $product->quantity);
             if (!$redirectMsg) {
                 //					$this->setCartIntoSession();
                 $this->redirect(JRoute::_('index.php?option=com_virtuemart&view=cart&task=checkout', false, VmConfig::get('useSSL', false)), $redirectMsg);
             }
         }
     }
     include JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'config' . DS . 'onepage.cfg.php';
     //But we check the data again to be sure
     if (empty($cart->BT)) {
         $this->redirect(JRoute::_('index.php?option=com_virtuemart&view=cart&task=checkout', false, VmConfig::get('useSSL', false)));
     } else {
         $redirectMsg = $this->validateUserData('BT', null, $cart);
         if ($redirectMsg) {
             $this->redirect(JRoute::_('index.php?option=com_virtuemart&view=cart&task=checkout', false, VmConfig::get('useSSL', false)), $redirectMsg);
         }
     }
     if ($cart->STsameAsBT !== 0) {
         $cart->ST = $cart->BT;
     } else {
         //Only when there is an ST data, test if all necessary fields are filled
         if (!empty($cart->ST)) {
             $redirectMsg = $this->validateUserData('ST', null, $cart);
             if ($redirectMsg) {
                 //				$cart->setCartIntoSession();
                 $this->redirect(JRoute::_('index.php?option=com_virtuemart&view=cart&task=checkout', false, VmConfig::get('useSSL', false)), $redirectMsg);
             }
         }
     }
     // Test Coupon
     $shipment = $cart->virtuemart_shipmentmethod_id;
     $payment = $cart->virtuemart_paymentmethod_id;
     //2.0.144: $prices = $cartClass->getCartPrices();
     $cart->virtuemart_shipmentmethod_id = $shipment;
     $cart->virtuemart_paymentmethod_id = $payment;
     //2.0.144 added
     if (!class_exists('calculationHelper')) {
         require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'calculationh.php';
     }
     $calc = calculationHelper::getInstance();
     if (method_exists($calc, 'setCartPrices')) {
         $vm2015 = true;
     } else {
         $vm2015 = false;
     }
     if ($vm2015) {
         $calc->setCartPrices(array());
     }
     //  $cart->pricesUnformatted = $prices = $calc->getCheckoutPrices(  $cart, false, 'opc');
     $cart->pricesUnformatted = $prices = OPCloader::getCheckoutPrices($cart, false, $vm2015, 'opc');
     //$calc->getCheckoutPrices(  $cart, false, 'opc');
     // Check if a minimun purchase value is set
     if (($msg = $this->checkPurchaseValue($prices)) != null) {
         $this->redirect(JRoute::_('index.php?option=com_virtuemart&view=cart&task=checkout', false, VmConfig::get('useSSL', false)), $msg);
     }
     if (!empty($prices['billTotal'])) {
         // special case for zero value orders, do not charge payment fee:
         if ($prices['billTotal'] == $prices['paymentValue']) {
             $savedp = $cart->virtuemart_paymentmethod_id;
             $cart->virtuemart_paymentmethod_id = 0;
             if (method_exists($calc, 'getCheckoutPricesOPC')) {
                 $prices = $calc->getCheckoutPricesOPC($cart, false);
             } else {
                 $prices = OPCloader::getCheckoutPrices($cart, false, $vm2015, 'opc');
             }
             $cart->virtuemart_paymentmethod_id = 0;
         }
     }
     //2.0.144:end
     if (!empty($cart->couponCode)) {
         if (!class_exists('CouponHelper')) {
             require JPATH_VM_SITE . DS . 'helpers' . DS . 'coupon.php';
         }
         $redirectMsg2 = CouponHelper::ValidateCouponCode($cart->couponCode, $prices['salesPrice']);
         /*
         stAn: OPC will not redirect the customer due to incorrect coupons here
         if (!empty($redirectMsg)) {
         	$cart->couponCode = '';
         	//				$this->setCartIntoSession();
         	$this->redirect(JRoute::_('index.php?option=com_virtuemart&view=cart',$cart->useXHTML,$cart->useSSL), $redirectMsg);
         }
         */
     }
     //Test Shipment and show shipment plugin
     $op_disable_shipping = OPCloader::getShippingEnabled($cart);
     if (empty($op_disable_shipping)) {
         if (empty($cart->virtuemart_shipmentmethod_id)) {
             $redirectMsg = JText::_('COM_VIRTUEMART_CART_NO_SHIPPINGRATE');
             $this->redirect(JRoute::_('index.php?option=com_virtuemart&view=cart&task=checkout', false, VmConfig::get('useSSL', false)), $redirectMsg);
         } else {
             if (!class_exists('vmPSPlugin')) {
                 require JPATH_VM_PLUGINS . DS . 'vmpsplugin.php';
             }
             JPluginHelper::importPlugin('vmshipment');
             //Add a hook here for other shipment methods, checking the data of the choosed plugin
             $dispatcher = JDispatcher::getInstance();
             $retValues = $dispatcher->trigger('plgVmOnCheckoutCheckDataShipment', array($cart));
             foreach ($retValues as $retVal) {
                 if ($retVal === true) {
                     break;
                     // Plugin completed succesful; nothing else to do
                 } elseif ($retVal === false) {
                     // Missing data, ask for it (again)
                     $redirectMsg = 'OPC2: ' . JText::_('COM_VIRTUEMART_CART_NO_SHIPPINGRATE');
                     $this->redirect(JRoute::_('index.php?option=com_virtuemart&view=cart&task=checkout', false, VmConfig::get('useSSL', false)), $redirectMsg);
                     // 	NOTE: inactive plugins will always return null, so that value cannot be used for anything else!
                 }
             }
         }
     }
     //echo 'hier ';
     //Test Payment and show payment plugin
     $total = (double) $prices['billTotal'];
     if ($total > 0) {
         if (empty($cart->virtuemart_paymentmethod_id)) {
             $this->redirect(JRoute::_('index.php?option=com_virtuemart&view=cart&task=checkout', false, VmConfig::get('useSSL', false)), $redirectMsg);
         } else {
             if (!class_exists('vmPSPlugin')) {
                 require JPATH_VM_PLUGINS . DS . 'vmpsplugin.php';
             }
             JPluginHelper::importPlugin('vmpayment');
             //Add a hook here for other payment methods, checking the data of the choosed plugin
             $dispatcher = JDispatcher::getInstance();
             $retValues = $dispatcher->trigger('plgVmOnCheckoutCheckDataPayment', array($cart));
             $session = JFactory::getSession();
             $sessionKlarna = $session->get('Klarna', 0, 'vm');
             foreach ($retValues as $retVal) {
                 if ($retVal === true) {
                     break;
                     // Plugin completed succesful; nothing else to do
                 } elseif ($retVal === false) {
                     $msg = JFactory::getSession()->get('application.queue');
                     $msgq1 = JFactory::getApplication()->get('messageQueue', array());
                     $msgq2 = JFactory::getApplication()->get('_messageQueue', array());
                     $res = array_merge($msg, $msgg1, $msgg2);
                     $msg = $res;
                     if (!empty($msg) && is_array($msg)) {
                         $redirectMsg = implode('<br />', $msg);
                     }
                     // Missing data, ask for it (again)
                     $this->redirect(JRoute::_('index.php?option=com_virtuemart&view=cart&task=checkout', false, VmConfig::get('useSSL', false)), $redirectMsg);
                     // 	NOTE: inactive plugins will always return null, so that value cannot be used for anything else!
                 }
             }
         }
     } else {
         $cart->virtuemart_paymentmethod_id = 0;
     }
     if (VmConfig::get('agree_to_tos_onorder', 1)) {
         if (empty($cart->tosAccepted)) {
             require_once JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'mini.php';
             $userFieldsModel = OPCmini::getModel('Userfields');
             $required = $userFieldsModel->getIfRequired('agreed');
             if (!empty($required)) {
                 $this->redirect(JRoute::_('index.php?option=com_virtuemart&view=cart&task=checkout', false, VmConfig::get('useSSL', false)), JText::_('COM_VIRTUEMART_CART_PLEASE_ACCEPT_TOS'));
             }
         }
     }
     /* stAn: 2.0.231: registered does not mean logged in, therefore we are going to disable this option with opc, so normal registration would still work when activation is enabled 
     		if (empty($GLOBALS['is_dup']))
     		if(VmConfig::get('oncheckout_only_registered',0)) {
     			$currentUser = JFactory::getUser();
     			if(empty($currentUser->id)){
     				$this->redirect(JRoute::_('index.php?option=com_virtuemart&view=cart', false, VmConfig::get('useSSL', false)), JText::_('COM_VIRTUEMART_CART_ONLY_REGISTERED') );
     			}
     		 }
     		 */
     //Show cart and checkout data overview
     $cart->_inCheckOut = false;
     $cart->_dataValidated = true;
     $cart->setCartIntoSession();
     return true;
 }
Exemple #4
0
    public static function getBasket(&$ref, $OPCloader, $withwrapper = true, &$op_coupon = '', $shipping = '', $payment = '', $isexpress = false)
    {
        include JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'config' . DS . 'onepage.cfg.php';
        $has_k2 = OPCloader::tableExists('k2mart');
        if (!class_exists('ShopFunctions')) {
            require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'shopfunctions.php';
        }
        if (!method_exists('ShopFunctions', 'convertWeightUnit')) {
            $opc_show_weight = false;
        }
        /*
           if (!class_exists('VirtueMartModelProduct'))
         require(JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'product.php');
        */
        require_once JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'mini.php';
        $productClass = OPCmini::getModel('product');
        //new VirtueMartModelProduct();
        if (!class_exists('CurrencyDisplay')) {
            require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'currencydisplay.php';
        }
        $currencyDisplay = CurrencyDisplay::getInstance($ref->cart->pricesCurrency);
        $google_html = '';
        $VM_LANG = new op_languageHelper();
        $product_rows = array();
        $p2 = $ref->cart->products;
        if (empty($ref->cart)) {
            $ref->cart = VirtueMartCart::getCart();
        }
        $vm2015 = false;
        $ref->cart->prices = $ref->cart->pricesUnformatted = OPCloader::getCheckoutPrices($ref->cart, false, $vm2015, 'opc');
        $useSSL = VmConfig::get('useSSL', 0);
        $action_url = $OPCloader->getActionUrl($OPCloader, true);
        $xi = 0;
        if (isset($currencyDisplay->_priceConfig)) {
            $savedConfig = $currencyDisplay->_priceConfig;
        }
        if (empty($product_price_display)) {
            $product_price_display = 'salesPrice';
        }
        //$test_product_price_display = array($product_price_display, 'salesPrice', 'basePrice', 'priceWithoutTax', 'basePriceWithTax', 'priceBeforeTax', 'costPrice');
        $test_product_price_display = array($product_price_display, 'salesPrice', 'basePrice', 'priceWithoutTax', 'basePriceWithTax', 'priceBeforeTax');
        // check price config
        $testf = false;
        foreach ($test_product_price_display as $product_price_display_test) {
            $test = $currencyDisplay->createPriceDiv($product_price_display, '', '10', false, false, 1);
            if (empty($test)) {
                if (isset($currencyDisplay->_priceConfig)) {
                    if (isset($currencyDisplay->_priceConfig[$product_price_display_test])) {
                        if (empty($currencyDisplay->_priceConfig[$product_price_display_test][0])) {
                            $currencyDisplay->_priceConfig[$product_price_display_test] = array(1, -1, 1);
                        }
                    }
                }
                $testf = true;
            } else {
                if (!isset($product_price_display_test2)) {
                    $product_price_display_test2 = $product_price_display_test;
                }
            }
        }
        if (empty($testf)) {
            $product_price_display = $product_price_display_test2;
        }
        $totalw = 0;
        $to_weight_unit = VmConfig::get('weight_unit_default', 'KG');
        foreach ($ref->cart->products as $pkey => $prow) {
            if ($opc_show_weight) {
                $totalw += ShopFunctions::convertWeightUnit((double) $prow->product_weight, $prow->product_weight_uom, $to_weight_unit) * (double) $prow->quantity;
            }
            $product = array();
            $id = $prow->virtuemart_media_id;
            if (empty($id)) {
                $imgf = '';
            } else {
                if (is_array($id)) {
                    $id = reset($id);
                }
                $imgf = $OPCloader->getImageFile($id);
            }
            $product['product_full_image'] = $imgf;
            if (!empty($opc_only_parent_links)) {
                if (!empty($prow->product_parent_id)) {
                    $parent = $prow->product_parent_id;
                    $prow->url = JRoute::_('index.php?option=com_virtuemart&virtuemart_product_id=' . $parent . '&view=productdetails', true);
                }
            }
            // check if k2 exists:
            if (!isset($prow->url)) {
                if (isset($prow->link)) {
                    $prow->url = $prow->link;
                    if (strpos($prow->url, '&amp;') === false) {
                        $prow->url = str_replace('&', '&amp;', $prow->url);
                    }
                } else {
                    $prow->url = JRoute::_('index.php?option=com_virtuemart&virtuemart_product_id=' . $prow->virtuemart_product_id . '&view=productdetails', true);
                }
            }
            if ($has_k2) {
                $db = JFactory::getDBO();
                $q = 'select baseID from #__k2mart where referenceID = ' . (int) $prow->virtuemart_product_id . ' limit 0,1';
                $db->setQuery($q);
                $k2_id = $db->loadResult();
                if (!empty($k2_id)) {
                    $prow->url = JRoute::_('index.php?option=com_k2&id=' . $k2_id . '&view=item', true);
                }
            }
            $product['product_name'] = JHTML::link($prow->url, $prow->product_name, ' class="opc_product_name" ');
            if ((!defined('VM_VERSION') || VM_VERSION < 3) && (isset($prow->customfields) && !is_array($prow->customfields))) {
                if (!empty($opc_editable_attributes)) {
                    $product['product_attributes'] = '<div style="clear:both;">' . OPCrenderer::getCustomFields($prow->virtuemart_product_id, $prow->cart_item_id, $prow->quantity) . '</div>';
                } else {
                    $product['product_attributes'] = $prow->customfields;
                }
            } else {
                $product['product_attributes'] = '';
            }
            /*
            var_dump($prow->customfields); 
            $cart = VirtuemartCart::getCart();
            
            $p = array(); 
            foreach ($cart->products as $k=>$v)
            {
              $p[$k] = $v; 
            } 
            unset($cart->products); 
            
            unset($cart->ST); 
            unset($cart->BT); 
            unset($cart->BTaddress); 
            unset($cart->STaddress); 
            $cart->products = $p; 
            $cart->setCartIntoSession(); 
            var_dump($cart->products); die(); 
            var_dump($cart); 
            JFactory::getApplication()->close(); 
            */
            if (defined('VM_VERSION') && VM_VERSION >= 3) {
            }
            if (isset($prow->customfields) && is_array($prow->customfields)) {
                $customfieldsModel = OPCmini::getModel('Customfields');
                $product['product_attributes'] = $customfieldsModel->CustomsFieldCartDisplay($prow);
            }
            $product['product_sku'] = $prow->product_sku;
            // end price test
            if (isset($prow->quantity)) {
                $product['product_quantity'] = $prow->quantity;
            }
            if (isset($prow->min_order_level)) {
                $product['min_order_level'] = $prow->min_order_level;
            }
            if (isset($prow->max_order_level)) {
                $product['max_order_level'] = $prow->max_order_level;
            }
            //$product_model = $OPCloader->getModel('product');
            $xi++;
            if (empty($no_extra_product_info)) {
                $prowcopy = $productClass->getProduct($prow->virtuemart_product_id, true);
            } else {
                $prowcopy = $prow;
            }
            $product['info'] = $prowcopy;
            $product['product'] = $prow;
            if (isset($ref->cart->prices[$pkey])) {
                $currentPrice = $ref->cart->prices[$pkey];
            } else {
                if (isset($prow->prices)) {
                    $currentPrice = $prow->prices;
                }
            }
            if ($product_price_display == 'salesPrice') {
                if (isset($prow->prices)) {
                    $product['product_price'] = $currentPrice['salesPrice'];
                } else {
                    if (isset($prow->salesPrice)) {
                        $product['product_price'] = $prow->salesPrice;
                    } else {
                        if (isset($prow->basePriceWithTax)) {
                            $product['product_price'] = $prow->basePriceWithTax;
                        } else {
                            if (isset($prow->basePrice)) {
                                $product['product_price'] = $prow->basePrice;
                            }
                        }
                    }
                }
            } else {
                if (isset($prow->prices)) {
                    $product['product_price'] = $currentPrice[$product_price_display];
                } else {
                    if (isset($prow->{$product_price_display})) {
                        $product['product_price'] = $prow->{$product_price_display};
                    } else {
                        if (isset($prow->salesPrice)) {
                            $product['product_price'] = $prow->salesPrice;
                        }
                    }
                }
            }
            if (!isset($product['product_price'])) {
                $price = $ref->cart->pricesUnformatted[$pkey];
                $product['product_price'] = $price[$product_price_display];
            }
            if (empty($product['product_price'])) {
                $product_price_display = 'salesPrice';
                $price = $ref->cart->pricesUnformatted[$pkey];
                $product['product_price'] = $price['salesPrice'];
            }
            $price_raw = $product['product_price'];
            // the quantity is not working up to 2.0.4
            $product['product_id'] = $prow->virtuemart_product_id;
            $google_html .= '<input type="hidden" name="prod_id" value="' . $prow->virtuemart_product_id . '" />
			   <input type="hidden" name="prodsku_' . $prow->virtuemart_product_id . '" id="prodsku_' . $prow->virtuemart_product_id . '" value="' . OPCloader::slash($prow->product_sku, false) . '" />
			   <input type="hidden" name="prodname_' . $prow->virtuemart_product_id . '" id="prodname_' . $prow->virtuemart_product_id . '" value="' . OPCloader::slash($prow->product_name, false) . '" />
			   <input type="hidden" name="prodq_' . $prow->virtuemart_product_id . '" id="prodq_' . $prow->virtuemart_product_id . '" value="' . $prow->quantity . '" />
			   <input type="hidden" name="produprice_' . $prow->virtuemart_product_id . '" id="produprice_' . $prow->virtuemart_product_id . '" value="' . $price_raw . '" />
			    <input type="hidden" name="prodcat_' . $prow->virtuemart_product_id . '" id="prodcat_' . $prow->virtuemart_product_id . '" value="' . $prow->category_name . '" />
			   
			   
			  ';
            if (isset($ref->cart->pricesUnformatted[$pkey])) {
                $price = $ref->cart->pricesUnformatted[$pkey];
            } else {
                $price = $prow->prices;
            }
            $product['prices'] = $price;
            $product['prices_formatted'] = array();
            if ($vm2015) {
                foreach ($price as $key => $pricev) {
                    //if (!isset($price[$key]))
                    if (!empty($pricev)) {
                        $product['prices_formatted'][$key] = $currencyDisplay->createPriceDiv($key, '', $price, false, true, 1);
                    }
                }
            }
            $product['product_price'] = $currencyDisplay->createPriceDiv($product_price_display, '', $price, false, true, 1);
            /*
            if (false)
            if (empty($product['product_price']))
            {
              // ok, we have a wrong type selected here
            				if ($product_price_display == 'salesPrice') 
            				$product['product_price'] = $currencyDisplay->createPriceDiv('basePrice','', $price,false,false, 1);
            				if (empty($product['product_price']))
            				$product['product_price'] = $currencyDisplay->createPriceDiv('priceWithoutTax','', $price,false,false, 1);
            				if (empty($product['product_price']))
            				$product['product_price'] = $currencyDisplay->createPriceDiv('basePriceWithTax','', $price,false,false, 1);
            				if (empty($product['product_price']))
            				$product['product_price'] = $currencyDisplay->createPriceDiv('priceBeforeTax','', $price,false,false, 1);
            				if (empty($product['product_price']))
            				$product['product_price'] = $currencyDisplay->createPriceDiv('costPrice','', $price,false,false, 1);
            				
            
            				 
            }
            */
            $product['product_price'] = str_replace('class="', 'class="opc_price_general opc_', $product['product_price']);
            if (!isset($prow->cart_item_id)) {
                $prow->cart_item_id = $pkey;
            }
            $v = array('product' => $prow, 'action_url' => $action_url, 'use_ssl' => $useSSL, 'useSSL' => $useSSL);
            if (!empty($ajaxify_cart)) {
                $update_form = $OPCloader->fetch($OPCloader, 'update_form_ajax.tpl', $v);
                $delete_form = $OPCloader->fetch($OPCloader, 'delete_form_ajax.tpl', $v);
            } else {
                $update_form = $OPCloader->fetch($OPCloader, 'update_form.tpl', $v);
                $delete_form = $OPCloader->fetch($OPCloader, 'delete_form.tpl', $v);
                $op_coupon_ajax = '';
            }
            if (empty($update_form)) {
                if (!empty($ajaxify_cart)) {
                    $product['update_form'] = '<input type="text" title="' . OPCLang::_('COM_VIRTUEMART_CART_UPDATE') . '" class="inputbox" size="3" name="quantity" id="quantity_for_' . md5($prow->cart_item_id) . '" value="' . $prow->quantity . '" /><a class="updatebtn" title="' . OPCLang::_('COM_VIRTUEMART_CART_DELETE') . '" href="#" rel="' . $prow->cart_item_id . '|' . md5($prow->cart_item_id) . '"> </a>';
                    $product['delete_form'] = '<a class="deletebtn" title="' . OPCLang::_('COM_VIRTUEMART_CART_DELETE') . '" href="#" rel="' . $prow->cart_item_id . '"> </a>';
                } else {
                    $product['update_form'] = '<form action="' . $action_url . '" method="post" style="display: inline;">
				<input type="hidden" name="option" value="com_virtuemart" />
				<input type="text" title="' . OPCLang::_('COM_VIRTUEMART_CART_UPDATE') . '" class="inputbox" size="3" name="quantity" value="' . $prow->quantity . '" />
				<input type="hidden" name="view" value="cart" />
				<input type="hidden" name="task" value="update" />
				<input type="hidden" name="cart_virtuemart_product_id" value="' . $prow->cart_item_id . '" />
				<input type="submit" class="updatebtn" name="update" title="' . OPCLang::_('COM_VIRTUEMART_CART_UPDATE') . '" value=" "/>
			  </form>';
                    if (defined('VM_VERSION') && VM_VERSION >= 3) {
                        $product['delete_form'] = '<a class="deletebtn" title="' . OPCLang::_('COM_VIRTUEMART_CART_DELETE') . '" href="' . JRoute::_('index.php?option=com_virtuemart&view=cart&task=delete.' . $prow->cart_item_id . '&cart_virtuemart_product_id=' . $prow->cart_item_id, true, $useSSL) . '"> </a>';
                    } else {
                        $product['delete_form'] = '<a class="deletebtn" title="' . OPCLang::_('COM_VIRTUEMART_CART_DELETE') . '" href="' . JRoute::_('index.php?option=com_virtuemart&view=cart&task=delete&cart_virtuemart_product_id=' . $prow->cart_item_id, true, $useSSL) . '"> </a>';
                    }
                }
            } else {
                $product['update_form'] = $update_form;
                $product['delete_form'] = $delete_form;
            }
            if (!empty($ajaxify_cart)) {
                $product['update_form'] = str_replace('href=', 'onclick="return Onepage.updateProduct(this);" href=', $product['update_form']);
                $product['delete_form'] = str_replace('href=', 'onclick="return Onepage.deleteProduct(this);" href=', $product['delete_form']);
            }
            //vm3 update:
            if (defined('VM_VERSION') && VM_VERSION >= 3) {
                $product['update_form'] = str_replace('name="quantity"', 'name="quantity[' . $prow->cart_item_id . ']"', $product['update_form']);
                $product['update_form'] = str_replace('value="update"', 'value="updatecart"', $product['update_form']);
            }
            $product['subtotal'] = $prow->quantity * $price_raw;
            //else
            //$product['subtotal'] = $prow->subtotal_with_tax;
            // this is fixed from 2.0.4 and would not be needed
            if (isset($ref->cart->pricesUnformatted[$pkey])) {
                $copy = $ref->cart->pricesUnformatted[$pkey];
            } else {
                $copy = $prow->prices;
            }
            //$copy['salesPrice'] = $copy['subtotal_with_tax'];
            $copy[$product_price_display] = $product['subtotal'];
            $product['subtotal'] = $currencyDisplay->createPriceDiv($product_price_display, '', $copy, false, true, 1);
            $product['subtotal'] = str_replace('class="', 'class="opc_', $product['subtotal']);
            // opc vars
            $product_rows[] = $product;
            //break;
        }
        //$shipping_inside_basket = false;
        $shipping_select = $shipping;
        $payment_select = $payment;
        if (!empty($ref->cart->prices['salesPriceCoupon'])) {
            if (empty($coupon_price_display)) {
                $coupon_price_display = 'salesPriceCoupon';
            }
            $coupon_display = $currencyDisplay->createPriceDiv($coupon_price_display, '', $ref->cart->prices, false, true, 1);
            //$ref->cart->prices['salesPriceCoupon'];
            $coupon_display = str_replace('class="', 'class="opc_', $coupon_display);
        } else {
            $coupon_display = '';
        }
        if (!empty($coupon_display)) {
            $discount_after = true;
        } else {
            $discount_after = false;
        }
        if (empty($other_discount_display)) {
            $other_discount_display = 'billDiscountAmount';
        }
        switch ($other_discount_display) {
            case 'billDiscountAmount':
                $coupon_display_before = $currencyDisplay->createPriceDiv('billDiscountAmount', '', $ref->cart->prices, false, false, 1);
                if (empty($ref->cart->prices['billDiscountAmount'])) {
                    $coupon_display_before = '';
                }
                break;
            case 'discountAmount':
                $coupon_display_before = $currencyDisplay->createPriceDiv('discountAmount', '', $ref->cart->prices, false, false, 1);
                if (empty($ref->cart->prices['discountAmount'])) {
                    $coupon_display_before = '';
                }
            case 'minus':
                $billD = abs($ref->cart->prices['billDiscountAmount']);
                foreach ($ref->cart->prices as $key => $val) {
                    if (!empty($ref->cart->products[$key])) {
                        if (is_array($val)) {
                            $billD -= abs($val['subtotal_discount']);
                        }
                    }
                }
                $billD = abs($billD) * -1;
                $prices_new['billTotal'] = $billD;
                if (!empty($billD)) {
                    $coupon_display_before = $currencyDisplay->createPriceDiv('billTotal', '', $prices_new, false, false, 1);
                } else {
                    $coupon_display_before = '';
                }
                break;
            case 'sum':
                $billD = 0;
                foreach ($ref->cart->prices as $key => $val) {
                    if (!empty($ref->cart->products[$key])) {
                        if (is_array($val)) {
                            $billD += $val['subtotal_discount'];
                        }
                    }
                }
                $billD = abs($billD) * -1;
                $prices_new['billTotal'] = $billD;
                if (!empty($billD)) {
                    $coupon_display_before = $currencyDisplay->createPriceDiv('billTotal', '', $prices_new, false, false, 1);
                } else {
                    $coupon_display_before = '';
                }
                break;
        }
        $coupon_display_before = str_replace('class="', 'class="opc_', $coupon_display_before);
        //else $coupon_display_before = '';
        $opc_show_weight_display = '';
        if (!empty($opc_show_weight) && !empty($totalw)) {
            $dec = $currencyDisplay->getDecimalSymbol();
            $th = $currencyDisplay->getThousandsSeperator();
            $w = VmConfig::get('weight_unit_default', 'KG');
            $w = strtoupper($w);
            if ($w == 'OZ') {
                $w = 'OUNCE';
            }
            $unit = JText::_('COM_VIRTUEMART_UNIT_SYMBOL_' . $w);
            if ($unit == 'COM_VIRTUEMART_UNIT_SYMBOL_' . $w) {
                $unit = $w = VmConfig('weight_unit_default', 'kg');
            }
            $opc_show_weight_display = number_format($totalw, 2, $dec, $th) . ' ' . $unit;
        }
        if (!empty($ajaxify_cart)) {
            $coupon_text = $ref->cart->couponCode ? OPCLang::_('COM_VIRTUEMART_COUPON_CODE_CHANGE') : OPCLang::_('COM_VIRTUEMART_COUPON_CODE_ENTER');
            $vars = array('coupon_text' => $coupon_text, 'coupon_display' => $coupon_display);
            $op_coupon_ajax = $OPCloader->fetch($OPCloader, 'couponField_ajax', $vars);
            if (stripos($op_coupon_ajax, 'Onepage.setCouponAjax') === false) {
                $op_coupon_ajax = str_replace('type="button', 'onclick="return Onepage.setCouponAjax(this);" type="button', $op_coupon_ajax);
            }
        }
        if (empty($subtotal_price_display)) {
            $subtotal_price_display = 'salesPrice';
        }
        if ($subtotal_price_display != 'diffTotals') {
            $subtotal_display = $currencyDisplay->createPriceDiv($subtotal_price_display, '', $ref->cart->prices, false, false, 1);
            if ($subtotal_price_display == 'basePriceWithTax') {
                if (stripos($subtotal_display, ' ></span') !== false) {
                    $subtotal_price_display = 'salesPrice';
                    $subtotal_display = $currencyDisplay->createPriceDiv($subtotal_price_display, '', $ref->cart->prices, false, false, 1);
                }
            }
        } else {
            $subtotal = $ref->cart->prices['billTotal'] - $ref->cart->prices['billTaxAmount'];
            $arr = array('diffTotals' => $subtotal);
            $subtotal_display = $currencyDisplay->createPriceDiv($subtotal_price_display, '', $arr, false, false, 1);
        }
        //$ref->cart->prices['salesPrice'];
        $subtotal_display = str_replace('class="', 'class="opc_', $subtotal_display);
        $prices = $ref->cart->prices;
        if (!isset($prices[$subtotal_price_display . 'Shipment'])) {
            if ($subtotal_price_display != 'salesPrice') {
                $order_shipping = $prices['shipmentValue'];
            } else {
                $order_shipping = $prices['salesPriceShipment'];
            }
        } else {
            $order_shipping = $prices[$subtotal_price_display . 'Shipment'];
        }
        if (!empty($order_shipping)) {
            $virtuemart_currency_id = OPCloader::getCurrency($ref->cart);
            $order_shipping = $currencyDisplay->convertCurrencyTo($virtuemart_currency_id, $order_shipping, false);
            $test = $currencyDisplay->createPriceDiv($product_price_display, '', $order_shipping, false, true, 1);
            if (!empty($test)) {
                $order_shipping = $test;
            }
            $order_shipping = str_replace('class="', 'class="opc_', $order_shipping);
        } else {
            $order_shipping = '';
        }
        $continue_link = $OPCloader->getContinueLink($ref);
        $order_total_display = $currencyDisplay->createPriceDiv('billTotal', '', $ref->cart->prices, false, false, 1);
        //$ref->cart->prices['billTotal'];
        $order_total_display = str_replace('class="', 'class="opc_', $order_total_display);
        // this will need a little tuning
        foreach ($ref->cart->cartData['taxRulesBill'] as $rule) {
            $rulename = $rule['calc_name'];
            if (!empty($ref->cart->prices[$rule['virtuemart_calc_id'] . 'Diff'])) {
                $tax_display = $currencyDisplay->createPriceDiv($rule['virtuemart_calc_id'] . 'Diff', '', $ref->cart->prices, false, false, 1);
                //$ref->cart->prices[$rule['virtuemart_calc_id'].'Diff'];
                $tax_display = str_replace('class="', 'class="opc_', $tax_display);
            } else {
                $tax_display = '';
            }
        }
        $op_disable_shipping = OPCloader::getShippingEnabled($ref->cart);
        if (!empty($payment_discount_before) && !empty($coupon_display_before)) {
            $discount_before = true;
        } else {
            $discount_before = false;
        }
        $disable_couponns = VmConfig::get('coupons_enable', true);
        if (empty($disable_couponns)) {
            $op_coupon = $op_coupon_ajax = '';
        }
        if (!empty($op_coupon_ajax)) {
            $op_coupon = $op_coupon_ajax;
        }
        if ($isexpress) {
            $payment_inside_basket = false;
        }
        if (empty($payment_inside_basket)) {
            $payment_select = '';
        }
        if (empty($shipping_inside_basket)) {
            $shipping_select = '';
        }
        if (empty($tax_display)) {
            $tax_display = '';
        }
        if (empty($op_disable_shipping)) {
            $op_disable_shipping = false;
        }
        $no_shipping = $op_disable_shipping;
        $vars = array('product_rows' => $product_rows, 'payment_inside_basket' => $payment_inside_basket, 'shipping_select' => $shipping_select, 'payment_select' => $payment_select, 'shipping_inside_basket' => $shipping_inside_basket, 'coupon_display' => $coupon_display, 'subtotal_display' => $subtotal_display, 'no_shipping' => $no_shipping, 'order_total_display' => $order_total_display, 'tax_display' => $tax_display, 'VM_LANG' => $VM_LANG, 'op_coupon_ajax' => $op_coupon_ajax, 'continue_link' => $continue_link, 'coupon_display_before' => $coupon_display_before, 'discount_before' => $discount_before, 'discount_after' => $discount_after, 'order_shipping' => $order_shipping, 'cart' => $ref->cart, 'op_coupon' => $op_coupon, 'opc_show_weight_display' => $opc_show_weight_display);
        //original cart support:
        $ref->cart->cartData['shipmentName'] = '';
        $ref->cart->cartData['paymentName'] = '';
        $totalInPaymentCurrency = $ref->getTotalInPaymentCurrency();
        $cd = CurrencyDisplay::getInstance($ref->cart->pricesCurrency);
        $layoutName = 'default';
        $confirm = 'confirm';
        $shippingText = '';
        $paymentText = '';
        $checkout_link_html = '';
        $useSSL = VmConfig::get('useSSL', 0);
        $useXHTML = true;
        $checkoutAdvertise = '';
        if (!class_exists('OPCrenderer')) {
            require JPATH_SITE . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'renderer.php';
        }
        $renderer = OPCrenderer::getInstance();
        if (method_exists($renderer, 'assignRef')) {
            $renderer->assignRef('cart', $renderer->cart);
            $renderer->assignRef('totalInPaymentCurrency', $totalInPaymentCurrency);
            $renderer->assignRef('layoutName', $layoutName);
            $renderer->assignRef('select_shipment_text', $shippingText);
            $renderer->assignRef('checkout_task', $confirm);
            $renderer->assignRef('currencyDisplay', $cd);
            $renderer->assignRef('select_payment_text', $paymentText);
            $renderer->assignRef('checkout_link_html', $checkout_link_html);
            $renderer->assignRef('useSSL', $useSSL);
            $renderer->assignRef('useXHTML', $useXHTML);
            $renderer->assignRef('totalInPaymentCurrency', $totalInPaymentCurrency);
            $renderer->assignRef('checkoutAdvertise', $checkoutAdvertise);
        }
        if (empty($use_original_basket)) {
            $html = $renderer->fetch($OPCloader, 'basket.html', $vars);
        } else {
            $html = $renderer->fetchBasket($OPCloader, 'basket.html', $vars);
        }
        if ($withwrapper) {
            $html = '<div id="opc_basket">' . $html . '</div>';
        }
        if (!empty($op_no_basket)) {
            $html = '<div style="display: none;">' . $html . '</div>';
        }
        if (isset($currencyDisplay->_priceConfig)) {
            $currencyDisplay->_priceConfig = $savedConfig;
        }
        $ret = $html . $google_html;
        return $ret;
    }
Exemple #5
0
 function getCachedShipping(&$cart, &$prices, $shipping_id, &$calc, $data = array())
 {
     if (!isset(OPCloader::$totalIsZero)) {
         OPCloader::$totalIsZero = true;
     }
     // cache dimensions:
     // this is a product hash (quantity, attributes, weight, etc..)
     include JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'config' . DS . 'onepage.cfg.php';
     self::$count++;
     $savedcoupon = $cart->couponCode;
     $data[] = $shipping_id;
     if (!empty($opc_calc_cache)) {
         $hash = OPCcache::getGeneralCacheHash('calc', $cart, $data);
     }
     $saved_id = $cart->virtuemart_shipmentmethod_id;
     //opc_request_cache
     if (class_exists('calculationHelperOPC')) {
         calculationHelperOPC::$_forhash = $hash;
     }
     // overrided class with the above hash knows if to re-fetch the shipping
     if (!empty($opc_request_cache)) {
         OPCcache::$cachedResult['currentshipping'] = $shipping_id;
         if (!empty(OPCcache::$cachedResult['shippingcache'][$shipping_id])) {
             $cart->virtuemart_shipmentmethod_id = (int) $cart->virtuemart_shipmentmethod_id;
             $cart->virtuemart_shipmentmethod_id = abs($cart->virtuemart_shipmentmethod_id) * -1;
         }
     }
     $vm2015 = false;
     if (method_exists($calc, 'getCheckoutPricesOPC')) {
         $prices = $calc->getCheckoutPricesOPC($cart, false);
         if (method_exists($calculator, 'getCartData')) {
             $cart->OPCCartData = $calc->getCartData();
         }
     } else {
         $prices = OPCloader::getCheckoutPrices($cart, false, $vm2015, 'opc');
     }
     if (!empty($prices['billTotal'])) {
         // special case for zero value orders, do not charge payment fee:
         if ($prices['billTotal'] == $prices['paymentValue']) {
             $savedp = $cart->virtuemart_paymentmethod_id;
             $cart->virtuemart_paymentmethod_id = 0;
             if (method_exists($calc, 'getCheckoutPricesOPC')) {
                 $prices = $calc->getCheckoutPricesOPC($cart, false);
             } else {
                 $prices = OPCloader::getCheckoutPrices($cart, false, $vm2015, 'opc');
             }
         }
     }
     if (!empty($prices['billTotal'])) {
         OPCloader::$totalIsZero = false;
     }
     OPCloader::opcDebug('OPC: getCheckoutPrices from ajaxhelper.php');
     OPCloader::opcDebug($prices);
     if (isset($cart->OPCCartData)) {
         OPCloader::opcDebug($cart->OPCCartData);
     }
     if (!empty($opc_request_cache)) {
         if (!empty($saved_id)) {
             $sprice['shipmentValue'] = $prices['shipmentValue'];
             $sprice['shipmentTax'] = $prices['shipmentTax'];
             $sprice['salesPriceShipment'] = $prices['salesPriceShipment'];
             $sprice['shipment_calc_id'] = $prices['shipment_calc_id'];
             $sprice['shipmentName'] = @$prices['shipmentName'];
             OPCcache::storeShipingCalculation($cart, $sprice, $sprice['shipmentName'], $shipping_id);
         }
     }
     // in case calculation invalidates it:
     $cart->virtuemart_shipmentmethod_id = $saved_id;
     $cart->couponCode = $savedcoupon;
 }