From a2198c7e4f061695bf7a5bd99c91204554116f2b Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Wed, 1 May 2024 14:37:02 +0530 Subject: [PATCH 01/19] Updated: The Navigation links having CMS pages work flow. Also the inactive or not existing cms pages will redirect to page not found. --- controllers/front/CmsController.php | 5 +- .../blocknavigationmenu.php | 41 +++++++++++++ .../classes/WkCustomNavigationLink.php | 9 +++ ...nCustomNavigationLinkSettingController.php | 58 ++++++++++++++++++- .../views/js/admin/wk_navigation_link.js | 56 +++++++++++++----- .../helpers/form/form.tpl | 20 ++++++- 6 files changed, 171 insertions(+), 18 deletions(-) diff --git a/controllers/front/CmsController.php b/controllers/front/CmsController.php index 01a4726bb..4eca2e8f6 100644 --- a/controllers/front/CmsController.php +++ b/controllers/front/CmsController.php @@ -79,8 +79,7 @@ class CmsControllerCore extends FrontController } elseif (Validate::isLoadedObject($this->cms_category) && $this->cms_category->active && $this->cms_category->isAssociatedToShop()) { $this->assignCase = 2; } else { - header('HTTP/1.1 404 Not Found'); - header('Status: 404 Not Found'); + Tools::redirect($this->context->link->getPageLink('pagenotfound')); } } @@ -134,6 +133,8 @@ class CmsControllerCore extends FrontController 'path' => ($this->cms_category->id !== 1) ? Tools::getPath($this->cms_category->id, $this->cms_category->name, false, 'CMS') : '', 'body_classes' => array($this->php_self.'-'.$this->cms_category->id, $this->php_self.'-'.$this->cms_category->link_rewrite) )); + } else { + Tools::redirect($this->context->link->getPageLink('pagenotfound')); } $this->setTemplate(_PS_THEME_DIR_.'cms.tpl'); diff --git a/modules/blocknavigationmenu/blocknavigationmenu.php b/modules/blocknavigationmenu/blocknavigationmenu.php index b6d2437b5..0c75505cc 100644 --- a/modules/blocknavigationmenu/blocknavigationmenu.php +++ b/modules/blocknavigationmenu/blocknavigationmenu.php @@ -103,6 +103,45 @@ class blocknavigationmenu extends Module } } + public function hookActionObjectCMSUpdateAfter($params) + { + $id_cms = $params['object']->id; + // Disabling all the related navigation links to disabled CMS page + if (!$params['object']->active) { + $this->disableRelatedLinks($id_cms); + } + } + + public function hookActionObjectCMSDeleteAfter($params) + { + $id_cms = $params['object']->id; + // Disabling all the related navigation links to deleted CMS page + $this->deleteRelatedLinks($id_cms); + } + + public function disableRelatedLinks($id_cms) + { + $objCustomNavigationLink = new WkCustomNavigationLink(); + if ($navLinks = $objCustomNavigationLink->getRelatedNavLinksByIdCMS($id_cms)) { + foreach ($navLinks as $navLink) { + $objCustomNavigationLink = new WkCustomNavigationLink((int) $navLink['id_navigation_link']); + $objCustomNavigationLink->active = 0; + $objCustomNavigationLink->save(); + } + } + } + + public function deleteRelatedLinks($id_cms) + { + $objCustomNavigationLink = new WkCustomNavigationLink(); + if ($navLinks = $objCustomNavigationLink->getRelatedNavLinksByIdCMS($id_cms)) { + foreach ($navLinks as $navLink) { + $objCustomNavigationLink = new WkCustomNavigationLink((int) $navLink['id_navigation_link']); + $objCustomNavigationLink->delete(); + } + } + } + public function install() { $objModuleDb = new WkBlockNavigationMenuDb(); @@ -125,6 +164,8 @@ class blocknavigationmenu extends Module array ( 'footer', 'actionObjectLanguageAddAfter', + 'actionObjectCMSUpdateAfter', + 'actionObjectCMSDeleteAfter', 'displayDefaultNavigationHook', 'displayNavigationHook', 'top', diff --git a/modules/blocknavigationmenu/classes/WkCustomNavigationLink.php b/modules/blocknavigationmenu/classes/WkCustomNavigationLink.php index b7e62b93e..8fc7a70f8 100644 --- a/modules/blocknavigationmenu/classes/WkCustomNavigationLink.php +++ b/modules/blocknavigationmenu/classes/WkCustomNavigationLink.php @@ -237,4 +237,13 @@ class WkCustomNavigationLink extends ObjectModel $objCustomNavigationLink->save(); return true; } + + public function getRelatedNavLinksByIdCMS($idCMS) + { + return Db::getInstance()->executeS(' + SELECT * FROM `'._DB_PREFIX_.'htl_custom_navigation_link` + WHERE `id_cms`='.(int) $idCMS + ); + } + } diff --git a/modules/blocknavigationmenu/controllers/admin/AdminCustomNavigationLinkSettingController.php b/modules/blocknavigationmenu/controllers/admin/AdminCustomNavigationLinkSettingController.php index 6e1668b84..fda9152e1 100644 --- a/modules/blocknavigationmenu/controllers/admin/AdminCustomNavigationLinkSettingController.php +++ b/modules/blocknavigationmenu/controllers/admin/AdminCustomNavigationLinkSettingController.php @@ -179,6 +179,16 @@ class AdminCustomNavigationLinkSettingController extends ModuleAdminController if (Validate::isLoadedObject($objNavigationLink)) { $smartyVars['navigationLinkInfo'] = (array) $objNavigationLink; $smartyVars['edit'] = 1; + if (!$objNavigationLink->is_custom_link + && Validate::isLoadedObject($objCMS = new CMS($objNavigationLink->id_cms)) + ) { + $smartyVars['id_cms_category'] = $objCMS->id_cms_category; + if (empty($this->errors) + && !$objCMS->active + ) { + $this->warnings[] = $this->l('To enable this link you need to enable the related CMS page first'); + } + } } // send theme's front pages $themePages = array(); @@ -196,7 +206,31 @@ class AdminCustomNavigationLinkSettingController extends ModuleAdminController $smartyVars['themePages'] = $themePages; $smartyVars['languages'] = Language::getLanguages(false); $smartyVars['currentLang'] = Language::getLanguage((int) Configuration::get('PS_LANG_DEFAULT')); - $smartyVars['cmsPages'] = CMS::getCMSPages($smartyVars['currentLang'], 1); + $categoryWiseCmsPages = array(); + if ($cmsPages = CMS::getCMSPages($smartyVars['currentLang'], null, false)) { + foreach ($cmsPages as $page) { + $cmsPage['id_cms'] = $page['id_cms']; + $cmsPage['meta_title'] = $page['meta_title']; + $categoryWiseCmsPages[$page['id_cms_category']][] = $cmsPage; + } + } + + if ($cmsCategories = CMSCategory::getCategories($this->context->language->id, false, false)) { + foreach ($cmsCategories as $cmsCatKey => $cmsCategory) { + if (!isset($categoryWiseCmsPages[$cmsCategory['id_cms_category']])) { + unset($cmsCategories[$cmsCatKey]); + } + } + } + + Media::addJsDef( + array( + 'catFormatCmsPages' => json_encode($categoryWiseCmsPages) + ) + ); + + $smartyVars['cmsPages'] = $cmsPages; + $smartyVars['categories'] = $cmsCategories; $this->context->smarty->assign($smartyVars); $this->fields_form = array( 'submit' => array( @@ -261,6 +295,10 @@ class AdminCustomNavigationLinkSettingController extends ModuleAdminController } if ($isCmsPage) { $objCustomNavigationLink->id_cms = $idCms; + $objCMS = new CMS((int) $idCms); + if (!$objCMS->active) { + $active = $objCMS->active; + } } else { $objCustomNavigationLink->id_cms = 0; foreach ($languages as $language) { @@ -381,6 +419,24 @@ class AdminCustomNavigationLinkSettingController extends ModuleAdminController } } + public function processStatus() + { + if (Validate::isLoadedObject($this->loadObject()) + && !$this->object->is_custom_link //Check for CMS related navigation link + ) { + $objCMS = new CMS($this->object->id_cms); + if (!$objCMS->active) { + $this->errors[] = $this->l('Please activate the relate CMS page to activate this link'); + } + } + + if (empty($this->errors)) { + return parent::processStatus(); + } + + return $this->object; + } + public function setMedia() { parent::setMedia(); diff --git a/modules/blocknavigationmenu/views/js/admin/wk_navigation_link.js b/modules/blocknavigationmenu/views/js/admin/wk_navigation_link.js index db7a3ff7e..b6339aaa4 100644 --- a/modules/blocknavigationmenu/views/js/admin/wk_navigation_link.js +++ b/modules/blocknavigationmenu/views/js/admin/wk_navigation_link.js @@ -18,24 +18,17 @@ */ $(document).ready(function() { + setCategoryWiseCmsPages(); $("input[name='is_cms_block_link").on('change', function () { - if (parseInt($(this).val())) { - $("#cms_block_content").removeClass('hidden'); - $("#non_cms_block_content").addClass('hidden'); - } else { - $("#cms_block_content").addClass('hidden'); - $("#non_cms_block_content").removeClass('hidden'); - } + toggleElements(this, "#cms_block_content", "#non_cms_block_content"); }); $("input[name='is_custom_redirect_link").on('change', function () { - if (parseInt($(this).val())) { - $(".custom_redirect_link_div").removeClass('hidden'); - $(".custom_redirect_page_div").addClass('hidden'); - } else { - $(".custom_redirect_link_div").addClass('hidden'); - $(".custom_redirect_page_div").removeClass('hidden'); - } + toggleElements(this, ".custom_redirect_link_div", ".custom_redirect_page_div"); + }); + + $(document).on('change', '#id_cms_category', function(){ + setCategoryWiseCmsPages(); }); }); @@ -45,4 +38,39 @@ function showNavigationLinkLangField(lang_iso_code, id_lang) $('.navigation_link_name_all').hide(); $('#navigation_link_name_'+id_lang).show(); +} + +function toggleElements(element, selectorFirst, selectorSecond) +{ + if (parseInt($(element).val())) { + $(selectorFirst).removeClass('hidden'); + $(selectorSecond).addClass('hidden'); + } else { + $(selectorFirst).addClass('hidden'); + $(selectorSecond).removeClass('hidden'); + } +} + +function setCategoryWiseCmsPages() +{ + var selectedPage = parseInt($('input[name="id_cms"]:checked').val()); + var selectedCategory = parseInt($('#id_cms_category').val()); + var formattedData = JSON.parse(catFormatCmsPages); + if (!isNaN(selectedCategory)) { + formattedData = formattedData[selectedCategory]; + var html = ''; + $.each(formattedData, function(i, v) { + html += ''; + html += ''; + html += ''+v['id_cms']+''; + html += '' + html += ''; + }); + $('table.cms_pages tbody').html(html); + } + + if (!isNaN(selectedPage)) { + $('input[name="id_cms"][value="'+selectedPage+'"]').attr('checked', 'checked'); + } + } \ No newline at end of file diff --git a/modules/blocknavigationmenu/views/templates/admin/custom_navigation_link_setting/helpers/form/form.tpl b/modules/blocknavigationmenu/views/templates/admin/custom_navigation_link_setting/helpers/form/form.tpl index fe9ceefc0..eedc9d62a 100644 --- a/modules/blocknavigationmenu/views/templates/admin/custom_navigation_link_setting/helpers/form/form.tpl +++ b/modules/blocknavigationmenu/views/templates/admin/custom_navigation_link_setting/helpers/form/form.tpl @@ -52,6 +52,24 @@ {* Feilds of cms page *}
+
+
+ +
+ +
+
+
{*Display CMS Pages*} {if isset($cmsPages)}
@@ -62,7 +80,7 @@
- +
'; html += ''; html += ''; From 8f524f0daa8bf466259a11c80a1a502e3c1e6be7 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Fri, 5 Jul 2024 12:09:20 +0530 Subject: [PATCH 08/19] Fixed admin was able to create the address for banned user --- .../template/controllers/addresses/helpers/form/form.tpl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/admin/themes/default/template/controllers/addresses/helpers/form/form.tpl b/admin/themes/default/template/controllers/addresses/helpers/form/form.tpl index cb9d740f7..7cd7a9ad0 100644 --- a/admin/themes/default/template/controllers/addresses/helpers/form/form.tpl +++ b/admin/themes/default/template/controllers/addresses/helpers/form/form.tpl @@ -50,11 +50,15 @@ {/if} {else if $input.type == 'select' && $input.name == 'id_customer'} {$smarty.block.parent} +
From 084b3c34ed5e65f9e71eaff08fe99324e9032d1c Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Tue, 14 May 2024 11:30:19 +0530 Subject: [PATCH 02/19] Fixed: The admin was unable to change the customer after any error is displayed while creating new address for the customer, also fixed the back button --- .../template/controllers/addresses/helpers/form/form.tpl | 2 +- controllers/admin/AdminAddressesController.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/admin/themes/default/template/controllers/addresses/helpers/form/form.tpl b/admin/themes/default/template/controllers/addresses/helpers/form/form.tpl index ec102910d..e46200e15 100644 --- a/admin/themes/default/template/controllers/addresses/helpers/form/form.tpl +++ b/admin/themes/default/template/controllers/addresses/helpers/form/form.tpl @@ -88,7 +88,7 @@
- +
{/if} {else} diff --git a/controllers/admin/AdminAddressesController.php b/controllers/admin/AdminAddressesController.php index 83a646cb6..6e052f39b 100644 --- a/controllers/admin/AdminAddressesController.php +++ b/controllers/admin/AdminAddressesController.php @@ -190,10 +190,10 @@ class AdminAddressesControllerCore extends AdminController $token_customer = Tools::getAdminToken('AdminCustomers'.(int)(Tab::getIdFromClassName('AdminCustomers')).(int)$this->context->employee->id); } + $this->fields_value['email'] = Tools::getValue('email'); $this->tpl_form_vars = array( - 'customer' => isset($customer) ? $customer : null, - 'tokenCustomer' => isset($token_customer) ? $token_customer : null, - 'back_url' => urldecode(Tools::getValue('back')) + 'customer' => (isset($customer) && $this->object->id) ? $customer : null, + 'tokenCustomer' => isset($token_customer) ? $token_customer : null ); // Order address fields depending on country format From 0d64da3315e29b0095cec6742f71df529b3f2e44 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Tue, 21 May 2024 10:48:42 +0530 Subject: [PATCH 03/19] Removed: Non required email templates from the order status email template dropdrown --- controllers/admin/AdminStatusesController.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/controllers/admin/AdminStatusesController.php b/controllers/admin/AdminStatusesController.php index e10140b77..01a1d9c0d 100644 --- a/controllers/admin/AdminStatusesController.php +++ b/controllers/admin/AdminStatusesController.php @@ -707,6 +707,14 @@ class AdminStatusesControllerCore extends AdminController $theme = new Theme($this->context->shop->id_theme); $default_path = '../mails/'; $theme_path = '../themes/'.$theme->directory.'/mails/'; // Mail templates can also be found in the theme folder + $templatesToIgnore = array( + 'footer.html', + 'header.html', + 'shipped.html', + 'in_transit.html', + 'download_products.html', + 'test.html' + ); $array = array(); foreach (Language::getLanguages(false) as $language) { @@ -722,7 +730,9 @@ class AdminStatusesControllerCore extends AdminController // We merge all available emails in one array $templates = array_unique(array_merge(scandir(_PS_ADMIN_DIR_.'/'.$default_path.$iso_code), $theme_templates)); foreach ($templates as $key => $template) { - if (!strncmp(strrev($template), 'lmth.', 5)) { + if (!strncmp(strrev($template), 'lmth.', 5) + && !in_array($template, $templatesToIgnore) + ) { $search_result = array_search($template, $theme_templates); $array[$iso_code][] = array( 'id' => substr($template, 0, -5), From e1fbeebd7f16b4675596366f17299461c6083378 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Tue, 18 Jun 2024 18:39:50 +0530 Subject: [PATCH 04/19] Added: Variable send_emails in validatOrder function call of the payment module to prevent the emails on the order validation process --- classes/PaymentModule.php | 63 +++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 25 deletions(-) diff --git a/classes/PaymentModule.php b/classes/PaymentModule.php index d7e75b7d2..79fe1a90b 100644 --- a/classes/PaymentModule.php +++ b/classes/PaymentModule.php @@ -162,7 +162,7 @@ abstract class PaymentModuleCore extends Module */ public function validateOrder($id_cart, $id_order_state, $amount_paid, $payment_method = 'Unknown', $message = null, $extra_vars = array(), $currency_special = null, $dont_touch_amount = false, - $secure_key = false, Shop $shop = null) + $secure_key = false, Shop $shop = null, $send_mails = true) { if (self::DEBUG_MODE) { PrestaShopLogger::addLog('PaymentModule::validateOrder - Function called', 1, null, 'Cart', (int)$id_cart, true); @@ -420,6 +420,7 @@ abstract class PaymentModuleCore extends Module && number_format($cart_total_paid, _PS_PRICE_COMPUTE_PRECISION_) != number_format($amount_paid, _PS_PRICE_COMPUTE_PRECISION_) && $this->name != 'wsorder' && $this->name != 'bo_order' + && (!isset($this->ValidateOrderAmount) || $this->validateOrderAmount) ) { // if customer is paying full payment amount $id_order_state = Configuration::get('PS_OS_ERROR'); @@ -684,24 +685,25 @@ abstract class PaymentModuleCore extends Module if ($voucher->add()) { // If the voucher has conditions, they are now copied to the new voucher CartRule::copyConditions($cart_rule['obj']->id, $voucher->id); - - $params = array( - '{voucher_amount}' => Tools::displayPrice($voucher->reduction_amount, $this->context->currency, false), - '{voucher_num}' => $voucher->code, - '{firstname}' => $this->context->customer->firstname, - '{lastname}' => $this->context->customer->lastname, - '{id_order}' => $order->reference, - '{order_name}' => $order->getUniqReference() - ); - Mail::Send( - (int)$order->id_lang, - 'voucher', - sprintf(Mail::l('New voucher for your order %s', (int)$order->id_lang), $order->reference), - $params, - $this->context->customer->email, - $this->context->customer->firstname.' '.$this->context->customer->lastname, - null, null, null, null, _PS_MAIL_DIR_, false, (int)$order->id_shop - ); + if ($send_mails) { + $params = array( + '{voucher_amount}' => Tools::displayPrice($voucher->reduction_amount, $this->context->currency, false), + '{voucher_num}' => $voucher->code, + '{firstname}' => $this->context->customer->firstname, + '{lastname}' => $this->context->customer->lastname, + '{id_order}' => $order->reference, + '{order_name}' => $order->getUniqReference() + ); + Mail::Send( + (int)$order->id_lang, + 'voucher', + sprintf(Mail::l('New voucher for your order %s', (int)$order->id_lang), $order->reference), + $params, + $this->context->customer->email, + $this->context->customer->firstname.' '.$this->context->customer->lastname, + null, null, null, null, _PS_MAIL_DIR_, false, (int)$order->id_shop + ); + } } } @@ -1050,10 +1052,12 @@ abstract class PaymentModuleCore extends Module // Set the order status $new_history = new OrderHistory(); $new_history->id_order = (int)$order->id; - $new_history->changeIdOrderState((int)$id_order_state, $order, true); - - $new_history->addWithemail(true, $extra_vars); + if ($send_mails) { + $new_history->addWithemail(true, $extra_vars); + } else { + $new_history->add(true); + } // Switch to back order if needed $objHotelBookingDetail = new HotelBookingDetail(); @@ -1089,7 +1093,11 @@ abstract class PaymentModuleCore extends Module $history = new OrderHistory(); $history->id_order = (int)$order->id; $history->changeIdOrderState($id_order_state, $order, true); - $history->addWithemail(); + if ($send_mails) { + $history->addWithemail(); + } else { + $history->add(); + } } unset($order_detail); @@ -1240,7 +1248,9 @@ abstract class PaymentModuleCore extends Module // Send order confirmation/overbooking mails to the reciepients according to the order mail configuration $overBookingStates = OrderState::getOverBookingStates(); $isOverBookingStatus = in_array($id_order_state, $overBookingStates); - if (Configuration::get('PS_ORDER_CONF_MAIL_TO_CUSTOMER')){ + if (Configuration::get('PS_ORDER_CONF_MAIL_TO_CUSTOMER') + && $send_mails + ){ // If order currenct state is overbooking, the send overbooking email or send order confirmation email if ($isOverBookingStatus) { $subject = Mail::l('Order Not Confirmed', (int)$order->id_lang); @@ -1292,7 +1302,9 @@ abstract class PaymentModuleCore extends Module } } } - if (Configuration::get('PS_ORDER_CONF_MAIL_TO_SUPERADMIN')){ + if (Configuration::get('PS_ORDER_CONF_MAIL_TO_SUPERADMIN') + && $send_mails + ){ // get superadmin employees if ($superAdminEmployees = Employee::getEmployeesByProfile(_PS_ADMIN_PROFILE_, true)) { // If order currenct state is overbooking, the send overbooking email or send order confirmation email @@ -1329,6 +1341,7 @@ abstract class PaymentModuleCore extends Module } if ($idHotel && Validate::isLoadedObject($objHotel = new HotelBranchInformation($idHotel)) + && $send_mails ) { if (Configuration::get('PS_ORDER_CONF_MAIL_TO_HOTEL_MANAGER')){ // If order currenct state is overbooking, the send overbooking email or send order confirmation email From e6b3dfaeeb55372cd1ac50748baf5e1e774d7c9a Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Tue, 18 Jun 2024 19:17:50 +0530 Subject: [PATCH 05/19] Updated: The Address creation process for the customer from the admin office --- .../addresses/helpers/form/form.tpl | 53 ++++++++-------- classes/Customer.php | 15 +++++ .../admin/AdminAddressesController.php | 60 +++++++++++++------ 3 files changed, 82 insertions(+), 46 deletions(-) diff --git a/admin/themes/default/template/controllers/addresses/helpers/form/form.tpl b/admin/themes/default/template/controllers/addresses/helpers/form/form.tpl index e46200e15..cb9d740f7 100644 --- a/admin/themes/default/template/controllers/addresses/helpers/form/form.tpl +++ b/admin/themes/default/template/controllers/addresses/helpers/form/form.tpl @@ -47,50 +47,47 @@ - {else} - - -
- - -
- {/if} + function resetCustomerRelatedAddressFields() { + $('input[name=firstname]').val(''); + $('input[name=lastname]').val(''); + $('input[name=company]').val(''); + $('input[name=id_customer]').val(''); + } + {else} {$smarty.block.parent} {/if} diff --git a/classes/Customer.php b/classes/Customer.php index a8c4c3609..4a55fa55d 100644 --- a/classes/Customer.php +++ b/classes/Customer.php @@ -951,4 +951,19 @@ class CustomerCore extends ObjectModel $sql_filter .= Shop::addSqlRestriction(Shop::SHARE_CUSTOMER, 'main'); return parent::getWebserviceObjectList($sql_join, $sql_filter, $sql_sort, $sql_limit); } + + public static function getAllCustomers($withAddress = null, $active = null, $deleted = null) + { + return Db::getInstance()->executeS( + 'SELECT c.`firstname`, c.`lastname`, c.`id_customer`, c.`email`, a.`id_address` + FROM `'._DB_PREFIX_.'customer` c + LEFT JOIN `'._DB_PREFIX_.'address` a + ON a.`id_customer` = c.`id_customer` AND a.`deleted`=0 + WHERE 1 '. + (!is_null($deleted) ? ' AND c.`deleted` = '.(int) $deleted : ' '). + (!is_null($active) ? ' AND c.`active` = '.(int) $active: ' ' ). + (!is_null($withAddress) ? (($withAddress) ? ' AND a.`id_address` !='.(int) 0: ' AND ISNULL(a.`id_address`)'): ' ' ) + ); + } + } diff --git a/controllers/admin/AdminAddressesController.php b/controllers/admin/AdminAddressesController.php index 6e052f39b..a963d6709 100644 --- a/controllers/admin/AdminAddressesController.php +++ b/controllers/admin/AdminAddressesController.php @@ -112,18 +112,41 @@ class AdminAddressesControllerCore extends AdminController public function renderForm() { + $customerSelectField =array( + 'type' => 'text_customer', + 'label' => $this->l('Customer'), + 'name' => 'id_customer', + 'required' => false, + ); + if ($this->loadObject(true) + && !$this->object->id + ) { + $customerEmails = array(array( + 'email' => $this->l('Select Customer'), + 'id_customer' => 0, + 'id_address'=> 0 + )); + $customerEmails = array_merge($customerEmails, Customer::getAllCustomers(false, null, 0)); + $customerSelectField = array( + 'type' => 'select', + 'label' => $this->l('Customer'), + 'name' => 'id_customer', + 'class' => 'chosen', + 'options' => array( + 'query' => $customerEmails, + 'id' => 'id_customer', + 'name' => 'email' + ), + ); + } + $this->fields_form = array( 'legend' => array( 'title' => $this->l('Addresses'), 'icon' => 'icon-envelope-alt' ), 'input' => array( - array( - 'type' => 'text_customer', - 'label' => $this->l('Customer'), - 'name' => 'id_customer', - 'required' => false, - ), + $customerSelectField, array( 'type' => 'text', 'label' => $this->l('Identification Number'), @@ -190,7 +213,6 @@ class AdminAddressesControllerCore extends AdminController $token_customer = Tools::getAdminToken('AdminCustomers'.(int)(Tab::getIdFromClassName('AdminCustomers')).(int)$this->context->employee->id); } - $this->fields_value['email'] = Tools::getValue('email'); $this->tpl_form_vars = array( 'customer' => (isset($customer) && $this->object->id) ? $customer : null, 'tokenCustomer' => isset($token_customer) ? $token_customer : null @@ -503,21 +525,23 @@ class AdminAddressesControllerCore extends AdminController return $out; } - /** - * Method called when an ajax request is made + /** + * Method called when an ajax request is made to load the customer info for the selected email * @see AdminController::postProcess() */ - public function ajaxProcess() + public function ajaxProcessLoadCustomer() { - if (Tools::isSubmit('email')) { - $email = pSQL(Tools::getValue('email')); - $customer = Customer::searchByName($email); - if (!empty($customer)) { - $customer = $customer['0']; - echo json_encode(array('infos' => pSQL($customer['firstname']).'_'.pSQL($customer['lastname']).'_'.pSQL($customer['company']).'_'.pSQL($customer['id_customer']))); - } + $response = array('status' => false); + if (Tools::getValue('id_customer') + && Validate::isLoadedObject($objCustomer = new Customer(Tools::getValue('id_customer'))) + ) { + $response['status'] = true; + $response['firstname'] = $objCustomer->firstname; + $response['lastname'] = $objCustomer->lastname; + $response['company'] = $objCustomer->company; } - die; + + $this->ajaxDie(json_encode($response)); } /** From f2d6cc391336665e4c81c164dbc63871f3df3028 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Thu, 20 Jun 2024 10:38:14 +0530 Subject: [PATCH 06/19] Updated: The trade mark in the head tag of the admin login page --- admin/themes/default/template/controllers/login/header.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/themes/default/template/controllers/login/header.tpl b/admin/themes/default/template/controllers/login/header.tpl index aff412764..d1d17ce21 100644 --- a/admin/themes/default/template/controllers/login/header.tpl +++ b/admin/themes/default/template/controllers/login/header.tpl @@ -39,7 +39,7 @@ - {$shop_name} {if $meta_title != ''}{if isset($navigationPipe)}{$navigationPipe|escape:'html':'UTF-8'}{else}>{/if} {$meta_title}{/if} (PrestaShop™) + {$shop_name} {if $meta_title != ''}{if isset($navigationPipe)}{$navigationPipe|escape:'html':'UTF-8'}{else}>{/if} {$meta_title}{/if} (QloApps™) {if isset($css_files)} {foreach from=$css_files key=css_uri item=media} From 7393661473cdec88226594769b9daf621f1234a7 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Fri, 28 Jun 2024 11:27:57 +0530 Subject: [PATCH 07/19] Optimized code for navigation links dependent on CMS pages --- controllers/front/CmsController.php | 2 ++ .../blocknavigationmenu.php | 35 ++++--------------- .../classes/WkCustomNavigationLink.php | 26 +++++++++++++- ...nCustomNavigationLinkSettingController.php | 10 ++++-- .../views/js/admin/wk_navigation_link.js | 6 ++-- 5 files changed, 44 insertions(+), 35 deletions(-) diff --git a/controllers/front/CmsController.php b/controllers/front/CmsController.php index 4eca2e8f6..c855df6b4 100644 --- a/controllers/front/CmsController.php +++ b/controllers/front/CmsController.php @@ -79,6 +79,7 @@ class CmsControllerCore extends FrontController } elseif (Validate::isLoadedObject($this->cms_category) && $this->cms_category->active && $this->cms_category->isAssociatedToShop()) { $this->assignCase = 2; } else { + // incase the cms page in invalid i.e, url is tampered Tools::redirect($this->context->link->getPageLink('pagenotfound')); } } @@ -134,6 +135,7 @@ class CmsControllerCore extends FrontController 'body_classes' => array($this->php_self.'-'.$this->cms_category->id, $this->php_self.'-'.$this->cms_category->link_rewrite) )); } else { + // incase the cms page is inactive Tools::redirect($this->context->link->getPageLink('pagenotfound')); } diff --git a/modules/blocknavigationmenu/blocknavigationmenu.php b/modules/blocknavigationmenu/blocknavigationmenu.php index 0c75505cc..224845228 100644 --- a/modules/blocknavigationmenu/blocknavigationmenu.php +++ b/modules/blocknavigationmenu/blocknavigationmenu.php @@ -105,41 +105,20 @@ class blocknavigationmenu extends Module public function hookActionObjectCMSUpdateAfter($params) { - $id_cms = $params['object']->id; - // Disabling all the related navigation links to disabled CMS page + $idCMS = $params['object']->id; if (!$params['object']->active) { - $this->disableRelatedLinks($id_cms); + $objCustomNavigationLink = new WkCustomNavigationLink(); + // Disabling depended Navigation link + $objCustomNavigationLink->disableNavigationLinksByIdCMS($idCMS); } } public function hookActionObjectCMSDeleteAfter($params) { - $id_cms = $params['object']->id; - // Disabling all the related navigation links to deleted CMS page - $this->deleteRelatedLinks($id_cms); - } - - public function disableRelatedLinks($id_cms) - { + $idCMS = $params['object']->id; $objCustomNavigationLink = new WkCustomNavigationLink(); - if ($navLinks = $objCustomNavigationLink->getRelatedNavLinksByIdCMS($id_cms)) { - foreach ($navLinks as $navLink) { - $objCustomNavigationLink = new WkCustomNavigationLink((int) $navLink['id_navigation_link']); - $objCustomNavigationLink->active = 0; - $objCustomNavigationLink->save(); - } - } - } - - public function deleteRelatedLinks($id_cms) - { - $objCustomNavigationLink = new WkCustomNavigationLink(); - if ($navLinks = $objCustomNavigationLink->getRelatedNavLinksByIdCMS($id_cms)) { - foreach ($navLinks as $navLink) { - $objCustomNavigationLink = new WkCustomNavigationLink((int) $navLink['id_navigation_link']); - $objCustomNavigationLink->delete(); - } - } + // Deleting depended Navigation link + $objCustomNavigationLink->deleteNavigationLinksByIdCMS($idCMS); } public function install() diff --git a/modules/blocknavigationmenu/classes/WkCustomNavigationLink.php b/modules/blocknavigationmenu/classes/WkCustomNavigationLink.php index 8fc7a70f8..d27a037f0 100644 --- a/modules/blocknavigationmenu/classes/WkCustomNavigationLink.php +++ b/modules/blocknavigationmenu/classes/WkCustomNavigationLink.php @@ -235,10 +235,11 @@ class WkCustomNavigationLink extends ObjectModel $objCustomNavigationLink->is_custom_link = 0; $objCustomNavigationLink->link = 'contact'; $objCustomNavigationLink->save(); + return true; } - public function getRelatedNavLinksByIdCMS($idCMS) + public function getNavigationLinksByIdCMS($idCMS) { return Db::getInstance()->executeS(' SELECT * FROM `'._DB_PREFIX_.'htl_custom_navigation_link` @@ -246,4 +247,27 @@ class WkCustomNavigationLink extends ObjectModel ); } + public function disableNavigationLinksByIdCMS($idCMS) + { + $objCustomNavigationLink = new WkCustomNavigationLink(); + if ($navLinks = $objCustomNavigationLink->getNavigationLinksByIdCMS($idCMS)) { + foreach ($navLinks as $navLink) { + $objCustomNavigationLink = new WkCustomNavigationLink((int) $navLink['id_navigation_link']); + $objCustomNavigationLink->active = 0; + $objCustomNavigationLink->save(); + } + } + } + + public function deleteNavigationLinksByIdCMS($idCMS) + { + $objCustomNavigationLink = new WkCustomNavigationLink(); + if ($navLinks = $objCustomNavigationLink->getNavigationLinksByIdCMS($idCMS)) { + foreach ($navLinks as $navLink) { + $objCustomNavigationLink = new WkCustomNavigationLink((int) $navLink['id_navigation_link']); + $objCustomNavigationLink->delete(); + } + } + } + } diff --git a/modules/blocknavigationmenu/controllers/admin/AdminCustomNavigationLinkSettingController.php b/modules/blocknavigationmenu/controllers/admin/AdminCustomNavigationLinkSettingController.php index fda9152e1..82c9b3cee 100644 --- a/modules/blocknavigationmenu/controllers/admin/AdminCustomNavigationLinkSettingController.php +++ b/modules/blocknavigationmenu/controllers/admin/AdminCustomNavigationLinkSettingController.php @@ -225,7 +225,7 @@ class AdminCustomNavigationLinkSettingController extends ModuleAdminController Media::addJsDef( array( - 'catFormatCmsPages' => json_encode($categoryWiseCmsPages) + 'categoryWiseCmsPages' => json_encode($categoryWiseCmsPages) ) ); @@ -425,7 +425,9 @@ class AdminCustomNavigationLinkSettingController extends ModuleAdminController && !$this->object->is_custom_link //Check for CMS related navigation link ) { $objCMS = new CMS($this->object->id_cms); - if (!$objCMS->active) { + if (!$objCMS->active + && !$this->object->active + ) { $this->errors[] = $this->l('Please activate the relate CMS page to activate this link'); } } @@ -440,6 +442,8 @@ class AdminCustomNavigationLinkSettingController extends ModuleAdminController public function setMedia() { parent::setMedia(); - $this->addJS(_MODULE_DIR_.$this->module->name.'/views/js/admin/wk_navigation_link.js'); + if ($this->display == 'edit' || $this->display == 'add') { + $this->addJS($this->module->getPathUri().'views/js/admin/wk_navigation_link.js'); + } } } diff --git a/modules/blocknavigationmenu/views/js/admin/wk_navigation_link.js b/modules/blocknavigationmenu/views/js/admin/wk_navigation_link.js index b6339aaa4..e6da30dfc 100644 --- a/modules/blocknavigationmenu/views/js/admin/wk_navigation_link.js +++ b/modules/blocknavigationmenu/views/js/admin/wk_navigation_link.js @@ -55,11 +55,11 @@ function setCategoryWiseCmsPages() { var selectedPage = parseInt($('input[name="id_cms"]:checked').val()); var selectedCategory = parseInt($('#id_cms_category').val()); - var formattedData = JSON.parse(catFormatCmsPages); + var cmsPages = JSON.parse(categoryWiseCmsPages); if (!isNaN(selectedCategory)) { - formattedData = formattedData[selectedCategory]; + cmsPages = cmsPages[selectedCategory]; var html = ''; - $.each(formattedData, function(i, v) { + $.each(cmsPages, function(i, v) { html += '
'+v['id_cms']+'