示例#1
0
 public function renderView($tpl = null)
 {
     if ($this->getLayout() !== 'modal') {
     }
     if ($this->context == null) {
         $this->context = JeproshopContext::getContext();
     }
     $db = JFactory::getDBO();
     $this->setLayout('view');
     $this->loadObject();
     if (!JeproshopTools::isLoadedObject($this->customer, 'customer_id')) {
         return;
     }
     $this->context->customer = $this->customer;
     $customer_stats = $this->customer->getStats();
     $query = "SELECT SUM(total_paid_real) FROM " . $db->quoteName('#__jeproshop_orders');
     $query .= " WHERE customer_id = " . (int) $this->customer->customer_id . " AND valid = 1";
     $db->setQuery($query);
     $total_customer = $db->loadResult();
     if ($total_customer) {
         $query = "SELECT SQL_CALC_FOUND_ROWS COUNT(*) FROM " . $db->quoteName('#__jeproshop_orders');
         $query .= " WHERE valid = 1 AND customer_id != " . (int) $this->customer->customer_id . " GROUP BY ";
         $query .= "customer_id HAVING SUM(total_paid_real) > " . (int) $total_customer;
         $db->setQuery($query);
         $db->loadResult();
         $count_better_customers = (int) $db->loadResult('SELECT FOUND_ROWS()') + 1;
     } else {
         $count_better_customers = '-';
     }
     $orders = JeproshopOrderModelOrder::getCustomerOrders($this->customer->customer_id, true);
     $total_orders = count($orders);
     for ($i = 0; $i < $total_orders; $i++) {
         $orders[$i]->total_paid_real_not_formated = $orders[$i]->total_paid_real;
         $orders[$i]->total_paid_real = JeproshopTools::displayPrice($orders[$i]->total_paid_real, new JeproshopCurrencyModelCurrency((int) $orders[$i]->currency_id));
     }
     $messages = JeproshopCustomerThreadModelCustomerThread::getCustomerMessages((int) $this->customer->customer_id);
     $total_messages = count($messages);
     for ($i = 0; $i < $total_messages; $i++) {
         $messages[$i]->message = substr(strip_tags(html_entity_decode($messages[$i]->message, ENT_NOQUOTES, 'UTF-8')), 0, 75);
         $messages[$i]->date_add = Tools::displayDate($messages[$i]->date_add, null, true);
     }
     $groups = $this->customer->getGroups();
     $total_groups = count($groups);
     for ($i = 0; $i < $total_groups; $i++) {
         $group = new JeproshopGroupModelGroup($groups[$i]);
         $groups[$i] = array();
         $groups[$i]['group_id'] = $group->group_id;
         $groups[$i]['name'] = $group->name[$this->context->controller->default_form_language];
     }
     $total_ok = 0;
     $orders_ok = array();
     $orders_ko = array();
     foreach ($orders as $order) {
         if (!isset($order->order_state)) {
             $order->order_state = JText::_('COM_JEPROSHOP_THERE_IS_NO_STATUS_DEFINED_FOR_THIS_ORDER_MESSAGE');
         }
         if ($order->valid) {
             $orders_ok[] = $order;
             $total_ok += $order->total_paid_real_not_formated;
         } else {
             $orders_ko[] = $order;
         }
     }
     $products = $this->customer->getBoughtProducts();
     $carts = JeproshopCartModelCart::getCustomerCarts($this->customer->customer_id);
     $total_carts = count($carts);
     for ($i = 0; $i < $total_carts; $i++) {
         $cart = new JeproshopCartModelCart((int) $carts[$i]->cart_id);
         $this->context->cart = $cart;
         $summary = $cart->getSummaryDetails();
         $currency = new JeproshopCurrencyModelCurrency((int) $carts[$i]->currency_id);
         $carrier = new JeproshopCarrierModelCarrier((int) $carts[$i]->carrier_id);
         $carts[$i]['id_cart'] = sprintf('%06d', $carts[$i]['id_cart']);
         $carts[$i]['date_add'] = JeproshopValidator::displayDate($carts[$i]->date_add, null, true);
         $carts[$i]['total_price'] = Tools::displayPrice($summary->total_price, $currency);
         $carts[$i]->name = $carrier->name;
     }
     $query = "SELECT DISTINCT cart_product.product_id, cart.cart_id, cart.shop_id, cart_product.shop_id ";
     $query .= " AS cart_product_shop_id FROM " . $db->quoteName('#__jeproshop_cart_product') . " AS cart_product";
     $query .= " JOIN " . $db->quoteName('#__jeproshop_cart') . " AS cart ON (cart.cart_id = cart_product.cart_id) ";
     $query .= "JOIN " . $db->quoteName('#__jeproshop_product') . " AS product ON (cart_product.product_id = product.";
     $query .= "product_id) WHERE cart.customer_id = " . (int) $this->customer->customer_id . " AND cart_product.product_id";
     $query .= " NOT IN ( SELECT product_id FROM " . $db->quoteName('#__jeproshop_orders') . " AS ord JOIN ";
     $query .= $db->quoteName('#__jeproshop_order_detail') . " AS ord_detail ON (ord.order_id = ord_detail.order_id ) WHERE ";
     $query .= "ord.valid = 1 AND ord.customer_id = " . (int) $this->customer->customer_id . ")";
     $db->setQuery($query);
     $interested = $db->loadObjectList();
     $total_interested = count($interested);
     for ($i = 0; $i < $total_interested; $i++) {
         $product = new JeproshopProductModelProduct($interested[$i]->product_id, false, $this->context->controller->default_form_language, $interested[$i]->shop_id);
         if (!Validate::isLoadedObject($product, 'product_id')) {
             continue;
         }
         $interested[$i]->url = $this->context->controller->getProductLink($product->product_id, $product->link_rewrite, JeproshopCategoryModelCategory::getLinkRewrite($product->default_category_id, $this->context->controller->default_form_language), null, null, $interested[$i]->cp_shop_id);
         $interested[$i]->product_id = (int) $product->product_id;
         $interested[$i]->name = htmlentities($product->name);
     }
     $connections = $this->customer->getLastConnections();
     if (!is_array($connections)) {
         $connections = array();
     }
     $total_connections = count($connections);
     for ($i = 0; $i < $total_connections; $i++) {
         $connections[$i]->http_referer = $connections[$i]->http_referer ? preg_replace('/^www./', '', parse_url($connections[$i]->http_referer, PHP_URL_HOST)) : JText::_('COM_JEPROSHOP_DIRECT_LINK_LABEL');
     }
     $referrers = JeproshopReferrerModelReferrer::getReferrers($this->customer->customer_id);
     $total_referrers = count($referrers);
     for ($i = 0; $i < $total_referrers; $i++) {
         $referrers[$i]->date_add = JeproshopTools::displayDate($referrers[$i]->date_add, null, true);
     }
     $customerLanguage = new JeproshopLanguageModelLanguage($this->customer->lang_id);
     $shop = new JeproshopShopModelShop($this->customer->shop_id);
     //$this->assignRef('customer', $customer);
     /*'gender' => $gender,
     		/*	'gender_image' => $gender_image,
     		// General information of the customer */
     $registration = JeproshopTools::displayDate($this->customer->date_add, null, true);
     $this->assignRef('registration_date', $registration);
     $this->assignRef('customer_stats', $customer_stats);
     $last_visit = JeproshopTools::displayDate($customer_stats->last_visit, null, true);
     $this->assignRef('last_visit', $last_visit);
     $this->assignRef('count_better_customers', $count_better_customers);
     $shop_feature_active = JeproshopShopModelShop::isFeaturePublished();
     $this->assignRef('shop_is_feature_active', $shop_feature_active);
     $this->assignRef('shop_name', $shop->shop_name);
     $customerBirthday = JeproshopTools::displayDate($this->customer->birthday);
     $this->assignRef('customer_birthday', $customerBirthday);
     $last_update = JeproshopTools::displayDate($this->customer->date_upd, null, true);
     $this->assignRef('last_update', $last_update);
     $customerExists = JeproshopCustomerModelCustomer::customerExists($this->customer->email);
     $this->assignRef('customer_exists', $customerExists);
     $this->assignRef('lang_id', $this->customer->lang_id);
     $this->assignRef('customerLanguage', $customerLanguage);
     // Add a Private note
     $customerNote = JeproshopTools::htmlentitiesUTF8($this->customer->note);
     $this->assignRef('customer_note', $customerNote);
     // Messages
     $this->assignRef('messages', $messages);
     // Groups
     $this->assignRef('groups', $groups);
     // Orders
     $this->assignRef('orders', $orders);
     $this->assignRef('orders_ok', $orders_ok);
     $this->assignRef('orders_ko', $orders_ko);
     $total_ok = JeproshopTools::displayPrice($total_ok, $this->context->currency->currency_id);
     $this->assignRef('total_ok', $total_ok);
     // Products
     $this->assignRef('products', $products);
     // Addresses
     $addresses = $this->customer->getAddresses($this->context->controller->default_form_language);
     $this->assignRef('addresses', $addresses);
     // Discounts
     $discounts = JeproshopCartRuleModelCartRule::getCustomerCartRules($this->context->controller->default_form_language, $this->customer->customer_id, false, false);
     $this->assignRef('discounts', $discounts);
     // Carts
     $this->assignRef('carts', $carts);
     // Interested
     $this->assignRef('interested_products', $interested);
     // Connections
     $this->assignRef('connections', $connections);
     // Referrers
     $this->assignRef('referrers', $referrers);
     if ($this->getLayout() != 'modal') {
         $this->addToolBar();
         $this->sideBar = JHtmlSidebar::render();
     }
     parent::display($tpl);
 }
示例#2
0
 public function update_message()
 {
     $app = JFactory::getApplication();
     $order_id = $app->input->get('order_id');
     $customer_id = $app->input->get('customer_id');
     $order = new JeproshopOrderModelOrder($order_id);
     if (isset($order)) {
         if ($this->viewAccess()) {
             $customer = new JeproshopCustomerModelCustomer($customer_id);
             if (!JeproshopTools::isLoadedObject($customer, 'customer_id')) {
                 JError::raiseError(JText::_('COM_JEPROSHOP_CUSTOMER_IS_INVALID_MESSAGE'));
             } elseif (!$inputMessage) {
                 JError::raiseError(JText::_('COM_JEPROSHOP_THE_MESSAGE_CANNOT_BE_BLANK_MESSAGE'));
             } else {
                 /** Get Message rules anf check fields validity */
                 $rules = JeproshopMessageModelMessage::getValidationRules();
                 foreach ($rules->required as $field) {
                     $value = $app->input->get($field) == false;
                     if ($value && (string) $value != '0') {
                         if ($order_id || $field != 'passwd') {
                             JError::raiseError($field . ' ' . JText::_('COM_JEPROSHOP_IS_REQUIRED_FIELD_MESSAGE'));
                         }
                     }
                 }
                 foreach ($rules->size as $field => $maxLength) {
                     if ($app->input->get($field) && strlen($field) > $maxLength) {
                         JError::raiseError($field . ' ' . JText::_('COM_JEPROSHOP_FIELD_IS_TOO_LONG_LABEL') . ' ' . $maxLength . ' ' . JText::_('COM_JEPROSHOP_MAX_CHARS_LABEL'));
                     }
                 }
                 foreach ($rules->validate as $field => $function) {
                     if ($app->input->get($field)) {
                         if (!JeproshopTools::$function()) {
                             JError::raiseError(JText::_('COm_JEPROSHOP_FIELD_IS_INVALID_LABEL'));
                         }
                     }
                 }
                 if (12) {
                     $customer_thread_id = JeproshopCustomerThreadModelCustomerThread::getCustomerThreadIdByEmailAndOrderId($customer->email, $order->order_id);
                     if (!$customer_thread_id) {
                         $customerThread = new JeproshopCustomerThreadModelCustomerThread();
                         $customerThread->contact_id = 0;
                         $customerThread->customer_id = (int) $order->customer_id;
                         $customerThread->shop_id = (int) $context->shop->shop_id;
                         $customerThread->order_id = (int) $order->order_id;
                         $customerThread->lang_id = (int) $context->language->lang_id;
                         $customerThread->email = $customer->email;
                         $customerThread->status = 'open';
                         $customerThread->token = JeproshopTools::passwdGen(12);
                         $customerThread->add();
                     } else {
                         $customerThread = new JeproshopCustomerThreadModelCustomerThread((int) $customer_thread_id);
                     }
                     $customerMessage = new JeproshopCustomerMessageModelCustomerMessage();
                     $customerMessage->customer_thread_id = $customerThread->customer_thread_id;
                     $customerMessage->employee_id = (int) $context->employee->employee_id;
                     $customerMessage->message = $app->input->get('message');
                     $customerMessage->private = $app->input->get('visibility');
                     if (!$customerMessage->add()) {
                         JError::raiseError(JText::_('COM_JEPROSHOP_AN_ERROR_WHILE_'));
                     } elseif ($customerMessage->private) {
                         $app->redirect('index.php?option=com_jeproshop&view=order&task=view&order_id=' . (int) $order->order_id);
                     } else {
                     }
                 }
             }
         }
     }
 }
示例#3
0
 public function renderView($tpl = NULL)
 {
     if (!isset($this->context) || $this->context == null) {
         $this->context = JeproshopContext::getContext();
     }
     $app = JFactory::getApplication();
     $order = new JeproshopOrderModelOrder($app->input->get('order_id'));
     if (!JeproshopTools::isLoadedObject($order, 'order_id')) {
         JError::raiseError(500, JText::_('COM_JEPROSHOP_THE_ORDER_CANNOT_BE_FOUND_WITHIN_YOUR_DATA_BASE_MESSAGE'));
     }
     $customer = new JeproshopCustomerModelCustomer($order->customer_id);
     $carrier = new JeproshopCarrierModelCarrier($order->carrier_id);
     $products = $this->getProducts($order);
     $currency = new JeproshopCurrencyModelCurrency((int) $order->currency_id);
     // Carrier module call
     $carrier_module_call = null;
     if ($carrier->is_module) {
         /*$module = Module::getInstanceByName($carrier->external_module_name);
         		if (method_exists($module, 'displayInfoByCart'))
         			$carrier_module_call = call_user_func(array($module, 'displayInfoByCart'), $order->id_cart); */
     }
     // Retrieve addresses information
     $addressInvoice = new JeproshopAddressModelAddress($order->address_invoice_id, $this->context->language->lang_id);
     if (JeproshopTools::isLoadedObject($addressInvoice, 'address_id') && $addressInvoice->state_id) {
         $invoiceState = new JeproshopStateModelState((int) $addressInvoice->state_id);
     }
     if ($order->address_invoice_id == $order->address_delivery_id) {
         $addressDelivery = $addressInvoice;
         if (isset($invoiceState)) {
             $deliveryState = $invoiceState;
         }
     } else {
         $addressDelivery = new JeproshopAddressModelAddress($order->address_delivery_id, $this->context->language->lang_id);
         if (JeproshopTools::isLoadedObject($addressDelivery, 'address_id') && $addressDelivery->state_id) {
             $deliveryState = new JeproshopStateModelState((int) $addressDelivery->state_id);
         }
     }
     $title = JText::_('COM_JEPROSHOP_ORDER_LABEL') . ' ';
     //todo learn how to display
     //$toolbar_title = sprintf($this->l('Order #%1$d (%2$s) - %3$s %4$s'), $order->order_id, $order->reference, $customer->firstname, $customer->lastname);
     if (JeproshopShopModelShop::isFeaturePublished()) {
         $shop = new JeproshopShopModelShop((int) $order->shop_id);
         //$this->toolbar_title .= ' - '.sprintf($this->l('Shop: %s'), $shop->name);
     }
     JToolBarHelper::title($title);
     // gets warehouses to ship products, if and only if advanced stock management is activated
     $warehouse_list = null;
     $order_details = $order->getOrderDetailList();
     foreach ($order_details as $order_detail) {
         $product = new JeproshopProductModelProduct($order_detail->product_id);
         if (JeproshopSettingModelSetting::getValue('advanced_stock_management') && $product->advanced_stock_management) {
             $warehouses = JeproshopWarehouseModelWarehouse::getWarehousesByProductId($order_detail->product_id, $order_detail->product_attribute_id);
             foreach ($warehouses as $warehouse) {
                 if (!isset($warehouse_list[$warehouse->warehouse_id])) {
                     $warehouse_list[$warehouse->warehouse_id] = $warehouse;
                 }
             }
         }
     }
     $payment_methods = array();
     /*foreach (PaymentModule::getInstalledPaymentModules() as $payment)
     		{
     			$module = Module::getInstanceByName($payment['name']);
     			if (Validate::isLoadedObject($module) && $module->active)
     				$payment_methods[] = $module->displayName;
     		}*/
     // display warning if there are products out of stock
     $display_out_of_stock_warning = false;
     $current_order_status = $order->getCurrentOrderStatus();
     if (JeproshopSettingModelSetting::getValue('stock_management') && (!JeproshopTools::isLoadedObject($current_order_status, 'order_id') || $current_order_status->delivery != 1 && $current_order_status->shipped != 1)) {
         $display_out_of_stock_warning = true;
     }
     // products current stock (from stock_available)
     foreach ($products as &$product) {
         $product->current_stock = JeproshopStockAvailableModelStockAvailable::getQuantityAvailableByProduct($product->product_id, $product->product_attribute_id, $product->shop_id);
         $resume = JeproshopOrderSlipModelOrderSlip::getProductSlipResume($product->order_detail_id);
         $product->quantity_refundable = $product->product_quantity - $resume->product_quantity;
         $product->amount_refundable = $product->total_price_tax_incl - $resume->amount_tax_incl;
         $product->amount_refund = JeproshopTools::displayPrice($resume->amount_tax_incl, $currency);
         $product->refund_history = JeproshopOrderSlipModelOrderSlip::getProductSlipDetail($product->order_detail_id);
         $product->return_history = JeproshopOrderReturnModelOrderReturn::getProductReturnDetail($product->order_detail_id);
         // if the current stock requires a warning
         if ($product->current_stock == 0 && $display_out_of_stock_warning) {
             JError::raiseWarning(500, JText::_('COM_JEPROSHOP_THIS_PRODUCT_IS_OUT_OF_STOCK_LABEL') . ' : ' . $product->product_name);
         }
         if ($product->warehouse_id != 0) {
             $warehouse = new JeproshopWarehouseModelWarehouse((int) $product->warehouse_id);
             $product->warehouse_name = $warehouse->name;
         } else {
             $product->warehouse_name = '--';
         }
     }
     //$gender = new Gender((int)$customer->id_gender, $this->context->language->id);
     $history = $order->getHistory($this->context->language->lang_id);
     foreach ($history as &$order_state) {
         $order_state->text_color = JeproshopTools::getBrightness($order_state->color) < 128 ? 'white' : 'black';
     }
     $this->setLayout('view');
     $this->assignRef('order', $order);
     $cart = new JeproshopCartModelCart($order->cart_id);
     $this->assignRef('cart', $cart);
     $this->assignRef('customer', $customer);
     $customer_addresses = $customer->getAddresses($this->context->language->lang_id);
     $this->assignRef('customer_addresses', $customer_addresses);
     $this->assignRef('delivery_address', $addressDelivery);
     $this->assignRef('deliveryState', isset($deliveryState) ? $deliveryState : null);
     $this->assignRef('invoice_address', $addressInvoice);
     $this->assignRef('invoiceState', isset($invoiceState) ? $invoiceState : null);
     $customerStats = $customer->getStats();
     $this->assignRef('customerStats', $customerStats);
     $this->assignRef('products', $products);
     $discounts = $order->getCartRules();
     $this->assignRef('discounts', $discounts);
     $orderTotalPaid = $order->getOrdersTotalPaid();
     $this->assignRef('orders_total_paid_tax_incl', $orderTotalPaid);
     // Get the sum of total_paid_tax_incl of the order with similar reference
     $totalPaid = $order->getTotalPaid();
     $this->assignRef('total_paid', $totalPaid);
     $returns = JeproshopOrderReturnModelOrderReturn::getOrdersReturn($order->customer_id, $order->order_id);
     $this->assignRef('returns', $returns);
     $customerThreads = JeproshopCustomerThreadModelCustomerThread::getCustomerMessages($order->customer_id);
     $this->assignRef('customer_thread_message', $customerThreads);
     $orderMessages = JeproshopOrderMessageModelOrderMessage::getOrderMessages($order->lang_id);
     $this->assignRef('order_messages', $orderMessages);
     $messages = JeproshopMessageModelMessage::getMessagesByOrderId($order->order_id, true);
     $this->assignRef('messages', $messages);
     $carrier = new JeproshopCarrierModelCarrier($order->carrier_id);
     $this->assignRef('carrier', $carrier);
     $this->assignRef('history', $history);
     $statues = JeproshopOrderStatusModelOrderStatus::getOrderStatus($this->context->language->lang_id);
     $this->assignRef('order_statues', $statues);
     $this->assignRef('warehouse_list', $warehouse_list);
     $sources = JeproshopConnectionSourceModelConnectionSource::getOrderSources($order->order_id);
     $this->assignRef('sources', $sources);
     $orderStatus = $order->getCurrentOrderStatus();
     $this->assignRef('current_status', $orderStatus);
     $this->assignRef('currency', new JeproshopCurrencyModelCurrency($order->currency_id));
     $currencies = JeproshopCurrencyModelCurrency::getCurrenciesByShopId($order->shop_id);
     $this->assignRef('currencies', $currencies);
     $previousOrder = $order->getPreviousOrderId();
     $this->assignRef('previousOrder', $previousOrder);
     $nextOrder = $order->getNextOrderId();
     $this->assignRef('nextOrder', $nextOrder);
     //$this->assignRef('current_index', self::$currentIndex);
     $this->assignRef('carrier_module_call', $carrier_module_call);
     $this->assignRef('iso_code_lang', $this->context->language->iso_code);
     $this->assignRef('lang_id', $this->context->language->lang_id);
     $can_edit = true;
     $this->assignRef('can_edit', $can_edit);
     //($this->tabAccess['edit'] == 1));
     $this->assignRef('current_id_lang', $this->context->language->lang_id);
     $invoiceCollection = $order->getInvoicesCollection();
     $this->assignRef('invoices_collection', $invoiceCollection);
     $unPaid = $order->getNotPaidInvoicesCollection();
     $this->assignRef('not_paid_invoices_collection', $unPaid);
     $this->assignRef('payment_methods', $payment_methods);
     $invoiceAllowed = JeproshopSettingModelSetting::getValue('invoice_allowed');
     $this->assignRef('invoice_management_active', $invoiceAllowed);
     $display_warehouse = (int) JeproshopSettingModelSetting::getValue('advanced_stock_management');
     $this->assignRef('display_warehouse', $display_warehouse);
     $stockManagement = JeproshopSettingModelSetting::getValue('stock_management');
     $this->assignRef('stock_management', $stockManagement);
     /*$this->assignRef('HOOK_CONTENT_ORDER', Hook::exec('displayAdminOrderContentOrder', array(
     				'order' => $order,
     				'products' => $products,
     				'customer' => $customer)
     				),
     		$this->assignRef('HOOK_CONTENT_SHIP' => Hook::exec('displayAdminOrderContentShip', array(
     				'order' => $order,
     				'products' => $products,
     				'customer' => $customer)
     				),
     		$this->assignRef('HOOK_TAB_ORDER' => Hook::exec('displayAdminOrderTabOrder', array(
     				'order' => $order,
     				'products' => $products,
     				'customer' => $customer)
     				
     		$this->assignRef('HOOK_TAB_SHIP' => Hook::exec('displayAdminOrderTabShip', array(
     		$this->assignRef('order' => $order,
     		$this->assignRef('products' => $products,
     		$this->assignRef('customer' => $customer) */
     $this->addToolBar();
     $this->sideBar = JHtmlSideBar::render();
     parent::display($tpl);
 }