/** * Return messages from Order ID * * @param integer $order_id Order ID * @param boolean $private return WITH private messages * @param JeproshopContext $context * @return array Messages */ public static function getMessagesByOrderId($order_id, $private = false, JeproshopContext $context = null) { if (!JeproshopTools::isBool($private)) { die(JError::raiseError()); } if (!$context) { $context = JeproshopContext::getContext(); } $db = JFactory::getDBO(); $query = "SELECT message.*, customer." . $db->quoteName('firstname') . " AS customer_firstname, customer."; $query .= $db->quoteName('lastname') . " AS customer_lastname, employee." . $db->quoteName('name') . " AS employee_name, "; $query .= "employee." . $db->quoteName('username') . " AS employee_user_name, (COUNT(message_readed.message_id) = 0 AND "; $query .= "message.customer_id != 0) AS is_new_for_me FROM " . $db->quoteName('#__jeproshop_message') . " AS message LEFT JOIN "; $query .= $db->quoteName('#__jeproshop_customer') . " AS customer ON message." . $db->quoteName('customer_id') . " = "; $query .= "customer." . $db->quoteName('customer_id') . " LEFT JOIN " . $db->quoteName('#__jeproshop_message_readed'); $query .= " AS message_readed ON message_readed." . $db->quoteName('message_id') . " = message." . $db->quoteName('message_id'); $query .= " AND message_readed." . $db->quoteName('employee_id') . " = " . (isset($context->employee) ? (int) $context->employee->employee_id : ""); $query .= " LEFT OUTER JOIN " . $db->quoteName('#__users') . " AS employee ON employee." . $db->quoteName('id'); $query .= " = message." . $db->quoteName('employee_id') . "\tWHERE order_id = " . (int) $order_id; $query .= (!$private ? " AND message." . $db->quoteName('private') . " = 0" : "") . " GROUP BY message.message_id"; $query .= " ORDER BY message.date_add DESC"; $db->setQuery($query); return $db->loadObjectList(); }
/** * Display date regarding to language preferences * * @param string $date Date to display format UNIX * @param boolean $full With time or not (optional) * @return string Date * @throws JException */ public static function displayDate($date, $full = false) { if (!$date || !($time = strtotime($date))) { return $date; } if ($date == '0000-00-00 00:00:00' || $date == '0000-00-00') { return ''; } if (!JeproshopTools::isDate($date) || !JeproshopTools::isBool($full)) { throw new JException('Invalid date'); } $context = JeproshopContext::getContext(); $date_format = $full ? $context->language->date_format_full : $context->language->date_format_lite; return date($date_format, $time); }
public static function getDeliveredCountries($lang_id, $active_countries = false, $active_carriers = false, $contain_states = null) { if (!JeproshopTools::isBool($active_countries) || !JeproshopTools::isBool($active_carriers)) { die(Tools::displayError()); } $db = JFactory::getDBO(); $query = "SELECT state.* FROM " . $db->quoteName('#__jeproshop_state') . " AS state ORDER BY state." . $db->quoteName('name') . " ASC"; $db->setQuery($query); $states = $db->loadObjectList(); $query = "SELECT country_lang.*, country.*, country_lang." . $db->quoteName('name') . " AS country_name, zone." . $db->quoteName('name') . " AS zone_name FROM " . $db->quoteName('#__jeproshop_country') . " AS country "; $query .= JeproshopShopModelShop::addSqlAssociation('country') . " LEFT JOIN " . $db->quoteName('#__jeproshop_country_lang') . " AS country_lang ON (country." . $db->quoteName('country_id') . " = country_lang." . $db->quoteName('country_id'); $query .= " AND country_lang." . $db->quoteName('lang_id') . " = " . (int) $lang_id . ") INNER JOIN (" . $db->quoteName('#__jeproshop_carrier_zone') . " AS carrier_zone INNER JOIN " . $db->quoteName('#__jeproshop_carrier'); $query .= " AS carrier ON ( carrier.carrier_id = carrier_zone.carrier_id AND carrier.deleted = 0 " . ($active_carriers ? " AND carrier.published = 1) " : ") ") . " LEFT JOIN " . $db->quoteName('#__jeproshop_zone') . " AS zone ON(carrier_zone."; $query .= $db->quoteName('zone_id') . " = zone." . $db->quoteName('zone_id') . " AND zone." . $db->quoteName('zone_id') . " = country." . $db->quoteName('zone_id') . ") WHERE 1 " . ($active_countries ? " AND country." . $db->quoteName('published') . " = 1" : ""); $query .= (!is_null($contain_states) ? " AND country." . $db->quoteName('contains_states') . " = " . (int) $contain_states : "") . " ORDER BY country_lang.name ASC"; $db->setQuery($query); $result = $db->loadObjectList(); $countries = array(); foreach ($result as &$country) { $countries[$country->country_id] = $country; } foreach ($states as &$state) { if (isset($countries[$state->country_id])) { /* Does not keep the state if its country has been disabled and not selected */ if ($state->published == 1) { $countries[$state->country_id]['states'][] = $state; } } } return $countries; }
public function renderDetails($tpl = null) { $app = JFactory::getApplication(); $order_id = $app->input->get('order_id'); if (!isset($this->context) || $this->context == null) { $this->context = JeproshopContext::getContext(); } /*global $orderTotal; $this->step = (int)($app->input->get('step')); if (!$this->nbProducts) { $this->step = -1; } if ($this->nbProducts) { $virtual_cart = $this->context->cart->isVirtualCart(); $this->assignRef('virtual_cart', $virtual_cart); } if (!$app->input->get('multi-shipping')) $this->context->cart->setNoMultiShipping(); // If some products have disappear if (!$this->context->cart->checkQuantities()){ $this->step = 0; $this->context->controller->has_errors = true; JEroor::raiseError(500, JText::_('COM_JEPROSHOP_AN_ITEM_IN_YOUR_CART_IS_NO_LONGER_AVAILABLE_IN_THIS_QUANTITY_YOU_CAN_NOT_PROCEED_WITH_YOUR_ORDER_UNTIL_THE_QUANTITY_IS_ADJUSTED_MESSAGE')); } // Check minimal amount $currency = JeproshopCurrencyModelCurrency::getCurrency((int)$this->context->cart->currency_id); $orderTotal = $this->context->cart->getOrderTotal(); $minimal_purchase = JeproshopTools::convertPrice((float)JeproshopSettingModelSetting::getValue('minimum_purchase'), $currency); if ($this->context->cart->getOrderTotal(false, JeproshopCartModelCart::ONLY_PRODUCTS) < $minimal_purchase && (isset($this->current_step) && $this->current_step != 'summary')){ $this->current_step = 0; $this->errors[] = sprintf( Tools::displayError('A minimum purchase total of %1s (tax excl.) is required in order to validate your order, current purchase total is %2s (tax excl.).'), Tools::displayPrice($minimal_purchase, $currency), Tools::displayPrice($this->context->cart->getOrderTotal(false, JeproshopCartModelCart::ONLY_PRODUCTS), $currency) ); } if (!$this->context->customer->isLogged(true) && in_array($this->current_step, array(1, 2, 3))) { $back_url = $this->context->controller->getPageLink('order', true, (int)$this->context->language->lang_id,'&step=' . $this->current_step . '&multi_shipping=' . (int)$app->input->get('multi_shipping')); $params = array('multi_shipping' => (int)Tools::getValue('multi_shipping'), 'display_guest_checkout' => (int)Configuration::get('PS_GUEST_CHECKOUT_ENABLED'), 'back' => $back_url); Tools::redirect($this->context->controller->getPageLink('authentication', true, (int)$this->context->language->lang_id, $params)); } if ($app->input->get('multi_shipping') == 1){ $multi_shipping = true; } else{ $multi_shipping = false; } $this->assignRef('multi_shipping', $multi_shipping); if ($this->context->customer->customer_id){ $address_list = $this->context->customer->getAddresses($this->context->language->lang_id); }else{ $address_list = array(); } $this->assignRef('address_list', $address_list); if ($app->input->get('use_ajax') && $app->input->get('method') == 'update_extra_carrier'){ // Change virtually the currents delivery options $delivery_option = $this->context->cart->getDeliveryOption(); $delivery_option[(int)$app->input->get('address_id')] = $app->input->get('delivery_option_id'); $this->context->cart->setDeliveryOption($delivery_option); $this->context->cart->save(); $return = array( 'content' => Hook::exec( 'displayCarrierList', array( 'address' => new JeproshopAddressModelAddress((int)$app->input->get('address_id')) ) ) ); die(Tools::jsonEncode($return)); } if ($this->nbProducts) $this->assignRef('virtual_cart', $this->context->cart->isVirtualCart()); if (!$app->input->get('multi-shipping')) $this->context->cart->setNoMultiShipping(); */ // 4 steps to the order switch ((int) $this->step) { case -1: $this->assignRef('empty', 1); $this->setLayout('shopping-_cart'); break; case 1: $this->assignAddress(); $this->processAddressFormat(); if ($app->input->get('multi_shipping') == 1) { $this->assignSummaryInformations(); $this->assignRef('product_list', $this->context->cart->getProducts()); $this->setLayout('order_address_multi_shipping'); } else { $this->setLayout('order_address'); } break; case 2: if ($app->input->get('process_address')) { $this->processAddress(); } $this->autoStep(); $this->context->controller->assignCarrier(); $this->setLayout('order_carrier'); break; case 3: // Check that the conditions (so active) were accepted by the customer $cgv = $app->input->get('cgv') || $this->context->cookie->check_cgv; if (JeproshopSettingModelSetting::getValue('conditions') && (!JeproshopTools::isBool($cgv) || $cgv == false)) { $app->redirect('index.php?option=com_jeproshop&view=order¤t_step=address'); } JeproshopContext::getContext()->cookie->check_cgv = true; // Check the delivery option is set if (!$this->context->cart->isVirtualCart()) { if (!Tools::getValue('delivery_option') && !$app->input->get('carrier_id') && !$this->context->cart->delivery_option && !$this->context->cart->carrier_id) { $app->redirect('index.php?option=com_jeproshop&view=order¤t_step=address'); } elseif (!$app->input->get('carrier_id') && !$this->context->cart->carrier_id) { $deliveries_options = $app->input->get('delivery_option'); if (!$deliveries_options) { $deliveries_options = $this->context->cart->delivery_option; } foreach ($deliveries_options as $delivery_option) { if (empty($delivery_option)) { $app->redirect('index.php?option=com_jeproshop&view=order¤t_step=address'); } } } } $this->autoStep(); // Bypass payment step if total is 0 $order_id = $this->context->controller->checkFreeOrder(); if ($order_id) { if ($this->context->customer->is_guest) { $order = new JeproshopOrderModelOrder((int) $order_id); $email = $this->context->customer->email; $this->context->customer->mylogout(); // If guest we clear the cookie for security reason $app->redirect('index.php?option=com_jeproshop&view=guest_tracking&order_id=' . urlencode($order->reference) . '&email=' . urlencode($email)); } else { $app->redirect('index.php?option=com_jeproshop&view=history'); } } $this->assignPayment(); // assign some informations to display cart $this->assignSummaryInformations(); $this->setLayout('order_payment'); break; default: $this->assignSummaryInformations(); $this->setLayout('shopping_cart'); break; } $this->assignRef('currency_sign', $this->context->currency->sign); $this->assignRef('currency_rate', $this->context->currency->conversion_rate); $this->assignRef('currency_format', $this->context->currency->format); $this->assignRef('currency_blank', $this->context->currency->blank); parent::display($tpl); }
/** * * @param int $parent_id * @param int $lang_id * @param bool $published * @param bool $shop_id * @return array */ public static function getChildren($parent_id, $lang_id, $published = true, $shop_id = false) { if (!JeproshopTools::isBool($published)) { die(JError::_()); } $cache_id = 'Category::getChildren_' . (int) $parent_id . '_' . (int) $lang_id . '-' . (bool) $published . '_' . (int) $shop_id; if (!JeproshopCache::isStored($cache_id)) { $db = JFactory::getDBO(); $query = "SELECT category." . $db->quoteName('category_id') . ", category_lang." . $db->quoteName('name') . ", category_lang." . $db->quoteName('link_rewrite'); $query .= ", category_shop." . $db->quoteName('shop_id') . " FROM " . $db->quoteName('#__jeproshop_category') . " AS category LEFT JOIN " . $db->quoteName('#__jeproshop_category_lang'); $query .= " AS category_lang ON (category." . $db->quoteName('category_id') . " = category_lang." . $db->quoteName('category_id') . JeproshopShopModelShop::addSqlRestrictionOnLang('category_lang'); $query .= ") " . JeproshopShopModelShop::addSqlAssociation('category') . " WHERE " . $db->quoteName('lang_id') . " = " . (int) $lang_id . " AND category." . $db->quoteName('parent_id'); $query .= " = " . (int) $parent_id . ($published ? " AND " . $db->quoteName('published') . " = 1" : "") . " GROUP BY category." . $db->quoteName('category_id') . " ORDER BY category_shop."; $query .= $db->quoteName('position') . " ASC"; $db->setQuery($query); $result = $db->loadObjectList(); JeproshopCache::store($cache_id, $result); } return JeproshopCache::retrieve($cache_id); }
/** * Get product price * * @param integer $product_id Product id * @param boolean $use_tax With taxes or not (optional) * @param integer $product_attribute_id Product attribute id (optional). * If set to false, do not apply the combination price impact. NULL does apply the default combination price impact. * @param integer $decimals Number of decimals (optional) * @param boolean $only_reduction Returns only the reduction amount * @param boolean $use_reduction Set if the returned amount will include reduction * @param integer $quantity Required for quantity discount application (default value: 1) * @param integer $customer_id Customer ID (for customer group reduction) * @param integer $cart_id Cart ID. Required when the cookie is not accessible (e.g., inside a payment module, a cron task...) * @param integer $address_id Customer address ID. Required for price (tax included) calculation regarding the guest localization * @param null $specific_price_output * @param boolean $with_ecotax insert ecotax in price output. * @param bool $use_group_reduction * @param JeproshopContext $context * @param bool $use_customer_price * @internal param int $divisor Useful when paying many time without fees (optional) * @internal param \variable_reference $specificPriceOutput . * If a specific price applies regarding the previous parameters, this variable is filled with the corresponding SpecificPrice object * @return float Product price */ public static function getStaticPrice($product_id, $use_tax = true, $product_attribute_id = null, $decimals = 6, $only_reduction = false, $use_reduction = true, $quantity = 1, $customer_id = null, $cart_id = null, $address_id = null, $specific_price_output = null, $with_ecotax = true, $use_group_reduction = true, JeproshopContext $context = null, $use_customer_price = true) { if (!$context) { $context = JeproshopContext::getContext(); } $cur_cart = $context->cart; if (!JeproshopTools::isBool($use_tax) || !JeproshopTools::isUnsignedInt($product_id)) { //die(Tools::displayError()); } // Initializations $group_id = (int) JeproshopGroupModelGroup::getCurrent()->group_id; // If there is cart in context or if the specified id_cart is different from the context cart id if (!is_object($cur_cart) || JeproshopTools::isUnsignedInt($cart_id) && $cart_id && $cur_cart->cart_id != $cart_id) { /* * When a user (e.g., guest, customer, Google...) is on Jeproshop, he has already its cart as the global (see /init.php) * When a non-user calls directly this method (e.g., payment module...) is on JeproShop, he does not have already it BUT knows the cart ID * When called from the back office, cart ID can be inexistant */ if (!$cart_id && !isset($context->employee)) { JError::raiseError(500, __FILE__ . ' ' . __LINE__); } $cur_cart = new JeproshopCartModelCart($cart_id); // Store cart in context to avoid multiple instantiations in BO if (!JeproshopTools::isLoadedObject($context->cart, 'cart_id')) { $context->cart = $cur_cart; } } $db = JFactory::getDBO(); $cart_quantity = 0; if ((int) $cart_id) { $cache_id = 'jeproshop_product_model_get_price_static_' . (int) $product_id . '_' . (int) $cart_id; $cart_qty = JeproshopCache::retrieve($cache_id); if (!JeproshopCache::isStored($cache_id) || $cart_qty != (int) $quantity) { $query = "SELECT SUM(" . $db->quoteName('quantity') . ") FROM " . $db->quoteName('#__jeproshop_cart_product'); $query .= " WHERE " . $db->quoteName('product_id') . " = " . (int) $product_id . " AND " . $db->quoteName('cart_id'); $query .= " = " . (int) $cart_id; $db->setQuery($query); $cart_quantity = (int) $db->loadResult(); JeproshopCache::store($cache_id, $cart_quantity); } $cart_quantity = JeproshopCache::retrieve($cache_id); } $currency_id = (int) JeproshopTools::isLoadedObject($context->currency, 'currency_id') ? $context->currency->currency_id : JeproshopSettingModelSetting::getValue('default_currency'); // retrieve address information $country_id = (int) $context->country->country_id; $state_id = 0; $zipcode = 0; if (!$address_id && JeproshopTools::isLoadedObject($cur_cart, 'cart_id')) { $address_id = $cur_cart->{JeproshopSettingModelSetting::getValue('tax_address_type')}; } if ($address_id) { $address_info = JeproshopAddressModelAddress::getCountryAndState($address_id); if ($address_info->country_id) { $country_id = (int) $address_info->country_id; $state_id = (int) $address_info->state_id; $zipcode = $address_info->postcode; } } else { if (isset($context->customer->geoloc_country_id)) { $country_id = (int) $context->customer->geoloc_country_id; $state_id = (int) $context->customer->state_id; $zipcode = (int) $context->customer->postcode; } } if (JeproshopTaxModelTax::taxExcludedOption()) { $use_tax = false; } if ($use_tax != false && !empty($address_info->vat_number) && $address_info->country_id != JeproshopSettingModelSetting::getValue('vat_number_country') && JeproshopSettingModelSetting::getValue('vat_number_management')) { $use_tax = false; } if (is_null($customer_id) && JeproshopTools::isLoadedObject($context->customer, 'customer_id')) { $customer_id = $context->customer->customer_id; } return JeproshopProductModelProduct::priceCalculation($context->shop->shop_id, $product_id, $product_attribute_id, $country_id, $state_id, $zipcode, $currency_id, $group_id, $quantity, $use_tax, $decimals, $only_reduction, $use_reduction, $with_ecotax, $specific_price_output, $use_group_reduction, $customer_id, $use_customer_price, $cart_id, $cart_quantity); }