/** * Only returns plugins that have a specific event * * @param $eventName * @param $folder * @return array of JTable objects */ public static function getPluginsWithEvent($eventName, $folder = 'J2Store') { $return = array(); if ($plugins = J2StoreHelperPlugin::getPlugins($folder)) { foreach ($plugins as $plugin) { if (J2StoreHelperPlugin::hasEvent($plugin, $eventName)) { $return[] = $plugin; } } } return $return; }
function shipping_payment_method() { $app = JFactory::getApplication(); $view = $this->getView('checkout', 'html'); $task = JRequest::getVar('task'); $model = $this->getModel('checkout'); $cart_helper = new J2StoreHelperCart(); $cart_model = $this->getModel('mycart'); if (!$cart_helper->hasProducts()) { $msg = JText::_('J2STORE_NO_ITEMS_IN_CART'); $link = JRoute::_('index.php?option=com_j2store&view=mycart'); $app->redirect($link, $msg); } //prepare order $order = $this->_order; $order = $this->populateOrder(false); // get the order totals $order->calculateTotals(); //print_r($order->order_discount); //print_r($order->order_tax); $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('j2store'); //custom fields $selectableBase = J2StoreFactory::getSelectableBase(); $view->assign('fieldsClass', $selectableBase); $address_table = JTable::getInstance('address', 'Table'); $fields = $selectableBase->getFields('payment', $address, 'address'); $view->assign('fields', $fields); $view->assign('address', $address_table); //get layout settings $view->assign('storeProfile', J2StoreHelperCart::getStoreAddress()); //shipping $showShipping = false; if ($this->params->get('show_shipping_address', 0)) { $showShipping = true; } if ($isShippingEnabled = $cart_model->getShippingIsEnabled()) { $showShipping = true; //$this->setShippingMethod(); } $view->assign('showShipping', $showShipping); if ($showShipping) { $rates = $this->getShippingRates(); $shipping_layout = "shipping_yes"; // if (!$this->session->has('shipping_address_id', 'j2store')) // { // $shipping_layout = "shipping_calculate"; // } $shipping_method_form = $this->getShippingHtml($shipping_layout); $view->assign('showShipping', $showShipping); $view->assign('shipping_method_form', $shipping_method_form); $view->assign('rates', $rates); } //process payment plugins $showPayment = true; if ((double) $order->order_total == (double) '0.00') { $showPayment = false; } $view->assign('showPayment', $showPayment); require_once JPATH_SITE . '/components/com_j2store/helpers/plugin.php'; $payment_plugins = J2StoreHelperPlugin::getPluginsWithEvent('onJ2StoreGetPaymentPlugins'); $plugins = array(); if ($payment_plugins) { foreach ($payment_plugins as $plugin) { $results = $dispatcher->trigger("onJ2StoreGetPaymentOptions", array($plugin->element, $order)); if (in_array(true, $results, true)) { $plugins[] = $plugin; } } } if (count($plugins) == 1) { $plugins[0]->checked = true; //ob_start(); $html = $this->getPaymentForm($plugins[0]->element, true); //$html = json_decode( ob_get_contents() ); //ob_end_clean(); $view->assign('payment_form_div', $html); } //print_r($plugins); $view->assign('plugins', $plugins); //also set the payment methods to session //terms and conditions if ($this->params->get('termsid')) { $tos_link = JRoute::_('index.php?option=com_content&view=article&tmpl=component&id=' . $this->params->get('termsid')); } else { $tos_link = null; } $view->assign('tos_link', $tos_link); //Get and Set Model $view->setModel($model, true); $view->assign('order', $order); $view->assign('params', $this->params); $view->setLayout('checkout_shipping_payment'); ob_start(); $view->display(); $html = ob_get_contents(); ob_end_clean(); echo $html; $app->close(); }