function search() { // Get the document object. $document = JFactory::getDocument(); $app = JFactory::getApplication(); $searches = explode(' ', $app->input->get('content')); $customers = array(); $searches = array_unique($searches); $document->setMimeEncoding('application/json'); foreach ($searches as $search) { if (!empty($search)) { $results = JeproshopCustomerModelCustomer::searchByName($search); if ($results) { foreach ($results as $result) { $customers[$result->customer_id] = $result; } } } } if (count($customers)) { $jsonData = array("success" => true, 'found' => true); //'{'; // "success": "true", '; $customersArray = array(); foreach ($customers as $customer) { //$jsonData .= '"customer_' . $customer->customer_id . '": {'; /*$toReturn .= '<div class="customer_card" ><div class="panel" ><div class="panel-title" >' . ucfirst($customer->firstname) . ' ' . ucfirst($customer->lastname) . '<span class="pull-right" ># ' . $customer->customer_id . '</span></div>'; $toReturn .= '<span>' . $customer->email . '</span><br/><span class="text-muted">' . (($customer->birthday != '0000-00-00') ? $customer->birthday : '') . '</span><br/><div class="panel-footer"><a href="'; $toReturn .= JRoute::_('index.php?option=com_jeproshop&view=customer&task=view&customer_id=' . $customer->customer_id . '&lite_displaying=1') .'" class="btn btn-default fancybox"><i class="icon-search"></i>' . JText::_('COM_JEPROSHOP_DETAILS_LABEL'); $toReturn .= '</a><button type="button" data-customer="'. $customer->customer_id . '" class="setup-customer btn btn-default pull-right"><i class="icon-arrow-right"></i>' . JText::_('COM_JEPROSHOP_CHOOSE_LABEL') . '</button></div></div></div>'; */ $customerData = array(); foreach ($customer as $key => $value) { $customerData[$key] = $value; } $customersArray[] = $customerData; } $jsonData['customers'] = $customersArray; } else { $jsonData = array("success" => false, 'found' => false); } // Set the MIME type for JSON output. //$document->setMimeEncoding('application/json'); // Change the suggested filename. //JResponse::setHeader('Content-Disposition','attachment;filename="result.json"'); //echo ($jsonData); echo json_encode($jsonData); $app->close(); }
public function initialize() { parent::initialize(); $app = JFactory::getApplication(); $context = JeproshopContext::getContext(); // Get address ID $address_id = 0; $type = $app->input->get('type'); if ($this->use_ajax && isset($type)) { if ($type == 'delivery' && isset($context->cart->address_delivery_id)) { $address_id = (int) $context->cart->address_delivery_id; } else { if ($type == 'invoice' && isset($context->cart->address_invoice_id) && $context->cart->id_address_invoice != $context->cart->address_delivery_id) { $address_id = (int) $context->cart->address_invoice_id; } } } else { $address_id = (int) $app->input->get('address_id', 0); } // Initialize address if ($address_id) { $address = new JeproshopAddressModelAddress($address_id); $view = $app->input->get('view'); $viewClass = $this->getView($view, JFactory::getDocument()->getType()); if (JeproshopTools::isLoadedObject($address, 'address_id') && JeproshopCustomerModelCustomer::customerHasAddress($context->customer->customer_id, $address_id)) { $task = $app->input->get('task'); if (isset($task) && $task == 'delete') { if ($address->delete()) { if ($context->cart->address_invoice_id == $address->address_id) { unset($context->cart->address_invoice_id); } if ($context->cart->id_address_delivery == $address->address_id) { unset($context->cart->id_address_delivery); $context->cart->updateAddressId($address->address_id, (int) JeproshopAddressModelAddress::getCustomerFirstAddressId($context->customer->customer_id)); } $app->redirect('index.php?option=com_jeproshop&view=address'); } $this->has_errors = true; JError::raiseError(500, 'This address cannot be deleted.'); } } elseif ($this->use_ajax) { $app->close; } else { $app->redirect('index.php?option=com_jeproshop&view=address'); } } }
} 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');
/** * @see ObjectModel::delete() */ public function delete() { if (JeproshopTools::isUnsignedInt($this->customer_id)) { JeproshopCustomerModelCustomer::resetAddressCache($this->customer_id); } if (!$this->isUsed()) { return parent::delete(); } else { $this->deleted = true; return $this->update(); } }
/** * Check if order is free * @return boolean * / public function checkFreeOrder(){ $context = JeproshopContext::getContext(); if ($context->cart->getOrderTotal() <= 0) { $order = new JeproshopFreeOrderModelFreeOrder(); $order->free_order_class = true; $order->validateOrder($context->cart->cart_id, Configuration::get('PS_OS_PAYMENT'), 0, Tools::displayError('Free order', false), null, array(), null, false, $context->cart->secure_key); return (int)JeproshopOrderModelOrder::getOrderByCartId($context->cart->cart_id); } return false; } public function assignCarrier(){ $view = JFactory::getDBO(); $context = JeproshopContext::getContext(); $address = new JeproshopAddressModelAddress($context->cart->address_delivery_id); $zone_id = JeproshopAddressModelAddress::getZoneIdByAddressId($address->address_id); $carriers = $context->cart->simulateCarriersOutput(null, true); $checked = $context->cart->simulateCarrierSelectedOutput(false); $delivery_option_list = $context->cart->getDeliveryOptionList(); $delivery_option = $context->cart->getDeliveryOption(null, false); $this->setDefaultCarrierSelection($delivery_option_list); $view->assignRef('address_collection', $context->cart->getAddressCollection()); $view->assignRef('delivery_option_list', $delivery_option_list); $view->assignRef('carriers', $carriers); $view->assignRef('checked', $checked); $view->assignRef('delivery_option', $delivery_option); $vars = array( /*'HOOK_BEFORECARRIER' => Hook::exec('displayBeforeCarrier', array( 'carriers' => $carriers, 'checked' => $checked, 'delivery_option_list' => $delivery_option_list, 'delivery_option' => $delivery_option ))* / ); JeproshopCartModelCart::addExtraCarriers($vars); $view->assignRef('extra_carriers', $vars); } /** * Decides what the default carrier is and update the cart with it * * @todo this function must be modified - id_carrier is now delivery_option * * @param array $carriers * * @deprecated since 1.5.0 * * @return number the id of the default carrier * / protected function setDefaultCarrierSelection($carriers) { $context = JeproshopContext::getContext(); if (!$context->cart->getDeliveryOption(null, true)) $context->cart->setDeliveryOption($context->cart->getDeliveryOption()); }*/ public function globalInitialization() { $app = JFactory::getApplication(); $view = $app->input->get('view'); $viewClass = $this->getView($view, JFactory::getDocument()->getType()); $context = JeproshopContext::getContext(); $this->isLogged = (bool) ($context->customer->customer_id && JeproshopCustomerModelCustomer::customerIdExistsStatic((int) $context->cookie->customer_id)); parent::initialize(); /* Disable some cache related bugs on the cart/order */ header('Cache-Control: no-cache, must-revalidate'); header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); if (!$context->customer->isLogged(true) && $this->useMobileTheme() && $app->input->get('step')) { $app->redirect(JRoute::_('index.php?option=com_jeproshop&view=authentication&lang_id=' . $context->language->lang_id, true, 1)); } // Redirect to the good order process $task = $app->input->get('task', ''); $order_process_type = JeproshopSettingModelSetting::getValue('order_process_type'); if ($order_process_type == 'standard' && ($task != '' || $task != 'display')) { //$app->redirect('index.php?option=com_jeproshop&view=order'); } if ($order_process_type == 'page_checkout' && $task != 'opc') { $step = $app->input->get('step'); if (isset($step) && $step == 3) { $app->redirect('index.php?option=com_jeproshop&view=order&task=opc&isPaymentStep=true'); } $app->redirect('index.php?option=com_jeproshop&view=order&task=opc'); } $catalog_mode = JeproshopSettingModelSetting::getValue('catalog_mode'); if ($catalog_mode) { $this->has_errors = true; JError::raiseError(500, JText::_('COM_JEPROSHOP_THIS_STORE_DOES_NOT_ACCEPT_NEW_ORDER_MESSAGE')); } $order_id = (int) $app->input->get('order_id'); $currentTask = $app->input->get('task'); if ($currentTask == 'submitReorder' && $order_id) { $oldCart = new JeproshopCartModelCart(JeproshopOrderModelOrder::getStaticCartId($order_id, $context->customer->customer_id)); $duplication = $oldCart->duplicate(); if (!$duplication || !JeproshopTools::isLoadedObject($duplication->cart, 'cart_id')) { $this->has_errors = true; Tools::displayError('Sorry. We cannot renew your order.'); } else { if (!$duplication->success) { $this->has_errors = true; Tools::displayError('Some items are no longer available, and we are unable to renew your order.'); } else { $context->cookie->cart_id = $duplication->cart->cart_id; $context->cookie->write(); if ($order_process_type == 'page_checkout') { $app->redirect('index.php?option=com_jeproshop&view=order&task=opc'); } $app->redirect('index.php?option=com_jeproshop&view=order'); } } } $viewClass->assignRef('order_process_type', $order_process_type); $nbProducts = $context->cart->numberOfProducts(); if ($nbProducts) { if (JeproshopCartRuleModelCartRule::isFeaturePublished()) { if (Tools::isSubmit('submitAddDiscount')) { if (!($code = trim(Tools::getValue('discount_name')))) { $this->has_errors = true; JError::raiseError('You must enter a voucher code.'); } elseif (!Validate::isCleanHtml($code)) { $this->has_errors = true; JEroor::raiseError('The voucher code is invalid.'); } else { $cartRule = new JeproshopCartRuleModelCartRule(JeproshopCartRuleModelCartRule::getIdByCode($code)); if ($cartRule && JeproshopTools::isLoadedObject($cartRule, 'cart_rule_id')) { if ($error = $cartRule->checkValidity($context, false, true)) { $this->has_errors = true; JError::raiseError(500, $error); } else { $context->cart->addCartRule($cartRule->cart_rule_id); if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 1) { Tools::redirect('index.php?controller=order-opc&addingCartRule=1'); } Tools::redirect('index.php?controller=order&task=adding_cart_rule'); } } else { $this->has_errors = true; Tools::displayError('This voucher does not exists.'); } } $discountName = JeproshopTools::safeOutput($code); $viewClass->assignRef('discount_name', $discountName); } elseif (($cart_rule_id = (int) Tools::getValue('delete_discount')) && JeproshopTools::isUnsignedId($cart_rule_id)) { $context->cart->removeCartRule($cart_rule_id); $app->redirect('index.php?option=com_jeproshop&view=order&task=opc'); } } /* Is there only virtual product in cart */ if ($isVirtualCart = $context->cart->isVirtualCart()) { $this->setNoCarrier(); } } //$viewClass->assignRef('back', JTools::safeOutput(Tools::getValue('back')));*/ }
/** * 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(); }
/** * @static * @param $lang_id * @param $customer_id * @param bool $published * @param bool $includeGeneric * @param bool $inStock * @param JeproshopCartModelCart|null $cart * @return array */ public static function getCustomerCartRules($lang_id, $customer_id, $published = false, $includeGeneric = true, $inStock = false, JeproshopCartModelCart $cart = null) { if (!JeproshopCartRuleModelCartRule::isFeaturePublished()) { return array(); } $db = JFactory::getDBO(); $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_cart_rule') . " AS cart_rule LEFT JOIN " . $db->quoteName('#__jeproshop_cart_rule_lang'); $query .= " AS cart_rule_lang ON (cart_rule." . $db->quoteName('cart_rule_id') . " = cart_rule_lang." . $db->quoteName('cart_rule_id') . " AND "; $query .= "cart_rule_lang." . $db->quoteName('lang_id') . " = " . (int) $lang_id . ") WHERE ( cart_rule." . $db->quoteName('customer_id') . " = "; $query .= (int) $customer_id . " OR cart_rule.group_restriction = 1 " . ($includeGeneric ? "OR cart_rule." . $db->quoteName('customer_id') . " = 0" : ""); $query .= ") AND cart_rule.date_from < \"" . date('Y-m-d H:i:s') . "\" AND cart_rule.date_to > \"" . date('Y-m-d H:i:s') . "\""; $query .= ($published ? " AND cart_rule" . $db->quoteName('published') . " = 1" : "") . ($inStock ? " AND cart_rule." . $db->quoteName('quantity') . " > 0" : ""); $db->setQuery($query); $result = $db->loadObjectList(); // Remove cart rule that does not match the customer groups $customerGroups = JeproshopCustomerModelCustomer::getGroupsStatic($customer_id); foreach ($result as $key => $cart_rule) { if ($cart_rule->group_restriction) { $query = "SELECT " . $db->quoteName('group_id') . " FROM " . $db->quoteName('#__jeproshop_cart_rule_group') . " WHERE " . $db->quoteName('cart_rule_id') . " = " . (int) $cart_rule->cart_rule_id; $db->setQuery($query); $cartRuleGroups = $db->loadObjectList(); foreach ($cartRuleGroups as $cartRuleGroup) { if (in_array($cartRuleGroup->group_id, $customerGroups)) { continue 2; } } unset($result[$key]); } } foreach ($result as &$cart_rule) { if ($cart_rule->quantity_per_user) { $quantity_used = JeproshopOrderModelOrder::getCustomerDiscounts((int) $customer_id, (int) $cart_rule->cart_rule_id); if (isset($cart) && isset($cart->cart_id)) { $quantity_used += $cart->getDiscountsCustomer((int) $cart_rule->cart_rule_id); } $cart_rule->quantity_for_user = $cart_rule->quantity_per_user - $quantity_used; } else { $cart_rule->quantity_for_user = 0; } } unset($cart_rule); foreach ($result as $cart_rule) { if ($cart_rule->shop_restriction) { $query = "SELECT shop_id FROM " . $db->quoteName('#__jeproshop_cart_rule_shop') . " WHERE cart_rule_id = " . (int) $cart_rule->cart_rule_id; $db->setQuery($query); $cartRuleShops = $db->loadObjectList(); foreach ($cartRuleShops as $cartRuleShop) { if (JeproshopShopModelShop::isFeatureActive() && $cartRuleShop->shop_id == JeproshopContext::getShopContext()->shop->shop_id) { continue 2; } } unset($result[$key]); } } // RetroCompatibility with 1.4 discounts foreach ($result as &$cart_rule) { $cart_rule->value = 0; $cart_rule->minimal = JeproshopTools::convertPriceFull($cart_rule->minimum_amount, new JeproshopCurrencyModelCurrency($cart_rule->minimum_amount_currency), JeproshopContext::getContext()->currency); $cart_rule->cumulable = !$cart_rule->cart_rule_restriction; $cart_rule->discount_type_id = false; if ($cart_rule->free_shipping) { $cart_rule->discount_type_id = Discount::FREE_SHIPPING; } elseif ($cart_rule->reduction_percent > 0) { $cart_rule->discount_type_id = Discount::PERCENT; $cart_rule->value = $cart_rule->reduction_percent; } elseif ($cart_rule->reduction_amount > 0) { $cart_rule->discount_type_id = Discount::AMOUNT; $cart_rule->value = $cart_rule->reduction_amount; } } return $result; }
public function cacheDatabaseRequiredFields() { if (!is_array(self::$_database_required_fields)) { $fields = JeproshopTools::getDatabaseRequiredFields(true, 'customer'); if ($fields) { foreach ($fields as $row) { self::$_database_required_fields[$row->object_name][(int) $row->required_fiel_id] = pSQL($row->field_name); } } else { self::$_database_required_fields = array(); } } }
/** * Assign price and tax to the template */ protected function assignPriceAndTax() { $customer_id = isset($this->context->customer) ? (int) $this->context->customer->customer_id : 0; $group_id = (int) JeproshopGroupModelGroup::getCurrent()->group_id; $country_id = (int) $customer_id ? JeproshopCustomerModelCustomer::getCurrentCountry($customer_id) : JeproshopSettingModelSetting::getValue('default_country'); $group_reduction = JeproshopGroupReductionModelGroupReduction::getValueForProduct($this->product->product_id, $group_id); if ($group_reduction === false) { $group_reduction = JeproshopGroupModelGroup::getReduction((int) $this->context->cookie->customer_id) / 100; } // Tax $tax = (double) $this->product->getTaxesRate(new JeproshopAddressModelAddress((int) $this->context->cart->{JeproshopSettingModelSetting::getValue('tax_address_type')})); $this->assignRef('tax_rate', $tax); $product_price_with_tax = JeproshopProductModelProduct::getStaticPrice($this->product->product_id, true, null, 6); if (JeproshopProductModelProduct::$_taxCalculationMethod == COM_JEPROSHOP_TAX_INCLUDED) { $product_price_with_tax = JeproshopTools::roundPrice($product_price_with_tax, 2); } $product_price_without_eco_tax = (double) $product_price_with_tax - $this->product->ecotax; $ecotax_rate = (double) JeproshopTaxModelTax::getProductEcotaxRate($this->context->cart->{JeproshopSettingModelSetting::getValue('tax_address_type')}); $ecotax_tax_amount = JeproshopTools::roundPrice($this->product->ecotax, 2); if (JeproshopProductModelProduct::$_taxCalculationMethod == COM_JEPROSHOP_TAX_INCLUDED && (int) JeproshopSettingModelSetting::getValue('use_tax')) { $ecotax_tax_amount = JeproshopTools::roundPrice($ecotax_tax_amount * (1 + $ecotax_rate / 100), 2); } $currency_id = (int) $this->context->cookie->currency_id; $product_id = (int) $this->product->product_id; $shop_id = $this->context->shop->shop_id; $quantity_discounts = JeproshopSpecificPriceModelSpecificPrice::getQuantityDiscounts($product_id, $shop_id, $currency_id, $country_id, $group_id, null, true, (int) $this->context->customer->customer_id); foreach ($quantity_discounts as &$quantity_discount) { if ($quantity_discount->product_attribute_id) { $combination = new JeproshopCombinationModelCombination((int) $quantity_discount->product_attribute_id); $attributes = $combination->getAttributesName((int) $this->context->language->lang_id); foreach ($attributes as $attribute) { $quantity_discount->attributes = $attribute->name . ' - '; } $quantity_discount->attributes = rtrim($quantity_discount->attributes, ' - '); } if ((int) $quantity_discount->currency_id == 0 && $quantity_discount->reduction_type == 'amount') { $quantity_discount->reduction = JeproshopTools::convertPriceFull($quantity_discount->reduction, null, JeproshopContext::getContext()->currency); } } $product_price = $this->product->getPrice(JeproshopProductModelProduct::$_taxCalculationMethod == COM_JEPROSHOP_TAX_INCLUDED, false); $address = new JeproshopAddressModelAddress($this->context->cart->{JeproshopSettingModelSetting::getValue('tax_address_type')}); $quantity_discounts = $this->formatQuantityDiscounts($quantity_discounts, $product_price, (double) $tax, $ecotax_tax_amount); $this->assignRef('quantity_discounts', $quantity_discounts); $this->assignRef('ecotax_tax_included', $ecotax_tax_amount); $ecotax_tax_excluded = JeproshopTools::roundPrice($this->product->ecotax, 2); $this->assignRef('ecotax_tax_excluded', $ecotax_tax_excluded); $this->assignRef('ecotaxTax_rate', $ecotax_rate); $display_price = JeproshopSettingModelSetting::getValue('display_price'); $this->assignRef('display_price', $display_price); $product_price_without_eco_tax = (double) $product_price_without_eco_tax; $this->assignRef('product_price_without_ecotax', $product_price_without_eco_tax); $this->assignRef('group_reduction', $group_reduction); $no_tax = JeproshopTaxModelTax::taxExcludedOption() || !$this->product->getTaxesRate($address); $this->assignRef('no_tax', $no_tax); $ecotax = !count($this->errors) && $this->product->ecotax > 0 ? JeproshopTools::convertPrice((double) $this->product->ecotax) : 0; $this->assignRef('ecotax', $ecotax); $tax_enabled = JeproshopSettingModelSetting::getValue('use_tax'); $this->assignRef('tax_enabled', $tax_enabled); $customer_group_without_tax = JeproshopGroupModelGroup::getPriceDisplayMethod($this->context->customer->default_group_id); $this->assignRef('customer_group_without_tax', $customer_group_without_tax); }
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); }
/** * @static * @param $lang_id * @param $customer_id * @param bool $published * @param bool $includeGeneric * @param bool $inStock * @param JeproshopCartModelCart|null $cart * @return array */ public static function getCustomerCartRules($lang_id, $customer_id, $published = false, $includeGeneric = true, $inStock = false, JeproshopCartModelCart $cart = null) { if (!JeproshopCartRuleModelCartRule::isFeaturePublished()) { return array(); } $db = JFactory::getDBO(); $query = "SELECT * FROM " . $db->quoteName('#_jeproshop_cart_rule') . " AS cart_rule LEFT JOIN " . $db->quoteName('#__jeproshop_cart_rule_lang') . " AS cart_ruler_lang"; $query .= " ON (cart_rule." . $db->quoteName('cart_rule_id') . " = cart_rule_lang." . $db->quoteName('cart_rule_id') . " AND cart_rule_lang." . $db->quoteName('lang_id'); $query .= " = " . (int) $lang_id . ") WHERE ( cart_rule." . $db->quoteName('customer_id') . " = " . (int) $customer_id . " OR cart_rule.group_restriction = 1 "; $query .= ($includeGeneric ? " OR cart_rule." . $db->quoteName('customer_id') . " = 0" : "") . ") AND cart_rule.date_from < '" . date('Y-m-d H:i:s') . "' AND cart_rule.date_to > '"; $query .= date('Y-m-d H:i:s') . "' " . ($published ? "AND cart_rule." . $db->quoteName('published') . " = 1" : "") . ($inStock ? " AND cart_rule." . $db->quoteName('quantity') . " > 0" : ""); $db->setQuery($query); $result = $db->loadObjectList(); // Remove cart rule that does not match the customer groups $customerGroups = JeproshopCustomerModelCustomer::getStaticGroups($customer_id); foreach ($result as $key => $cart_rule) { if ($cart_rule->group_restriction) { $cartRuleGroups = Db::getInstance()->executeS('SELECT id_group FROM ' . _DB_PREFIX_ . 'cart_rule_group WHERE id_cart_rule = ' . (int) $cart_rule['id_cart_rule']); foreach ($cartRuleGroups as $cartRuleGroup) { if (in_array($cartRuleGroup->group_id, $customerGroups)) { continue 2; } } unset($result[$key]); } } foreach ($result as &$cart_rule) { if ($cart_rule->quantity_per_user) { $quantity_used = Order::getDiscountsCustomer((int) $customer_id, (int) $cart_rule->cart_rule_id); if (isset($cart) && isset($cart)) { $quantity_used += $cart->getDiscountsCustomer((int) $cart_rule->cart_rule_id); } $cart_rule->quantity_for_user = $cart_rule->quantity_per_user - $quantity_used; } else { $cart_rule->quantity_for_user = 0; } } unset($cart_rule); foreach ($result as $key => $cart_rule) { if ($cart_rule->shop_restriction) { $cartRuleShops = Db::getInstance()->executeS('SELECT id_shop FROM ' . _DB_PREFIX_ . 'cart_rule_shop WHERE id_cart_rule = ' . (int) $cart_rule['id_cart_rule']); foreach ($cartRuleShops as $cartRuleShop) { if (Shop::isFeatureActive() && $cartRuleShop->shop_id == JeproshopContext::getContext()->shop->shop_id) { continue 2; } } unset($result[$key]); } } if (isset($cart) && isset($cart->cart_id)) { foreach ($result as $key => $cart_rule) { if ($cart_rule->product_restriction) { $cr = new JeproshopCartRuleModelCartRule((int) $cart_rule->cart_rule_id); $restriction = $cr->checkProductRestrictions(JeproshopContext::getContext(), false, false); if ($restriction !== false) { continue; } unset($result[$key]); } } } foreach ($result as $key => $cart_rule) { if ($cart_rule['country_restriction']) { $countries = Db::getInstance()->ExecuteS(' SELECT `id_country` FROM `' . _DB_PREFIX_ . 'address` WHERE `customer_id` = ' . (int) $customer_id . ' AND `deleted` = 0'); if (is_array($countries) && count($countries)) { foreach ($countries as $country) { $id_cart_rule = (bool) Db::getInstance()->getValue(' SELECT crc.id_cart_rule FROM ' . _DB_PREFIX_ . 'cart_rule_country crc WHERE crc.id_cart_rule = ' . (int) $cart_rule['id_cart_rule'] . ' AND crc.id_country = ' . (int) $country['id_country']); if (!$id_cart_rule) { unset($result[$key]); } } } } } // Retro-compatibility with 1.4 discounts foreach ($result as &$cart_rule) { $cart_rule['value'] = 0; $cart_rule['minimal'] = Tools::convertPriceFull($cart_rule['minimum_amount'], new Currency($cart_rule['minimum_amount_currency']), Context::getContext()->currency); $cart_rule['cumulable'] = !$cart_rule['cart_rule_restriction']; $cart_rule['id_discount_type'] = false; if ($cart_rule['free_shipping']) { $cart_rule['id_discount_type'] = Discount::FREE_SHIPPING; } elseif ($cart_rule['reduction_percent'] > 0) { $cart_rule['id_discount_type'] = Discount::PERCENT; $cart_rule['value'] = $cart_rule['reduction_percent']; } elseif ($cart_rule['reduction_amount'] > 0) { $cart_rule->discount_type_id = Discount::AMOUNT; $cart_rule['value'] = $cart_rule['reduction_amount']; } } unset($cart_rule); return $result; }
/** * Check customer informations and return customer validity * * @since 1.5.0 * @param boolean $with_guest * @return boolean customer validity */ public function isLogged($with_guest = false) { if (!$with_guest && $this->is_guest == 1) { return false; } /** Customer is valid only if it can be load and if object password is the same as database one **/ if ($this->logged == 1 && $this->customer_id && JeproshopTools::isUnsignedInt($this->customer_id) && JeproshopCustomerModelCustomer::checkPassword($this->customer_id, $this->passwd)) { return true; } return false; }
/** * For a given {product, warehouse}, gets the carrier available * * @param JeproshopProductModelProduct $product The id of the product, or an array with at least the package size and weight * @param int $warehouse_id * @param int $address_delivery_id * @param int $shop_id * @param $cart * @return array */ public static function getAvailableCarrierList(JeproshopProductModelProduct $product, $warehouse_id, $address_delivery_id = null, $shop_id = null, $cart = null) { if (is_null($shop_id)) { $shop_id = JeproshopContext::getContext()->shop->shop_id; } if (is_null($cart)) { $cart = JeproshopContext::getContext()->cart; } $address_id = (int) (!is_null($address_delivery_id) && $address_delivery_id != 0 ? $address_delivery_id : $cart->address_delivery_id); if ($address_id) { $address = new JeproshopAddressModelAddress($address_id); $zone_id = JeproshopAddressModelAddress::getZoneIdByAddressId($address->address_id); // Check the country of the address is activated if (!JeproshopAddressModelAddress::isCountryActiveById($address->address_id)) { return array(); } } else { $country = new JeproshopCountryModelCountry(JeproshopSettingModelSetting::getValue('default_country')); $izone_id = $country->zone_id; } // Does the product is linked with carriers? $query = new DbQuery(); $query->select('id_carrier'); $query->from('product_carrier', 'pc'); $query->innerJoin('carrier', 'c', 'c.id_reference = pc.id_carrier_reference AND c.deleted = 0'); $query->where('pc.id_product = ' . (int) $product->product_id); $query->where('pc.id_shop = ' . (int) $shop_id); $cache_id = 'Carrier::getAvailableCarrierList_' . (int) $product->id . '-' . (int) $id_shop; if (!Cache::isStored($cache_id)) { $carriers_for_product = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query); Cache::store($cache_id, $carriers_for_product); } $carriers_for_product = Cache::retrieve($cache_id); $carrier_list = array(); if (!empty($carriers_for_product)) { //the product is linked with carriers foreach ($carriers_for_product as $carrier) { //check if the linked carriers are available in current zone if (Carrier::checkCarrierZone($carrier['id_carrier'], $id_zone)) { $carrier_list[] = $carrier['id_carrier']; } } if (empty($carrier_list)) { return array(); } //no linked carrier are available for this zone } // The product is not directly linked with a carrier // Get all the carriers linked to a warehouse if ($warehouse_id) { $warehouse = new JeproshopWarehouseModelWarehouse($warehouse_id); $warehouse_carrier_list = $warehouse->getCarriers(); } $available_carrier_list = array(); $customer = new JeproshopCustomerModelCustomer($cart->customer_id); $carriers = JeproshopCarrierModelCarrier::getCarriersForOrder($zone_id, $customer->getGroups(), $cart); foreach ($carriers as $carrier) { $available_carrier_list[] = $carrier->carrier_id; } if ($carrier_list) { $carrier_list = array_intersect($available_carrier_list, $carrier_list); } else { $carrier_list = $available_carrier_list; } if (isset($warehouse_carrier_list)) { $carrier_list = array_intersect($carrier_list, $warehouse_carrier_list); } if ($product->width > 0 || $product->height > 0 || $product->depth > 0 || $product->weight > 0) { foreach ($carrier_list as $key => $carrier_id) { $carrier = new JeproshopCarrierModelCarrier($carrier_id); if ($carrier->max_width > 0 && $carrier->max_width < $product->width || $carrier->max_height > 0 && $carrier->max_height < $product->height || $carrier->max_depth > 0 && $carrier->max_depth < $product->depth || $carrier->max_weight > 0 && $carrier->max_weight < $product->weight) { unset($carrier_list[$key]); } } } return $carrier_list; }
public function initialize() { if (self::$initialized) { return; } self::$initialized = true; $app = JFactory::getApplication(); $context = JeproshopContext::getContext(); $view = $app->input->get('view', 'default'); $viewClass = $this->getView($view, JFactory::getDocument()->getType()); if (JeproshopTools::usingSecureMode()) { $this->ssl_enabled = true; } if (isset($context->cookie->account_created)) { $accountCreated = true; $viewClass->assignRef('account_created', $accountCreated); $context->cookie->account_created = 0; } JeproshopTools::setCookieLanguage($context->cookie); $cart_id = (int) $this->recoverCart(); if ($cart_id) { $context->cookie->cart_id = $cart_id; } if ($this->authenticated && !$context->customer->isLogged($this->guest_allowed)) { $app->redirect('index.php?option=com_jeproshop&view=authentication'); // todo add retun option } if (JeproshopSettingModelSetting::getValue('enable_geolocation')) { $defaultCountry = $this->geolocationManagement($context->country); if ($defaultCountry && JeproshopTools::isLoadedObject($defaultCountry, 'country_id')) { $context->country = $defaultCountry; } } $currency = JeproshopTools::setCurrency($context->cookie); $logout = $app->input->get('logout'); $myLogout = $app->input->get('mylogout'); if (isset($logout) || $context->customer->logged && JeproshopCustomerModelCustomer::isBanned($context->cutomer->customer_id)) { $context->customer->logout(); //$app->input->get('') } elseif (isset($myLogout)) { $context->customer->mylogout(); } if ((int) $context->cookie->cart_id) { $cart = new JeproshopCartModelCart($context->cookie->cart_id); if ($cart->orderExists()) { $context->cookie->cart_id = null; $context->cookie->check_selling_condition = false; } elseif ((int) JeproshopSettingModelSetting::getValue('enable_geolocation') && !in_array(strtoupper($context->cookie->iso_code_country), explode(';', JeproshopSettingModelSetting::getValue('allowed_countries'))) && $cart->numberOfProducts() && (int) JeproshopSettingModelSetting::getValue('geolocation_behavior') != -1 && !self::isInWhiteListForGeolocation() && !in_array($_SERVER['SERVER_NAME'], array('localhost', '127.0.0.1'))) { $context->cookie->cart_id = null; $cart = null; } elseif ($context->cookie->customer_id != $cart->customer_id || $context->cookie->lang_id != $cart->lang_id || $currency->currency_id != $cart->currency_id) { if ($context->cookie->customer_id) { $cart->customer_id = (int) $context->cookie->customer_id; } $cart->lang_id = (int) $context->cookie->lang_id; $cart->currency_id = (int) $currency->currency_id; $cart->update(); } if (isset($cart) && (!isset($cart->address_delivery_id) || $cart->address_delivery_id == 0 || !isset($cart->address_invoice_id) || $cart->address_invoice_id) && $context->cookie->customer_id) { $toUpdate = false; if (!isset($cart->address_delivery_id) || $cart->address_delivery_id == 0) { $toUpdate = true; $cart->address_delivery_id = (int) JeproshopAddressModelAddress::getCustomerFirstAddressId($cart->customer_id); } if (!isset($cart->address_invoice_id) || $cart->address_invoice_id == 0) { $toUpdate = true; $cart->address_invoice_id = (int) JeproshopAddressModelAddress::getCustomerFirstAddressId($cart->customer_id); } if ($toUpdate) { $cart->update(); } } } if (!isset($cart) || $cart->cart_id) { $cart = new JeproshopCartModelCart(); $cart->lang_id = (int) $context->cookie->lang_id; $cart->currency_id = (int) $context->cookie->currency_id; $cart->guest_id = (int) $context->cookie->guest_id; $cart->shop_group_id = (int) $context->shop->shop_group_id; $cart->shop_id = $context->shop->shop_id; if ($context->cookie->customer_id) { $cart->customer_id = (int) $context->cookie->id_customer; $cart->address_delivery_id = (int) JeproshopAddressModelAddress::getCustomerFirstAddressId($cart->customer_id); $cart->address_invoice_id = $cart->address_delivery_id; } else { $cart->address_delivery_id = 0; $cart->address_invoice_id = 0; } // Needed if the merchant want to give a free product to every visitors $context->cart = $cart; JeproshopCartRuleModelCartRule::autoAddToCart($context); } else { $context->cart = $cart; } JeproshopProductModelProduct::initPricesComputation(); $display_tax_label = $context->country->display_tax_label; if (isset($cart->{JeproshopSettingModelSetting::getValue('tax_address_type')}) && $cart->{JeproshopSettingModelSetting::getValue('tax_address_type')}) { $info = JeproshopAddressModelAddress::getCountryAndState($cart->{JeproshopSettingModelSetting::getValue('tax_address_type')}); $country = new JeproshopCountryModelCountry((int) $info->country_id); $context->country = $country; if (JeproshopTools::isLoadedObject($country, 'country_id')) { $display_tax_label = $country->display_tax_label; } } $languages = JeproshopLanguageModelLanguage::getLanguages(true); $meta_language = array(); foreach ($languages as $lang) { $meta_language[] = $lang->iso_code; } $compared_products = array(); $comparatorMaxItem = JeproshopSettingModelSetting::getValue('comparator_max_item'); if ($comparatorMaxItem && isset($context->cookie->compare_id)) { $compared_products = JeproshopProductComparedModelProductCompared::getComparedProducts($context->cookie->compare_id); } $mobileDevice = $context->getMobileDevice(); $viewClass->assignRef('mobile_device', $mobileDevice); $viewClass->assignRef('cart', $cart); $viewClass->assignRef('currency', $currency); $viewClass->assignRef('display_tax_label', $display_tax_label); $isLogged = (bool) $context->customer->isLogged(); $viewClass->assignRef('is_logged', $isLogged); $isGuest = (bool) $context->customer->isGuest(); $viewClass->assignRef('is_guest', $isGuest); $priceRoundMode = JeproshopSettingModelSetting::getValue('price_round_mode'); $viewClass->assignRef('price_round_mode', $priceRoundMode); $useTax = JeproshopSettingModelSetting::getValue('use_tax'); $viewClass->assignRef('use_taxes', $useTax); $showTax = (int) JeproshopSettingModelSetting::getValue('display_tax') == 1 && JeproshopSettingModelSetting::getValue('use_tax'); $viewClass->assignRef('show_tax', $showTax); $catalogMode = (bool) JeproshopSettingModelSetting::getValue('catalog_mode') || !JeproshopGroupModelGroup::getCurrent()->show_prices; $viewClass->assignRef('catalog_mode', $catalogMode); $enableB2bMode = (bool) JeproshopSettingModelSetting::getValue('enable_b2b_mode'); $viewClass->assignRef('enable_b2b_mode', $enableB2bMode); $stockManagement = JeproshopSettingModelSetting::getValue('stock_management'); $viewClass->assignRef('stock_management', $stockManagement); $metaLanguages = implode(',', $meta_language); $viewClass->assignRef('meta_languages', $metaLanguages); $viewClass->assignRef('languages', $languages); $numberOfProducts = $cart->numberOfProducts(); $viewClass->assignRef('cart_quantities', $numberOfProducts); $currencies = JeproshopCurrencyModelCurrency::getCurrencies(); $viewClass->assignRef('currencies', $currencies); $comparatorMaxItem = JeproshopSettingModelSetting::getValue('comparator_max_item'); $viewClass->assignRef('comparator_max_item', $comparatorMaxItem); $quickView = (bool) JeproshopSettingModelSetting::getValue('quick_view'); $viewClass->assignRef('quick_view', $quickView); $restrictedCountryMode = false; $viewClass->assignRef('restricted_country_mode', $restrictedCountryMode); $displayPrice = JeproshopProductModelProduct::getTaxCalculationMethod((int) $context->cookie->customer_id); $viewClass->assignRef('display_price', $displayPrice); /*$viewClass->assignRef(''); $viewClass->assignRef(''); $viewClass->assignRef('');*/ $viewClass->assignRef('compared_products', $compared_products); /*$viewClass->assignRef('comparator_max_item', $comparatorMaxItem); */ }