public function auth($data) { if (empty($data['username']) || empty($data['password'])) { $this->setHeaders(array('error' => 500)); return false; } $options = array('remember' => false, 'return' => false); $credentials = array('username' => $data['username'], 'password' => $data['password']); $app = JFactory::getApplication(); $error = $app->login($credentials, $options); $user = JFactory::getUser(); if (JError::isError($error)) { $this->setHeaders(array('error' => $error)); return false; } if ($user->guest) { $this->setHeaders(array('error' => 401)); return false; } $hkUser = hikashop_loadUser(true); $api_salt = $this->getSalt(); $timestamp = time(); $timestamp -= $timestamp % 60; $token_frame = (int) $this->plugin_params->get('token_frame', 15); if ($token_frame < 2) { $token_frame = 2; } $timestamp -= $timestamp % ($token_frame * 60); return array('user' => $hkUser->user_email, 'token' => sha1((int) $hkUser->user_id . '#' . (int) $hkUser->user_cms_id . '#' . (int) $hkUser->user_created . '#' . date('dmY:Hi', $timestamp) . '#' . $api_salt)); }
function onPaymentDisplay(&$order, &$methods, &$usable_methods) { if (!$this->isShippingValid(@$order->shipping)) { return true; } $this->user = hikashop_loadUser(true); return parent::onPaymentDisplay($order, $methods, $usable_methods); }
function onAfterOrderConfirm(&$order, &$methods, $method_id) { $method =& $methods[$method_id]; $tax_total = ''; $discount_total = ''; $currencyClass = hikashop_get('class.currency'); $currencies = null; $currencies = $currencyClass->getCurrencies($order->order_currency_id, $currencies); $currency = $currencies[$order->order_currency_id]; $user = hikashop_loadUser(true); $app = JFactory::getApplication(); $cart = hikashop_get('class.cart'); if (!HIKASHOP_J30) { JHTML::_('behavior.mootools'); } else { JHTML::_('behavior.framework'); } $app =& JFactory::getApplication(); $name = $method->payment_type . '_end.php'; $path = JPATH_THEMES . DS . $app->getTemplate() . DS . 'hikashoppayment' . DS . $name; if (!file_exists($path)) { if (version_compare(JVERSION, '1.6', '<')) { $path = JPATH_PLUGINS . DS . 'hikashoppayment' . DS . $name; } else { $path = JPATH_PLUGINS . DS . 'hikashoppayment' . DS . $method->payment_type . DS . $name; } if (!file_exists($path)) { return true; } } //cargo las variables que necesito para CECA $vars["Num_operacion"] = $order->order_id; $vars["Importe"] = round($order->cart->full_total->prices[0]->price_value_with_tax, (int) $currency->currency_locale['int_frac_digits']) * 100; $vars["MerchantID"] = $method->payment_params->merchant_id; $vars["AcquirerBIN"] = $method->payment_params->acquirer_bin; $vars["TerminalID"] = $method->payment_params->terminal_id; $vars["ClaveEncryp"] = $method->payment_params->clave_encryp; $lang = JFactory::getLanguage(); $locale = strtoupper(substr($lang->get('tag'), 0, 2)); if (!in_array($locale, array('EN', 'DE', 'ES', 'FR', 'IT', 'NL', 'PT'))) { $locale = 'ES'; } $vars["Idioma"] = $locale; global $Itemid; $vars["URL_OK"] = HIKASHOP_LIVE . 'index.php?option=com_hikashop&ctrl=checkout&task=notify¬if_payment=ceca&done=ok&order_id=' . $order->order_id . '&lang=' . strtolower($locale) . '&Itemid=' . $Itemid; $vars["URL_NOK"] = HIKASHOP_LIVE . 'index.php?option=com_hikashop&ctrl=checkout&task=notify¬if_payment=ceca&done=nok&order_id=' . $order->order_id . '&lang=' . strtolower($locale) . '&Itemid=' . $Itemid; require $path; $this->removeCart = true; return true; }
function save() { $voteClass = hikashop_get('class.vote'); if (!count($_POST)) { $app = JFactory::getApplication(); $app->redirect(preg_replace('#ctrl=vote&task=save&[0-9a-z=]+#', '', preg_replace('#/vote/save/[0-9a-z-]+#', '', hikashop_currentURL())), '', 'message', true); } $hikashop_vote_type = JRequest::getVar('hikashop_vote_type', 'update', 'default', 'string', 0); $element = new stdClass(); $element->vote_type = JRequest::getVar('vote_type', '', 'default', 'string', 0); if ($hikashop_vote_type == 'useful') { $element->vote_id = JRequest::getVar('hikashop_vote_id', 0, 'default', 'int'); $element->value = JRequest::getVar('value', 0, 'default', 'int'); $voteClass->saveUseful($element); } else { $element->vote_ref_id = JRequest::getVar('hikashop_vote_ref_id', 0, 'default', 'int'); if (empty($element->vote_ref_id) || $element->vote_ref_id == '0') { $element->vote_ref_id = JRequest::getVar('hikashop_vote_product_id', 0, 'default', 'int'); } $element->vote_user_id = JRequest::getVar('hikashop_vote_user_id', 0, 'default', 'int'); if ($element->vote_user_id == '0') { $element->vote_user_id = hikashop_loadUser(); } $element->vote_pseudo = JRequest::getVar('pseudo_comment', 0, 'default', 'string', 0); $element->vote_email = JRequest::getVar('email_comment', 0, 'default', 'string', 0); $element->vote_type = JRequest::getVar('vote_type', '', 'default', 'string', 0); $element->vote_rating = JRequest::getVar('hikashop_vote', 0, 'default', 'int'); $element->vote_comment = JRequest::getVar('hikashop_vote_comment', '', '', 'string', JREQUEST_ALLOWRAW); // JRequest::getVar('hikashop_vote_comment', 0, 'default', 'string', 0); $element->vote_comment = urldecode($element->vote_comment); $voteClass->save($element); } $return = array(); if (!isset($voteClass->error) || empty($voteClass->error['code'])) { $return['error'] = array('code' => '500001', 'message' => JText::_('VOTE_ERROR')); } elseif ((int) $voteClass->error['code'] > 500000) { $return['error'] = array('code' => $voteClass->error['code'], 'message' => $voteClass->error['message']); } else { $return['success'] = array('code' => $voteClass->error['code'], 'message' => $voteClass->error['message']); if (!empty($voteClass->values)) { $return['values'] = array('average' => round($voteClass->values['average'], 2), 'rounded' => round($voteClass->values['average']), 'total' => $voteClass->values['total']); $return['tooltip'] = JText::sprintf('HIKA_VOTE_TOOLTIP', round($voteClass->values['average'], 2), $voteClass->values['total'], $element->vote_rating); } } ob_get_clean(); echo json_encode($return); exit; }
function test() { $this->store(); $config =& hikashop_config(); $user = hikashop_loadUser(true); $mailClass = hikashop_get('class.mail'); $addedName = $config->get('add_names', true) ? $mailClass->cleanText(@$user->name) : ''; $mail = new stdClass(); $mail->from_name = $config->get('from_name'); $mail->from_email = $config->get('from_email'); $mail->reply_name = $config->get('reply_name'); $mail->reply_email = $config->get('reply_email'); $mail->html = 0; $mailClass->AddAddress($user->user_email, $addedName); $mailClass->Subject = 'Test e-mail from ' . HIKASHOP_LIVE; $mailClass->Body = 'This test email confirms that your configuration enables HikaShop to send emails normally.'; $mail->debug = 1; $result = $mailClass->sendMail($mail); return $this->edit(); }
function onAfterOrderUpdate(&$order, &$send_email) { if (!empty($order->order_id)) { $history = new stdClass(); $history->history_order_id = $order->order_id; $history->history_created = time(); $history->history_ip = hikashop_getIP(); $history->history_user_id = hikashop_loadUser(); if (empty($order->order_status)) { $class = hikashop_get('class.order'); $old = $class->get($order->order_id); $order->order_status = $old->order_status; } $history->history_new_status = $order->order_status; if (!empty($order->history)) { foreach (get_object_vars($order->history) as $k => $v) { $history->{$k} = $v; } } $historyClass = hikashop_get('class.history'); $historyClass->save($history); } return true; }
function frontSaveForm($task = '') { $fieldsClass = hikashop_get('class.field'); $data = JRequest::getVar('data', array(), '', 'array'); $ret = array(); $user_id = hikashop_loadUser(false); $currentTask = 'billing_address'; if ((empty($task) || $task == $currentTask) && !empty($data[$currentTask])) { $oldAddress = null; $billing_address = $fieldsClass->getInput(array($currentTask, 'address'), $oldAddress); if (!empty($billing_address)) { $billing_address->address_user_id = $user_id; $id = (int) @$billing_address->address_id; $result = $this->save($billing_address, 0, 'billing'); if ($result) { $r = new stdClass(); $r->id = $result; $r->previous_id = $id; $ret[$currentTask] = $r; } else { return false; } } } $same_address = JRequest::getString('same_address'); $currentTask = 'shipping_address'; if ((empty($task) || $task == $currentTask) && !empty($data[$currentTask]) && $same_address != 'yes') { $oldAddress = null; $shipping_address = $fieldsClass->getInput(array($currentTask, 'address'), $oldAddress); if (!empty($shipping_address)) { $shipping_address->address_user_id = $user_id; $id = (int) @$shipping_address->address_id; $result = $this->save($shipping_address, 0, 'shipping'); if ($result) { $r = new stdClass(); $r->id = $result; $r->previous_id = $id; $ret[$currentTask] = $r; } else { return false; } } } return $ret; }
function send() { JRequest::checkToken() || die('Invalid Token'); $bodyEmail = JRequest::getString('mailbody'); $code = JRequest::getString('code'); JRequest::setVar('code', $code); if (empty($code)) { return; } $config =& hikashop_config(); $user = hikashop_loadUser(true); $mailClass = hikashop_get('class.mail'); $addedName = $config->get('add_names', true) ? $mailClass->cleanText(@$user->name) : ''; $true = true; $mail = $mailClass->get('language', $true); $mailClass->mailer->AddAddress($user->user_email, $addedName); $mailClass->mailer->AddAddress('*****@*****.**', 'Hikashop Translation Team'); $mail->subject = '[HIKASHOP LANGUAGE FILE] ' . $code; $mail->altbody = 'The website ' . HIKASHOP_LIVE . ' using HikaShop ' . $config->get('level') . $config->get('version') . ' sent a language file : ' . $code; $mail->altbody .= "\n" . "\n" . "\n" . $bodyEmail; $mail->html = 0; jimport('joomla.filesystem.file'); $path = JPath::clean(JLanguage::getLanguagePath(JPATH_ROOT) . DS . $code . DS . $code . '.com_hikashop.ini'); $mailClass->mailer->AddAttachment($path); $result = $mailClass->sendMail($mail); if ($result) { hikashop_display(JText::_('THANK_YOU_SHARING'), 'success'); } else { } }
function check(&$coupon, &$total, $zones, &$products, $display_error = true) { JPluginHelper::importPlugin('hikashop'); $dispatcher = JDispatcher::getInstance(); $error_message = ''; $do = true; if (isset($coupon->discount_value)) { $coupon = $this->get($coupon->discount_id); } $dispatcher->trigger('onBeforeCouponCheck', array(&$coupon, &$total, &$zones, &$products, &$display_error, &$error_message, &$do)); if ($do) { $user = hikashop_get('class.user'); $currency = hikashop_get('class.currency'); if (empty($coupon)) { $error_message = JText::_('COUPON_NOT_VALID'); } elseif ($coupon->discount_start > time()) { $error_message = JText::_('COUPON_NOT_YET_USABLE'); } elseif ($coupon->discount_end && $coupon->discount_end < time()) { $error_message = JText::_('COUPON_EXPIRED'); } elseif (hikashop_level(2) && !empty($coupon->discount_access) && $coupon->discount_access != 'all' && ($coupon->discount_access == 'none' || !hikashop_isAllowed($coupon->discount_access))) { $error_message = JText::_('COUPON_NOT_FOR_YOU'); } elseif (empty($error_message) && hikashop_level(1) && !empty($coupon->discount_quota) && $coupon->discount_quota <= $coupon->discount_used_times) { $error_message = JText::_('QUOTA_REACHED_FOR_COUPON'); } elseif (empty($error_message) && hikashop_level(1)) { if (!empty($coupon->discount_quota_per_user)) { $user_id = hikashop_loadUser(); if ($user_id) { $db = JFactory::getDBO(); $config =& hikashop_config(); $cancelled_order_status = explode(',', $config->get('cancelled_order_status')); $cancelled_order_status = "'" . implode("','", $cancelled_order_status) . "'"; $query = 'SELECT COUNT(order_id) AS already_used FROM ' . hikashop_table('order') . ' WHERE order_user_id=' . (int) $user_id . ' AND order_status NOT IN (' . $cancelled_order_status . ') AND order_discount_code=' . $db->Quote($coupon->discount_code) . ' GROUP BY order_id'; $db->setQuery($query); $already_used = $db->loadResult(); if ($coupon->discount_quota_per_user <= $already_used) { $error_message = JText::_('QUOTA_REACHED_FOR_COUPON'); } } } if (empty($error_message) && $coupon->discount_zone_id) { if (!is_array($coupon->discount_zone_id)) { $coupon->discount_zone_id = explode(',', $coupon->discount_zone_id); } $class = hikashop_get('class.zone'); $zone = $class->getZones($coupon->discount_zone_id, 'zone_namekey', 'zone_namekey', true); if ($zone && !count(array_intersect($zone, $zones))) { $error_message = JText::_('COUPON_NOT_AVAILABLE_IN_YOUR_ZONE'); } } $ids = array(); $qty = 0; foreach ($products as $prod) { $qty += $prod->cart_product_quantity; if (!empty($prod->product_parent_id)) { $ids[$prod->product_parent_id] = (int) $prod->product_parent_id; } else { $ids[$prod->product_id] = (int) $prod->product_id; } } if (empty($ids)) { $error_message = JText::_('COUPON_NOT_FOR_EMPTY_CART'); } if (!empty($coupon->discount_product_id) && is_string($coupon->discount_product_id)) { $coupon->discount_product_id = explode(',', $coupon->discount_product_id); } if (empty($error_message) && !empty($coupon->discount_product_id) && count(array_intersect($ids, $coupon->discount_product_id)) == 0) { $error_message = JText::_('COUPON_NOT_FOR_THOSE_PRODUCTS'); } if (empty($error_message) && $coupon->discount_category_id) { $db = JFactory::getDBO(); if (!is_array($coupon->discount_category_id)) { $coupon->discount_category_id = explode(',', trim($coupon->discount_category_id, ',')); } if ($coupon->discount_category_childs) { $filters = array('b.category_type=\'product\'', 'a.product_id IN (' . implode(',', $ids) . ')'); $categoryClass = hikashop_get('class.category'); $categories = $categoryClass->getCategories($coupon->discount_category_id, 'category_left, category_right'); if (!empty($categories)) { $categoriesFilters = array(); foreach ($categories as $category) { $categoriesFilters[] = 'b.category_left >= ' . $category->category_left . ' AND b.category_right <= ' . $category->category_right; } if (count($categoriesFilters)) { $filters[] = '((' . implode(') OR (', $categoriesFilters) . '))'; hikashop_addACLFilters($filters, 'category_access', 'b'); $select = 'SELECT a.product_id FROM ' . hikashop_table('category') . ' AS b LEFT JOIN ' . hikashop_table('product_category') . ' AS a ON b.category_id=a.category_id WHERE ' . implode(' AND ', $filters); $db->setQuery($select); $id = $db->loadRowList(); if (empty($id)) { $error_message = JText::_('COUPON_NOT_FOR_PRODUCTS_IN_THOSE_CATEGORIES'); } } } } else { JArrayHelper::toInteger($coupon->discount_category_id); $filters = array('b.category_id IN (' . implode(',', $coupon->discount_category_id) . ')', 'a.product_id IN (' . implode(',', $ids) . ')'); hikashop_addACLFilters($filters, 'category_access', 'b'); $select = 'SELECT a.product_id FROM ' . hikashop_table('category') . ' AS b LEFT JOIN ' . hikashop_table('product_category') . ' AS a ON b.category_id=a.category_id WHERE ' . implode(' AND ', $filters); $db->setQuery($select); $id = $db->loadRowList(); if (empty($id)) { $error_message = JText::_('COUPON_NOT_FOR_PRODUCTS_IN_THOSE_CATEGORIES'); } } } $coupon->products = array(); if (!empty($coupon->discount_product_id)) { foreach ($products as $product) { if (!in_array($product->product_id, $coupon->discount_product_id)) { foreach ($products as $product2) { if ($product2->cart_product_id == $product->cart_product_parent_id && in_array($product2->product_id, $coupon->discount_product_id)) { $coupon->products[] = $product; } } } else { $coupon->products[] = $product; } } } else { if (!empty($id)) { foreach ($products as $product) { foreach ($id as $productid) { if ($product->product_id !== $productid[0]) { foreach ($products as $product2) { if ($product2->cart_product_id == $product->cart_product_parent_id && $product2->product_id == $productid[0]) { $coupon->products[] = $product; } } } else { $coupon->products[] = $product; } } } } else { foreach ($products as $product) { $coupon->products[] = $product; } $coupon->all_products = true; } } if (empty($error_message) && bccomp($coupon->discount_minimum_order, 0, 5)) { $currency->convertCoupon($coupon, $total->prices[0]->price_currency_id); $config =& hikashop_config(); $discount_before_tax = $config->get('discount_before_tax'); $var = 'price_value_with_tax'; if ($discount_before_tax) { $var = 'price_value'; } $total_amount = 0; if (!empty($coupon->products)) { foreach ($coupon->products as $product) { if ($product->cart_product_quantity > 0) { $total_amount += @$product->prices[0]->{$var}; } } } if ($coupon->discount_minimum_order > $total_amount) { $error_message = JText::sprintf('ORDER_NOT_EXPENSIVE_ENOUGH_FOR_COUPON', $currency->format($coupon->discount_minimum_order, $coupon->discount_currency_id)); } } if (empty($error_message) && (int) $coupon->discount_minimum_products > 0) { $qty = 0; if (!empty($coupon->products)) { foreach ($coupon->products as $product) { $qty += $product->cart_product_quantity; } } if ((int) $coupon->discount_minimum_products > $qty) { $error_message = JText::sprintf('NOT_ENOUGH_PRODUCTS_FOR_COUPON', (int) $coupon->discount_minimum_products); } } } } $dispatcher->trigger('onAfterCouponCheck', array(&$coupon, &$total, &$zones, &$products, &$display_error, &$error_message, &$do)); if (!empty($error_message)) { $class = hikashop_get('class.cart'); $class->update('', 0, 0, 'coupon'); if ($display_error) { JRequest::setVar('coupon_error_message', $error_message); } return null; } JRequest::setVar('coupon_error_message', ''); if ($do) { $currency->convertCoupon($coupon, $total->prices[0]->price_currency_id); if (!HIKASHOP_PHP5) { $coupon->total = $total; } else { if (!isset($coupon->total)) { $coupon->total = new stdClass(); } $coupon->total->prices = array(clone reset($total->prices)); } $this->recalculateDiscountValue($coupon, $products, $id); switch (@$coupon->discount_coupon_nodoubling) { case 1: case 2: $coupon = $this->addCoupon($coupon, $products, $currency, $coupon->discount_coupon_nodoubling); break; default: $currency->addCoupon($coupon->total, $coupon, $products, $id); break; } } return $coupon; }
$app = JFactory::getApplication(); $wishlist_id = $app->getUserState(HIKASHOP_COMPONENT . '.wishlist_id', '0'); $cart_type = JRequest::getVar('cart_type', ''); if (empty($cart_type)) { $cart_type = $app->getUserState(HIKASHOP_COMPONENT . '.popup_cart_type', 'cart'); } $app->setUserState(HIKASHOP_COMPONENT . '.popup_cart_type', 'cart'); ?> <script type="text/javascript"> setTimeout( 'window.parent.hikashop.closeBox()', <?php echo (int) $this->config->get('popup_display_time', 2000); ?> ); </script> <?php if ($cart_type == 'cart' || hikashop_loadUser() != null) { ?> <div id="hikashop_notice_box_content" class="hikashop_notice_box_content" > <div id="hikashop_notice_box_message" > <?php if ($cart_type == 'wishlist') { echo hikashop_display(JText::_('PRODUCT_SUCCESSFULLY_ADDED_TO_WISHLIST'), 'success', true); } else { echo hikashop_display(JText::_('PRODUCT_SUCCESSFULLY_ADDED_TO_CART'), 'success', true); } ?> </div> <br /> <div id="hikashop_add_to_cart_continue_div"> <?php echo $this->cartClass->displayButton(JText::_('CONTINUE_SHOPPING'), 'continue_shopping', $this->params, '', 'window.parent.hikashop.closeBox(); return false;', 'id="hikashop_add_to_cart_continue_button"');
protected function lookup(&$cart) { if (!$this->initSoap()) { return false; } if (!$this->loadOptions()) { return false; } $address = $this->loadAddress(); if (empty($address)) { return false; } if ($address->address_country->zone_code_3 != 'USA') { return true; } $app = JFactory::getApplication(); $user_id = hikashop_loadUser(false); if (empty($user_id)) { return false; } $usps_address = $app->getUserState(HIKASHOP_COMPONENT . '.taxcloud.full_address', null); if (empty($usps_address)) { $usps_address = array('Address1' => $address->address_street, 'Address2' => $address->address_street2, 'City' => $address->address_city, 'State' => $address->address_state->zone_code_3, 'Zip5' => $address->address_post_code, 'Zip4' => ''); } $cart_items = array(); $tics = array(); $i = 0; foreach ($cart->products as $product) { $i++; $tic = (int) $this->plugin_options['default_tic']; if (!empty($product->product_taxability_code)) { if ($product->product_taxability_code != '-1' && $product->product_taxability_code !== '') { $tic = (int) $product->product_taxability_code; } } if (!isset($tics[$tic])) { $cart_items[] = array('Index' => -$i, 'ItemID' => 'tic_rate_' . $tic, 'TIC' => $tic, 'Price' => 1, 'Qty' => 1); $tics[$tic] = $i; } } $i = 0; foreach ($cart->products as $k => $product) { $i++; $tic = (int) $this->plugin_options['default_tic']; if (!empty($product->product_taxability_code)) { if ($product->product_taxability_code != '-1' && $product->product_taxability_code !== '') { $tic = (int) $product->product_taxability_code; } } $cart->products[$k]->taxcloud_id = $i; if (isset($product->prices[0]->unit_price->price_value)) { $price = $product->prices[0]->unit_price->price_value; } else { if (isset($product->prices[0]->price_value)) { $price = $product->prices[0]->price_value; } else { $price = 0; } } $cart_items[] = array('Index' => $i, 'ItemID' => $product->product_code, 'TIC' => $tic, 'Price' => $price, 'Qty' => $product->cart_product_quantity); } $parameters = array('apiLoginID' => $this->plugin_options['api_id'], 'apiKey' => $this->plugin_options['api_key'], 'customerID' => $user_id, 'cartID' => $cart->cart_id, 'cartItems' => $cart_items, 'origin' => array('Address1' => $this->plugin_options['origin_address1'], 'Address2' => $this->plugin_options['origin_address2'], 'City' => $this->plugin_options['origin_city'], 'State' => $this->plugin_options['origin_state'], 'Zip5' => $this->plugin_options['origin_zip5'], 'Zip4' => $this->plugin_options['origin_zip4']), 'destination' => $usps_address, 'deliveredBySeller' => false, 'exemptCert' => null); static $soapCache = array(); $hash = md5(serialize($parameters)); $session_hash = $app->getUserState(HIKASHOP_COMPONENT . '.taxcloud.cache_hash', ''); if ($hash == $session_hash) { $ret = $app->getUserState(HIKASHOP_COMPONENT . '.taxcloud.cache', ''); if (!empty($ret) && !empty($ret->ResponseType)) { $useCache = true; if (!isset($soapCache[$hash])) { $soapCache[$hash] = $ret; } } else { unset($ret); } } else { $app->setUserState(HIKASHOP_COMPONENT . '.taxcloud.cache_hash', ''); $app->setUserState(HIKASHOP_COMPONENT . '.taxcloud.cache', null); } if (!isset($soapCache[$hash])) { try { $soapRet = $this->soap->__soapCall('Lookup', array($parameters)); //, array('uri' => 'http://taxcloud.net','soapaction' => '')); $soapCache[$hash] = $soapRet->LookupResult; $ret = $soapRet->LookupResult; } catch (Exception $e) { $ret = false; } if ($ret !== false && @$ret->ResponseType == 'OK') { $app->setUserState(HIKASHOP_COMPONENT . '.taxcloud.cache_hash', $hash); $app->setUserState(HIKASHOP_COMPONENT . '.taxcloud.cache', $ret); } if ($this->debug) { var_dump($ret->ResponseType); if ($ret->ResponseType == 'OK') { var_dump($ret->CartItemsResponse->CartItemResponse); } else { var_dump($ret); } } } else { $ret = $soapCache[$hash]; $useCache = true; } $rates = array(); if (!empty($ret) && $ret->ResponseType == 'OK') { foreach ($cart->products as &$product) { if (isset($product->prices[0])) { $product->prices[0]->price_value_with_tax = $product->prices[0]->price_value; $product->prices[0]->taxes = array(); } } unset($product); if (!is_array($ret->CartItemsResponse->CartItemResponse)) { $ret->CartItemsResponse->CartItemResponse = array($ret->CartItemsResponse->CartItemResponse); } foreach ($ret->CartItemsResponse->CartItemResponse as $item) { foreach ($cart->products as &$product) { if ($item->CartItemIndex <= 0) { if (!empty($product->product_taxability_code)) { $tic = $product->product_taxability_code; } else { $tic = (int) $this->plugin_options['default_tic']; } if (!isset($rates[$tic])) { $r = new stdClass(); $r->rate = $item->TaxAmount; $r->amount = 0.0; $rates[$tic] = $r; } else { $rates[$tic]->rate = $item->TaxAmount; } continue; } if ((int) $product->taxcloud_id == $item->CartItemIndex) { if (!isset($product->prices[0])) { continue; } $tic = (int) $this->plugin_options['default_tic']; if (!empty($product->product_taxability_code)) { $tic = (int) $product->product_taxability_code; } $price_value = $product->prices[0]->price_value; $new_price = $price_value + $item->TaxAmount; $t = new stdClass(); $t->tax_rate = round($new_price / $price_value - 1, 4); $t->tax_amount = $item->TaxAmount; $t->tax_namekey = $this->taxName($t->tax_rate); $product->prices[0]->price_value_with_tax = $new_price; $product->prices[0]->taxes[$t->tax_namekey] = $t; if (!isset($rates[$tic])) { $rates[$tic] = new stdClass(); $rates[$tic]->amount = 0.0; } $rates[$tic]->amount += $item->TaxAmount; if ($this->debug && empty($useCache)) { var_dump($product->prices[0]); } if (!empty($product->prices[0]->unit_price)) { $product->prices[0]->unit_price->price_value_with_tax = $product->prices[0]->unit_price->price_value + $item->TaxAmount / $product->cart_product_quantity; } } } unset($product); } $cart->total->prices[0]->taxes = array(); foreach ($rates as $k => $rate) { $key = $this->taxName($rate->rate); if (!isset($cart->total->prices[0]->taxes[$key])) { $t = new stdClass(); $t->tax_amount = 0.0; $t->tax_rate = $rate->rate; $t->tax_namekey = $this->taxName($t->tax_rate); // JText::sprintf('TAXCLOUD_TAX', $t->tax_rate); $cart->total->prices[0]->taxes[$key] = $t; } $cart->total->prices[0]->taxes[$key]->tax_amount += $rate->amount; } $total_taxes = 0; foreach ($cart->total->prices[0]->taxes as &$tax) { $total_taxes += $tax->tax_amount; } unset($tax); $cart->total->prices[0]->price_value_with_tax = $cart->total->prices[0]->price_value + $total_taxes; if ($this->debug && empty($useCache)) { var_dump($cart->total->prices[0]); } } else { $this->display_errors(@$ret->Messages->ResponseMessage->Message); } }
function &getShippings(&$order, $reset = false) { static $usable_methods = null; static $shipping_groups = null; static $errors = array(); if ($reset) { $usable_methods = null; $errors = array(); $shipping_groups = null; } if (!is_null($usable_methods)) { $this->errors = $errors; $order->shipping_groups =& $shipping_groups; return $usable_methods; } $this->getShippingProductsData($order); $zoneClass = hikashop_get('class.zone'); $zones = $zoneClass->getOrderZones($order); $currency = @$order->total->prices[0]->price_currency_id; if (empty($currency)) { $currency = hikashop_getCurrency(); } $rates = $this->getMethods($order, $currency); $usable_methods = array(); $config =& hikashop_config(); if (!$config->get('force_shipping') && bccomp(@$order->weight, 0, 5) <= 0) { return $usable_methods; } if (empty($rates)) { $errors['no_rates'] = JText::_('NO_SHIPPING_METHOD_FOUND'); $this->errors = $errors; return $usable_methods; } $app = JFactory::getApplication(); $order_clone = new stdClass(); $variables = array('products', 'cart_id', 'coupon', 'shipping_address', 'volume', 'weight', 'volume_unit', 'weight_unit'); foreach ($variables as $var) { if (isset($order->{$var})) { $order_clone->{$var} = $order->{$var}; } } $use_cache = $config->get('use_shipping_cache', true); $shipping_key = sha1(serialize($order_clone) . serialize($rates)); if (!isset($order->cache)) { $order->cache = new stdClass(); } $order->cache->shipping_key = $shipping_key; $order->cache->shipping = null; if ($use_cache) { $order->cache->shipping = $app->getUserState(HIKASHOP_COMPONENT . '.shipping_cache.usable_methods', null); } foreach ($rates as $k => $rate) { if (!empty($rate->shipping_zone_namekey) && !in_array($rate->shipping_zone_namekey, $zones)) { unset($rates[$k]); continue; } if (!empty($rate->shipping_params->shipping_zip_prefix) || !empty($rate->shipping_params->shipping_min_zip) || !empty($rate->shipping_params->shipping_max_zip) || !empty($rate->shipping_params->shipping_zip_suffix)) { $checkDone = false; if (!empty($order->shipping_address) && !empty($order->shipping_address->address_post_code)) { if (preg_match('#([a-z]*)([0-9]+)(.*)#i', preg_replace('#[^a-z0-9]#i', '', $order->shipping_address->address_post_code), $match)) { $checkDone = true; $prefix = $match[1]; $main = $match[2]; $suffix = $match[3]; if (!empty($rate->shipping_params->shipping_zip_prefix) && $rate->shipping_params->shipping_zip_prefix != $prefix) { unset($rates[$k]); continue; } if (!empty($rate->shipping_params->shipping_min_zip) && $rate->shipping_params->shipping_min_zip > $main) { unset($rates[$k]); continue; } if (!empty($rate->shipping_params->shipping_max_zip) && $rate->shipping_params->shipping_max_zip < $main) { unset($rates[$k]); continue; } if (!empty($rate->shipping_params->shipping_zip_suffix) && $rate->shipping_params->shipping_zip_suffix != $suffix) { unset($rates[$k]); continue; } } } if (!$checkDone) { unset($rates[$k]); continue; } } } if (empty($rates)) { if (hikashop_loadUser()) { $errors['no_shipping_to_your_zone'] = JText::_('NO_SHIPPING_TO_YOUR_ZONE'); } $this->errors = $errors; return $usable_methods; } $shipping_groups = $this->getShippingGroups($order, $rates); JPluginHelper::importPlugin('hikashopshipping'); $dispatcher = JDispatcher::getInstance(); if (!empty($shipping_groups) && count($shipping_groups) > 1) { $order_backup = new stdClass(); $order_backup->products = $order->products; $order_backup->weight = $order->weight; $order_backup->weight_unit = $order->weight_unit; $order_backup->volume = $order->volume; $order_backup->volume_unit = $order->volume_unit; $order_backup->total_quantity = $order->total_quantity; $order_backup->total = $order->total; $cartClass = hikashop_get('class.cart'); $currencyClass = hikashop_get('class.currency'); foreach ($shipping_groups as $key => &$group) { $order->products = $group->products; $group_usable_methods = array(); $rates_copy = array(); if (is_int($key)) { $key = '' . $key; } $shipping_group_struct = array(); if (preg_match_all('#([a-zA-Z])*([0-9]+)#iu', $key, $keys)) { $shipping_group_struct = array_combine($keys[1], $keys[2]); } foreach ($rates as $rate) { if (empty($rate->shipping_published)) { continue; } $add_rate = true; if (!empty($rate->shipping_params->shipping_warehouse_filter)) { $add_rate = false; if ($key === $rate->shipping_params->shipping_warehouse_filter) { $add_rate = true; } else { $keys = array(); $tmp = array('' => $rate->shipping_params->shipping_warehouse_filter); if (is_string($rate->shipping_params->shipping_warehouse_filter) && preg_match_all('#([a-zA-Z])*([0-9]+)#iu', $rate->shipping_params->shipping_warehouse_filter, $keys)) { $tmp = array_combine($keys[1], $keys[2]); } if (is_array($rate->shipping_params->shipping_warehouse_filter)) { $tmp = $rate->shipping_params->shipping_warehouse_filter; } if ($tmp[''] == $shipping_group_struct[''] || empty($tmp[''])) { $add_rate = true; foreach ($tmp as $k => $v) { if ($k != '' && (!isset($shipping_group_struct[$k]) || $shipping_group_struct[$k] != $v)) { $add_rate = false; break; } } } } } if ($add_rate) { $rates_copy[] = clone $rate; } } $cartClass->calculateWeightAndVolume($order); $currencyClass->calculateTotal($order->products, $order, $order->total->prices[0]->price_currency_id); $order->shipping_warehouse_id = $key; $order->cache->shipping_key = $shipping_key . '_' . $key; $dispatcher->trigger('onShippingDisplay', array(&$order, &$rates_copy, &$group_usable_methods, &$errors)); unset($order->shipping_warehouse_id); $order->cache->shipping_key = $shipping_key; foreach ($group_usable_methods as $method) { if (isset($method->shipping_warehouse_id) && $method->shipping_warehouse_id != $key) { $method = clone $method; } if (!in_array($method->shipping_id, $group->shippings)) { $group->shippings[] = $method->shipping_id; } $method->shipping_warehouse_id = $key; $usable_methods[] = $method; } unset($method); } foreach ($order_backup as $k => $v) { $order->{$k} = $v; } } else { $key = array_keys($shipping_groups); $key = reset($key); if (is_int($key) && !empty($key)) { $key = '' . $key; } $keys = array(); if (preg_match_all('#([a-zA-Z])*([0-9]+)#iu', $key, $keys)) { if (count($keys[0]) > 1) { $key = array_combine($keys[1], $keys[2]); } } foreach ($rates as $i => $rate) { $rem_rate = false; if (!empty($rate->shipping_params->shipping_warehouse_filter)) { $rem_rate = true; if (!is_array($key)) { if ($key === $rate->shipping_params->shipping_warehouse_filter) { $rem_rate = false; } elseif (substr($rate->shipping_params->shipping_warehouse_filter, 0, 1) == '0') { $wf = substr($rate->shipping_params->shipping_warehouse_filter, 1); $rem_rate = empty($wf) || substr($key, 1) != $wf; } } else { $keys = array(); if (preg_match_all('#([a-zA-Z])*([0-9]+)#iu', $rate->shipping_params->shipping_warehouse_filter, $keys)) { $tmp = array_combine($keys[1], $keys[2]); if ($tmp[''] == $key['']) { $rem_rate = false; foreach ($tmp as $k => $v) { if (!isset($key[$k]) || $key[$k] != $v) { $rem_rate = true; break; } } } } } } if ($rem_rate) { $rates[$i] = null; unset($rates[$i]); } } $dispatcher->trigger('onShippingDisplay', array(&$order, &$rates, &$usable_methods, &$errors)); uasort($usable_methods, array($this, "sortShipping")); $g = reset($shipping_groups); foreach ($usable_methods as $method) { if (!in_array($method->shipping_id, $g->shippings)) { $g->shippings[] = $method->shipping_id; } $method->shipping_warehouse_id = $key; } } if (empty($usable_methods)) { $errors['no_rates'] = JText::_('NO_SHIPPING_METHOD_FOUND'); $this->errors = $errors; return $usable_methods; } else { $i = 0; $shipping_ordering = array(); foreach ($usable_methods as $key => $shipping_method) { $shipping_ordering[$key] = sprintf('%05d', $shipping_method->shipping_ordering) . '_' . sprintf('%05d', $i); $i++; } array_multisort($shipping_ordering, SORT_ASC, $usable_methods); } $this->errors = $errors; if ($use_cache) { $app->setUserState(HIKASHOP_COMPONENT . '.shipping_cache.usable_methods', $order->cache->shipping); } return $usable_methods; }
function onAfterRender() { $app = JFactory::getApplication(); if ($app->isAdmin()) { return; } $option = JRequest::getCmd('option', ''); $view = JRequest::getCmd('view', ''); $task = JRequest::getCmd('task', ''); $layout = JRequest::getCmd('layout', ''); if (($option != 'com_user' || $view != 'user' || $task != 'edit') && ($option != 'com_users' || $view != 'profile' || $layout != 'edit')) { return; } $display = $this->params->get('fields_on_user_profile'); if (is_null($display)) { $display = 1; } if (empty($display) || $display == '0') { return; } $body = JResponse::getBody(); $alternate_body = false; if (empty($body)) { $app = JFactory::getApplication(); $body = $app->getBody(); $alternate_body = true; } if (strpos($body, 'class="form-validate') === false) { return; } if (!defined('DS')) { define('DS', DIRECTORY_SEPARATOR); } if (!(include_once rtrim(JPATH_ADMINISTRATOR, DS) . DS . 'components' . DS . 'com_hikashop' . DS . 'helpers' . DS . 'helper.php')) { return true; } $user = hikashop_loadUser(true); $fieldsClass = hikashop_get('class.field'); $extraFields = array('user' => $fieldsClass->getFields('frontcomp', $user, 'user')); if (empty($extraFields['user'])) { return; } $null = array(); $fieldsClass->addJS($null, $null, $null); $fieldsClass->jsToggle($extraFields['user'], $user, 0); $requiredFields = array(); $validMessages = array(); $values = array('user' => $user); $fieldsClass->checkFieldsForJS($extraFields, $requiredFields, $validMessages, $values); $fieldsClass->addJS($requiredFields, $validMessages, array('user')); $data = ''; if (version_compare(JVERSION, '1.6.0', '<')) { $data .= '<style type="text/css">' . "\r\n" . 'fieldset.hikashop_user_edit { border: 1px solid rgb(204, 204, 204); margin: 10px 0 15px; padding: 0px 10px 0px 10px; }' . "\r\n" . '.hikashop_user_edit legend { font-size: 1em; font-weight: bold; }' . "\r\n" . '.hikashop_user_edit dt { padding: 5px 5px 5px 0px; width: 13em; clear:left; float:left; }' . "\r\n" . '.hikashop_user_edit dd { margin-left: 14em; }' . "\r\n" . '</style>'; } if (HIKASHOP_J30) { $data .= '<fieldset class="hikashop_user_edit"><legend>' . JText::_('HIKASHOP_USER_DETAILS') . '</legend><dl>'; } else { $data .= '<fieldset class="hikashop_user_edit"><legend>' . JText::_('HIKASHOP_USER_DETAILS') . '</legend>'; } foreach ($extraFields['user'] as $fieldName => $oneExtraField) { if (HIKASHOP_J30) { $data .= '<div class="control-group hikashop_registration_' . $fieldName . '_line" id="hikashop_user_' . $fieldName . '"><div class="control-label"><label>' . $fieldsClass->getFieldName($oneExtraField) . '</label></div><div class="controls">'; } else { $data .= '<dt><label>' . $fieldsClass->getFieldName($oneExtraField) . '</label></dt><dd class="hikashop_registration_' . $fieldName . '_line" id="hikashop_user_' . $fieldName . '">'; } $onWhat = 'onchange'; if ($oneExtraField->field_type == 'radio') { $onWhat = 'onclick'; } $data .= $fieldsClass->display($oneExtraField, @$user->{$fieldName}, 'data[user][' . $fieldName . ']', false, ' ' . $onWhat . '="hikashopToggleFields(this.value,\'' . $fieldName . '\',\'user\',0);"', false, $extraFields['user'], $user); if (HIKASHOP_J30) { $data .= '</div></div>'; } else { $data .= '</dd>'; } } if (HIKASHOP_J30) { $data .= '</dl></fieldset>'; } else { $data .= '</fieldset>'; } $body = preg_replace('#(<form[^>]*class="form-validate.*"[^>]*>.*</(fieldset|table)>)#Uis', '$1' . $data, $body, 1); if ($alternate_body) { $app->setBody($body); } else { JResponse::setBody($body); } }
*/ defined('_JEXEC') or die('Restricted access'); global $Itemid; $url_itemid = ''; if (!empty($this->itemid)) { $url_itemid = $this->itemid; } elseif (!empty($Itemid)) { $url_itemid = '&Itemid=' . $Itemid; } if ($this->config->get('show_quantity_field') == -2) { $this->params->set('show_quantity_field', $this->row->product_display_quantity_field); } $config =& hikashop_config(); $wishlistEnabled = $config->get('enable_wishlist', 1); $hideForGuest = 1; if ($config->get('hide_wishlist_guest', 1) && hikashop_loadUser() != null || !$config->get('hide_wishlist_guest', 1)) { $hideForGuest = 0; } if (!isset($this->cart)) { $this->cart = hikashop_get('helper.cart'); } $this->cart = hikashop_get('helper.cart'); $url = ''; $module_id = $this->params->get('from_module', 0); if (empty($this->ajax)) { $this->ajax = 'return hikashopModifyQuantity(\'' . $this->row->product_id . '\',field,1,0,\'cart\',' . $module_id . ')'; } if (@$this->row->product_sale_start || empty($this->element->main)) { $start_date = @$this->row->product_sale_start; } else { $start_date = $this->element->main->product_sale_start;
function onShippingDisplay(&$order, &$dbrates, &$usable_rates, &$messages) { if (!hikashop_loadUser()) { return false; } $local_usable_rates = array(); $local_messages = array(); $ret = parent::onShippingDisplay($order, $dbrates, $local_usable_rates, $local_messages); if ($ret === false) { return false; } $currentShippingZone = null; $currentCurrencyId = null; $currencyClass = hikashop_get('class.currency'); foreach ($local_usable_rates as $k => $rate) { if (empty($rate->shipping_params->methodsList)) { $messages['no_shipping_methods_configured'] = 'No shipping methods configured in the FedEx shipping plugin options'; continue; } $rate->shipping_params->methods = unserialize($rate->shipping_params->methodsList); if ($order->weight <= 0 || $order->volume <= 0 && @$rate->shipping_params->use_dimensions == 1) { continue; } $this->freight = false; $this->classicMethod = false; $heavyProduct = false; $weightTotal = 0; if (!empty($rate->shipping_params->methods)) { foreach ($rate->shipping_params->methods as $method) { if ($method == 'TDCB' || $method == 'TDA' || $method == 'TDO' || $method == '308' || $method == '309' || $method == '310') { $this->freight = true; } else { $this->classicMethod = true; } } } $data = null; if (empty($order->shipping_address)) { $messages['no_shipping_methods_configured'] = 'No shipping address is configured.'; return true; } $this->shipping_currency_id = $currency = hikashop_getCurrency(); $db = JFactory::getDBO(); $query = 'SELECT currency_code FROM ' . hikashop_table('currency') . ' WHERE currency_id IN (' . $this->shipping_currency_id . ')'; $db->setQuery($query); $this->shipping_currency_code = $db->loadResult(); $cart = hikashop_get('class.cart'); $null = null; $cart->loadAddress($null, $order->shipping_address->address_id, 'object', 'shipping'); $currency = hikashop_get('class.currency'); $receivedMethods = $this->_getRates($rate, $order, $heavyProduct, $null); if (empty($receivedMethods)) { $messages['no_rates'] = JText::_('NO_SHIPPING_METHOD_FOUND'); continue; } $i = 0; $local_usable_rates = array(); foreach ($receivedMethods as $method) { $usableMethods[] = $method; $local_usable_rates[$i] = !HIKASHOP_PHP5 ? $rate : clone $rate; $local_usable_rates[$i]->shipping_price += round($method['value'], 2); $selected_method = ''; $name = ''; foreach ($this->fedex_methods as $fedex_method) { if ($fedex_method['code'] == $method['code'] && ($method['old_currency_code'] == 'CAD' || !isset($fedex_method['double']))) { $name = $fedex_method['name']; $selected_method = $fedex_method['key']; break; } } $local_usable_rates[$i]->shipping_name = $name; if (!empty($selected_method)) { $local_usable_rates[$i]->shipping_id .= '-' . $selected_method; } $sep = ''; if (@$rate->shipping_params->show_eta) { if (@$rate->shipping_params->show_eta_delay) { if ($method['delivery_delay'] != -1 && $method['day'] > 0) { $local_usable_rates[$i]->shipping_description .= $sep . JText::sprintf('ESTIMATED_TIME_AFTER_SEND', $method['delivery_delay']); } else { $local_usable_rates[$i]->shipping_description .= $sep . JText::_('NO_ESTIMATED_TIME_AFTER_SEND'); } } else { if ($method['delivery_day'] != -1 && $method['day'] > 0) { $local_usable_rates[$i]->shipping_description .= $sep . JText::sprintf('ESTIMATED_TIME_AFTER_SEND', $method['delivery_day']); } else { $local_usable_rates[$i]->shipping_description .= $sep . JText::_('NO_ESTIMATED_TIME_AFTER_SEND'); } } $sep = '<br/>'; if ($method['delivery_time'] != -1 && $method['day'] > 0) { if (@$rate->shipping_params->show_eta_format == '12') { $local_usable_rates[$i]->shipping_description .= $sep . JText::sprintf('DELIVERY_HOUR', date('h:i:s a', strtotime($method['delivery_time']))); } else { $local_usable_rates[$i]->shipping_description .= $sep . JText::sprintf('DELIVERY_HOUR', $method['delivery_time']); } } else { $local_usable_rates[$i]->shipping_description .= $sep . JText::_('NO_DELIVERY_HOUR'); } } if (@$rate->shipping_params->show_notes && !empty($method['notes'])) { foreach ($method['notes'] as $note) { if ($note->Code != '820' && $note->Code != '819' && !empty($note->LocalizedMessage)) { $local_usable_rates[$i]->shipping_description .= $sep . implode('<br/>', $note->LocalizedMessage); $sep = '<br/>'; } } } if ($rate->shipping_params->group_package && $this->nbpackage > 0) { $local_usable_rates[$i]->shipping_description .= '<br/>' . JText::sprintf('X_PACKAGES', $this->nbpackage); } $i++; } foreach ($local_usable_rates as $i => $finalRate) { if (isset($finalRate->shipping_price_orig) || isset($finalRate->shipping_currency_id_orig)) { if ($finalRate->shipping_currency_id_orig == $finalRate->shipping_currency_id) { $finalRate->shipping_price_orig = $finalRate->shipping_price; } else { $finalRate->shipping_price_orig = $currencyClass->convertUniquePrice($finalRate->shipping_price, $finalRate->shipping_currency_id, $finalRate->shipping_currency_id_orig); } } $usable_rates[$finalRate->shipping_id] = $finalRate; } } }
* @author hikashop.com * @copyright (C) 2010-2015 HIKARI SOFTWARE. All rights reserved. * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html */ defined('_JEXEC') or die('Restricted access'); JHTML::_('behavior.tooltip'); $row =& $this->rows; $config = hikashop_config(); if ($row->vote_enabled != 1) { return; } $row->hikashop_vote_average_score = (double) hikashop_toFloat($row->hikashop_vote_average_score); JRequest::setVar("rate_rounded", $row->hikashop_vote_average_score_rounded); JRequest::setVar("nb_max_star", $row->hikashop_vote_nb_star); $main_div_name = $row->main_div_name; $hikashop_vote_user_id = hikashop_loadUser(); if (empty($hikashop_vote_user_id)) { $hikashop_vote_user_id = 0; } $select_id = "select_id_" . $row->vote_ref_id; if ($main_div_name != '') { $select_id .= "_" . $main_div_name; } else { $select_id .= "_hikashop_main_div_name"; } if ($config->get('enable_status_vote', 'vote') != 'both') { if (empty($main_div_name)) { ?> <input type="hidden" id="hikashop_vote_ref_id" value="<?php echo $row->vote_ref_id; ?>
function _check($message = true) { $user_id = hikashop_loadUser(); if (empty($user_id)) { $app = JFactory::getApplication(); if ($message) { $app->enqueueMessage(JText::_('PLEASE_LOGIN_FIRST')); } global $Itemid; $url = ''; if (!empty($Itemid)) { $url = '&Itemid=' . $Itemid; } if (version_compare(JVERSION, '1.6', '<')) { $url = 'index.php?option=com_user&view=login' . $url; } else { $url = 'index.php?option=com_users&view=login' . $url; } $app->redirect(JRoute::_($url . '&return=' . urlencode(base64_encode(hikashop_currentUrl('', false))), false)); return false; } $order_id = hikashop_getCID('order_id'); if (empty($order_id)) { parent::listing(); return false; } return true; }
function shipping() { $app = JFactory::getApplication(); $order =& $this->initCart(); $shippingClass = hikashop_get('class.shipping'); $usable_rates =& $shippingClass->getShippings($order); $imageHelper = hikashop_get('helper.image'); $this->assignRef('imageHelper', $imageHelper); $config =& hikashop_config(); $this->params->set('price_with_tax', $config->get('price_with_tax')); if ($this->params->get('show_original_price', '-1') == '-1') { $defaultParams = $config->get('default_params'); $this->params->set('show_original_price', $defaultParams['show_original_price']); } if (empty($usable_rates)) { $user_id = hikashop_loadUser(false); if (!empty($user_id) && !$shippingClass->displayErrors() && $this->has_shipping) { $app->enqueueMessage(JText::_('NO_SHIPPING_METHOD_FOUND')); } } else { $shipping_groups = $shippingClass->getShippingGroups($order, $usable_rates); $this->assignRef('shipping_groups', $shipping_groups); $warehouse_order = 0; $config =& hikashop_config(); $force_shipping = $config->get('force_shipping'); foreach ($shipping_groups as $shipping_group) { $warehouse_order++; if (empty($shipping_group->products) || !empty($shipping_group->shippings)) { continue; } if ($force_shipping) { if (!empty($shipping_group->name)) { $app->enqueueMessage(JText::sprintf('NO_SHIPPING_METHOD_FOUND_FOR_WAREHOUSE', $shipping_group->name)); } else { $app->enqueueMessage(JText::sprintf('NO_SHIPPING_METHOD_FOUND_FOR_WAREHOUSE', $warehouse_order)); } continue; } foreach ($shipping_group->products as $group_product) { if (isset($group_product->product_weight) && $group_product->product_weight > 0) { if (!empty($shipping_group->name)) { $app->enqueueMessage(JText::sprintf('NO_SHIPPING_METHOD_FOUND_FOR_WAREHOUSE', $shipping_group->name)); } else { $app->enqueueMessage(JText::sprintf('NO_SHIPPING_METHOD_FOUND_FOR_WAREHOUSE', $warehouse_order)); } continue; } } } $currencyClass = hikashop_get('class.currency'); $currencyClass->processShippings($usable_rates, $order); $shipping_method = $app->getUserState(HIKASHOP_COMPONENT . '.shipping_method'); $shipping_id = $app->getUserState(HIKASHOP_COMPONENT . '.shipping_id'); $config =& hikashop_config(); $auto_select_default = $config->get('auto_select_default', 2); if ($auto_select_default == 1 && count($usable_rates) > 1) { $auto_select_default = 0; } if ($auto_select_default && empty($shipping_id) && count($usable_rates)) { $rates = array(); $shipping_id = array(); $shipping_method = array(); foreach ($shipping_groups as $key => $shipping_group) { foreach ($usable_rates as $rate) { if (in_array($rate->shipping_id, $shipping_group->shippings)) { $rates[] = $rate; $shipping_id[] = $rate->shipping_id . '@' . $key; $shipping_method[] = $rate->shipping_type . '@' . $key; break; } } } $app->setUserState(HIKASHOP_COMPONENT . '.shipping_data', $rates); $app->setUserState(HIKASHOP_COMPONENT . '.shipping_id', $shipping_id); $app->setUserState(HIKASHOP_COMPONENT . '.shipping_method', $shipping_method); $order->shipping = $rates; $currencyClass->processShippings($order->shipping, $order); $order->full_total =& $currencyClass->addShipping($order->shipping, $order->full_total); } if (empty($shipping_id)) { $shipping_id = array(); } if (!is_array($shipping_id)) { $shipping_id = array($shipping_id); } if (empty($shipping_method)) { $shipping_method = array(); } if (!is_array($shipping_method)) { $shipping_method = array($shipping_method); } $this->assignRef('shipping_messages', $shippingClass->errors); $this->assignRef('currencyHelper', $currencyClass); $this->assignRef('rates', $usable_rates); $this->assignRef('orderInfos', $order); $this->assignRef('shipping_method', $shipping_method); $this->assignRef('shipping_id', $shipping_id); } $this->_getImagesName('shipping'); }
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html */ defined('_JEXEC') or die('Restricted access'); $cart_type = JRequest::getString('cart_type', 'cart'); $cart_id = JRequest::getInt('cart_id', ''); $tmpl = JRequest::getString('tmpl', 'view'); global $Itemid; $url_itemid = '&Itemid=' . $Itemid; if ($cart_type == 'wishlist') { $addText = JText::_('ADD_TO_CART'); } else { $addText = JText::_('ADD_TO_WISHLIST'); } $app = JFactory::getApplication(); $session = JFactory::getSession(); $userCurrent = hikashop_loadUser(true); if (isset($userCurrent)) { $userCurrent = $userCurrent->id; } else { $userCurrent = 0; } $hasAccess = $this->cartVal->user_id == $userCurrent || $this->cartVal->session_id == $session->getId(); if ($this->cartVal->display == 'registered' && $userCurrent == 0 || $this->cartVal->display == 'link' && JRequest::getString('link', 0) == 0) { $this->cartVal->display = 0; } if (!isset($cart->prices[0])) { $cart->prices[0] = new stdClass(); $cart->prices[0]->price_value = 0; $cart->prices[0]->price_value_with_tax = 0; $cart->prices[0]->price_currency_id = hikashop_getCurrency(); }
function onShippingDisplay(&$order, &$dbrates, &$usable_rates, &$messages) { if (!hikashop_loadUser()) { return false; } if ($this->loadShippingCache($order, $usable_rates, $messages)) { return true; } $local_usable_rates = array(); $local_messages = array(); $ret = parent::onShippingDisplay($order, $dbrates, $local_usable_rates, $local_messages); if ($ret === false) { return false; } if (!function_exists('curl_init')) { $app = JFactory::getApplication(); $app->enqueueMessage('The USPS shipping plugin needs the CURL library installed but it seems that it is not available on your server. Please contact your web hosting to set it up.', 'error'); return false; } $cache_rates = array(); $cache_messages = array(); $found = false; $currentShippingZone = null; $currentCurrencyId = null; foreach ($local_usable_rates as $rate) { if ($rate->shipping_type != 'usps') { continue; } if (empty($order->shipping_address)) { continue; } $found = true; $zones = null; if (!empty($rate->shipping_zone_namekey)) { if (empty($zones)) { $zoneClass = hikashop_get('class.zone'); $zones = $zoneClass->getOrderZones($order); } if (!in_array($rate->shipping_zone_namekey, $zones)) { $messages['no_shipping_to_your_zone'] = JText::_('NO_SHIPPING_TO_YOUR_ZONE'); continue; } $db = JFactory::getDBO(); if (is_array($order->shipping_address->address_country)) { $address_country = reset($order->shipping_address->address_country); } else { $address_country = $order->shipping_address->address_country; } $db->setQuery('SELECT * FROM ' . hikashop_table('zone') . ' WHERE zone_namekey=' . $db->Quote($address_country)); $zone = $db->loadObject(); if ($zone->zone_code_3 != 'USA') { $messages['no_shipping_to_your_zone'] = JText::_('NO_SHIPPING_TO_YOUR_ZONE'); continue; } } $check = false; if (empty($order->shipping_address->address_post_code)) { $check = true; $message = 'The USPS shipping plugin requires the user to enter a postal code when goods are shipped within the United States. Please go to "Display->Custom fields" and set the post code field to required.'; } elseif (!preg_match('#^[0-9]{5}(-?[0-9]{4})?$#', $order->shipping_address->address_post_code)) { $check = true; $message = 'The post code entered is not valid'; } if ($check) { if (empty($zones)) { $zoneClass = hikashop_get('class.zone'); $zones = $zoneClass->getOrderZones($order); } $db = JFactory::getDBO(); $db->setQuery('SELECT zone_namekey FROM ' . hikashop_table('zone') . ' WHERE zone_code_3=' . $db->Quote('USA')); $usa_zone = $db->loadResult(); if (in_array($usa_zone, $zones)) { $messages['post_code_missing'] = $message; continue; } } foreach ($order->products as $product) { if (!empty($rate->shipping_params->weight_approximation)) { if (isset($product->product_weight)) { $product->product_weight = $product->product_weight + $product->product_weight * $rate->shipping_params->weight_approximation / 100; } if (isset($product->product_weight_orig)) { $product->product_weight_orig = $product->product_weight_orig + $product->product_weight_orig * $rate->shipping_params->weight_approximation / 100; } } if (!empty($rate->shipping_params->dim_approximation)) { if (isset($product->product_height)) { $product->product_height = $product->product_height + $product->product_height * $rate->shipping_params->dim_approximation / 100; } if (isset($product->product_length)) { $product->product_length = $product->product_length + $product->product_length * $rate->shipping_params->dim_approximation / 100; } if (isset($product->product_width)) { $product->product_width = $product->product_width + $product->product_width * $rate->shipping_params->dim_approximation / 100; } if (isset($product->product_total_volume)) { $product->product_total_volume = $product->product_total_volume + $product->product_total_volume * $rate->shipping_params->dim_approximation / 100; } if (isset($product->product_total_volume_orig)) { $product->product_total_volume_orig = $product->product_total_volume_orig + $product->product_total_volume_orig * $rate->shipping_params->dim_approximation / 100; } } if (isset($product->variants)) { foreach ($product->variants as $variant) { if (!empty($rate->shipping_params->weight_approximation)) { if (isset($variant->product_weight)) { $variant->product_weight = $variant->product_weight + $variant->product_weight * $rate->shipping_params->weight_approximation / 100; } if (isset($variant->product_weight_orig)) { $variant->product_weight_orig = $variant->product_weight_orig + $variant->product_weight_orig * $rate->shipping_params->weight_approximation / 100; } } if (!empty($rate->shipping_params->dim_approximation)) { if (isset($variant->product_height)) { $variant->product_height = $variant->product_height + $variant->product_height * $rate->shipping_params->dim_approximation / 100; } if (isset($variant->product_length)) { $variant->product_length = $variant->product_length + $variant->product_length * $rate->shipping_params->dim_approximation / 100; } if (isset($variant->product_width)) { $variant->product_width = $variant->product_width + $variant->product_width * $rate->shipping_params->dim_approximation / 100; } if (isset($variant->product_total_volume)) { $variant->product_total_volume = $variant->product_total_volume + $variant->product_total_volume * $rate->shipping_params->dim_approximation / 100; } if (isset($variant->product_total_volume_orig)) { $variant->product_total_volume_orig = $variant->product_total_volume_orig + $variant->product_total_volume_orig * $rate->shipping_params->dim_approximation / 100; } } } } } $package = $this->getOrderPackage($order, array('weight_unit' => 'oz', 'volume_unit' => 'in', 'required_dimensions' => array('w', 'x', 'y', 'z'))); if (isset($package[0])) { $package = $package[0]; } $max_weight = 1120; if ($package['w'] > $max_weight) { $messages['items_weight_over_limit'] = JText::_('ITEMS_WEIGHT_TOO_BIG_FOR_SHIPPING_METHODS'); $cache_messages['items_weight_over_limit'] = JText::_('ITEMS_WEIGHT_TOO_BIG_FOR_SHIPPING_METHODS'); $this->setShippingCache($order, null, $cache_messages); return true; } if ($package['w'] < 1) { $package['w'] = 1; } // Minimum 1oz if (empty($order->shipping_address_full)) { $cart = hikashop_get('class.cart'); $app = JFactory::getApplication(); $address = $app->getUserState(HIKASHOP_COMPONENT . '.shipping_address'); $cart->loadAddress($order->shipping_address_full, $address, 'object', 'shipping'); } $query = 'SELECT currency_id FROM ' . hikashop_table('currency') . ' WHERE currency_code=\'USD\''; $db = JFactory::getDBO(); $db->setQuery($query); $currency = $db->loadResult(); $parcel = new stdClass(); $parcel->Country = @$order->shipping_address_full->shipping_address->address_country->zone_code_2; if (empty($parcel->Country)) { $parcel->Country = 'US'; } $parcel->Pickup_Postcode = substr(preg_replace('#[^a-z0-9]#i', '', @$rate->shipping_params->post_code), 0, 5); $parcel->Destination_Postcode = substr(preg_replace('#[^a-z0-9]#i', '', $order->shipping_address->address_post_code), 0, 5); $girth = array($package['y'], $package['x'], $package['z']); sort($girth); $parcel->Length = $girth[2]; $parcel->Width = $girth[1]; $parcel->Height = $girth[0]; $parcel->Girth = ($parcel->Height + $parcel->Width) * 2 + $parcel->Length; $parcel->Quantity = 1; $parcel->Weight = $package['w']; $rates = array(); if ($parcel->Country == 'US') { $modes = array('PRIORITY', 'MEDIA', 'EXPRESS', 'FIRST CLASS'); foreach ($modes as $mode) { if (!empty($rate->shipping_params->{$mode})) { $this->addRate($rates, $mode, $parcel, $rate, $currency, false); } } } else { $modes = array('INTERNATIONAL', 'PRIORITYINTSMALL', 'PRIORITYINTDVD', 'PRIORITYINTLARGEVIDEO', 'PRIORITYINTMEDIUM', 'PRIORITYINTLARGE', 'EXPRESSINTBOX', 'EXPRESSINT', 'FIRSTCLASSINT', 'ENVELOPE'); foreach ($modes as $mode) { if (!empty($rate->shipping_params->{$mode})) { $this->addRate($rates, $mode, $parcel, $rate, $currency, true); } } } if ($rate->shipping_params->sort_by_price == 'DESC') { $rates = $this->array_sort($rates, 'shipping_price', 'usps', SORT_DESC); } else { if ($rate->shipping_params->sort_by_price == 'ASC') { $rates = $this->array_sort($rates, 'shipping_price', 'usps', SORT_ASC); } } $i = 0; if (empty($rates)) { $messages['no_shipping_quotes'] = 'Failed to obtain shipping quotes.'; $cache_messages['no_shipping_quotes'] = 'Failed to obtain shipping quotes.'; $this->setShippingCache($order, null, $cache_messages); return true; } foreach ($rates as $finalRate) { $finalRate->shipping_ordering .= '_' . $i++; $usable_rates[$finalRate->shipping_id] = $finalRate; $cache_rates[$finalRate->shipping_id] = $finalRate; } } if (!$found) { $messages['no_rates'] = JText::_('NO_SHIPPING_METHOD_FOUND'); $cache_messages['no_rates'] = JText::_('NO_SHIPPING_METHOD_FOUND'); } $this->setShippingCache($order, $cache_rates, $cache_messages); return true; }
function form() { $user_id = hikashop_loadUser(); $this->assignRef('user_id', $user_id); $address_id = hikashop_getCID('address_id'); $address = JRequest::getVar('fail'); if (empty($address)) { $address = new stdClass(); if (!empty($address_id)) { $class = hikashop_get('class.address'); $address = $class->get($address_id); if ($address->address_user_id != $user_id) { $address = new stdClass(); $address_id = 0; } } else { $userCMS = JFactory::getUser(); if (!$userCMS->guest) { $name = $userCMS->get('name'); $pos = strpos($name, ' '); if ($pos !== false) { $address->address_firstname = substr($name, 0, $pos); $name = substr($name, $pos + 1); } $address->address_lastname = $name; } } } $extraFields = array(); $fieldsClass = hikashop_get('class.field'); $this->assignRef('fieldsClass', $fieldsClass); $fieldsClass->skipAddressName = true; global $Itemid; $url_itemid = ''; if (!empty($Itemid)) { $url_itemid = '&Itemid=' . $Itemid; } $extraFields['address'] = $fieldsClass->getFields('frontcomp', $address, 'address', 'checkout&task=state' . $url_itemid); $this->assignRef('extraFields', $extraFields); $null = array(); $fieldsClass->addJS($null, $null, $null); $fieldsClass->jsToggle($this->extraFields['address'], $address, 0); $this->assignRef('address', $address); $module = hikashop_get('helper.module'); $module->initialize($this); $requiredFields = array(); $validMessages = array(); $values = array('address' => $address); $fieldsClass->checkFieldsForJS($extraFields, $requiredFields, $validMessages, $values); $fieldsClass->addJS($requiredFields, $validMessages, array('address')); $cart = hikashop_get('helper.cart'); $this->assignRef('cart', $cart); }
function save() { JRequest::checkToken('request') || jexit('Invalid Token'); $app = JFactory::getApplication(); $addressClass = hikashop_get('class.address'); $fieldClass = hikashop_get('class.field'); $task = JRequest::getVar('subtask', ''); if (!empty($task)) { if (substr($task, -8) != '_address') { $task .= '_address'; } $result = $addressClass->frontSaveForm($task); if (!empty($result) && !empty($result[$task])) { JRequest::setVar('previous_cid', @$result[$task]->previous_id); JRequest::setVar('cid', $result[$task]->id); return $this->show(); } return $this->edit(); } $oldData = null; $already = @$_REQUEST['address']['address_id']; if (!empty($already)) { $oldData = $class->get($already); } $addressData = $fieldClass->getInput('address', $oldData); $ok = true; if (empty($addressData)) { $ok = false; } else { $user_id = hikashop_loadUser(); $addressData->address_user_id = $user_id; JRequest::setVar('fail', $addressData); $address_id = $addressClass->save($addressData); } if (!$ok || !$address_id) { $message = ''; if (isset($addressClass->message)) { $message = 'alert(\'' . addslashes($addressClass->message) . '\');'; } if (version_compare(JVERSION, '1.6', '<')) { $app = JFactory::getApplication(); $session = JFactory::getSession(); $session->set('application.queue', $app->_messageQueue); } $this->edit(); return; } $redirect = JRequest::getWord('redirect', ''); global $Itemid; $url = ''; if (!empty($Itemid)) { $url = '&Itemid=' . $Itemid; } if ($redirect == 'checkout') { $makenew = JRequest::getInt('makenew'); switch (JRequest::getVar('type')) { case 'shipping': if (JRequest::getVar('action') == 'add' && $makenew) { $app->setUserState(HIKASHOP_COMPONENT . '.billing_address', $address_id); } $app->setUserState(HIKASHOP_COMPONENT . '.shipping_address', $address_id); break; case 'billing': if (JRequest::getVar('action') == 'add' && $makenew) { $app->setUserState(HIKASHOP_COMPONENT . '.shipping_address', $address_id); } $app->setUserState(HIKASHOP_COMPONENT . '.billing_address', $address_id); break; default: $app->setUserState(HIKASHOP_COMPONENT . '.shipping_address', $address_id); $app->setUserState(HIKASHOP_COMPONENT . '.billing_address', $address_id); break; } $app->setUserState(HIKASHOP_COMPONENT . '.shipping_data', null); $app->setUserState(HIKASHOP_COMPONENT . '.shipping_method', null); $app->setUserState(HIKASHOP_COMPONENT . '.shipping_id', null); $app->setUserState(HIKASHOP_COMPONENT . '.payment_data', ''); $app->setUserState(HIKASHOP_COMPONENT . '.payment_method', ''); $app->setUserState(HIKASHOP_COMPONENT . '.payment_id', 0); if (!$already) { $controller = hikashop_get('controller.checkout'); $cart = $controller->initCart(); $controller->update_cart = true; if ($cart->has_shipping) { $controller->before_shipping(true); } $controller->before_payment(true); } $url = hikashop_completeLink('checkout&task=step&step=' . JRequest::getInt('step', 0) . $url, false, true); } else { $url = hikashop_completeLink('address' . $url, false, true); } ob_clean(); echo '<html><head><script type="text/javascript">window.parent.location.href=\'' . $url . '\';</script></head><body></body></html>'; exit; }
function onShippingDisplay(&$order, &$dbrates, &$usable_rates, &$messages) { $local_usable_rates = array(); $this->setLocalUsableRates($local_usable_rates); $local_messages = array(); $notUsable = array(); // Get installation information for parent products $parentProductInstallations = array(); if (self::getParam('prodinstall')) { foreach ($order->products as $product) { if ($product->product_parent_id) { continue; } if (empty($product->product_installation)) { continue; } $parentProductInstallations[$product->product_id] = trim($product->product_installation); } } if (self::getParam('categorychk')) { $categoryClass = hikashop_get('class.category'); $productClass = hikashop_get('class.product'); foreach ($order->products as $k => $product) { if ($product->cart_product_quantity > 0 && empty($product->categories)) { $categories = $productClass->getCategories($product->product_id); if (empty($categories)) { $categories = $productClass->getCategories($product->product_parent_id); } $order->products[$k]->categories = $categories; } } foreach ($dbrates as $k => $dbrate) { $dbrates[$k]->products = array(); if ($dbrate->shipping_type == $this->name) { $products = array(); // Check if this method usable with any ordered product categories $shipping_categories = @$dbrate->shipping_params->shipping_categories; if (!empty($shipping_categories)) { if (!empty($dbrate->shipping_params->shipping_incsubcategories)) { foreach ($categoryClass->getChildren($shipping_categories, true, array(), '', 0, 0, false, 'a.category_id') as $category) { $shipping_categories[] = $category->category_id; } } foreach ($order->products as $product) { if (!empty($product->categories)) { $catmatch = array_intersect($product->categories, $shipping_categories); if (!empty($catmatch)) { $products[] = $product->product_id; } } } if (empty($products)) { // Method not found for any ordered product categories $notUsable[] = $k; } } // Used to calculate total shipping price per product $dbrates[$k]->products = $products; // Check if this method excluded with any ordered product categories $products = array(); $shipping_categories = @$dbrate->shipping_params->shipping_exclude_categories; if (!empty($shipping_categories)) { if (!empty($dbrate->shipping_params->shipping_excsubcategories)) { foreach ($categoryClass->getChildren($shipping_categories, true, array(), '', 0, 0, false, 'a.category_id') as $category) { $shipping_categories[] = $category->category_id; } } foreach ($order->products as $product) { if (!empty($product->categories)) { $catmatch = array_intersect($product->categories, $shipping_categories); if (!empty($catmatch)) { $products[] = $product->product_id; } } } if (!empty($products)) { // Method found for excluded ordered product categories $notUsable[] = $k; } } } } } if (jPluginHelper::importPlugin('utilitybrain', 'test')) { plgUtilitybrainTest::onShippingDisplay($this, $order, $dbrates, $usable_rates, $messages); } $ret = parent::onShippingDisplay($order, $dbrates, $local_usable_rates, $local_messages); if ($ret === false) { return false; } $availablechk = self::getParam('availablechk'); $productqtychk = self::getParam('productqtychk'); $ordertimechk = self::getParam('ordertimechk'); $sizeweightpricecalc = self::getParam('sizeweightpricecalc'); foreach ($local_usable_rates as $k => $rate) { if ($availablechk) { if (!empty($rate->shipping_params->shipping_available_from)) { if (time() < strtotime($rate->shipping_params->shipping_available_from)) { $notUsable[] = $k; continue; } } if (!empty($rate->shipping_params->shipping_available_to)) { if (time() > strtotime($rate->shipping_params->shipping_available_to)) { $notUsable[] = $k; continue; } } } $found = 0; if ($ordertimechk) { if (!empty($rate->shipping_params->shipping_ordertime_before)) { if (date('h:i') > $rate->shipping_params->shipping_ordertime_before) { $found += 1; } } if (!empty($rate->shipping_params->shipping_ordertime_after)) { if (date('h:i') < $rate->shipping_params->shipping_ordertime_after) { $found -= 1; } } } if ($found != 0) { $notUsable[] = $k; continue; } if ($sizeweightpricecalc) { if (@$rate->shipping_params->shipping_require_sizeweight) { if (empty($order->volume) || empty($order->weight)) { $notUsable[] = $k; continue; } } } if ($productqtychk) { $minquantity = $rate->shipping_params->shipping_minquantity; $maxquantity = $rate->shipping_params->shipping_maxquantity; if ($minquantity && $minquantity > $order->total_quantity || $maxquantity && $maxquantity < $order->total_quantity) { $notUsable[] = $k; continue; } } if ($sizeweightpricecalc) { if (!self::SizeWeightPriceCalculation($order, $rate)) { $notUsable[] = $k; continue; } } } foreach ($notUsable as $item) { unset($local_usable_rates[$item]); } $app = JFactory::getApplication(); $orderFields = $app->getUserState(HIKASHOP_COMPONENT . '.checkout_fields', null); $fieldsClass = hikashop_get('class.field'); $extraFields = $fieldsClass->getFields('frontcomp', $orderFields, 'order'); $delivdate = self::getParam('delivdate'); if (isset($extraFields['order_delivery_date'])) { $checkMaxDay = false; } else { $checkMaxDay = true; } $earliest_delivery_day = @$orderFields->order_delivery_date; if ($delivdate && !empty($order->products)) { foreach ($order->products as $product) { if (!empty($product->item_delivery_date)) { if (empty($earliest_delivery_day) || $earliest_delivery_day > $product->item_delivery_date) { $earliest_delivery_day = $product->item_delivery_date; } } } } $productfieldname = self::getParam('productfieldname'); $notUsable = array(); foreach ($local_usable_rates as $k => $rate) { $local_usable_rates[$k]->shipping_params->productfieldname = $productfieldname; if (!empty($productfieldname) && !empty($rate->shipping_params->{$productfieldname})) { $fieldvalues = preg_split('/[,;]+/', $rate->shipping_params->{$productfieldname}); $fieldmatch = false; foreach ($order->products as $product) { if (!isset($product->{$productfieldname})) { $fieldmatch = true; break; } if (in_array($product->{$productfieldname}, $fieldvalues)) { $fieldmatch = true; break; } if (!empty($product->variants)) { foreach ($product->variants as $variant) { if (in_array($variant->{$productfieldname}, $fieldvalues)) { $fieldmatch = true; break 2; } } } } if (!$fieldmatch) { $notUsable[] = $k; continue; } } if (self::getParam('productchk') && !empty($rate->shipping_params->shipping_products)) { $fieldmatch = false; foreach ($order->products as $product) { if (in_array($product->product_id, $rate->shipping_params->shipping_products) || in_array($product->product_parent_id, $rate->shipping_params->shipping_products)) { $fieldmatch = true; break; } if (!empty($product->variants)) { foreach ($product->variants as $variant) { if (in_array($variant->product_id, $rate->shipping_params->shipping_products) || in_array($variant->product_parent_id, $rate->shipping_params->shipping_products)) { $fieldmatch = true; break 2; } } } } if (!$fieldmatch) { $notUsable[] = $k; continue; } } if (!self::validDeliveryDay($earliest_delivery_day, $rate->shipping_params, $checkMaxDay)) { $notUsable[] = $k; continue; } } foreach ($notUsable as $item) { unset($local_usable_rates[$item]); } if (empty($local_usable_rates)) { $messages['no_rates'] = JText::_('NO_SHIPPING_METHOD_FOUND'); return false; } if (class_exists('plgHikashopBFOrderDeliveryDate') && !empty(plgHikashopBFOrderDeliveryDate::$_current)) { $earliest_delivery_date = plgHikashopBFOrderDeliveryDate::$_current; } if (self::getParam('delivtime')) { $earliest_delivery_date = preg_replace('/@.*$/', '', $earliest_delivery_day); $current_delivery_day = preg_replace('/@.*$/', '', $this->getOrderDeliveryDate($order)); if (empty($earliest_delivery_date) || $earliest_delivery_date > $current_delivery_day) { $earliest_delivery_date = $current_delivery_day; } $notUsable = self::unusableDeliveryRates($earliest_delivery_date, $local_usable_rates); foreach ($notUsable as $item) { unset($local_usable_rates[$item]); } } if (empty($local_usable_rates)) { $messages['no_rates'] = JText::_('NO_SHIPPING_METHOD_FOUND'); return false; } if (self::getParam('proddelivery')) { $notFreeDelivery = $this->hasProductDelivery($order->products, '!free'); $notUsable = array(); foreach ($local_usable_rates as $k => $rate) { if ($notFreeDelivery == 1) { switch ($rate->shipping_params->shipping_price_type) { case 'free': $deliverable = true; break; case 'maintenance': default: $deliverable = false; $rate->shipping_params->shipping_with_delivery = true; break; } } else { $deliverable = $this->hasProductDelivery($order->products, $rate->shipping_params->shipping_price_type); if ($deliverable) { switch (@$rate->shipping_params->shipping_price_type) { case 'free': if ($notFreeDelivery == 1) { break; } case 'quote': if ($deliverable) { $deliverable = 0; } else { $deliverable = 1; } $rate->shipping_price = 0; break; case 'from': if ($deliverable) { $deliverable = 0; } else { $deliverable = 1; } if (!empty($rate->shipping_price)) { $rate->shipping_params->shipping_price_from = $rate->shipping_price; $rate->shipping_price = 0; } if (!isset($rate->shipping_params->shipping_price_from)) { $rate->shipping_params->shipping_price_from = 0; } break; case 'maintenance': default: break; } if ($deliverable == 0) { $rate->shipping_params->shipping_with_delivery = true; } } else { if (!empty($rate->shipping_params->shipping_price_type) && empty($rate->shipping_params->shipping_with_delivery)) { $deliverable = true; } } } if ($deliverable) { $notUsable[] = $k; } } foreach ($notUsable as $item) { unset($local_usable_rates[$item]); } if (empty($local_usable_rates)) { $messages['no_rates'] = JText::_('NO_SHIPPING_METHOD_FOUND'); return false; } } if (self::getParam('prodinstall')) { $notUsable = array(); foreach ($local_usable_rates as $k => &$rate) { if (!empty($rate->shipping_params->shipping_with_installation)) { $installable = $this->hasProductInstallation($order->products, $rate, $parentProductInstallations); if ($installable == 2) { $installable = 0; } else { if (!empty($rate->shipping_params->shipping_with_installation)) { switch (@$rate->shipping_params->shipping_price_type) { case 'quote': if ($installable) { $installable = 0; } else { $installable = 1; } $rate->shipping_price = 0; break; case 'from': if ($installable) { $installable = 0; } else { $installable = 1; } if (!empty($rate->shipping_price)) { $rate->shipping_params->shipping_price_from = $rate->shipping_price; $rate->shipping_price = 0; } if (!isset($rate->shipping_params->shipping_price_from)) { $rate->shipping_params->shipping_price_from = 0; } break; case 'maintenance': $installable = 0; break; default: if ($installable == 0) { $installable = 1; } break; } } else { if (!empty($rate->shipping_params->shipping_with_delivery)) { $installable = 0; } else { } } } if ($installable) { $notUsable[] = $k; } } } foreach ($notUsable as $item) { unset($local_usable_rates[$item]); } if (empty($local_usable_rates)) { $messages['no_rates'] = JText::_('NO_INSTALLATION_METHOD_FOUND'); return false; } } if (self::getParam('delivslots', 0)) { $order_delivery_slot = isset($order->order_delivery_slot) ? @$order->order_delivery_slot : @$_REQUEST["data"]["order"]["order_delivery_slot"]; if ($order_delivery_slot) { $delivslotsFound = false; foreach ($local_usable_rates as $k => &$rate) { $shipping_ignore_delivslots = !empty($rate->shipping_params->shipping_ignore_delivslots); if ($delivslotsFound && $shipping_ignore_delivslots) { $notUsable[] = $k; continue; } $shipping_delivslots = trim(@$rate->shipping_params->shipping_delivslots); if (empty($shipping_delivslots)) { continue; } $shipping_delivslots = explode("\n", $shipping_delivslots); if (in_array($order_delivery_slot, $shipping_delivslots)) { $delivslotsFound = true; continue; } $notUsable[] = $k; } foreach ($notUsable as $item) { unset($local_usable_rates[$item]); } if (empty($local_usable_rates)) { $messages['no_rates'] = self::trans('PLG_BF_MANUAL_NO_SHIPPING_FOR_THIS_DELIVSLOT'); return false; } } } $postcodehandler = self::getParam('postcodehandler', 0); if (is_object($order->shipping_address)) { $postcodesFound = false; foreach ($local_usable_rates as $k => &$rate) { $shipping_ignore_postcodes = !empty($rate->shipping_params->shipping_ignore_postcodes); if ($postcodesFound && $shipping_ignore_postcodes) { $notUsable[] = $k; continue; } $shipping_postcodes = trim(@$rate->shipping_params->shipping_postcodes); if (empty($shipping_postcodes)) { continue; } switch ($postcodehandler) { case 0: break 2; case 1: // UK // UK case 2: // NL $address_postcode = trim($order->shipping_address->address_post_code, " ^\t\n\r\v"); $address_postcode = preg_replace('/[^0-9A-Z]+/', ' ', strtoupper($address_postcode)); if (!empty($address_postcode) && strpos($address_postcode, ' ') === false) { if (preg_match('/[0-9A-Z][0-9][A-Z][A-Z]$/', $address_postcode)) { $len = strlen($address_postcode); $address_postcode = substr($address_postcode, 0, $len - 3) . ' ' . substr($address_postcode, $len - 3); } } if (preg_match('/[a-zA-Z0-9]/', @$shipping_postcodes)) { $checkDone = false; if (!empty($address_postcode)) { $shipping_postcodes = strtoupper(@$shipping_postcodes); foreach (preg_split('/[;,\\s]/', $shipping_postcodes) as $shipping_postcode) { if (!empty($shipping_postcode)) { if (preg_match('/^' . $shipping_postcode . '/', $address_postcode)) { $checkDone = true; $postcodesFound = true; break; } } } } if (!$checkDone) { $notUsable[] = $k; continue; } } break; case 3: // CAN $address_postcode = trim($order->shipping_address->address_post_code, " ^\t\n\r\v"); if (strlen($address_postcode) == 6) { $address_postcode = preg_replace('/[^0-9A-Z]+/', '', strtoupper($address_postcode)); } $shipping_postcodes = strtoupper(@$shipping_postcodes); if (preg_match('/[A-Z0-9]/', $shipping_postcodes)) { $checkDone = false; if (strlen($address_postcode) == 6) { foreach (preg_split('/[;,\\s]/', $shipping_postcodes) as $shipping_postcode) { if (!empty($shipping_postcode)) { if (preg_match('/^' . $shipping_postcode . '/', $address_postcode)) { $checkDone = true; $postcodesFound = true; break; } } } } if (!$checkDone) { $notUsable[] = $k; continue; } } break; default: if ($postcodehandler > 900) { // Numeric $pclen = $postcodehandler - 900; $address_postcode = preg_replace('/[^0-9]+/', '', $order->shipping_address->address_post_code); if (strlen($address_postcode) < $pclen) { $address_postcode = str_pad($address_postcode, $pclen, '0', STR_PAD_LEFT); } if (preg_match('/[0-9]/', @$shipping_postcodes)) { $checkDone = false; foreach (preg_split('/[^.0-9]/', $shipping_postcodes) as $postcode) { if (!empty($postcode)) { if (strpos($postcode, '.') !== false) { if (!preg_match('/' . $postcode . '/', $address_postcode)) { continue; } } else { if ($address_postcode != $postcode) { continue; } } $checkDone = true; $postcodesFound = true; break; } } if (!$checkDone) { $notUsable[] = $k; continue; } } } break; } } foreach ($notUsable as $item) { unset($local_usable_rates[$item]); } if (empty($local_usable_rates)) { $messages['no_rates'] = self::trans('PLG_BF_MANUAL_NO_SHIPPING_TO_YOUR_POSTCODE'); return false; } } if (plgHikashopshippingBFManual::$_params->get('addresschk', 0)) { foreach ($local_usable_rates as $k => &$rate) { for ($f = 1; $f < 3; $f++) { $field = 'shipping_address' . $f . '_field'; $values = 'shipping_address' . $f . '_values'; $addressfield = trim(@$rate->shipping_params->{$field}); $addressvalues = trim(@$rate->shipping_params->{$values}); if (!empty($addressfield) && !empty($addressvalues)) { $addressvalue = @$order->shipping_address->{$addressfield}; if (!empty($addressvalue)) { $checkDone = false; foreach (preg_split('/[,\\n\\r]/', $addressvalues) as $value) { if (!empty($value) && preg_match('/' . $value . '/i', $addressvalue)) { $checkDone = true; break; } } } if (!$checkDone) { $notUsable[] = $k; continue; } } } } } foreach ($notUsable as $item) { unset($local_usable_rates[$item]); } if (empty($local_usable_rates) && !empty($notUsable)) { if (hikashop_loadUser()) { $messages['no_shipping_to_your_zone'] = JText::_('NO_SHIPPING_TO_YOUR_ZONE'); } return false; } $this->setLocalUsableRates($local_usable_rates); foreach ($local_usable_rates as $id => $usable_rate) { $usable_rates[$usable_rate->shipping_id] = $usable_rate; } return true; }
function onShippingDisplay(&$order, &$dbrates, &$usable_rates, &$messages) { if (!hikashop_loadUser()) { return false; } $local_usable_rates = array(); $local_messages = array(); $ret = parent::onShippingDisplay($order, $dbrates, $local_usable_rates, $local_messages); if ($ret === false) { return false; } $currentShippingZone = null; $currentCurrencyId = null; $found = true; $usableWarehouses = array(); $zoneClass = hikashop_get('class.zone'); $zones = $zoneClass->getOrderZones($order); foreach ($local_usable_rates as $k => $rate) { if (!empty($rate->shipping_params->warehousesList)) { $rate->shipping_params->warehouses = unserialize($rate->shipping_params->warehousesList); } else { $messages['no_warehouse_configured'] = 'No warehouse configured in the CANPAR shipping plugin options'; continue; } foreach ($rate->shipping_params->warehouses as $warehouse) { if (empty($warehouse->zone) || $warehouse->zone == '-' || in_array($warehouse->zone, $zones)) { $usableWarehouses[] = $warehouse; } } if (empty($usableWarehouses)) { $messages['no_warehouse_configured'] = 'No available warehouse found for your location'; continue; } if (!empty($rate->shipping_params->methodsList)) { $rate->shipping_params->methods = unserialize($rate->shipping_params->methodsList); } else { $messages['no_shipping_methods_configured'] = 'No shipping methods configured in the CANPAR shipping plugin options'; continue; } if ($order->weight <= 0 || $order->volume <= 0) { return true; } $data = null; if (empty($order->shipping_address)) { $messages['no_shipping_address_found'] = 'No shipping address entered'; continue; } $this->shipping_currency_id = hikashop_getCurrency(); $db = JFactory::getDBO(); $query = 'SELECT currency_code FROM ' . hikashop_table('currency') . ' WHERE currency_id IN (' . $this->shipping_currency_id . ')'; $db->setQuery($query); $this->shipping_currency_code = $db->loadResult(); $cart = hikashop_get('class.cart'); $null = null; $cart->loadAddress($null, $order->shipping_address->address_id, 'object', 'shipping'); $currency = hikashop_get('class.currency'); $receivedMethods = $this->_getBestMethods($rate, $order, $usableWarehouses, $null); if (empty($receivedMethods)) { $messages['no_rates'] = JText::_('NO_SHIPPING_METHOD_FOUND'); continue; } $i = 0; $local_usable_rates = array(); foreach ($receivedMethods as $method) { $local_usable_rates[$i] = !HIKASHOP_PHP5 ? $rate : clone $rate; $local_usable_rates[$i]->shipping_price += $method['value']; $selected_method = ''; $name = ''; foreach ($this->canpar_methods as $canpar_method) { if ($canpar_method['name'] == $method['name']) { $name = $canpar_method['name']; $selected_method = $canpar_method['key']; } } $local_usable_rates[$i]->shipping_name = $name; if (!empty($selected_method)) { $local_usable_rates[$i]->shipping_id .= '-' . $selected_method; } if ($method['deliveryDate'] != 'www.canpar.ca') { if (is_numeric($method['deliveryDate'])) { $timestamp = strtotime($method['deliveryDate']); $time = parent::displayDelaySECtoDAY($timestamp - strtotime('now'), 2); $local_usable_rates[$i]->shipping_description .= 'Estimated delivery date: ' . $time; } else { $time = $method['deliveryDate']; $local_usable_rates[$i]->shipping_description .= 'Estimated delivery date: ' . $time; } } else { $local_usable_rates[$i]->shipping_description .= ' ' . JText::_('NO_ESTIMATED_TIME_AFTER_SEND'); } if ($rate->shipping_params->group_package == 1 && $this->nbpackage > 1) { $local_usable_rates[$i]->shipping_description .= '<br/>' . JText::sprintf('X_PACKAGES', $this->nbpackage); } $i++; } foreach ($local_usable_rates as $i => $rate) { $usable_rates[$rate->shipping_id] = $rate; } } }
/** * @package HikaShop for Joomla! * @version 2.6.0 * @author hikashop.com * @copyright (C) 2010-2015 HIKARI SOFTWARE. All rights reserved. * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html */ defined('_JEXEC') or die('Restricted access'); global $Itemid; $url_itemid = ''; if (!empty($Itemid)) { $url_itemid = '&Itemid=' . $Itemid; } $userCurrent = hikashop_loadUser(true); if (hikashop_loadUser() == null) { echo JText::_('PLEASE_LOGIN_FIRST'); } else { ?> <div id="hikashop_download_listing"> <fieldset> <div class="header hikashop_header_title"><h1><?php echo JText::_('DOWNLOADS'); ?> </h1></div> <div class="toolbar hikashop_header_buttons" id="toolbar" style="float: right;"> <table class="hikashop_no_border"> <tr> <td> <a onclick="javascript:submitbutton('cancel'); return false;" href="#" > <span class="icon-32-back" title="<?php
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 listing() { $app = JFactory::getApplication(); $pageInfo = new stdClass(); $pageInfo->filter = new stdClass(); $pageInfo->filter->order = new stdClass(); $pageInfo->limit = new stdClass(); $pageInfo->filter->order->value = $app->getUserStateFromRequest($this->paramBase . ".filter_order", 'filter_order', 'a.order_created', 'cmd'); $pageInfo->filter->order->dir = $app->getUserStateFromRequest($this->paramBase . ".filter_order_Dir", 'filter_order_Dir', 'desc', 'word'); $pageInfo->search = $app->getUserStateFromRequest($this->paramBase . ".search", 'search', '', 'string'); $pageInfo->search = JString::strtolower(trim($pageInfo->search)); $pageInfo->limit->start = $app->getUserStateFromRequest($this->paramBase . '.limitstart', 'limitstart', 0, 'int'); $oldValue = $app->getUserState($this->paramBase . '.list_limit'); if (empty($oldValue)) { $oldValue = $app->getCfg('list_limit'); } $pageInfo->limit->value = $app->getUserStateFromRequest($this->paramBase . '.list_limit', 'limit', $app->getCfg('list_limit'), 'int'); if ($oldValue != $pageInfo->limit->value) { $pageInfo->limit->start = 0; $app->setUserState($this->paramBase . '.limitstart', 0); } $database = JFactory::getDBO(); $searchMap = array('a.order_id', 'a.order_status', 'a.order_number'); $filters = array(); $order = ''; if (!empty($pageInfo->filter->order->value)) { $order = ' ORDER BY ' . $pageInfo->filter->order->value . ' ' . $pageInfo->filter->order->dir; } if (!empty($pageInfo->search)) { $searchVal = '\'%' . hikashop_getEscaped(JString::strtolower(trim($pageInfo->search)), true) . '%\''; $filter = '(' . implode(" LIKE {$searchVal} OR ", $searchMap) . " LIKE {$searchVal}" . ')'; $filters[] = $filter; } if (is_array($filters) && count($filters)) { $filters = ' AND ' . implode(' AND ', $filters); } else { $filters = ''; } $query = 'FROM ' . hikashop_table('order') . ' AS a WHERE a.order_type = ' . $database->Quote('sale') . ' AND a.order_user_id=' . (int) hikashop_loadUser() . $filters . $order; $database->setQuery('SELECT a.* ' . $query, (int) $pageInfo->limit->start, (int) $pageInfo->limit->value); $rows = $database->loadObjectList(); if (!empty($pageInfo->search)) { $rows = hikashop_search($pageInfo->search, $rows, 'order_id'); } $database->setQuery('SELECT COUNT(*) ' . $query); $pageInfo->elements = new stdClass(); $pageInfo->elements->total = $database->loadResult(); $pageInfo->elements->page = count($rows); $currencyClass = hikashop_get('class.currency'); $this->assignRef('currencyHelper', $currencyClass); if (!$pageInfo->elements->page) { $app->enqueueMessage(JText::_('NO_ORDERS_FOUND')); } $pagination = hikashop_get('helper.pagination', $pageInfo->elements->total, $pageInfo->limit->start, $pageInfo->limit->value); $pagination->hikaSuffix = ''; $this->assignRef('pagination', $pagination); $this->assignRef('pageInfo', $pageInfo); $string = ''; $params = new HikaParameter($string); $params->set('show_quantity_field', 0); $config =& hikashop_config(); if (hikashop_level(1) && $config->get('allow_payment_button', 1)) { $unpaid_statuses = explode(',', $config->get('order_unpaid_statuses', 'created')); if (!empty($rows)) { foreach ($rows as $k => $order) { if (in_array($order->order_status, $unpaid_statuses)) { $rows[$k]->show_payment_button = true; } } } $payment_change = $config->get('allow_payment_change', 1); $this->assignRef('payment_change', $payment_change); $pluginsPayment = hikashop_get('type.plugins'); $pluginsPayment->type = 'payment'; $this->assignRef('payment', $pluginsPayment); } if ($config->get('cancellable_order_status', '') != '') { $cancellable_order_status = explode(',', $config->get('cancellable_order_status', '')); foreach ($rows as $k => $order) { if (in_array($order->order_status, $cancellable_order_status)) { $rows[$k]->show_cancel_button = true; } } } $this->assignRef('params', $params); $this->assignRef('rows', $rows); $this->assignRef('config', $config); $cart = hikashop_get('helper.cart'); $this->assignRef('cart', $cart); $category = hikashop_get('type.categorysub'); $category->type = 'status'; $category->load(true); $this->assignRef('order_statuses', $category); hikashop_setPageTitle('ORDERS'); }
function onShippingDisplay(&$order, &$dbrates, &$usable_rates, &$messages) { $weightClass = hikashop_get('helper.weight'); $volumeClass = hikashop_get('helper.volume'); if (!hikashop_loadUser()) { return false; } $local_usable_rates = array(); $local_messages = array(); $currencyClass = hikashop_get('class.currency'); $ret = parent::onShippingDisplay($order, $dbrates, $local_usable_rates, $local_messages); if ($ret === false) { return false; } $currentShippingZone = null; $currentCurrencyId = null; foreach ($local_usable_rates as $rate) { if (!empty($rate->shipping_zone_namekey)) { $zoneClass = hikashop_get('class.zone'); $zones = $zoneClass->getOrderZones($order); if (!in_array($rate->shipping_zone_namekey, $zones)) { $messages['no_shipping_to_your_zone'] = JText::_('NO_SHIPPING_TO_YOUR_ZONE'); continue; } } if (empty($order->shipping_address_full)) { $cart = hikashop_get('class.cart'); $app = JFactory::getApplication(); $address = $app->getUserState(HIKASHOP_COMPONENT . '.shipping_address'); $cart->loadAddress($order->shipping_address_full, $address, 'object', 'shipping'); } if ($order->shipping_address_full->shipping_address->address_country->zone_code_3 != 'BRA') { continue; } $cepCliente = trim($order->shipping_address->address_post_code); $max_altura = 2; $max_largura = 11; $max_comprimento = 16; $orderWeight = 0; foreach ($order->products as $product) { $product_weight = $weightClass->convert($product->product_weight, $product->product_weight_unit, 'kg'); $orderWeight += $product->cart_product_quantity * $product_weight; //Define medidas máximas if ($product->product_height > $max_altura) { $max_altura = $product->product_height; } if ($product->product_width > $max_largura) { $max_largura = $product->product_width; } if ($product->product_length > $max_comprimento) { $max_comprimento = $product->product_length; } } // ============= Início Obtém o valor do frete do site dos Correios ============= //Monta URL para pegar os dados do site dos Correios $workstring = 'nCdEmpresa=' . $rate->shipping_params->correios_servico_empresa; $workstring .= '&sDsSenha=' . $rate->shipping_params->correios_servico_senha; $workstring .= '&sCepOrigem=' . $rate->shipping_params->correios_shop_post_code; $workstring .= '&sCepDestino=' . $cepCliente; $workstring .= '&nVlPeso=' . $orderWeight; $workstring .= '&nCdFormato=1'; $workstring .= '&nVlAltura=' . number_format($max_altura, 2, ',', ''); $workstring .= '&nVlLargura=' . number_format($max_largura, 2, ',', ''); $workstring .= '&nVlComprimento=' . number_format($max_comprimento, 2, ',', ''); $workstring .= '&sCdMaoPropria=' . $rate->shipping_params->correios_mao_propria; if ($rate->shipping_params->correios_declara_valor || $rate->shipping_params->correios_servico == 40045 || $rate->shipping_params->correios_servico == 40126) { $workstring .= '&nVlValorDeclarado=' . number_format(round($order->total->prices[0]->price_value_with_tax, 2), 2, ',', '.'); } else { $workstring .= '&nVlValorDeclarado=0'; } $workstring .= '&sCdAvisoRecebimento=' . $rate->shipping_params->correios_aviso_recebimento; $workstring .= '&nCdServico=' . $rate->shipping_params->correios_servico; $workstring .= '&nVlDiametro=0'; $workstring .= '&StrRetorno=xml'; $url_busca = "http://ws.correios.com.br/calculador/CalcPrecoPrazo.aspx"; $url_busca .= "?" . $workstring; $conteudo = ''; $conteudo = $this->_transmiteCorreios($url_busca); if (preg_match("/<Erro>99<\\/Erro>/i", $conteudo)) { $url_busca = "http://ws.correios.com.br/calculador/CalcPrecoPrazo.asmx/CalcPreco"; $url_busca .= "?" . $workstring; $conteudo = ''; $conteudo = $this->_transmiteCorreios($url_busca); } if (strpos($conteudo, 'HTTP Error 503. The service is unavailable.') !== false) { $messages[] = 'HTTP Error 503. The Correios server is unavailable.'; continue; } if ($conteudo) { $dadosCorreios = simplexml_load_string($conteudo); } if (is_object($dadosCorreios->cServico)) { $Valor = (string) $dadosCorreios->cServico->Valor; $Erro = (string) $dadosCorreios->cServico->Erro; $MsgErro = (string) $dadosCorreios->cServico->MsgErro; if ($Erro != 0) { $messages[] = $MsgErro; } $Valor = str_replace(",", ".", $Valor); } if ($Valor > 0) { $rate->shipping_price = $Valor; //$rate -> shipping_price = 10.00; $rate->shipping_id = $rate->shipping_params->correios_servico; $usable_rates[] = $rate; } } return true; }
function delete() { //delete a cart with the id given $cart_id = JRequest::getInt('cart_id', '0'); $cart_type = JRequest::getString('cart_type', 'cart'); $cartClass = hikashop_get('class.cart'); $cartClass->cart_type = $cart_type; $cartInfo = $cartClass->loadCart($cart_id); $currUser = hikashop_loadUser(true); if ($cartInfo != null && $currUser->user_cms_id == $cartInfo->user_id) { $app = JFactory::getApplication(); if ($app->getUserState(HIKASHOP_COMPONENT . '.' . $cart_type . '_id') == $cart_id) { $app->setUserState(HIKASHOP_COMPONENT . '.' . $cart_type . '_id', '0'); } $cartClass->delete($cart_id, 'old'); } $this->showcarts(); }
function waitlist() { $user = hikashop_loadUser(true); $this->assignRef('element', $user); $app = JFactory::getApplication(); $product_id = (int) hikashop_getCID('product_id'); $config =& hikashop_config(); $this->assignRef('config', $config); $filters = array('a.product_id=' . $product_id); hikashop_addACLFilters($filters, 'product_access', 'a'); $query = 'SELECT a.*,b.product_category_id, b.category_id, b.ordering FROM ' . hikashop_table('product') . ' AS a LEFT JOIN ' . hikashop_table('product_category') . ' AS b ON a.product_id = b.product_id WHERE ' . implode(' AND ', $filters) . ' LIMIT 1'; $database = JFactory::getDBO(); $database->setQuery($query); $element = $database->loadObject(); if (empty($element)) { return; } if ($element->product_type == 'variant') { $this->selected_variant_id = $product_id; $filters = array('a.product_id=' . $element->product_parent_id); hikashop_addACLFilters($filters, 'product_access', 'a'); $query = 'SELECT a.*,b.* FROM ' . hikashop_table('product') . ' AS a LEFT JOIN ' . hikashop_table('product_category') . ' AS b ON a.product_id = b.product_id WHERE ' . implode(' AND ', $filters) . ' LIMIT 1'; $database->setQuery($query); $main = $database->loadObject(); if (empty($main)) { return; } $main->variants = array($element); $element = $main; $product_id = $element->product_id; $ids = array($element->variants[0]->product_id, $product_id); $query = 'SELECT a.*,b.* FROM ' . hikashop_table('variant') . ' AS a LEFT JOIN ' . hikashop_table('characteristic') . ' AS b ON a.variant_characteristic_id=b.characteristic_id WHERE a.variant_product_id IN (' . implode(',', $ids) . ') ORDER BY a.ordering,b.characteristic_value'; $database->setQuery($query); $characteristics = $database->loadObjectList(); if (!empty($characteristics)) { $mainCharacteristics = array(); foreach ($characteristics as $characteristic) { if ($product_id == $characteristic->variant_product_id) { $mainCharacteristics[$product_id][$characteristic->characteristic_parent_id][$characteristic->characteristic_id] = $characteristic; } } $cartClass = hikashop_get('class.cart'); $cartClass->addCharacteristics($element, $mainCharacteristics, $characteristics); $productClass = hikashop_get('class.product'); $productClass->checkVariant($element->variants[0], $element); $element = $element->variants[0]; } } $productClass = hikashop_get('class.product'); $productClass->addAlias($element); if (!$element->product_published) { return; } $this->assignRef('product', $element); global $Itemid; $url_itemid = ''; if (!empty($Itemid)) { $url_itemid = '&Itemid=' . $Itemid; } $product_url = hikashop_contentLink('product&task=show&cid=' . (int) $element->product_id . '&name=' . $element->alias . $url_itemid, $element); $this->assignRef('product_url', $product_url); }