/** * Process submit on an account */ public function register() { $app = JFactory::getApplication(); $context = JeproshopContext::getContext(); $view = $app->input->get('view'); $viewClass = $this->getView($view, JFactory::getDocument()->getType()); $input = JRequest::get('get'); $jsonData = array("success" => true); $errors = array(); $task = $app->input->get('task'); if (isset($task) && $task == 'register') { $emailCreate = 1; $viewClass->assign('email_create', 1); } $isNewCustomer = isset($input['is_new_customer']) ? 1 : 0; if (!$isNewCustomer && !JeproshopSettingModelSetting::getValue('enable_guest_checkout')) { $this->has_errors = true; $errors[] = JText::_('You cannot create a guest account..'); } $guestEmail = isset($input['guest_email']) ? $input['guest_email'] : ''; $email = isset($input['email']) ? $input['email'] : ''; if (isset($guestEmail) && $guestEmail) { $email = $guestEmail; } // Checked the user address in case he changed his email address if (JeproshopTools::isEmail($email) && !empty($email)) { if (JeproshopCustomerModelCustomer::customerExists($email)) { $this->has_errors = true; $errors[] = JText::_('An account using this email address has already been registered.'); //, false); } } // Preparing customer $customer = new JeproshopCustomerModelCustomer(); $lastNameAddress = isset($input['lastname']) ? $input['lastname'] : ''; $firstNameAddress = isset($input['firstname']) ? $input['firstname'] : ''; $lastname = isset($input['customer_lastname']) ? $input['customer_lastname'] : $lastNameAddress; $firstname = isset($input['customer_firstname']) ? $input['customer_firstname'] : $firstNameAddress; $addresses_types = array('address'); $inputInvoiceAddress = isset($input['invoice_address']) ? $input['invoice_address'] : 0; if (JeproshopSettingModelSetting::getValue('order_process_type') == 'standard' && JeproshopSettingModelSetting::getValue('enable_guest_checkout') && $inputInvoiceAddress) { $addresses_types[] = 'invoice_address'; } $error_phone = false; $phone = isset($input['phone']) ? $input['phone'] : null; $phone_mobile = isset($input['phone_mobile']) ? $input['phone_mobile'] : null; if (JeproshopSettingModelSetting::getValue('one_phone_at_least')) { if ($task == 'submitGuestAccount' || !$isNewCustomer) { if (!$phone && !$phone_mobile) { $error_phone = true; } } elseif ((JeproshopSettingModelSetting::getValue('registration_process_type') != 'account_only' && JeproshopSettingModelSetting::getValue('order_process_type') != 'standard' || JeproshopSettingModelSetting::getValue('order_process_type') != 'standard' && !$viewClass->email_create || JeproshopSettingModelSetting::getValue('registration_process_type') != 'account_only' && $viewClass->email_create) && (!$phone && !$phone_mobile)) { $error_phone = true; } } if ($error_phone) { $this->has_errors = true; $errors[] = JText::_('You must register at least one phone number.'); } $errors = array_unique(array_merge($errors, $customer->validateController())); if (JeproshopSettingModelSetting::getValue('registration_process_type') == 'account_only' && !$this->use_ajax && !Tools::isSubmit('submitGuestAccount')) { if (!$this->has_errors) { if (isset($input['newsletter']) && $input['newsletter']) { $this->processCustomerNewsletter($customer); } $customer->firstname = JeproshopTools::ucwords($customer->firstname); $customer->birthday = empty($input['year']) ? '' : (int) $input['year'] . '-' . (int) $input['month'] . '-' . (int) $input['day']; if (!JeproshopTools::isBirthDate($customer->birthday)) { $this->has_errors = true; $errors[] = JText::_('Invalid date of birth.'); } // New Guest customer $customer->is_guest = isset($isNewCustomer) ? !$isNewCustomer : 0; $customer->published = 1; if (!$this->has_errors) { if ($customer->add()) { if (!$customer->is_guest) { if (!$this->sendConfirmationMail($customer)) { $this->has_errors = true; $errors[] = JText::_('The email cannot be sent.'); } } $this->updateContext($customer); $context->cart->update(); Hook::exec('actionCustomerAccountAdd', array('_POST' => $_POST, 'newCustomer' => $customer)); if ($this->use_ajax) { $return = array('hasError' => $this->has_errors, 'errors' => $errors, 'isSaved' => true, 'customer_id' => (int) $context->cookie->customer_id, 'delivery_address_id' => $context->cart->delivery_address_id, 'invoice_address_id' => $context->cart->invoice_address_id, 'token' => Tools::getToken(false)); echo json_encode($return); $app->close(); } if (($back = Tools::getValue('back')) && $back == Tools::secureReferrer($back)) { $app->redirect(html_entity_decode($back)); } // redirection: if cart is not empty : redirection to the cart if (count($context->cart->getProducts(true)) > 0) { $app->redirect('index.php?option=com_jeproshop&view=order&multi-shipping=' . (int) Tools::getValue('multi-shipping')); } else { Tools::redirect('index.php?controller=' . ($this->authRedirection !== false ? urlencode($this->authRedirection) : 'my-account')); } } else { $this->has_errors = true; JText::_('An error occurred while creating your account.'); } } } } else { // if registration type is in one step, we save the address $input['lastname'] = $lastNameAddress; $input['firstname'] = $firstNameAddress; $post_back = $_POST; // Preparing addresses foreach ($addresses_types as $addresses_type) { $address_type = new JeproshopAddressModelAddress(); $address_type->customer_id = 1; if ($addresses_type == 'invoice_address') { foreach ($input as $key => &$post) { if (isset($input['invoice_' . $key])) { $post = $input['invoice_' . $key]; } } } $this->has_errors = true; $errors = array_unique(array_merge($errors, $address_type->validateController())); if ($addresses_type == 'invoice_address') { $_POST = $post_back; } if (!($country = new JeproshopCountryModelCountry($address_type->country_id)) || !JeproshopTools::isLoadedObject($country, 'country_id')) { $this->has_errors = true; $errors[] = JText::_('Country cannot be loaded with address->id_country'); } if (!$country->published) { $this->has_errors = true; $errors[] = JText::_('This country is not active.'); } $postcode = isset($input['postcode']) ? $input['postcode'] : ''; /* Check zip code format */ if ($country->zip_code_format && !$country->checkZipCode($postcode)) { $this->has_errors = true; $errors[] = JText::_('The Zip/Postal code you\'ve entered is invalid. It must follow this format: %s'); //, str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $country->zip_code_format)))); } elseif (empty($postcode) && $country->need_zip_code) { $this->has_errors = true; $errors[] = JText::_('A Zip / Postal code is required.'); } elseif ($postcode && !JeproshopTools::isPostCode($postcode)) { $this->has_errors = true; $errors[] = JText::_('The Zip / Postal code is invalid.'); } $identificationNumber = isset($input['dni']) ? $input['dni'] : ''; if ($country->need_identification_number && (!$identificationNumber || !JeproshopTools::isDniLite($identificationNumber))) { $this->has_errors = true; $errors[] = JText::_('The identification number is incorrect or has already been used.'); } elseif (!$country->need_identification_number) { $address_type->dni = null; } if ($task == 'register' || $task == 'submitGuestAccount') { if (!($country = new JeproshopCountryModelCountry($address_type->country_id, JeproshopSettingModelSetting::getValue('default_lang'))) || !JeproshopTools::isLoadedObject($country, 'country_id')) { $this->has_errors = true; $errors[] = JText::_('Country is invalid'); } } $contains_state = isset($country) && is_object($country) ? (int) $country->contains_states : 0; $state_id = isset($address_type) && is_object($address_type) ? (int) $address_type->state_id : 0; if (($task == 'register' || $task == 'submitGuestAccount') && $contains_state && !$state_id) { $this->has_errors = true; $errors[] = JText::_('This country requires you to choose a State.'); } } } $days = isset($input['day']) ? $input['day'] : ''; $months = isset($input['month']) ? $input['month'] : ''; $years = isset($input['year']) ? $input['year'] : ''; if (!@checkdate($months, $days, $years) && !($months == '' && $days == '' && $years == '')) { $this->has_errors = true; $errors[] = JText::_('Invalid date of birth'); } if ($this->has_errors) { //todo set negation $email = isset($input['email']) ? $input['email'] : ''; if (JeproshopCustomerModelCustomer::customerExists($email)) { $this->has_errors = true; $errors[] = JText::_('An account using this email address has already been registered. Please enter a valid password or request a new one. '); } if (isset($input['newsletter'])) { $this->processCustomerNewsletter($customer); } $customer->birthday = empty($years) ? '' : (int) $years . '-' . (int) $months . '-' . (int) $days; if (!JeproshopTools::isBirthDate($customer->birthday)) { $this->has_errors = true; $errors[] = JText::_('Invalid date of birth'); } echo $input['passwd'] . ' on line ' . __LINE__; if ($this->has_errors) { //todo reset negation $customer->published = 1; // New Guest customer if (isset($isNewCustomer)) { $customer->is_guest = !$isNewCustomer ? 1 : 0; } else { $customer->is_guest = 0; } if (!$customer->add()) { $this->has_errors = true; $errors[] = JText::_('An error occurred while creating your account.'); } else { foreach ($addresses_types as $addresses_type) { $address_type->customer_id = (int) $customer->customer_id; if ($addresses_type == 'invoice_address') { foreach ($input as $key => &$post) { if (isset($input['invoice_' . $key])) { $post = $input['invoice_' . $key]; } } } $errors = array_unique(array_merge($errors, $address_type->validateController())); if ($address_type == 'invoice_address') { $input = $post_back; } if (!$this->has_errors && (JeproshopSettingModelSetting::getValue('registration_process_type') || $this->use_ajax || $task == 'submitGuestAccount') && !$address_type->add()) { $this->has_errors = true; $errors[] = JText::_('An error occurred while creating your address.'); } } if (!$this->has_errors) { if (!$customer->is_guest) { $context->customer = $customer; $customer->cleanGroups(); // we add the guest customer in the default customer group $customer->addGroups(array((int) JeproshopSettingModelSetting::getValue('customer_group'))); if (!$this->sendConfirmationMail($customer)) { $this->has_errors = true; } $errors[] = JText::_('The email cannot be sent.'); } else { $customer->cleanGroups(); // we add the guest customer in the guest customer group $customer->addGroups(array((int) JeproshopSettingModelSetting::getValue('guest_group'))); } $this->updateContext($customer); $context->cart->delivery_address_id = (int) JeproshopAddressModelAddress::getCustomerFirstAddressId((int) $customer->customer_id); $context->cart->invice_address_id = (int) JeproshopAddressModelAddress::getCustomerFirstAddressId((int) $customer->customer_id); if (isset($invoice_address) && JeproshopTools::isLoadedObject($invoice_address, 'address_id')) { $context->cart->invoice_address_id = (int) $invoice_address->address_id; } if ($this->use_ajax && JeproshopSettingModelSetting::getValue('order_process_type') != 'standard') { $delivery_option = array((int) $context->cart->delivery_address_id => (int) $context->cart->carrier_id . ','); $context->cart->setDeliveryOption($delivery_option); } // If a logged guest logs in as a customer, the cart secure key was already set and needs to be updated $context->cart->update(); // Avoid articles without delivery address on the cart $context->cart->autosetProductAddress(); Hook::exec('actionCustomerAccountAdd', array('_POST' => $_POST, 'newCustomer' => $customer)); if ($this->use_ajax) { $return = array('hasError' => $this->has_errors, 'errors' => $errors, 'isSaved' => true, 'customer_id' => (int) $context->cookie->customer_id, 'id_address_delivery' => $context->cart->delivery_address_id, 'id_address_invoice' => $context->cart->invoice_address_id, 'token' => Tools::getToken(false)); echo json_encode($return); $app->close(); } // if registration type is in two steps, we redirect to register address if (JeproshopSettingModelSetting::getValue('registration_process_type') == 'account_only' && !$this->use_ajax && $task != 'submitGuestAccount') { $app->redirect('index.php?option=com_jeproshop&view=address'); } if (($back = Tools::getValue('back')) && $back == Tools::secureReferrer($back)) { Tools::redirect(html_entity_decode($back)); } // redirection: if cart is not empty : redirection to the cart if (count($context->cart->getProducts(true)) > 0) { $app->redirect('index.php?option=com_jeproshop&view=order&multi-shipping=' . (int) $input['multi-shipping']); // else : redirection to the account } else { //todo$app->redirect('index.php?controller=' . (($this->authRedirection !== false) ? urlencode($this->authRedirection) : 'my-account')); } } } } } if ($this->has_errors) { //for retro compatibility to display guest account creation form on authentication page if ($task == 'guest_account') { $_GET['display_guest_checkout'] = 1; } if (!$isNewCustomer) { unset($_POST['passwd']); } if ($this->use_ajax) { $return = array('hasError' => $this->has_errors, 'errors' => $errors, 'isSaved' => false, 'customer_id' => 0); echo json_encode($return); $app->close(); } $viewClass->assign('account_error', $this->has_errors); } echo json_encode($jsonData); $app->close(); }
} echo JText::_('COM_JEPROSHOP_' . strtoupper($this->customer->title) . '_LABEL') . ' ' . strtoupper($this->customer->lastname) . ' ' . $this->customer->firstname; ?> </a> </span> <span class="badge badge-success"><?php echo '#' . $this->customer->customer_id; ?> </span> </div> <div class="panel-content well" > <div class="half_wrapper left" > <?php if ($this->customer->isGuest()) { echo JText::_('COM_JEPROSHOP_THIS_ORDER_HAS_BEEN_PLACED_BY_A_GUEST_LABEL'); if (!JeproshopCustomerModelCustomer::customerExists($this->customer->email)) { ?> <form method="post" action="<?php echo JRoute::_('index.php?option=com_jeproshop&view=customer&task=edit&customer_id=' . (int) $this->customer->customer_id . '&' . JSession::getFormToken() . '=1'); ?> " > <input type="hidden" name="jform[lang_id]" value="<?php echo $this->order->lang_id; ?> " /> <input class="btn btn-default" type="submit" name="submitGuestToCustomer" value="<?php echo JText::_('COM_JEPROSHOP_TRANSFORM_GUEST_INTO_CUSTOMER_MESSAGE'); ?> " /> <p class="help-block"><?php echo JText::_('COM_JEPROSHOP_THIS_FEATURE_WILL_GENERATE_A_RANDOM_PASSWORD_AND_SEND_AN_EMAIL_CUSTOMER_MESSAGE');
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); }