function update() { $currency = JRequest::getInt('hikashopcurrency', 0); if (!empty($currency)) { $app = JFactory::getApplication(); $app->setUserState(HIKASHOP_COMPONENT . '.currency_id', $currency); $url = JRequest::getString('return_url', ''); if (!empty($url)) { if (hikashop_disallowUrlRedirect($url)) { return false; } $app->redirect(urldecode($url)); } return true; } $ratePlugin = hikashop_import('hikashop', 'rates'); if ($ratePlugin) { $ratePlugin->updateRates(); } else { if (!HIKASHOP_PHP5) { $app =& JFactory::getApplication(); } else { $app = JFactory::getApplication(); } $app->enqueueMessage('Currencies rates auto update plugin not found !', 'error'); } $this->listing(); }
function show() { $user = hikashop_loadUser(true); $userClass = hikashop_get('class.user'); $userClass->loadPartnerData($user); $config =& hikashop_config(); if (empty($user->user_params->user_custom_fee)) { $user->user_params->user_partner_click_fee = $config->get('partner_click_fee', 0); $user->user_params->user_partner_lead_fee = $config->get('partner_lead_fee', 0); $user->user_params->user_partner_percent_fee = $config->get('partner_percent_fee', 0); $user->user_params->user_partner_flat_fee = $config->get('partner_flat_fee', 0); } $query = 'SELECT * FROM ' . hikashop_table('banner') . ' WHERE banner_published=1 ORDER BY banner_ordering ASC;'; $database = JFactory::getDBO(); $database->setQuery($query); $banners = $database->loadObjectList(); $this->assignRef('banners', $banners); $advanced_stats = $config->get('affiliate_advanced_stats', 1); $this->assignRef('advanced_stats', $advanced_stats); $this->assignRef('user', $user); $currencyType = hikashop_get('type.currency'); $this->assignRef('currencyType', $currencyType); $currencyHelper = hikashop_get('class.currency'); $this->assignRef('currencyHelper', $currencyHelper); $popup = hikashop_get('helper.popup'); $this->assignRef('popup', $popup); JHTML::_('behavior.tooltip'); $affiliate_plugin = hikashop_import('system', 'hikashopaffiliate'); $partner_id = (int) @$user->user_id; $this->assignRef('partner_id', $partner_id); $partner_info = $affiliate_plugin->params->get('partner_key_name', 'partner_id') . '=' . $partner_id; $this->assignRef('partner_info', $partner_info); $allow_currency_selection = $config->get('allow_currency_selection'); $this->assignRef('allow_currency_selection', $allow_currency_selection); if (empty($this->user->user_id)) { $app = JFactory::getApplication(); global $Itemid; $url = ''; if (!empty($Itemid)) { $url = '&Itemid=' . $Itemid; } if (!HIKASHOP_J16) { $url = 'index.php?option=com_user&view=login' . $url; } else { $url = 'index.php?option=com_users&view=login' . $url; } $url = JRoute::_($url . '&return=' . urlencode(base64_encode(hikashop_currentUrl('', false)))); $app->enqueueMessage('<a href="' . $url . '">' . JText::_('PLEASE_LOGIN_FIRST') . '</a>'); } $config =& hikashop_config(); $affiliate_terms = $config->get('affiliate_terms', 0); $this->assignRef('affiliate_terms', $affiliate_terms); hikashop_setPageTitle('AFFILIATE'); }
function loadCurrentPlugin($id, $name) { static $plugins = array(); if (!isset($plugins[$id])) { $plugins[$id] = hikashop_import('payment', $name); $plugins[$id]->params =& $this; JPluginHelper::importPlugin('payment'); $plugin = JPluginHelper::getPlugin('payment', $name); if (is_object($plugin)) { $plugin->params = json_encode($this->payment_params); } } return $plugins[$id]; }
function trigger() { $cid = JRequest::getInt('cid', 0); $function = 'productDisplay'; if (empty($cid) || empty($function)) { return false; } $pluginsClass = hikashop_get('class.plugins'); $plugin = $pluginsClass->get($cid); if (empty($plugin)) { return false; } $plugin = hikashop_import($plugin->folder, $plugin->element); if (method_exists($plugin, $function)) { return $plugin->{$function}(); } return false; }
protected function processPaymentNotification() { if (!(include_once rtrim(JPATH_ADMINISTRATOR, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_hikashop' . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'helper.php')) { return; } JRequest::setVar('hikashop_payment_notification_plugin', true); ob_start(); $payment = JRequest::getCmd('notif_payment', @$_REQUEST['notif_payment']); $data = hikashop_import('hikashoppayment', $payment); if (!empty($data)) { $trans = hikashop_get('helper.translation'); $cleaned_statuses = $trans->getStatusTrans(); $data = $data->onPaymentNotification($cleaned_statuses); } $dbg = ob_get_clean(); if (!empty($dbg)) { $config =& hikashop_config(); jimport('joomla.filesystem.file'); $file = $config->get('payment_log_file', ''); $file = rtrim(JPath::clean(html_entity_decode($file)), DIRECTORY_SEPARATOR . ' '); if (!preg_match('#^([A-Z]:)?/.*#', $file) && (!$file[0] == '/' || !file_exists($file))) { $file = JPath::clean(HIKASHOP_ROOT . DIRECTORY_SEPARATOR . trim($file, DIRECTORY_SEPARATOR . ' ')); } if (!empty($file) && defined('FILE_APPEND')) { if (!file_exists(dirname($file))) { jimport('joomla.filesystem.folder'); JFolder::create(dirname($file)); } file_put_contents($file, $dbg, FILE_APPEND); } } if (is_string($data) && !empty($data)) { echo $data; } exit; }
function address() { $app = JFactory::getApplication(); $addresses = array(); $fields = null; $user_id = hikashop_loadUser(); if ($user_id) { $class = hikashop_get('class.address'); $addresses = $class->loadUserAddresses($user_id); if (!empty($addresses)) { $addressClass = hikashop_get('class.address'); $addressClass->loadZone($addresses); $fields =& $addressClass->fields; } } $cart = $this->initCart(); if (!$this->has_shipping) { $app->setUserState(HIKASHOP_COMPONENT . '.shipping_method', null); $app->setUserState(HIKASHOP_COMPONENT . '.shipping_id', null); $app->setUserState(HIKASHOP_COMPONENT . '.shipping_data', null); $app->setUserState(HIKASHOP_COMPONENT . '.shipping_address', null); } $this->assignRef('fields', $fields); $this->assignRef('addresses', $addresses); $fieldsClass = hikashop_get('class.field'); $this->assignRef('fieldsClass', $fieldsClass); $identified = (bool) $user_id; $this->assignRef('identified', $identified); JHTML::_('behavior.modal'); $billing_address = $app->getUserState(HIKASHOP_COMPONENT . '.billing_address'); if (empty($billing_address) && count($addresses)) { $address = reset($addresses); $app->setUserState(HIKASHOP_COMPONENT . '.shipping_address', $address->address_id); $app->setUserState(HIKASHOP_COMPONENT . '.billing_address', $address->address_id); $class = hikashop_get('class.cart'); $class->loadAddress($cart, $address->address_id); $cart->billing_address =& $cart->shipping_address; } $shipping_address = $app->getUserState(HIKASHOP_COMPONENT . '.shipping_address'); $billing_address = $app->getUserState(HIKASHOP_COMPONENT . '.billing_address'); $this->assignRef('shipping_address', $shipping_address); $this->assignRef('billing_address', $billing_address); $shipping_method = $app->getUserState(HIKASHOP_COMPONENT . '.shipping_method'); if (empty($shipping_method)) { $shipping_method = array(); } if (!is_array($shipping_method)) { $shipping_method = array($shipping_method); } $currentShipping = array(); if (count($shipping_method) == 1) { foreach ($shipping_method as $method) { $method = explode('@', $method); $method = $method[0]; $currentShipping[] = hikashop_import('hikashopshipping', $method); } } $this->assignRef('currentShipping', $currentShipping); $js = "\nfunction hikashopEditAddress(obj,val,new_address){\n\tvar same_address = document.getElementById('same_address');\n\tif(val && same_address && (new_address && same_address.checked || !new_address && !same_address.checked)){\n\t\tvar nextChar = '?';\n\t\tif(obj.href.indexOf('?')!='-1'){ nextChar='&'; }\n\t\tobj.href+=nextChar+'makenew=1';\n\t}\n\twindow.hikashop.openBox(obj,obj.href);\n\treturn false;\n}\nfunction hikashopSameAddress(value){\n\tvar shipdiv = document.getElementById('hikashop_checkout_shipping_div');\n\tif(shipdiv){\n\t\tif(!value){\n\t\t\tshipdiv.style.display='';\n\t\t}else{\n\t\t\tshipdiv.style.display='none';\n\t\t}\n\t}\n\treturn true;\n}"; if (!HIKASHOP_PHP5) { $doc =& JFactory::getDocument(); } else { $doc = JFactory::getDocument(); } $doc->addScriptDeclaration("\n<!--\n" . $js . "\n//-->\n"); }
function pluginsEnabled($elementPkey, &$value, $task = 'enabled') { $plugins = hikashop_get('class.plugins'); $obj = new stdClass(); if (!HIKASHOP_J16) { $obj->id = $elementPkey; } else { $obj->extension_id = $elementPkey; } $obj->{$task} = $value; $plugins->save($obj); $result = $plugins->get($elementPkey); if ($result) { if ($result->{$task} != $value) { $value = $result->{$task}; } if ($result->folder != 'hikashop') { $type = str_replace('hikashop', '', $result->folder); $db = JFactory::getDBO(); $type_name = $type . '_type'; if ($type == 'payment' || $type == 'shipping') { $db->setQuery('SELECT * FROM ' . hikashop_table($type) . ' WHERE ' . $type_name . '=\'' . $result->element . '\''); $data = $db->loadObject(); } if (empty($data)) { $plugin = hikashop_import($result->folder, $result->element); if ($plugin && method_exists($plugin, 'onPaymentConfiguration')) { $obj = null; $plugin->onPaymentConfiguration($obj); if (!empty($obj) && is_array($obj) && count($obj) > 0) { $obj = reset($obj); $params_name = $type . '_params'; if (!empty($obj->{$params_name}) && !is_string($obj->{$params_name})) { $obj->{$params_name} = serialize($obj->{$params_name}); } $class = hikashop_get('class.' . $type); $class->save($obj); $pluginsClass = hikashop_get('class.plugins'); $pluginsClass->cleanPluginCache(); } } } } } }
function pay_process() { $order_id = hikashop_getCID('order_id'); if (empty($order_id)) { return false; } $orderClass = hikashop_get('class.order'); $order = $orderClass->get($order_id); $userClass = hikashop_get('class.user'); $user = $userClass->get($order->order_user_id); $orderClass->loadProducts($order); $order->cart->products =& $order->products; $pluginClass = hikashop_get('class.plugins'); $methods = $pluginClass->getMethods('payment'); $methods[$order->order_payment_id]->payment_params->address_type = ''; $methods[$order->order_payment_id]->payment_params->cancel_url = HIKASHOP_LIVE . 'administrator/index.php?option=com_hikashop&ctrl=user&task=edit&user_id=' . $user->user_id; $methods[$order->order_payment_id]->payment_params->return_url = HIKASHOP_LIVE . 'administrator/index.php?option=com_hikashop&ctrl=user&task=edit&user_id=' . $user->user_id; $methods[$order->order_payment_id]->payment_params->email = $user->user_partner_email; $data = hikashop_import('hikashoppayment', $order->order_payment_method); $data->onAfterOrderConfirm($order, $methods, $order->order_payment_id); }
function onCheckoutStepDisplay($layoutName, &$html, &$view) { if ($layoutName != 'plg.shop.userpoints') { return; } $this->_readOptions(); if (empty($this->plugin_options['checkout_step'])) { return; } switch ($this->plugin_options['show_points']) { case 'aup': $points = $this->getUserPoints(null, 'aup'); break; case 'hk': default: $points = $this->getUserPoints(null, 'hk'); break; } if ($points === false) { return; } if (!empty($this->plugin_options['hide_when_no_points']) && empty($points)) { return; } $app = JFactory::getApplication(); $currencyClass = hikashop_get('class.currency'); $consume = null; $discount = ''; $earn_points = false; $use_coupon = 1 - (int) $app->getUserState(HIKASHOP_COMPONENT . '.userpoints_no_virtual_coupon', (int) (@$this->plugin_options['checkout_step'] && @$this->plugin_options['default_no_use'])); $paymentUserPoints = hikashop_import('hikashoppayment', 'userpoints'); if (!empty($paymentUserPoints)) { $cart = $view->initCart(); $consume = $paymentUserPoints->getCartUsedPoints($cart); if (!empty($consume) && $consume['mode'] != $this->plugin_options['show_points']) { $consume = null; } if (!empty($this->plugin_options['show_earn_points'])) { $earn_points = 0; $this->onGetUserPointsEarned($cart, $earn_points, $this->plugin_options['show_points']); } if (!empty($consume)) { if (isset($cart->order_currency_id)) { $currency_id = $cart->order_currency_id; } else { $currency_id = hikashop_getCurrency(); } $discount = $currencyClass->format($consume['value'], $currency_id); } } $app = JFactory::getApplication(); $path = JPATH_THEMES . DS . $app->getTemplate() . DS . 'plg_hikashop_userpoints' . DS . 'checkout.php'; if (!file_exists($path)) { if (version_compare(JVERSION, '1.6', '<')) { $path = JPATH_PLUGINS . DS . 'hikashop' . DS . 'userpoints_checkout.php'; } else { $path = JPATH_PLUGINS . DS . 'hikashop' . DS . 'userpoints' . DS . 'userpoints_checkout.php'; } } if (!file_exists($path)) { return false; } require $path; }
function getShippingName($shipping_method, $shipping_id) { $shipping_name = $shipping_method . ' ' . $shipping_id; if (strpos($shipping_id, '-') !== false) { $shipping_ids = explode('-', $shipping_id, 2); $shipping = $this->shippingClass->get($shipping_ids[0]); if (!empty($shipping->shipping_params) && is_string($shipping->shipping_params)) { $shipping->shipping_params = unserialize($shipping->shipping_params); } $shippingMethod = hikashop_import('hikashopshipping', $shipping_method); $methods = $shippingMethod->shippingMethods($shipping); if (isset($methods[$shipping_id])) { $shipping_name = $shipping->shipping_name . ' - ' . $methods[$shipping_id]; } else { $shipping_name = $shipping_id; } } return $shipping_name; }
function loadFullOrder($order_id, $additionalData = false, $checkUser = true) { $order = $this->get($order_id); $app = JFactory::getApplication(); $type = 'frontcomp'; if (empty($order)) { return null; } $userClass = hikashop_get('class.user'); $order->customer = $userClass->get($order->order_user_id); if ($app->isAdmin()) { if (hikashop_level(1)) { $query = 'SELECT * FROM ' . hikashop_table('geolocation') . ' WHERE geolocation_type=\'order\' AND geolocation_ref_id=' . $order_id; $this->database->setQuery($query); $order->geolocation = $this->database->loadObject(); } $query = 'SELECT * FROM ' . hikashop_table('history') . ' WHERE history_order_id=' . $order_id . ' ORDER BY history_created DESC'; $this->database->setQuery($query); $order->history = $this->database->loadObjectList(); if (!empty($order->order_partner_id)) { $order->partner = $userClass->get($order->order_partner_id); } $type = 'backend'; } elseif ($checkUser && hikashop_loadUser() != $order->order_user_id) { return null; } $this->orderNumber($order); $order->order_subtotal = $order->order_full_price + $order->order_discount_price - $order->order_shipping_price - $order->order_payment_price; $this->loadAddress($order->order_shipping_address_id, $order, 'shipping', 'name', $type); $this->loadAddress($order->order_billing_address_id, $order, 'billing', 'name', $type); if (empty($order->fields)) { $fieldClass = hikashop_get('class.field'); $order->fields = $fieldClass->getData($type, 'address'); } if (!empty($order->order_payment_params) && is_string($order->order_payment_params)) { $order->order_payment_params = unserialize($order->order_payment_params); } if (!empty($order->order_shipping_params) && is_string($order->order_shipping_params)) { $order->order_shipping_params = unserialize($order->order_shipping_params); } if (!empty($order->order_shipping_id)) { $order->shippings = array(); if (strpos($order->order_shipping_id, ';') !== false) { $shipping_ids = explode(';', $order->order_shipping_id); } else { $shipping_ids = array($order->order_shipping_id); } JArrayHelper::toInteger($shipping_ids); $query = 'SELECT * FROM ' . hikashop_table('shipping') . ' WHERE shipping_id IN (' . implode(',', $shipping_ids) . ')'; $this->database->setQuery($query); $order->shippings = $this->database->loadObjectList('shipping_id'); } if (!empty($order->order_shipping_method)) { $currentShipping = hikashop_import('hikashopshipping', $order->order_shipping_method); if (method_exists($currentShipping, 'getShippingAddress')) { $override = $currentShipping->getShippingAddress($order->order_shipping_id); if ($override !== false) { $order->override_shipping_address = $override; } } } $this->loadProducts($order); if (!empty($order->additional)) { foreach ($order->additional as $additional) { $order->order_subtotal -= $additional->order_product_price - $additional->order_product_tax; } } $order->order_subtotal_no_vat = 0; JPluginHelper::importPlugin('hikashop'); $dispatcher = JDispatcher::getInstance(); foreach ($order->products as $k => $product) { $dispatcher->trigger('onBeforeCalculateProductPriceForQuantityInOrder', array(&$order->products[$k])); if (function_exists('hikashop_product_price_for_quantity_in_order')) { hikashop_product_price_for_quantity_in_order($order->products[$k]); } else { $order->products[$k]->order_product_total_price_no_vat = $product->order_product_price * $product->order_product_quantity; $order->products[$k]->order_product_total_price = ($product->order_product_price + $product->order_product_tax) * $product->order_product_quantity; } $dispatcher->trigger('onAfterCalculateProductPriceForQuantityInOrder', array(&$order->products[$k])); $order->order_subtotal_no_vat += $order->products[$k]->order_product_total_price_no_vat; if (!empty($product->order_product_options)) { $order->products[$k]->order_product_options = unserialize($product->order_product_options); } } if ($additionalData) { $this->getOrderAdditionalInfo($order); } return $order; }
function import() { JRequest::checkToken('request') || die('Invalid Token'); $function = JRequest::getCmd('importfrom'); $this->helper->addTemplate(JRequest::getInt('template_product', 0)); switch ($function) { case 'file': $this->_file(); break; case 'textarea': $this->_textarea(); break; case 'folder': if (hikashop_level(2)) { $this->_folder(); } else { $app =& JFactory::getApplication(); $app->enqueueMessage(Text::_('ONLY_FROM_HIKASHOP_BUSINESS'), 'error'); } break; case 'vm': $query = 'SHOW TABLES LIKE ' . $this->db->Quote($this->db->getPrefix() . substr(hikashop_table('virtuemart_products', false), 3)); $this->db->setQuery($query); $table = $this->db->loadResult(); if (empty($table)) { $query = 'SHOW TABLES LIKE ' . $this->db->Quote($this->db->getPrefix() . substr(hikashop_table('vm_product', false), 3)); $this->db->setQuery($query); $table = $this->db->loadResult(); if (empty($table)) { $app =& JFactory::getApplication(); $app->enqueueMessage('VirtueMart has not been found in the database', 'error'); } else { $this->helperImport = hikashop_get('helper.import-vm1', $this); $this->_vm(); } } else { $this->helperImport = hikashop_get('helper.import-vm2', $this); $this->_vm(); } break; case 'mijo': $this->helperImport = hikashop_get('helper.import-mijo', $this); $query = 'SHOW TABLES LIKE ' . $this->db->Quote($this->db->getPrefix() . substr(hikashop_table('mijoshop_product', false), 3)); $this->db->setQuery($query); $table = $this->db->loadResult(); if (empty($table)) { $app =& JFactory::getApplication(); $app->enqueueMessage('Mijoshop has not been found in the database', 'error'); } else { $this->_mijo(); } break; case 'redshop': $this->helperImport = hikashop_get('helper.import-reds', $this); $query = 'SHOW TABLES LIKE ' . $this->db->Quote($this->db->getPrefix() . substr(hikashop_table('redshop_product', false), 3)); $this->db->setQuery($query); $table = $this->db->loadResult(); if (empty($table)) { $app =& JFactory::getApplication(); $app->enqueueMessage('Redshop has not been found in the database', 'error'); } else { $this->_redshop(); } break; case 'openc': $this->helperImport = hikashop_get('helper.import-openc', $this); $this->_opencart(); break; default: $plugin = hikashop_import('hikashop', $function); if ($plugin) { $plugin->onImportRun(); } break; } return $this->show(); }
function after_confirm($success) { if (!$success) { return false; } if (!JRequest::getVar('validate', 0)) { return false; } if ($this->current == $this->previous) { return true; } foreach ($this->steps as $i => $step) { $this->_checkStep(trim($step), $i); } $app = JFactory::getApplication(); $db = JFactory::getDBO(); $config =& hikashop_config(); $pluginsClass = hikashop_get('class.plugins'); $cart = $this->initCart(); $shippings = array(); $shipping = $app->getUserState(HIKASHOP_COMPONENT . '.shipping_method'); $shipping_id = $app->getUserState(HIKASHOP_COMPONENT . '.shipping_id'); if (!empty($shipping)) { foreach ($shipping as $ship) { $ship = explode('@', $ship, 2); $current_id = 0; foreach ($shipping_id as $sid) { list($i, $k) = explode('@', $sid, 2); if ($k == $ship[1]) { $current_id = $i; break; } } $shippings[$ship[1]] = array('id' => $current_id, 'name' => $ship[0]); } $shippingClass = hikashop_get('class.shipping'); $methods =& $shippingClass->getShippings($cart); $shipping_groups = $shippingClass->getShippingGroups($cart, $methods); } $payment = $app->getUserState(HIKASHOP_COMPONENT . '.payment_method'); $payment_id = $app->getUserState(HIKASHOP_COMPONENT . '.payment_id'); $ids = array(); foreach ($cart->products as $product) { if ($product->cart_product_quantity > 0 && $product->product_type == 'variant') { $ids[$product->product_id] = $product->product_id; } } if (!empty($ids)) { $database = JFactory::getDBO(); $query = 'SELECT a.variant_product_id as product_id,b.characteristic_id as value_id,b.characteristic_value as value,c.characteristic_id as name_id,c.characteristic_value as name FROM ' . hikashop_table('variant') . ' AS a LEFT JOIN ' . hikashop_table('characteristic') . ' AS b ON a.variant_characteristic_id=b.characteristic_id LEFT JOIN ' . hikashop_table('characteristic') . ' AS c ON b.characteristic_parent_id = c.characteristic_id WHERE a.variant_product_id IN (' . implode(',', $ids) . ')'; $database->setQuery($query); $characteristics = $database->loadObjectList(); if (!empty($characteristics)) { foreach ($characteristics as $characteristic) { foreach ($cart->products as $k => $product) { if ($product->product_id == $characteristic->product_id) { if (empty($product->characteristics)) { $product->characteristics = array($characteristic->name => $characteristic->value); } else { $product->characteristics[$characteristic->name] = $characteristic->value; } } } } } } if (hikashop_level(2)) { $element = null; $fieldsClass = hikashop_get('class.field'); $itemFields = $fieldsClass->getFields('', $element, 'item'); } $products = array(); foreach ($cart->products as $product) { if ($product->cart_product_quantity > 0) { $orderProduct = new stdClass(); $orderProduct->product_id = $product->product_id; $orderProduct->order_product_quantity = $product->cart_product_quantity; if (empty($product->cart_product_option_parent_id)) { $text = $product->product_name; } elseif (empty($optionElement->variant_name)) { if (empty($product->characteristics_text)) { $text = $product->product_name; } else { $text = $product->characteristics_text; } } else { $text = $product->variant_name; } $orderProduct->order_product_name = $text; $orderProduct->cart_product_id = $product->cart_product_id; $orderProduct->cart_product_option_parent_id = $product->cart_product_option_parent_id; $orderProduct->order_product_code = $product->product_code; $orderProduct->order_product_price = @$product->prices[0]->unit_price->price_value; $orderProduct->order_product_wishlist_id = $product->cart_product_wishlist_id; $orderProduct->product_subscription_id = @$product->product_subscription_id; $tax = 0; if (!empty($product->prices[0]->unit_price->price_value_with_tax) && bccomp($product->prices[0]->unit_price->price_value_with_tax, 0, 5)) { $tax = $product->prices[0]->unit_price->price_value_with_tax - $product->prices[0]->unit_price->price_value; } $orderProduct->order_product_tax = $tax; $characteristics = ''; if (!empty($product->characteristics)) { $characteristics = serialize($product->characteristics); } $orderProduct->order_product_options = $characteristics; if (!empty($product->discount)) { $orderProduct->discount = clone $product->discount; $orderProduct->discount->price_value_without_discount = $product->prices[0]->unit_price->price_value_without_discount; $orderProduct->discount->price_value_without_discount_with_tax = @$product->prices[0]->unit_price->price_value_without_discount_with_tax; $orderProduct->discount->taxes_without_discount = @$product->prices[0]->unit_price->taxes_without_discount; } if (!empty($itemFields)) { foreach ($itemFields as $field) { $namekey = $field->field_namekey; if (isset($product->{$namekey})) { $orderProduct->{$namekey} = $product->{$namekey}; } } } if (isset($product->prices[0]->unit_price->taxes)) { $orderProduct->order_product_tax_info = $product->prices[0]->unit_price->taxes; } if (isset($product->files)) { $orderProduct->files =& $product->files; } if (!empty($shipping)) { $shipping_done = false; foreach ($shipping_groups as $group_key => $group_products) { if (!isset($shippings[$group_key])) { continue; } foreach ($group_products->products as $group_product) { if ((int) $group_product->cart_product_id == (int) $product->cart_product_id) { $orderProduct->order_product_shipping_id = $shippings[$group_key]['id'] . '@' . $group_key; $orderProduct->order_product_shipping_method = $shippings[$group_key]['name']; $shipping_done = true; break; } } if ($shipping_done) { break; } } } $products[] = $orderProduct; } } $cart->products =& $products; foreach ($cart->products as $cartContent) { if ((int) $cartContent->order_product_wishlist_id != 0) { $query = 'SELECT * FROM ' . hikashop_table('cart_product') . ' WHERE cart_id =' . (int) $cartContent->order_product_wishlist_id . ' AND product_id=' . (int) $cartContent->product_id; $db->setQuery($query); $wishlistData = $db->loadObject(); $quantity = $wishlistData->cart_product_quantity - $cartContent->order_product_quantity; if ($quantity < 0) { $quantity = 0; } $query = 'UPDATE ' . hikashop_table('cart_product') . ' SET cart_product_quantity = ' . (int) $quantity . ' WHERE cart_id =' . (int) $cartContent->order_product_wishlist_id . ' AND product_id=' . (int) $cartContent->product_id; } } $shipping_address = $app->getUserState(HIKASHOP_COMPONENT . '.shipping_address'); $billing_address = $app->getUserState(HIKASHOP_COMPONENT . '.billing_address'); $main_currency = (int) $config->get('main_currency', 1); $currency_id = (int) $app->getUserState(HIKASHOP_COMPONENT . '.currency_id', $main_currency); $order = new stdClass(); $order->order_user_id = @hikashop_loadUser(); $order->order_status = $config->get('order_created_status'); $order->order_shipping_address_id = $shipping_address; $order->order_billing_address_id = $billing_address; $order->order_discount_code = @$cart->coupon->discount_code; $order->order_currency_id = $cart->full_total->prices[0]->price_currency_id; $order->order_currency_info = new stdClass(); $currencyClass = hikashop_get('class.currency'); $currencies = null; $currencies = $currencyClass->getCurrencies($order->order_currency_id, $currencies); $currency = $currencies[$order->order_currency_id]; $order->order_currency_info->currency_code = $currency->currency_code; $order->order_currency_info->currency_rate = $currency->currency_rate; $order->order_currency_info->currency_percent_fee = $currency->currency_percent_fee; $order->order_currency_info->currency_modified = $currency->currency_modified; $order->order_type = 'sale'; $order->order_full_price = $cart->full_total->prices[0]->price_value_with_tax; $order->order_tax_info = @$cart->full_total->prices[0]->taxes; $order->order_shipping_price = 0.0; $order->order_shipping_tax = 0.0; $order->order_shipping_params = null; if (!empty($cart->shipping)) { $order->order_shipping_params = new stdClass(); $order->order_shipping_params->prices = array(); foreach ($cart->shipping as $cart_shipping) { $price_key = $cart_shipping->shipping_id; if (isset($cart_shipping->shipping_warehouse_id)) { if (is_string($cart_shipping->shipping_warehouse_id) || is_int($cart_shipping->shipping_warehouse_id)) { $price_key .= '@' . $cart_shipping->shipping_warehouse_id; } else { $price_key .= '@'; foreach ($cart_shipping->shipping_warehouse_id as $k => $v) { $price_key .= $k . $v; } } } $order->order_shipping_params->prices[$price_key] = new stdClass(); $order->order_shipping_params->prices[$price_key]->price_with_tax = $cart_shipping->shipping_price_with_tax; $order->order_shipping_price += $cart_shipping->shipping_price_with_tax; if (!empty($cart_shipping->shipping_price_with_tax) && !empty($cart_shipping->shipping_price)) { $order->order_shipping_tax += $cart_shipping->shipping_price_with_tax - $cart_shipping->shipping_price; $order->order_shipping_params->prices[$price_key]->tax = $cart_shipping->shipping_price_with_tax - $cart_shipping->shipping_price; if (!empty($cart_shipping->taxes)) { $order->order_shipping_params->prices[$price_key]->taxes = array(); foreach ($cart_shipping->taxes as $tax) { $order->order_shipping_params->prices[$price_key]->taxes[$tax->tax_namekey] = $tax->tax_amount; if (isset($order->order_tax_info[$tax->tax_namekey])) { if (empty($order->order_tax_info[$tax->tax_namekey]->tax_amount_for_shipping)) { $order->order_tax_info[$tax->tax_namekey]->tax_amount_for_shipping = 0; } $order->order_tax_info[$tax->tax_namekey]->tax_amount_for_shipping += $tax->tax_amount; } elseif (!empty($order->order_tax_info[$tax->tax_namekey]->tax_amount) && $order->order_tax_info[$tax->tax_namekey]->tax_amount > 0) { $order->order_tax_info[$tax->tax_namekey] = $tax; $order->order_tax_info[$tax->tax_namekey]->tax_amount_for_shipping = $order->order_tax_info[$tax->tax_namekey]->tax_amount; $order->order_tax_info[$tax->tax_namekey]->tax_amount = 0; } } } } } } $order->order_payment_price = @$cart->payment->payment_price_with_tax; if (!empty($cart->payment)) { if (!empty($cart->payment->payment_price_with_tax) && !empty($cart->payment->payment_price)) { $order->order_payment_tax = $cart->payment->payment_price_with_tax - $cart->payment->payment_price; if (!empty($cart->payment->taxes)) { foreach ($cart->payment->taxes as $tax) { if (isset($order->order_tax_info[$tax->tax_namekey])) { $order->order_tax_info[$tax->tax_namekey]->tax_amount_for_payment = $tax->tax_amount; } elseif (!empty($order->order_tax_info[$tax->tax_namekey]->tax_amount) && $order->order_tax_info[$tax->tax_namekey]->tax_amount > 0) { $order->order_tax_info[$tax->tax_namekey] = $tax; $order->order_tax_info[$tax->tax_namekey]->tax_amount_for_payment = $order->order_tax_info[$tax->tax_namekey]->tax_amount; $order->order_tax_info[$tax->tax_namekey]->tax_amount = 0; } } } } } $discount_price = 0; $discount_tax = 0; if (!empty($cart->coupon) && !empty($cart->coupon->total->prices[0]->price_value_without_discount_with_tax)) { $discount_price = @$cart->coupon->total->prices[0]->price_value_without_discount_with_tax - @$cart->coupon->total->prices[0]->price_value_with_tax; if (!empty($cart->coupon->total->prices[0]->price_value_with_tax) && !empty($cart->coupon->total->prices[0]->price_value)) { $discount_tax = @$cart->coupon->total->prices[0]->price_value_without_discount_with_tax - @$cart->coupon->total->prices[0]->price_value_without_discount - (@$cart->coupon->total->prices[0]->price_value_with_tax - @$cart->coupon->total->prices[0]->price_value); if (isset($cart->coupon->taxes)) { foreach ($cart->coupon->taxes as $tax) { if (isset($order->order_tax_info[$tax->tax_namekey])) { $order->order_tax_info[$tax->tax_namekey]->tax_amount_for_coupon = $tax->tax_amount; } else { $order->order_tax_info[$tax->tax_namekey] = $tax; $order->order_tax_info[$tax->tax_namekey]->tax_amount_for_coupon = $order->order_tax_info[$tax->tax_namekey]->tax_amount; $order->order_tax_info[$tax->tax_namekey]->tax_amount = 0; } } } } } $order->order_discount_tax = $discount_tax; $order->order_discount_price = $discount_price; $order->order_shipping_id = $shipping_id; $order->order_shipping_method = $shipping; $order->order_payment_id = $payment_id; $order->order_payment_method = $payment; $order->cart =& $cart; $order->history = new stdClass(); $order->history->history_reason = JText::_('ORDER_CREATED'); $order->history->history_notified = 0; $order->history->history_type = 'creation'; $app = JFactory::getApplication(); if (hikashop_level(2)) { $orderData = $app->getUserState(HIKASHOP_COMPONENT . '.checkout_fields'); if (!empty($orderData)) { foreach (get_object_vars($orderData) as $key => $val) { $order->{$key} = $val; } } } if (!empty($shippings)) { if (count($shippings) == 1) { $s = reset($shippings); $order->order_shipping_id = $s['id']; $order->order_shipping_method = $s['name']; } else { $ids = array(); foreach ($shippings as $key => $ship) { $ids[] = $ship['id'] . '@' . $key; } $order->order_shipping_id = implode(';', $ids); $order->order_shipping_method = ''; } } $paymentClass = hikashop_get('class.payment'); $paymentClass->checkPaymentOptions($order); $orderClass = hikashop_get('class.order'); $order->order_id = $orderClass->save($order); $removeCart = false; if (empty($order->order_id)) { return false; } $app->setUserState(HIKASHOP_COMPONENT . '.checkout_fields_ok', 0); $entriesData = $app->getUserState(HIKASHOP_COMPONENT . '.entries_fields'); if (!empty($entriesData)) { $entryClass = hikashop_get('class.entry'); foreach ($entriesData as $entryData) { $entryData->order_id = $order->order_id; $entryClass->save($entryData); } $app->setUserState(HIKASHOP_COMPONENT . '.entries_fields', null); } if (!empty($payment)) { $query = 'SELECT * FROM ' . hikashop_table('payment') . ' WHERE payment_type=' . $db->Quote($payment); $db->setQuery($query); $paymentData = $db->loadObjectList('payment_id'); $pluginsClass->params($paymentData, 'payment'); } else { $paymentData = null; } if (!empty($shipping)) { $shippings_quoted = array(); foreach ($shippings as $ship) { $shippings_quoted[] = $db->Quote($ship['name']); } $query = 'SELECT * FROM ' . hikashop_table('shipping') . ' WHERE shipping_type IN (' . implode(',', $shippings_quoted) . ')'; $db->setQuery($query); $shippingData = $db->loadObjectList('shipping_id'); $pluginsClass->params($shippingData, 'shipping'); } else { $shippingData = null; } ob_start(); if (!empty($shippingData)) { foreach ($shippings as $ship) { $data = hikashop_import('hikashopshipping', $ship['name']); $data->onAfterOrderConfirm($order, $shippingData, $ship['id']); if (!empty($data->removeCart)) { $removeCart = true; } } } if (!empty($paymentData)) { $data = hikashop_import('hikashoppayment', $payment); $data->onAfterOrderConfirm($order, $paymentData, $payment_id); if (!empty($data->removeCart)) { $removeCart = true; } } JRequest::setVar('hikashop_plugins_html', ob_get_clean()); $app->setUserState(HIKASHOP_COMPONENT . '.order_id', $order->order_id); if ($config->get('clean_cart', 'order_created') == 'order_created' || $removeCart) { $cart_id = $app->getUserState(HIKASHOP_COMPONENT . '.cart_id'); if ($cart_id) { $class = hikashop_get('class.cart'); $class->delete($cart_id); $app->setUserState(HIKASHOP_COMPONENT . '.cart_id', 0); } $app->setUserState(HIKASHOP_COMPONENT . '.coupon_code', ''); $app->setUserState(HIKASHOP_COMPONENT . '.cc_number', ''); $app->setUserState(HIKASHOP_COMPONENT . '.cc_month', ''); $app->setUserState(HIKASHOP_COMPONENT . '.cc_year', ''); $app->setUserState(HIKASHOP_COMPONENT . '.cc_CCV', ''); $app->setUserState(HIKASHOP_COMPONENT . '.cc_type', ''); $app->setUserState(HIKASHOP_COMPONENT . '.cc_owner', ''); $app->setUserState(HIKASHOP_COMPONENT . '.cc_valid', 0); $app->setUserState(HIKASHOP_COMPONENT . '.checkout_terms', 0); $app->setUserState(HIKASHOP_COMPONENT . '.checkout_fields_ok', 0); $app->setUserState(HIKASHOP_COMPONENT . '.checkout_fields', null); $user = JFactory::getUser(); if ($user->guest) { $app->setUserState(HIKASHOP_COMPONENT . '.user_id', 0); } } return true; }
function form() { JHTML::_('behavior.modal'); $app = JFactory::getApplication(); $db = JFactory::getDBO(); $task = JRequest::getVar('task'); $config = hikashop_config(); $this->assignRef('config', $config); $toggle = hikashop_get('helper.toggle'); $this->assignRef('toggle', $toggle); $popup = hikashop_get('helper.popup'); $this->assignRef('popup', $popup); $this->content = ''; $this->plugin_name = JRequest::getCmd('name', ''); if (empty($this->plugin_name)) { hikashop_setTitle(JText::_($this->nameListing), $this->icon, $this->ctrl); return false; } $this->plugin_type = ''; $type = $app->getUserStateFromRequest(HIKASHOP_COMPONENT . '.plugin_type', 'plugin_type', 'shipping'); if (in_array($type, array('shipping', 'payment', 'plugin'))) { if ($type == 'plugin') { $plugin = hikashop_import('hikashop', $this->plugin_name); if (!is_subclass_of($plugin, 'hikashopPlugin')) { if (!HIKASHOP_J16) { $url = 'index.php?option=com_plugins&view=plugin&client=site&task=edit&cid[]='; $db->setQuery("SELECT id FROM `#__plugins` WHERE `folder` = 'hikashop' and element=" . $db->Quote($this->plugin_name)); $plugin_id = $db->loadResult(); } else { $url = 'index.php?option=com_plugins&task=plugin.edit&extension_id='; $db->setQuery("SELECT extension_id as id FROM `#__extensions` WHERE `folder` = 'hikashop' AND `type`='plugin' AND element=" . $db->Quote($this->plugin_name)); $plugin_id = $db->loadResult(); } $app->redirect($url . $plugin_id); } } else { $plugin = hikashop_import('hikashop' . $type, $this->plugin_name); } if (!$plugin) { hikashop_setTitle(JText::_($this->nameListing), $this->icon, $this->ctrl); return false; } $this->plugin_type = $type; } else { hikashop_setTitle(JText::_($this->nameListing), $this->icon, $this->ctrl); return false; } $multiple_plugin = false; $multiple_interface = false; if (method_exists($plugin, 'isMultiple')) { $multiple_interface = true; $multiple_plugin = $plugin->isMultiple(); } $subtask = JRequest::getCmd('subtask', ''); if ($multiple_plugin && empty($subtask)) { $querySelect = array(); $queryFrom = array(); $queryWhere = array(); $filters = array(); JPluginHelper::importPlugin('hikashop'); $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('onHikaPluginListing', array($type, &$querySelect, &$queryFrom, &$queryWhere, &$filters)); if (!empty($querySelect)) { $querySelect = ', ' . implode(',', $querySelect); } else { $querySelect = ''; } if (!empty($queryFrom)) { $queryFrom = ', ' . implode(',', $queryFrom); } else { $queryFrom = ''; } if (!empty($queryWhere)) { $queryWhere = ' AND (' . implode(') AND (', $queryWhere) . ') '; } else { $queryWhere = ''; } $this->assignRef('filters', $filters); } else { $querySelect = ''; $queryFrom = ''; $queryWhere = ''; } $query = 'SELECT plugin.* ' . $querySelect . ' FROM ' . hikashop_table($this->plugin_type) . ' as plugin ' . $queryFrom . ' WHERE (plugin.' . $this->plugin_type . '_type = ' . $db->Quote($this->plugin_name) . ') ' . $queryWhere . ' ORDER BY plugin.' . $this->plugin_type . '_ordering ASC'; $db->setQuery($query); $elements = $db->loadObjectList($this->plugin_type . '_id'); if (!empty($elements)) { $params_name = $this->plugin_type . '_params'; foreach ($elements as $k => $el) { if (!empty($el->{$params_name})) { $elements[$k]->{$params_name} = unserialize($el->{$params_name}); } } } $function = 'pluginConfiguration'; $ctrl = '&plugin_type=' . $this->plugin_type . '&task=' . $task . '&name=' . $this->plugin_name; if ($multiple_plugin === true) { $subtask = JRequest::getCmd('subtask', ''); $ctrl .= '&subtask=' . $subtask; if (empty($subtask)) { $function = 'pluginMultipleConfiguration'; } else { $typeFunction = 'on' . ucfirst($this->plugin_type) . 'Configuration'; if (method_exists($plugin, $typeFunction)) { $function = $typeFunction; } } $cid = hikashop_getCID($this->plugin_type . '_id'); if (isset($elements[$cid])) { $this->assignRef('element', $elements[$cid]); $configParam =& $elements[$cid]; $ctrl .= '&' . $this->plugin_type . '_id=' . $cid; } else { $configParam = new stdClass(); $this->assignRef('element', $configParam); } } else { $configParam =& $elements; $element = null; if (!empty($elements)) { $element = reset($elements); } $this->assignRef('element', $element); $typeFunction = 'on' . ucfirst($this->plugin_type) . 'Configuration'; if (method_exists($plugin, $typeFunction)) { $function = $typeFunction; } } $this->assignRef('elements', $elements); if ($multiple_interface && !isset($subtask) || !empty($subtask)) { $extra_config = array(); $extra_blocks = array(); JPluginHelper::importPlugin('hikashop'); $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('onHikaPluginConfiguration', array($type, &$plugin, &$this->element, &$extra_config, &$extra_blocks)); $this->assignRef('extra_config', $extra_config); $this->assignRef('extra_blocks', $extra_blocks); } $setTitle = true; if (method_exists($plugin, $function)) { if (empty($plugin->title)) { $plugin->title = JText::_('HIKA_PLUGIN') . ' ' . $this->plugin_name; } ob_start(); $plugin->{$function}($configParam); $this->content = ob_get_clean(); $this->data = $plugin->getProperties(); $setTitle = false; } if (isset($this->data['toolbar'])) { $this->toolbar = $this->data['toolbar']; } else { $this->toolbar = array('save', 'apply', 'cancel', '|'); } $this->assignRef('name', $this->plugin_name); $this->assignRef('plugin', $plugin); $this->assignRef('multiple_plugin', $multiple_plugin); $this->assignRef('multiple_interface', $multiple_interface); $this->assignRef('content', $this->content); $this->assignRef('plugin_type', $this->plugin_type); $categoryType = hikashop_get('type.categorysub'); $categoryType->type = 'tax'; $categoryType->field = 'category_id'; $this->assignRef('categoryType', $categoryType); if ($this->plugin_type == 'shipping') { $warehouseType = hikashop_get('type.warehouse'); $this->assignRef('warehouseType', $warehouseType); if (!empty($this->element->shipping_params->override_tax_zone)) { $zoneClass = hikashop_get('class.zone'); $this->element->shipping_params->override_tax_zone = $zoneClass->get($this->element->shipping_params->override_tax_zone); } } $this->_noForm($type, $elements); $currencies = hikashop_get('type.currency'); $column_name = $type . '_currency'; $this->element->{$column_name} = explode(',', trim(@$this->element->{$column_name}, ',')); $this->assignRef('currencies', $currencies); if ($type == 'payment') { $this->_loadPayment(); } if (empty($plugin->pluginView)) { $this->content .= $this->loadPluginTemplate(@$plugin->view, $type); } if ($setTitle) { hikashop_setTitle(JText::_('HIKA_PLUGIN') . ' ' . $this->name, $this->icon, $this->ctrl . $ctrl); } return true; }
function pay() { if (!$this->_check()) { return false; } $order_id = hikashop_getCID('order_id'); if (empty($order_id)) { parent::listing(); return false; } $class = hikashop_get('class.order'); $order = $class->loadFullOrder($order_id, true); if (empty($order->order_id)) { $app =& JFactory::getApplication(); $app->enqueueMessage('The order ' . $order_id . ' could not be found'); parent::listing(); return false; } $config =& hikashop_config(); $unpaid_statuses = explode(',', $config->get('order_unpaid_statuses', 'created')); if (!in_array($order->order_status, $unpaid_statuses)) { $app =& JFactory::getApplication(); $app->enqueueMessage('The order ' . $order->order_number . ' cannot be paid anymore.'); parent::listing(); return false; } if (empty($order->order_currency_id)) { $null = new stdClass(); $null->order_currency_id = hikashop_getCurrency(); $null->order_id = $order->order_id; $order->order_currency_id = $null->order_currency_id; $class->save($null); } $new_payment_method = JRequest::getVar('new_payment_method', ''); $config =& hikashop_config(); if ($config->get('allow_payment_change', 1) && !empty($new_payment_method)) { $new_payment_method = explode('_', $new_payment_method); $payment_id = array_pop($new_payment_method); $payment_method = implode('_', $new_payment_method); if ($payment_id != $order->order_payment_id || $payment_method != $order->order_payment_method) { $updateOrder = new stdClass(); $updateOrder->order_id = $order->order_id; $updateOrder->order_payment_id = $payment_id; $updateOrder->order_payment_method = $payment_method; $paymentClass = hikashop_get('class.payment'); $payment = $paymentClass->get($payment_id); if (!empty($payment->payment_params) && is_string($payment->payment_params)) { $payment->payment_params = unserialize($payment->payment_params); } $full_price_without_payment = $order->order_full_price - $order->order_payment_price; $new_payment = $payment; $new_payment_price = $paymentClass->computePrice($order, $new_payment, $full_price_without_payment, @$payment->payment_price, hikashop_getCurrency()); $new_payment_tax = @$new_payment->payment_tax; $updateOrder->order_payment_price = $new_payment_price; $updateOrder->order_full_price = $full_price_without_payment + $new_payment_price + $new_payment_tax; $updateOrder->history = new stdClass(); $updateOrder->history->history_payment_id = $payment_id; $updateOrder->history->history_payment_method = $payment_method; $class->save($updateOrder); $order->order_payment_id = $payment_id; $order->order_payment_method = $payment_method; $order->order_payment_price = $updateOrder->order_payment_price; $order->order_full_price = $updateOrder->order_full_price; } } $userClass = hikashop_get('class.user'); $order->customer = $userClass->get($order->order_user_id); $db = JFactory::getDBO(); $query = 'SELECT * FROM ' . hikashop_table('payment') . ' WHERE payment_type=' . $db->Quote($order->order_payment_method); $db->setQuery($query); $paymentData = $db->loadObjectList('payment_id'); $pluginsClass = hikashop_get('class.plugins'); $pluginsClass->params($paymentData, 'payment'); if (empty($paymentData)) { $app =& JFactory::getApplication(); $app->enqueueMessage('The payment method ' . $order->order_payment_method . ' could not be found'); parent::listing(); return false; } $order->cart =& $order; $order->cart->coupon = new stdClass(); $price = new stdClass(); $price->price_value_with_tax = $order->order_full_price; $order->cart->full_total = new stdClass(); $order->cart->full_total->prices = array($price); $price2 = new stdClass(); $total = 0; $class = hikashop_get('class.currency'); $order->cart->total = new stdClass(); $price2 = $class->calculateTotal($order->products, $order->cart->total, $order->order_currency_id); $order->cart->coupon->discount_value =& $order->order_discount_price; $shippingClass = hikashop_get('class.shipping'); $methods = $shippingClass->getMethods($order->cart); $data = hikashop_import('hikashopshipping', $order->order_shipping_method); if (!empty($data)) { $order->cart->shipping = $data->onShippingSave($order->cart, $methods, $order->order_shipping_id); } $app = JFactory::getApplication(); $app->setUserState(HIKASHOP_COMPONENT . '.shipping_address', $order->order_shipping_address_id); $app->setUserState(HIKASHOP_COMPONENT . '.billing_address', $order->order_billing_address_id); ob_start(); $data = hikashop_import('hikashoppayment', $order->order_payment_method); if (!empty($data)) { $needCC = false; if (method_exists($data, 'needCC')) { $method =& $paymentData[$order->order_payment_id]; $needCC = $data->needCC($method); } if (!$needCC) { $itemid_for_checkout = $config->get('checkout_itemid', '0'); if ($itemid_for_checkout) { global $Itemid; $Itemid = $itemid_for_checkout; } if (method_exists($data, 'onAfterOrderConfirm')) { $data->onAfterOrderConfirm($order, $paymentData, $order->order_payment_id); } } else { $paymentClass = hikashop_get('class.payment'); $do = false; $app->setUserState(HIKASHOP_COMPONENT . '.payment_method', $order->order_payment_method); $app->setUserState(HIKASHOP_COMPONENT . '.payment_id', $order->order_payment_id); $app->setUserState(HIKASHOP_COMPONENT . '.payment_data', $method); if ($paymentClass->readCC()) { $do = true; if (method_exists($data, 'onBeforeOrderCreate')) { $data->onBeforeOrderCreate($order, $do); } } if (!$do) { $app->setUserState(HIKASHOP_COMPONENT . '.cc_number', ''); $app->setUserState(HIKASHOP_COMPONENT . '.cc_month', ''); $app->setUserState(HIKASHOP_COMPONENT . '.cc_year', ''); $app->setUserState(HIKASHOP_COMPONENT . '.cc_CCV', ''); $app->setUserState(HIKASHOP_COMPONENT . '.cc_type', ''); $app->setUserState(HIKASHOP_COMPONENT . '.cc_owner', ''); $params = ''; $js = ''; echo hikashop_getLayout('checkout', 'ccinfo', $params, $js); } else { $order->history->history_notified = 1; $class = hikashop_get('class.order'); $updateOrder = new stdClass(); $updateOrder->order_id = $order->order_id; $updateOrder->order_status = $order->order_status; $updateOrder->order_payment_id = $payment_id; $updateOrder->order_payment_method = $payment_method; $updateOrder->history =& $order->history; $class->save($updateOrder); $app->redirect(hikashop_completeLink('checkout&task=after_end', false, true)); } } } $html = ob_get_clean(); if (empty($html)) { $app =& JFactory::getApplication(); $app->enqueueMessage('The payment method ' . $order->order_payment_method . ' does not handle payments after the order has been created'); parent::listing(); return false; } echo $html; return true; }
} else { echo JText::_('HIKASHOP_TOTAL') . ' : ' . $currencyHelper->format($data->cart->full_total->prices[0]->price_value_with_tax, $data->order_currency_id) . "\n"; } $app = JFactory::getApplication(); if ($app->isAdmin()) { $view = 'order'; } else { $view = 'address'; } $addressClass = hikashop_get('class.address'); if (!empty($data->cart->billing_address)) { echo JText::_('HIKASHOP_BILLING_ADDRESS') . "\n"; echo $addressClass->displayAddress($data->order_addresses_fields, $data->order_addresses[$data->cart->billing_address->address_id], $view, true); } if (!empty($data->order_shipping_method)) { $currentShipping = hikashop_import('hikashopshipping', $data->order_shipping_method); if (method_exists($currentShipping, 'getShippingAddress')) { $override = $currentShipping->getShippingAddress($data->order_shipping_id); if ($override !== false) { $data->override_shipping_address = $override; } } } if (!empty($data->cart->has_shipping) && (!empty($data->cart->shipping_address) || !empty($data->override_shipping_address))) { if (!empty($data->override_shipping_address)) { echo str_replace('<br/>', "\r\n", $data->override_shipping_address); } else { echo JText::_('HIKASHOP_SHIPPING_ADDRESS') . "\n"; echo $addressClass->displayAddress($data->order_addresses_fields, $data->order_addresses[$data->cart->shipping_address->address_id], $view, true); } }
function wizard_save() { $layoutType = JRequest::getVar('layout_type'); $currency = JRequest::getVar('currency'); $taxName = JRequest::getVar('tax_name'); $taxRate = JRequest::getVar('tax_rate'); $addressCountry = JRequest::getVar('address_country'); $data = JRequest::getVar('data', array(), '', 'array'); $addressState = !empty($data['address']['address_state']) ? $data['address']['address_state'] : ''; $shopAddress = JRequest::getVar('shop_address'); $paypalEmail = JRequest::getVar('paypal_email'); $productType = JRequest::getVar('product_type'); $dataExample = JRequest::getVar('data_sample'); $ratePlugin = hikashop_import('hikashop', 'rates'); if ($ratePlugin) { $ratePlugin->updateRates(); } $db = JFactory::getDBO(); foreach ($_POST as $key => $data) { if ($data == '0') { continue; } if (preg_match('#menu#', $key)) { // menu if (preg_match('#categories#', $key)) { $alias = 'hikashop-menu-for-categories-listing'; } else { $alias = 'hikashop-menu-for-products-listing'; } $db->setQuery('SELECT * FROM ' . hikashop_table('menu', false) . ' WHERE `alias` = ' . $db->Quote($alias)); $data = $db->loadAssoc(); $db->setQuery('SELECT `menutype` FROM ' . hikashop_table('menu', false) . ' WHERE `home` = 1'); $menutype = $db->loadResult(); $data['menutype'] = $menutype; $menuTable = JTable::getInstance('Menu', 'JTable', array()); if (is_object($menuTable)) { $menuTable->save($data); if (method_exists($menuTable, 'rebuild')) { $menuTable->rebuild(); } } } elseif (preg_match('#module#', $key)) { // module if (preg_match('#categories#', $key)) { $db->setQuery('UPDATE ' . hikashop_table('modules', false) . ' SET `published` = 1 WHERE `title` = ' . $db->Quote('Categories on 2 levels')); $db->query(); } } } $db->setQuery('SELECT `config_value` FROM ' . hikashop_table('config') . ' WHERE `config_namekey` = "default_params"'); $oldDefaultParams = $db->loadResult(); $oldDefaultParams = unserialize(base64_decode($oldDefaultParams)); $oldDefaultParams['layout_type'] = preg_replace('#listing_#', '', $layoutType); $defaultParams = base64_encode(serialize($oldDefaultParams)); if ($addressCountry == 'country_United_States_of_America_223') { $main_zone = $addressState; } else { $main_zone = $addressCountry; } $zoneClass = hikashop_get('class.zone'); $zone = $zoneClass->get($main_zone); $db->setQuery('REPLACE INTO ' . hikashop_table('config') . ' (config_namekey, config_value) VALUES ("main_tax_zone", ' . $db->Quote($zone->zone_id) . '), ("store_address", ' . $db->Quote($shopAddress) . '), ("main_currency", ' . $db->Quote($currency) . '), ("default_params", ' . $db->Quote($defaultParams) . ')'); $db->query(); $db->setQuery('UPDATE ' . hikashop_table('field') . ' SET `field_default` = ' . $db->Quote($addressState) . ' WHERE field_namekey = "address_state"'); $db->query(); $db->setQuery('UPDATE ' . hikashop_table('field') . ' SET `field_default` = ' . $db->Quote($addressCountry) . ' WHERE field_namekey = "address_country"'); $db->query(); $import_language = JRequest::getVar('import_language'); if ($import_language != '0') { if (preg_match('#_#', $import_language)) { $languages = explode('_', $import_language); } else { $languages = array($import_language); } $updateHelper = hikashop_get('helper.update'); foreach ($languages as $code) { $path = JLanguage::getLanguagePath(JPATH_ROOT) . DS . $code . DS . $code . '.com_hikashop.ini'; jimport('joomla.filesystem.file'); if (!JFile::exists($path)) { $url = str_replace('https://', 'http://', HIKASHOP_UPDATEURL . 'languageload&raw=1&code=' . $code); $data = ''; if (function_exists('curl_version')) { $ch = curl_init(); $timeout = 5; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $data = curl_exec($ch); curl_close($ch); } else { $data = file_get_contents($url); } if (!empty($data)) { $result = JFile::write($path, $data); if ($result) { $updateHelper->installMenu($code); hikashop_display(JText::_('HIKASHOP_SUCC_SAVED'), 'success'); } else { hikashop_display(JText::sprintf('FAIL_SAVE', $path), 'error'); } } else { hikashop_display(JText::sprintf('CANT_GET_LANGUAGE_FILE_CONTENT', $path), 'error'); } } } } if (isset($taxRate) && (!empty($taxRate) || $taxRate != '0')) { $taxRate = (double) $taxRate / 100; $db->setQuery('REPLACE INTO ' . hikashop_table('tax') . ' (tax_namekey,tax_rate) VALUES (' . $db->Quote($taxName) . ',' . (double) $taxRate . ')'); $db->query(); $db->setQuery('SELECT `taxation_id` FROM ' . hikashop_table('taxation') . ' ORDER BY `taxation_id` DESC LIMIT 0,1'); $maxId = $db->loadResult(); if (is_null($maxId)) { $maxId = 1; } else { $maxId = (int) $maxId + 1; } $tax = array(); $tax['taxation_id'] = (int) $maxId; if ($addressCountry == 'country_United_States_of_America_223') { $tax['zone_namekey'] = $db->Quote($addressState); } else { $tax['zone_namekey'] = $db->Quote($addressCountry); } $tax['category_namekey'] = $db->Quote('default_tax'); $tax['tax_namekey'] = $db->Quote($taxName); $tax['taxation_published'] = 1; $tax['taxation_type'] = $db->Quote(''); $tax['taxation_access'] = $db->Quote('all'); $tax['taxation_cumulative'] = 0; $tax['taxation_post_code'] = $db->Quote(''); $tax['taxation_date_start'] = 0; $tax['taxation_date_end'] = 0; $tax['taxation_internal_code'] = 0; $tax['taxation_note'] = $db->Quote(''); $query = 'INSERT INTO ' . hikashop_table('taxation') . ' (' . implode(',', array_keys($tax)) . ') VALUES (' . implode(',', $tax) . ')'; $db->setQuery($query); $db->query(); } if (isset($paypalEmail) && !empty($paypalEmail)) { $pluginData = array('payment' => array('payment_name' => 'PayPal', 'payment_published' => '1', 'payment_images' => 'MasterCard,VISA,Credit_card,PayPal', 'payment_price' => '', 'payment_params' => array('url' => 'https://www.paypal.com/cgi-bin/webscr', 'email' => $paypalEmail), 'payment_zone_namekey' => '', 'payment_access' => 'all', 'payment_id' => '0', 'payment_type' => 'paypal')); JRequest::setVar('name', 'paypal'); JRequest::setVar('plugin_type', 'payment'); JRequest::setVar('data', $pluginData); $pluginsController = hikashop_get('controller.plugins'); $pluginsController->store(true); } if (isset($productType) && !empty($productType)) { if ($productType == 'real') { $forceShipping = 1; } else { $forceShipping = 0; } $db->setQuery('REPLACE INTO ' . hikashop_table('config') . ' (config_namekey, config_value) VALUES ("force_shipping", ' . (int) $forceShipping . ')'); $db->query(); if ($productType == 'virtual') { $product_type = 'virtual'; } else { $product_type = 'shippable'; } $db->setQuery('REPLACE INTO ' . hikashop_table('config') . ' (config_namekey, config_value) VALUES ("default_product_type", ' . (int) $product_type . ')'); $db->query(); } if ($dataExample == 1) { $app = JFactory::getApplication(); $app->setUserState('WIZARD_DATA_SAMPLE_PAYPAL', $paypalEmail); $app->redirect('index.php?option=com_hikashop&ctrl=update&task=process_data_save&step=1&' . hikashop_getFormToken() . '=1'); } $url = 'index.php?option=com_hikashop&ctrl=product&task=add'; $this->setRedirect($url); }
function preload($backend = true) { $pluginsClass = hikashop_get('class.plugins'); $this->methods[$this->type][(string) @$this->order->order_id] = $pluginsClass->getMethods($this->type); if (!empty($this->methods[$this->type][(string) @$this->order->order_id])) { $max = 0; $already = array(); foreach ($this->methods[$this->type][(string) @$this->order->order_id] as $method) { if (!empty($method->ordering) && $max < $method->ordering) { $max = $method->ordering; } } foreach ($this->methods[$this->type][(string) @$this->order->order_id] as $k => $method) { if (empty($method->ordering)) { $max++; $this->methods[$this->type][(string) @$this->order->order_id][$k]->ordering = $max; } while (isset($already[$this->methods[$this->type][(string) @$this->order->order_id][$k]->ordering])) { $max++; $this->methods[$this->type][(string) @$this->order->order_id][$k]->ordering = $max; } $already[$this->methods[$this->type][(string) @$this->order->order_id][$k]->ordering] = true; } } if (!$backend) { JPluginHelper::importPlugin('hikashoppayment'); $dispatcher = JDispatcher::getInstance(); $usable_methods = null; $class = hikashop_get('class.order'); $this->order = $class->loadFullOrder($this->order->order_id, true); $dispatcher->trigger('onPaymentDisplay', array(&$this->order, &$this->methods[$this->type][(string) @$this->order->order_id], &$usable_methods)); if (!empty($usable_methods)) { ksort($usable_methods); } $this->methods[$this->type][(string) @$this->order->order_id] = $usable_methods; } if ($this->type == 'shipping') { $unset = array(); $add = array(); foreach ($this->methods[$this->type][(string) @$this->order->order_id] as $k => $method) { if ($method->shipping_type != 'manual') { $plugin = hikashop_import('hikashop' . $this->type, $method->shipping_type); if ($plugin && method_exists($plugin, 'shippingMethods')) { $methods = $plugin->shippingMethods($method); if (is_array($methods) && !empty($methods)) { $unset[] = $k; foreach ($methods as $id => $name) { $new = clone $method; $new->shipping_id = $id; $new->shipping_name = $method->shipping_name . ' - ' . $name; $add[] = $new; } } else { $unset[] = $k; } } else { $unset[] = $k; } } } foreach ($unset as $k) { unset($this->methods[$this->type][(string) @$this->order->order_id][$k]); } foreach ($add as $v) { $this->methods[$this->type][(string) @$this->order->order_id][] = $v; } } return true; }
function store($new = false) { $this->plugin = JRequest::getCmd('name', 'manual'); $this->plugin_type = JRequest::getCmd('plugin_type', 'shipping'); if (!in_array($this->plugin_type, array('shipping', 'payment', 'plugin'))) { return false; } if ($this->plugin_type == 'plugin') { $data = hikashop_import('hikashop', $this->plugin); } else { $data = hikashop_import('hikashop' . $this->plugin_type, $this->plugin); } $element = new stdClass(); $id = hikashop_getCID($this->plugin_type . '_id'); $formData = JRequest::getVar('data', array(), '', 'array'); $params_name = $this->plugin_type . '_params'; if (!empty($formData[$this->plugin_type])) { $plugin_id = $this->plugin_type . '_id'; $element->{$plugin_id} = $id; foreach ($formData[$this->plugin_type] as $column => $value) { hikashop_secureField($column); if (is_array($value)) { if ($column == $params_name) { $element->{$params_name} = new stdClass(); foreach ($formData[$this->plugin_type][$column] as $key => $val) { hikashop_secureField($key); if (in_array($key, array('shipping_percentage', 'shipping_min_price', 'shipping_max_price', 'shipping_min_weight', 'shipping_max_weight', 'shipping_min_volume', 'shipping_max_volume'))) { $val = hikashop_toFloat($val); } if (is_array($val) || $key == 'information') { $element->{$params_name}->{$key} = $val; } elseif ($key == 'shipping_override_address_text' && $formData[$this->plugin_type][$column]['shipping_override_address'] == '4') { $safeHtmlFilter = JFilterInput::getInstance(null, null, 1, 1); $element->{$params_name}->{$key} = $safeHtmlFilter->clean($val, 'string'); } else { $element->{$params_name}->{$key} = strip_tags($val); } } } elseif ($column == 'payment_shipping_methods' || $column == 'payment_currency' || $column == 'shipping_currency') { $element->{$column} = array(); foreach ($formData[$this->plugin_type][$column] as $key => $val) { $element->{$column}[(int) $key] = strip_tags($val); } } } else { $element->{$column} = strip_tags($value); } } if ($this->plugin_type == 'payment') { if (!isset($element->payment_shipping_methods)) { $element->payment_shipping_methods = array(); } if (!isset($element->payment_currency)) { $element->payment_currency = array(); } } elseif ($this->plugin_type == 'shipping') { if (!isset($element->shipping_currency)) { $element->shipping_currency = array(); } } $plugin_description = $this->plugin_type . '_description'; $plugin_description_data = JRequest::getVar($plugin_description, '', '', 'string', JREQUEST_ALLOWRAW); $element->{$plugin_description} = $plugin_description_data; $translationHelper = hikashop_get('helper.translation'); $translationHelper->getTranslations($element); } $function = 'on' . ucfirst($this->plugin_type) . 'ConfigurationSave'; if (method_exists($data, $function)) { $data->{$function}($element); } if (!empty($element)) { $pluginClass = hikashop_get('class.' . $this->plugin_type); $status = $pluginClass->save($element); if (!$status) { JRequest::setVar('fail', $element); } else { $translationHelper->handleTranslations($this->plugin_type, $status, $element); $app = JFactory::getApplication(); if (!HIKASHOP_J30) { $app->enqueueMessage(JText::_('HIKASHOP_SUCC_SAVED'), 'success'); } else { $app->enqueueMessage(JText::_('HIKASHOP_SUCC_SAVED')); } if (empty($id)) { JRequest::setVar($this->plugin_type . '_id', $status); } } } }
protected function loadAddress() { $app = JFactory::getApplication(); $shipping_method = $app->getUserState(HIKASHOP_COMPONENT . '.shipping_method'); if (empty($shipping_method)) { $shipping_method = array(); } if (!is_array($shipping_method)) { $shipping_method = array($shipping_method); } $currentShipping = array(); if (count($shipping_method) == 1) { foreach ($shipping_method as $method) { $method = explode('@', $method); $method = $method[0]; $currentShipping[] = hikashop_import('hikashopshipping', $method); } } $override = false; foreach ($currentShipping as $selectedMethod) { if (!empty($selectedMethod) && method_exists($selectedMethod, 'getShippingAddress')) { $override = $selectedMethod->getShippingAddress(); } } if ($override) { if (@$this->plugin_options['use_origin_address_when_override']) { $address = new stdClass(); $address->address_street = $this->plugin_options['origin_address1']; $address->address_street2 = $this->plugin_options['origin_address2']; $address->address_city = $this->plugin_options['origin_city']; $address->address_state = new stdClass(); $address->address_state->zone_code_3 = $this->plugin_options['origin_state']; $address->address_post_code = $this->plugin_options['origin_zip5'] . $this->plugin_options['origin_zip4']; return $address; } return false; } $shipping_address = (int) $app->getUserState(HIKASHOP_COMPONENT . '.shipping_address', 0); if (empty($shipping_address)) { $shipping_address = (int) $app->getUserState(HIKASHOP_COMPONENT . '.billing_address', 0); } if (empty($shipping_address)) { return false; } $addressClass = hikashop_get('class.address'); $address = $addressClass->get($shipping_address); if (empty($address)) { return false; } $array = array(&$address); $addressClass->loadZone($array, 'object'); if (empty($address->address_country)) { $address->address_country = new stdClass(); $address->address_country->zone_code_3 = 'USA'; } return $address; }
function giveAndGiveBack(&$order) { $plugin = hikashop_import('hikashop', 'userpoints'); return $plugin->giveAndGiveBack($order); }