diff --git a/admin-dev/password.php b/admin-dev/password.php index e8ac846dc..deac428d2 100644 --- a/admin-dev/password.php +++ b/admin-dev/password.php @@ -35,8 +35,13 @@ $errors = array(); $id_lang = (int)Configuration::get('PS_LANG_DEFAULT'); $iso = strtolower(Language::getIsoById((int)$id_lang)); include(_PS_TRANSLATIONS_DIR_.$iso.'/admin.php'); - -if (isset($_POST['Submit'])) +/* PrestaShop demo mode */ +if (_PS_MODE_DEMO_) +{ + $errors[] = Tools::displayError('This functionnality has been disabled.'); +} +/* PrestaShop demo mode*/ +else if (isset($_POST['Submit'])) { $errors = array(); if (empty($_POST['email'])) diff --git a/admin-dev/tabs/AdminAccess.php b/admin-dev/tabs/AdminAccess.php index 4a2975c0e..e32e238d9 100644 --- a/admin-dev/tabs/AdminAccess.php +++ b/admin-dev/tabs/AdminAccess.php @@ -1,6 +1,6 @@ execute('UPDATE `'._DB_PREFIX_.'access` SET `view` = '.$enabled.', `add` = '.$enabled.', `edit` = '.$enabled.', `delete` = '.$enabled.' WHERE `id_tab` = '.(int)($id_tab).' AND `id_profile` = '.(int)($id_profile)); else $res &= Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'access` SET `'.pSQL($perm).'` = '.$enabled.' WHERE `id_tab` = '.(int)($id_tab).' AND `id_profile` = '.(int)($id_profile)); - + $this->return_status = $res?'ok':'error'; if ($res) $this->return_message = $this->l('Access successfully updated'); @@ -71,24 +71,24 @@ class AdminAccess extends AdminTab if (!in_array($perm, array('view', 'configure'))) throw new PrestashopException('permission not exists'); - + if ($id_module == -1) $res &= Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'module_access` SET `'.pSQL($perm).'` = '.(int)$enabled.' WHERE `id_profile` = '.(int)$id_profile); else $res &= Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'module_access` SET `'.pSQL($perm).'` = '.(int)$enabled.' WHERE `id_module` = '.(int)$id_module.' AND `id_profile` = '.(int)$id_profile); - + $this->return_status = $res?'ok':'error'; if ($res) $this->return_message = $this->l('Access successfully updated.'); else $this->return_message = $this->l('An error when updating access.'); } - - + + public function displayAjax() { $return = array('result'=>$this->return_status,'msg'=>$this->return_message); - + echo Tools::jsonEncode($return); } public function display() @@ -97,16 +97,16 @@ class AdminAccess extends AdminTab echo ''; - + } - + /** * Get the current profile id * @@ -151,7 +151,7 @@ class AdminAccess extends AdminTab { return (isset($_GET['profile']) AND !empty($_GET['profile']) AND is_numeric($_GET['profile'])) ? (int)($_GET['profile']) : 1; } - + public function displayForm($isMainTab = true) { parent::displayForm(); @@ -159,7 +159,7 @@ class AdminAccess extends AdminTab $tabs = Tab::getTabs($this->context->language->id); $profiles = Profile::getProfiles($this->context->language->id); $accesses = Profile::getProfileAccesses($currentProfile); - + echo ' + @@ -332,7 +340,7 @@ class AdminAccess extends AdminTab ORDER BY m.name'); if (!sizeof($modules)) echo ''; - else + else foreach ($modules AS $module) echo ' diff --git a/admin-dev/tabs/AdminAttachments.php b/admin-dev/tabs/AdminAttachments.php index e255d8c4c..3c42e13af 100644 --- a/admin-dev/tabs/AdminAttachments.php +++ b/admin-dev/tabs/AdminAttachments.php @@ -50,6 +50,13 @@ class AdminAttachments extends AdminTab public function postProcess() { + /* PrestaShop demo mode */ + if (_PS_MODE_DEMO_) + { + $this->_errors[] = Tools::displayError('This functionnality has been disabled.'); + return; + } + /* PrestaShop demo mode*/ if (Tools::isSubmit('submitAdd'.$this->table)) { if ($id = (int)(Tools::getValue('id_attachment')) AND $a = new Attachment($id)) diff --git a/admin-dev/tabs/AdminDb.php b/admin-dev/tabs/AdminDb.php index 5517e9a58..73d44c0b4 100644 --- a/admin-dev/tabs/AdminDb.php +++ b/admin-dev/tabs/AdminDb.php @@ -54,6 +54,14 @@ class AdminDb extends AdminPreferences public function postProcess() { + /* PrestaShop demo mode */ + if (_PS_MODE_DEMO_) + { + $this->_errors[] = Tools::displayError('This functionnality has been disabled.'); + return; + } + /* PrestaShop demo mode*/ + if (isset($_POST['submitDatabase'.$this->table])) { if ($this->tabAccess['edit'] === '1') diff --git a/admin-dev/tabs/AdminEmails.php b/admin-dev/tabs/AdminEmails.php index 5293cb872..680592a73 100644 --- a/admin-dev/tabs/AdminEmails.php +++ b/admin-dev/tabs/AdminEmails.php @@ -66,6 +66,14 @@ class AdminEmails extends AdminPreferences public function beforeUpdateOptions() { + /* PrestaShop demo mode */ + if (_PS_MODE_DEMO_) + { + $this->_errors[] = Tools::displayError('This functionnality has been disabled.'); + return; + } + /* PrestaShop demo mode*/ + if ($_POST['PS_MAIL_METHOD'] == 2 AND (empty($_POST['PS_MAIL_SERVER']) OR empty($_POST['PS_MAIL_SMTP_PORT']))) $this->_errors[] = Tools::displayError('You must define a SMTP server and a SMTP port. If you do not know, use the PHP mail() function instead.'); } @@ -73,6 +81,7 @@ class AdminEmails extends AdminPreferences public function display() { parent::display(); + $this->_displayMailTest(); } diff --git a/admin-dev/tabs/AdminEmployees.php b/admin-dev/tabs/AdminEmployees.php index 4b010dfcc..7678962f6 100644 --- a/admin-dev/tabs/AdminEmployees.php +++ b/admin-dev/tabs/AdminEmployees.php @@ -1,6 +1,6 @@ context = Context::getContext(); $this->table = 'employee'; $this->className = 'Employee'; $this->lang = false; - $this->edit = true; + $this->edit = true; $this->delete = true; $this->_select = 'pl.`name` AS profile'; - $this->_join = 'LEFT JOIN `'._DB_PREFIX_.'profile` p ON a.`id_profile` = p.`id_profile` + $this->_join = 'LEFT JOIN `'._DB_PREFIX_.'profile` p ON a.`id_profile` = p.`id_profile` LEFT JOIN `'._DB_PREFIX_.'profile_lang` pl ON (pl.`id_profile` = p.`id_profile` AND pl.`id_lang` = '.(int)$this->context->language->id.')'; $profiles = Profile::getProfiles($this->context->language->id); @@ -53,7 +53,7 @@ class AdminEmployees extends AdminTab 'id_employee' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25), 'lastname' => array('title' => $this->l('Last name'), 'width' => 130), 'firstname' => array('title' => $this->l('First name'), 'width' => 130), - 'email' => array('title' => $this->l('E-mail address'), 'width' => 180), + 'email' => array('title' => $this->l('E-mail address'), 'width' => 180), 'profile' => array('title' => $this->l('Profile'), 'width' => 90, 'type' => 'select', 'select' => $this->profilesArray, 'filter_key' => 'pl!name'), 'active' => array('title' => $this->l('Can log in'), 'align' => 'center', 'active' => 'status', 'type' => 'bool'), ); @@ -98,7 +98,7 @@ class AdminEmployees extends AdminTab var employeePage = true; - + '.($obj->id ? '' : '').' '.((int)$this->tabAccess['view'] ? '' : '').' @@ -184,7 +184,7 @@ class AdminEmployees extends AdminTab $(\'select[name=id_profile]\').change(function(){ ifSuperAdmin($(this)); }); - + ifSuperAdmin($(\'select[name=id_profile]\')); }); @@ -220,6 +220,14 @@ class AdminEmployees extends AdminTab $this->context = Context::getContext(); if (Tools::isSubmit('deleteemployee') || Tools::isSubmit('status') || Tools::isSubmit('statusemployee')) { + /* PrestaShop demo mode */ + if (_PS_MODE_DEMO_ && $id_employee = Tools::getValue('id_employee') && (int)$id_employee == _PS_DEMO_MAIN_BO_ACCOUNT_) + { + $this->_errors[] = Tools::displayError('This functionnality has been disabled.'); + return; + } + /* PrestaShop demo mode*/ + if ($this->context->employee->id == Tools::getValue('id_employee')) { $this->_errors[] = Tools::displayError('You cannot disable or delete your own account.'); diff --git a/admin-dev/tabs/AdminImport.php b/admin-dev/tabs/AdminImport.php index ec5ae0352..bc456524c 100644 --- a/admin-dev/tabs/AdminImport.php +++ b/admin-dev/tabs/AdminImport.php @@ -1732,6 +1732,7 @@ class AdminImport extends AdminTab Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'specific_price'); Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'specific_price_priority'); Image::deleteAllImages(_PS_PROD_IMG_DIR_); + mkdir(_PS_PROD_IMG_DIR_); break; case $this->entities[$this->l('Customers')]: Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'customer'); @@ -1770,6 +1771,14 @@ class AdminImport extends AdminTab public function postProcess() { + /* PrestaShop demo mode */ + if (_PS_MODE_DEMO_) + { + $this->_errors[] = Tools::displayError('This functionnality has been disabled.'); + return; + } + /* PrestaShop demo mode*/ + if (Tools::isSubmit('submitFileUpload')) { if (isset($_FILES['file']) AND !empty($_FILES['file']['error'])) diff --git a/admin-dev/tabs/AdminModules.php b/admin-dev/tabs/AdminModules.php index fb4e1c494..664c0ce87 100644 --- a/admin-dev/tabs/AdminModules.php +++ b/admin-dev/tabs/AdminModules.php @@ -223,6 +223,13 @@ class AdminModules extends AdminTab /* Automatically copy a module from external URL and unarchive it in the appropriated directory */ if (Tools::isSubmit('submitDownload')) { + /* PrestaShop demo mode */ + if (_PS_MODE_DEMO_) + { + $this->_errors[] = Tools::displayError('This functionnality has been disabled.'); + return; + } + /* PrestaShop demo mode*/ if ($this->tabAccess['add'] === '1') { if (Validate::isModuleUrl($url = Tools::getValue('url'), $this->_errors)) @@ -238,6 +245,13 @@ class AdminModules extends AdminTab } if (Tools::isSubmit('submitDownload2')) { + /* PrestaShop demo mode */ + if (_PS_MODE_DEMO_) + { + $this->_errors[] = Tools::displayError('This functionnality has been disabled.'); + return; + } + /* PrestaShop demo mode*/ if ($this->tabAccess['add'] === '1') { if (!isset($_FILES['file']['tmp_name']) OR empty($_FILES['file']['tmp_name'])) diff --git a/admin-dev/tabs/AdminProfiles.php b/admin-dev/tabs/AdminProfiles.php index eff8c961b..9bee579fc 100644 --- a/admin-dev/tabs/AdminProfiles.php +++ b/admin-dev/tabs/AdminProfiles.php @@ -50,6 +50,14 @@ class AdminProfiles extends AdminTab public function postProcess() { + /* PrestaShop demo mode */ + if (_PS_MODE_DEMO_) + { + $this->_errors[] = Tools::displayError('This functionnality has been disabled.'); + return; + } + /* PrestaShop demo mode*/ + if (isset($_GET['delete'.$this->table]) AND $_GET[$this->identifier] == (int)(_PS_ADMIN_PROFILE_)) $this->_errors[] = $this->l('For security reasons, you cannot delete the Administrator profile'); else diff --git a/admin-dev/tabs/AdminTabs.php b/admin-dev/tabs/AdminTabs.php index c7f4ef03c..ff2079abd 100644 --- a/admin-dev/tabs/AdminTabs.php +++ b/admin-dev/tabs/AdminTabs.php @@ -55,6 +55,14 @@ class AdminTabs extends AdminTab public function postProcess() { + /* PrestaShop demo mode */ + if (_PS_MODE_DEMO_) + { + $this->_errors[] = Tools::displayError('This functionnality has been disabled.'); + return; + } + /* PrestaShop demo mode*/ + if (($id_tab = (int)(Tools::getValue('id_tab'))) AND ($direction = Tools::getValue('move')) AND Validate::isLoadedObject($tab = new Tab($id_tab))) { if ($tab->move($direction)) diff --git a/admin-dev/tabs/AdminTranslations.php b/admin-dev/tabs/AdminTranslations.php index f965a3677..c19ecb5c2 100644 --- a/admin-dev/tabs/AdminTranslations.php +++ b/admin-dev/tabs/AdminTranslations.php @@ -424,6 +424,14 @@ class AdminTranslations extends AdminTab public function postProcess() { + /* PrestaShop demo mode */ + if (_PS_MODE_DEMO_) + { + $this->_errors[] = Tools::displayError('This functionnality has been disabled.'); + return; + } + /* PrestaShop demo mode*/ + if (Tools::isSubmit('submitCopyLang')) { if ($this->tabAccess['add'] === '1') diff --git a/classes/AdminTab.php b/classes/AdminTab.php index a0d09075a..33309f5e3 100644 --- a/classes/AdminTab.php +++ b/classes/AdminTab.php @@ -641,8 +641,7 @@ abstract class AdminTabCore elseif (!$object->updatePosition((int)(Tools::getValue('way')), (int)(Tools::getValue('position')))) $this->_errors[] = Tools::displayError('Failed to update the position.'); else - Tools::redirectAdmin(self::$currentIndex.'&'.$this->table.'Orderby=position&'.$this->table.'Orderway=asc&conf=5'.(($id_category = (int)(Tools::getValue($this->identifier))) ? ('&'.$this->identifier.'='.$id_category) : '').'&token='.$token); - Tools::redirectAdmin(self::$currentIndex.'&'.$this->table.'Orderby=position&'.$this->table.'Orderway=asc&conf=5'.((($id_category = (int)(Tools::getValue('id_category'))) && Tools::getValue('id_product')) ? '&id_category='.$id_category : '').'&token='.$token); + Tools::redirectAdmin(self::$currentIndex.'&'.$this->table.'Orderby=position&'.$this->table.'Orderway=asc&conf=5'.(($id_identifier = (int)(Tools::getValue($this->identifier))) ? ('&'.$this->identifier.'='.$id_identifier) : '').'&token='.$token); } /* Delete multiple objects */ elseif (Tools::getValue('submitDel'.$this->table)) diff --git a/classes/Tools.php b/classes/Tools.php index e39abf616..7bbd4e73a 100644 --- a/classes/Tools.php +++ b/classes/Tools.php @@ -1764,8 +1764,12 @@ FileETag INode MTime Size switch ($type) { case 'by' : + $list = array(0 => 'name', 1 => 'price', 2 => 'date_add', 3 => 'date_upd', 4 => 'position', 5 => 'manufacturer_name', 6 => 'quantity'); + $value = (is_null($value) || $value === false || $value === '') ? (int)Configuration::get('PS_PRODUCTS_ORDER_BY') : $value; + $value = (isset($list[$value])) ? $list[$value] : ((in_array($value, $list)) ? $value : 'position'); $orderByPrefix = ''; - if($prefix) { + if ($prefix) + { if ($value == 'id_product' || $value == 'date_add' || $value == 'price') $orderByPrefix = 'p.'; elseif ($value == 'name') @@ -1776,9 +1780,7 @@ FileETag INode MTime Size $orderByPrefix = 'cp.'; } - $value = (is_null($value) || $value === false || $value === '') ? (int)Configuration::get('PS_PRODUCTS_ORDER_BY') : $value; - $list = array(0 => 'name', 1 => 'price', 2 => 'date_add', 3 => 'date_upd', 4 => 'position', 5 => 'manufacturer_name', 6 => 'quantity'); - return $orderByPrefix.((isset($list[$value])) ? $list[$value] : ((in_array($value, $list)) ? $value : 'position')); + return $orderByPrefix.$value; break; case 'way' : diff --git a/config/defines.inc.php b/config/defines.inc.php index 7a12e495a..af9e70744 100755 --- a/config/defines.inc.php +++ b/config/defines.inc.php @@ -26,6 +26,8 @@ */ define('_PS_MODE_DEV_', true); +define('_PS_MODE_DEMO_', false); +define('_PS_DEMO_MAIN_BO_ACCOUNT_', 1); $currentDir = dirname(__FILE__); diff --git a/controllers/admin/AdminBackupController.php b/controllers/admin/AdminBackupController.php index d75d94fc5..02596eae6 100644 --- a/controllers/admin/AdminBackupController.php +++ b/controllers/admin/AdminBackupController.php @@ -127,11 +127,19 @@ class AdminBackupControllerCore extends AdminController public function postProcess() { + /* PrestaShop demo mode */ + if (_PS_MODE_DEMO_) + { + $this->_errors[] = Tools::displayError('This functionnality has been disabled.'); + return; + } + /* PrestaShop demo mode*/ + // Test if the backup dir is writable - if(!is_writable(_PS_ADMIN_DIR_.'/backups/')) + if (!is_writable(_PS_ADMIN_DIR_.'/backups/')) $this->warnings[] = $this->l('"Backups" Directory in admin directory must be writeable (CHMOD 755 / 777)'); - if($this->action == 'new' && is_writable(_PS_ADMIN_DIR_.'/backups/')) + if ($this->action == 'new' && is_writable(_PS_ADMIN_DIR_.'/backups/')) { if (($object = $this->loadObject())) { diff --git a/install-dev/php/country_to_timezone.php b/install-dev/php/country_to_timezone.php index 93533119c..40f619a34 100644 --- a/install-dev/php/country_to_timezone.php +++ b/install-dev/php/country_to_timezone.php @@ -1,6 +1,6 @@ 0) { @@ -270,7 +274,7 @@ var ajaxCart = { var removedProductData = null; var removedProductDomId = null; //look for a product to delete... - $('#cart_block_list dl.products dt').each(function(){ + $('#'+parentId+' #cart_block_list dl.products dt').each(function(){ //retrieve idProduct and idCombination from the displayed product in the block cart var domIdProduct = $(this).attr('id'); var firstCut = domIdProduct.replace('cart_block_product_', ''); @@ -303,48 +307,51 @@ var ajaxCart = { var firstCut = removedProductId.replace('cart_block_product_', ''); var ids = firstCut.split('_'); - $('#'+removedProductId).addClass('strike').fadeTo('slow', 0, function(){ + $('#'+parentId+' #'+removedProductId).addClass('strike').fadeTo('slow', 0, function(){ $(this).slideUp('slow', function(){ $(this).remove(); //if the cart is now empty, show the 'no product in the cart' message - if($('#cart_block dl.products dt').length == 0) + if($('#'+parentId+' #cart_block dl.products dt').length == 0) { - $('p#cart_block_no_products:hidden').slideDown('fast'); - $('div#cart_block dl.products').remove(); + $('#'+parentId+' p#cart_block_no_products').slideDown('fast'); + $('#'+parentId+' div#cart_block dl.products').remove(); } }); }); - $('dd#cart_block_combination_of_' + ids[0] + (ids[1] ? '_'+ids[1] : '') ).fadeTo('fast', 0, function(){ + $('#'+parentId+' dd#cart_block_combination_of_' + ids[0] + (ids[1] ? '_'+ids[1] : '') ).fadeTo('fast', 0, function(){ $(this).slideUp('fast', function(){ $(this).remove(); }); }); } - } + }); }, hideOldProductCustomizations : function (product, domIdProduct) { - var customizationList = $('#cart_block #cart_block_list ul#customization_' + product['id'] + '_' + product['idCombination']); - if(customizationList.length > 0) + $(['left_column', 'right_column']).each(function(id, parentId) { - $(customizationList).find("li").each(function(){ - $(this).find("div").each(function() { - var customizationDiv = $(this).attr('id'); - var tmp = customizationDiv.replace('deleteCustomizableProduct_', ''); - var ids = tmp.split('_'); - if ((parseInt(product.idCombination) == parseInt(ids[2])) && !ajaxCart.doesCustomizationStillExist(product, ids[0])) - $('#' + customizationDiv).parent().addClass('strike').fadeTo('slow', 0, function(){ - $(this).slideUp('slow'); - $(this).remove(); - }); + var customizationList = $('#'+parentId+' #cart_block #cart_block_list ul#customization_' + product['id'] + '_' + product['idCombination']); + if(customizationList.length > 0) + { + $(customizationList).find("li").each(function(){ + $(this).find("div").each(function() { + var customizationDiv = $(this).attr('id'); + var tmp = customizationDiv.replace('deleteCustomizableProduct_', ''); + var ids = tmp.split('_'); + if ((parseInt(product.idCombination) == parseInt(ids[2])) && !ajaxCart.doesCustomizationStillExist(product, ids[0])) + $('#' + customizationDiv).parent().addClass('strike').fadeTo('slow', 0, function(){ + $(this).slideUp('slow'); + $(this).remove(); + }); + }); }); - }); - } - var removeLinks = $('#cart_block_product_' + domIdProduct).find('a.ajax_cart_block_remove_link'); - if (!product.hasCustomizedDatas && !removeLinks.length) - $('#' + domIdProduct + ' span.remove_link').html(' '); + } + var removeLinks = $('#'+parentId+' #cart_block_product_' + domIdProduct).find('a.ajax_cart_block_remove_link'); + if (!product.hasCustomizedDatas && !removeLinks.length) + $('#'+parentId+' #' + domIdProduct + ' span.remove_link').html(' '); + }); }, doesCustomizationStillExist : function (product, customizationId) @@ -393,7 +400,9 @@ var ajaxCart = { // Update product quantity updateProductQuantity : function (product, quantity) { - $('dt#cart_block_product_' + product.id + (product.idCombination ? '_' + product.idCombination : '') + ' .quantity').fadeTo('fast', 0, function() { + $(['left_column', 'right_column']).each(function(id, parentId) + { + $('#'+parentId+' dt#cart_block_product_' + product.id + (product.idCombination ? '_' + product.idCombination : '') + ' .quantity').fadeTo('fast', 0, function() { $(this).text(quantity); $(this).fadeTo('fast', 1, function(){ $(this).fadeTo('fast', 0, function(){ @@ -405,27 +414,29 @@ var ajaxCart = { }); }); }); + }); }, //display the products witch are in json data but not already displayed displayNewProducts : function(jsonData) { - + $(['left_column', 'right_column']).each(function(id, parentId) + { //add every new products or update displaying of every updated products $(jsonData.products).each(function(){ //fix ie6 bug (one more item 'undefined' in IE6) if (this.id != undefined) { //create a container for listing the products and hide the 'no product in the cart' message (only if the cart was empty) - if ($('div#cart_block dl.products').length == 0) - $('p#cart_block_no_products:visible').fadeTo('fast', 0, function(){ + if ($('#'+parentId+' div#cart_block dl.products').length == 0) + $('#'+parentId+' p#cart_block_no_products').fadeTo('fast', 0, function(){ $(this).slideUp('fast').fadeTo(0, 1); }).before('
'); //if product is not in the displayed cart, add a new product's line var domIdProduct = this.id + (this.idCombination ? '_' + this.idCombination : ''); var domIdProductAttribute = this.id + '_' + (this.idCombination ? this.idCombination : '0'); - if($('#cart_block dt#cart_block_product_'+ domIdProduct ).length == 0) + if($('#'+parentId+' #cart_block dt#cart_block_product_'+ domIdProduct ).length == 0) { var productId = parseInt(this.id); var productAttributeId = (this.hasAttributes ? parseInt(this.attributes) : 0); @@ -441,51 +452,53 @@ var ajaxCart = { if (this.hasCustomizedDatas) content += ajaxCart.displayNewCustomizedDatas(this); if (this.hasAttributes) content += ''; - - $('#cart_block dl.products').append(content); + $('#'+parentId+' #cart_block dl.products').append(content); } //else update the product's line else{ var jsonProduct = this; - if($('dt#cart_block_product_' + domIdProduct + ' .quantity').text() != jsonProduct.quantity || $('dt#cart_block_product_' + domIdProduct + ' .price').text() != jsonProduct.priceByLine) + if($('#'+parentId+' dt#cart_block_product_' + domIdProduct + ' .quantity').text() != jsonProduct.quantity || $('dt#cart_block_product_' + domIdProduct + ' .price').text() != jsonProduct.priceByLine) { // Usual product - $('dt#cart_block_product_' + domIdProduct + ' .price').text(jsonProduct.priceByLine); + $('#'+parentId+' dt#cart_block_product_' + domIdProduct + ' .price').text(jsonProduct.priceByLine); ajaxCart.updateProductQuantity(jsonProduct, jsonProduct.quantity); // Customized product if (jsonProduct.hasCustomizedDatas) { customizationFormatedDatas = ajaxCart.displayNewCustomizedDatas(jsonProduct); - if (!$('#cart_block ul#customization_' + domIdProductAttribute).length) + if (!$('#'+parentId+' #cart_block ul#customization_' + domIdProductAttribute).length) { if (jsonProduct.hasAttributes) - $('#cart_block dd#cart_block_combination_of_' + domIdProduct).append(customizationFormatedDatas); + $('#'+parentId+' #cart_block dd#cart_block_combination_of_' + domIdProduct).append(customizationFormatedDatas); else - $('#cart_block dl.products').append(customizationFormatedDatas); + $('#'+parentId+' #cart_block dl.products').append(customizationFormatedDatas); } else - $('#cart_block ul#customization_' + domIdProductAttribute).append(customizationFormatedDatas); + $('#'+parentId+' #cart_block ul#customization_' + domIdProductAttribute).append(customizationFormatedDatas); } } } - $('#cart_block dl.products .hidden').slideDown('slow').removeClass('hidden'); + $('#'+parentId+' #cart_block dl.products .hidden').slideDown('slow').removeClass('hidden'); - var removeLinks = $('#cart_block_product_' + domIdProduct).find('a.ajax_cart_block_remove_link'); + var removeLinks = $('#'+parentId+' #cart_block_product_' + domIdProduct).find('a.ajax_cart_block_remove_link'); if (this.hasCustomizedDatas && removeLinks.length) $(removeLinks).each(function() { $(this).remove(); }); } }); + }); }, displayNewCustomizedDatas : function(product) { + $(['left_column', 'right_column']).each(function(id, parentId) + { var content = ''; var productId = parseInt(product.id); var productAttributeId = typeof(product.idCombination) == 'undefined' ? 0 : parseInt(product.idCombination); - var hasAlreadyCustomizations = $('#cart_block ul#customization_' + productId + '_' + productAttributeId).length; + var hasAlreadyCustomizations = $('#'+parentId+' #cart_block ul#customization_' + productId + '_' + productAttributeId).length; if (!hasAlreadyCustomizations) { @@ -498,7 +511,7 @@ var ajaxCart = { customizationId = parseInt(this.customizationId); productAttributeId = typeof(product.idCombination) == 'undefined' ? 0 : parseInt(product.idCombination); // If the customization is already displayed on the cart, no update's needed - if($('#cart_block').find("div[id^=deleteCustomizableProduct_" + customizationId + "_]").length) + if($('#'+parentId+' #cart_block').find("div[id^=deleteCustomizableProduct_" + customizationId + "_]").length) return (''); content += '
  • ' + parseInt(this.quantity) + 'x'; @@ -524,8 +537,8 @@ var ajaxCart = { // Field cleaning if (customizationId) { - $('#uploadable_files li div.customizationUploadBrowse img').remove(); - $('#text_fields li input').attr('value', ''); + $('#'+parentId+' #uploadable_files li div.customizationUploadBrowse img').remove(); + $('#'+parentId+' #text_fields li input').attr('value', ''); } }); @@ -535,6 +548,7 @@ var ajaxCart = { if (!product.hasAttributes) content += ''; } return (content); + }); }, @@ -558,10 +572,13 @@ var ajaxCart = { ajaxCart.refreshVouchers(jsonData); //update 'first' and 'last' item classes - $('#cart_block dl.products dt').removeClass('first_item').removeClass('last_item').removeClass('item'); - $('#cart_block dl.products dt:first').addClass('first_item'); - $('#cart_block dl.products dt:not(:first,:last)').addClass('item'); - $('#cart_block dl.products dt:last').addClass('last_item'); + $(['left_column', 'right_column']).each(function(id, parentId) + { + $('#'+parentId+' #cart_block dl.products dt').removeClass('first_item').removeClass('last_item').removeClass('item'); + $('#'+parentId+' #cart_block dl.products dt:first').addClass('first_item'); + $('#'+parentId+' #cart_block dl.products dt:not(:first,:last)').addClass('item'); + $('#'+parentId+' #cart_block dl.products dt:last').addClass('last_item'); + }); //reset the onlick events in relation to the cart block (it allow to bind the onclick event to the new 'delete' buttons added) ajaxCart.overrideButtonsInThePage(); diff --git a/modules/dejala/ajaxStoreShippingInfo.php b/modules/dejala/ajaxStoreShippingInfo.php new file mode 100644 index 000000000..76e6f8dc4 --- /dev/null +++ b/modules/dejala/ajaxStoreShippingInfo.php @@ -0,0 +1,13 @@ +id_cart); +$djl = new Dejala() ; + +$result = array() ; + +$djl->hookProcessCarrier($params) ; +echo json_encode($result); diff --git a/modules/dejala/calendarutils.php b/modules/dejala/calendarutils.php index 70c8f8d91..cbd8b4f22 100644 --- a/modules/dejala/calendarutils.php +++ b/modules/dejala/calendarutils.php @@ -74,6 +74,7 @@ class CalendarUtils return $dateUtc ; } + public function skipCurDay($dateUtc) { $currentDayZero = mktime(0, 0, 0, date('m', time()), date('d', time()), date('Y', time())); @@ -84,6 +85,7 @@ class CalendarUtils } return $dateUtc ; } + /** * Renvoie la prochaine journée disponible (soit $dateUtc, soit la prochaine à 00h00) * Si aucune ds les 15j, renvoie NULL @@ -97,6 +99,7 @@ class CalendarUtils $loopcount = 0; // on positionne au début de journée $dateUtc = mktime(0, 0, 0, date('m', $dateUtc), date('d', $dateUtc), date('Y', $dateUtc)); + // on boucle pour trouver une journée dispo (si ds les 15j, y a pas : on laisse tomber do { @@ -107,6 +110,7 @@ class CalendarUtils while (!$isDateFree && ($loopcount < 15) ); if ($isDateFree) return ($dateUtc); + return (NULL); } @@ -117,10 +121,13 @@ class CalendarUtils { // jour ferié ? $mCalDate = date("d/m/Y", $dateUtc); + if (in_array($mCalDate, $exceptions)) return (false); + // jour fermé ? $wd = date('w', $dateUtc); + if (!isset($calendar[$wd])) return (false); @@ -128,8 +135,10 @@ class CalendarUtils $stopHour = (int)($calendar[$wd]['stop_hour']); $currentHour = (int)(date('H', $dateUtc)); $currentMin = (int)(date('i', $dateUtc)); + if ($currentMin > 0) $currentHour = $currentHour + 1; + // avant l'heure de fermeture ? if ($currentHour <= $stopHour) return (true); diff --git a/modules/dejala/dejala.php b/modules/dejala/dejala.php index 0f06f0aad..65aa12fbc 100644 --- a/modules/dejala/dejala.php +++ b/modules/dejala/dejala.php @@ -1,43 +1,18 @@ -* @copyright 2007-2011 PrestaShop SA -* @version Release: $Revision$ -* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*/ if (!defined('_PS_VERSION_')) exit; - require_once(_PS_MODULE_DIR_ . "dejala/dejalaconfig.php"); - require_once(_PS_MODULE_DIR_ . "dejala/dejalautils.php"); - require_once(_PS_MODULE_DIR_ . "dejala/dejalacarrierutils.php"); - require_once(_PS_MODULE_DIR_ . "dejala/dejalacart.php"); - require_once(_PS_MODULE_DIR_ . "dejala/calendarutils.php"); +require_once(_PS_MODULE_DIR_ . "dejala/dejalaconfig.php"); +require_once(_PS_MODULE_DIR_ . "dejala/dejalautils.php"); +require_once(_PS_MODULE_DIR_ . "dejala/dejalacarrierutils.php"); +require_once(_PS_MODULE_DIR_ . "dejala/dejalacart.php"); +require_once(_PS_MODULE_DIR_ . "dejala/calendarutils.php"); /** * This module enables the interractions with dejala.com carrier services -**/ + **/ class Dejala extends CarrierModule { const INSTALL_SQL_FILE = 'install.sql'; @@ -46,33 +21,36 @@ class Dejala extends CarrierModule public $id_lang ; private $wday_labels ; private static $INSTANCE = NULL ; + private $useAlphaPDFInvoicePatcher = true ; + private $useBetaOrderDetailPatch = true ; public static function getInstance() { if (!self::$INSTANCE) { - self::$INSTANCE = new Dejala(); + self::$INSTANCE = new Dejala(); } return self::$INSTANCE; } public function __construct() { + global $cookie ; //TODO Iso code of countries where the module can be used, if none module available for all countries $this->limited_countries = array('fr'); $this->name = 'dejala'; $this->tab = 'shipping_logistics'; $this->version = 1.4; - $this->internal_version = '1.3'; - parent::__construct(); - - $this->id_lang = $this->context->language->id; + $this->internal_version = '1.4'; + $this->id_lang = (!isset($cookie) OR !is_object($cookie)) ? (int)(Configuration::get('PS_LANG_DEFAULT')) : (int)($cookie->id_lang); $this->wday_labels = array($this->l('Sunday'), $this->l('Monday'), $this->l('Tuesday'), $this->l('Wednesday'), $this->l('Thursday'), $this->l('Friday'), $this->l('Saturday')); + parent::__construct(); + // The parent construct is required for translations $this->page = basename(__FILE__, '.php'); - $this->displayName = $this->l('Dejala.com : Courier delivery'); + $this->displayName = $this->l('Dejala.com : Courier delivery'); $this->description = $this->l('Lets Dejala.com handle your deliveries by courier'); // load configuration only if installed @@ -90,16 +68,16 @@ class Dejala extends CarrierModule if (!isset($this->dejalaConfig->internal_version) || $this->dejalaConfig->internal_version < $this->internal_version) { $this->unregisterHook('cart') ; - $res = Db::getInstance()->executeS('SELECT * FROM `'._DB_PREFIX_.'dejala_cart` LIMIT 1') ; + $res = Db::getInstance()->ExecuteS('SELECT * FROM `'._DB_PREFIX_.'dejala_cart` LIMIT 1') ; if ($res) { - if (!array_key_exists('cart_date_upd', (int)$res[0])) + if (!array_key_exists('cart_date_upd', $res[0])) { - Db::getInstance()->execute('ALTER TABLE `'._DB_PREFIX_.'dejala_cart` ADD COLUMN cart_date_upd DATETIME DEFAULT 0;'); + Db::getInstance()->Execute('ALTER TABLE `'._DB_PREFIX_.'dejala_cart` ADD COLUMN cart_date_upd DATETIME DEFAULT 0;'); } - if (!array_key_exists('delivery_price', (int)$res[0])) + if (!array_key_exists('delivery_price', $res[0])) { - Db::getInstance()->execute('ALTER TABLE `'._DB_PREFIX_.'dejala_cart` ADD COLUMN delivery_price FLOAT DEFAULT NULL;'); + Db::getInstance()->Execute('ALTER TABLE `'._DB_PREFIX_.'dejala_cart` ADD COLUMN delivery_price FLOAT DEFAULT NULL;'); } } $this->dejalaConfig->internal_version = $this->internal_version ; @@ -108,70 +86,81 @@ class Dejala extends CarrierModule } } - /** - * install dejala module - */ - public function install() - { - if (!file_exists(dirname(__FILE__).'/'.self::INSTALL_SQL_FILE)) + * install dejala module + */ + public function install() + { + if (!file_exists(dirname(__FILE__).'/'.self::INSTALL_SQL_FILE)) return (false); - elseif (!$sql = file_get_contents(dirname(__FILE__).'/'.self::INSTALL_SQL_FILE)) - return (false); - - $sql = str_replace(array('PREFIX_', 'ENGINE_TYPE'), array(_DB_PREFIX_, _MYSQL_ENGINE_), $sql); - $sql = preg_split("/;\s*[\r\n]+/",$sql); - - foreach ($sql as $query) - if (!empty($query)) - { - if (!Db::getInstance()->execute(trim($query))) + elseif (!$sql = file_get_contents(dirname(__FILE__).'/'.self::INSTALL_SQL_FILE)) return (false); - } - if (parent::install() == false + $sql = str_replace(array('PREFIX_', 'ENGINE_TYPE'), array(_DB_PREFIX_, _MYSQL_ENGINE_), $sql); + $sql = preg_split("/;\s*[\r\n]+/",$sql); + + foreach ($sql as $query) + if (!empty($query)) + { + if (!Db::getInstance()->Execute(trim($query))) + return (false); + } + + if (parent::install() == false OR $this->registerHook('updateOrderStatus') == false OR $this->registerHook('extraCarrier') == false - OR $this->registerHook('processCarrier') == false) - return (false); + OR $this->registerHook('processCarrier') == false + OR $this->registerHook('orderDetailDisplayed') == false + OR $this->registerHook('PDFInvoice') == false + ) + return (false); - $this->dejalaConfig = new DejalaConfig(); - if (!$this->dejalaConfig->saveConfig()) - return (false); + $this->dejalaConfig = new DejalaConfig(); - DejalaCarrierUtils::createDejalaCarrier($this->dejalaConfig) ; - return (true); - } + if (!$this->dejalaConfig->saveConfig()) + return (false); - public function uninstall() - { - // If Dejala is default carrier, try to set another one as default - $djlCarrier = DejalaCarrierUtils::getCarrierByName($this->name) ; - if (Configuration::get('PS_CARRIER_DEFAULT') == (int)($djlCarrier->id)) - { - $carriers = Carrier::getCarriers($this->context->language->id, true, false, false, NULL, Carrier::PS_CARRIERS_AND_CARRIER_MODULES_NEED_RANGE); - foreach($carriers as $carrier) - { - if ($carrier['active'] AND !$carrier['deleted'] AND ($carrier['external_module_name'] != $this->name)) - { - Configuration::updateValue('PS_CARRIER_DEFAULT', (int)$carrier['id_carrier']); - break ; - } - } - } - $djlCarrier->deleted = 1; - if (!$djlCarrier->update()) return false; + // Cleanup pre-existing Dejala Carriers (in case the module had previously been tested and not removed cleanly) + while (!is_null($carrier = DejalaCarrierUtils::getCarrierByName($this->name, true))) { + $carrier->deleted = 1 ; + if (!$carrier->update()) return false; + } - $this->dejalaConfig->uninstall(); - if (!parent::uninstall() OR - !$this->unregisterHook('updateOrderStatus') OR - !$this->unregisterHook('extraCarrier') OR - !$this->unregisterHook('processCarrier')) - return false; + DejalaCarrierUtils::createDejalaCarrier($this->dejalaConfig) ; - return true; - } + return (true); + } + + public function uninstall() + { + + // If Dejala is default carrier, try to set another one as default + $defaultCarrier = new Carrier((int)Configuration::get('PS_CARRIER_DEFAULT')) ; + if (DejalaCarrierUtils::getCarrierName($defaultCarrier) == $this->name) { + $defaultCarrier = DejalaCarrierUtils::getFirstActiveCarrierWithNameNotBeing($this->name) ; + if (Validate::isLoadedObject($defaultCarrier)) { + Configuration::updateValue('PS_CARRIER_DEFAULT', $defaultCarrier->id_carrier) ; + } + } + + while (!is_null($carrier = DejalaCarrierUtils::getCarrierByName($this->name, true))) { + $carrier->deleted = 1 ; + if (!$carrier->update()) return false; + } + + $this->dejalaConfig->uninstall(); + if (!parent::uninstall() OR + !$this->unregisterHook('updateOrderStatus') OR + !$this->unregisterHook('extraCarrier') OR + !$this->unregisterHook('processCarrier') OR + !$this->unregisterHook('orderDetailDisplayed') OR + !$this->registerHook('PDFInvoice') + ) + return false; + + return true; + } /** @@ -191,7 +180,7 @@ class Dejala extends CarrierModule if (empty($_POST['country'])) $errors[] = $this->l('country is required.'); } - else if ($method == 'register') + elseif ($method == 'register') { if (empty($_POST['login'])) $errors[] = $this->l('login is required.'); @@ -204,13 +193,13 @@ class Dejala extends CarrierModule if (empty($_POST['country'])) $errors[] = $this->l('country is required.'); } - else if ($method == 'products') + elseif ($method == 'products') { $products = array(); $djlUtil = new DejalaUtils(); $responseArray = $djlUtil->getStoreProducts($this->dejalaConfig, $products); if ('200' != $responseArray['status']) - $products = array(); + $products = array(); foreach ($_POST as $key=>$value) { if (0 === strpos($key, 'margin_')) @@ -218,7 +207,7 @@ class Dejala extends CarrierModule $this->mylog( "key=" . substr($key, 7) ); $productID = (int)(substr($key, 7)); if ( is_null($_POST[$key]) || (0 == strlen($_POST[$key])) ) - $_POST[$key] = 0; + $_POST[$key] = 0; $_POST[$key] = str_replace(',', '.', $_POST[$key]); $_POST[$key] = str_replace(' ', '', $_POST[$key]); @@ -254,6 +243,7 @@ class Dejala extends CarrierModule **/ public function _postProcess() { + global $smarty; $errors = array(); $method = Tools::getValue('method'); @@ -283,7 +273,7 @@ class Dejala extends CarrierModule $this->dejalaConfig->password = null; } } - else if ($method == 'register') + elseif ($method == 'register') { $djlUtil = new DejalaUtils(); $this->dejalaConfig->mode = 'TEST'; @@ -294,6 +284,7 @@ class Dejala extends CarrierModule $this->dejalaConfig->sandboxServiceURL = str_replace('.fr', '.'.$this->dejalaConfig->country, $this->dejalaConfig->sandboxServiceURL); $this->dejalaConfig->storeUrl = Dejala::getHttpHost(true, true) ; $response = $djlUtil->createInstantStore($this->dejalaConfig, Tools::getValue('store_name')); + if ($response['status'] == 201) $this->dejalaConfig->saveConfig(); elseif ($response['status'] == 409) @@ -304,40 +295,40 @@ class Dejala extends CarrierModule $errors[] = $this->l('Unable to process the action.') . '(' . $response['status'] . ')'; $this->dejalaConfig->loadConfig(); } - else if ($method == 'location') + elseif ($method == 'location') { $djlUtil = new DejalaUtils(); $response = $djlUtil->setStoreLocation($this->dejalaConfig, $_POST); if ($response['status'] != 200) - $errors[] = $this->l('An error occurred while updating location'); + $errors[] = $this->l('An error occurred while updating location'); } - else if ($method == 'contact') + elseif ($method == 'contact') { $djlUtil = new DejalaUtils(); $response = $djlUtil->setStoreContacts($this->dejalaConfig, $_POST); if ($response['status'] != 200) - $errors[] = $this->l('An error occurred while updating contacts'); + $errors[] = $this->l('An error occurred while updating contacts'); } - else if ($method == 'processes') + elseif ($method == 'processes') { $djlUtil = new DejalaUtils(); $response = $djlUtil->setStoreProcesses($this->dejalaConfig, $_POST); if ($response['status'] != 200) - $errors[] = $this->l('An error occurred while updating processes'); + $errors[] = $this->l('An error occurred while updating processes'); } - else if ($method == 'products') { + elseif ($method == 'products') { $djlUtil = new DejalaUtils(); $response = $djlUtil->setStoreProducts($this->dejalaConfig, $_POST); if ($response['status'] != 200) - $errors[] = $this->l('An error occurred while updating products'); + $errors[] = $this->l('An error occurred while updating products'); } - else if ($method == 'technical_options') + elseif ($method == 'technical_options') { - $maxSatuses = (int)$_POST['status_max']; - if ($maxSatuses > 30) - $maxSatuses = 30; + $maxStatuses = (int)$_POST['status_max']; + if ($maxStatuses > 30) + $maxStatuses = 30; $selectedTriggers=array(); - for ($i = 0; $i < $maxSatuses; $i++) + for ($i = 0; $i < $maxStatuses; $i++) { $l_val = Tools::getValue('status_'.$i); if ($l_val) @@ -348,12 +339,12 @@ class Dejala extends CarrierModule $this->dejalaConfig->saveConfig(); $this->dejalaConfig->loadConfig(); } - else if ($method == 'delivery_options') + elseif ($method == 'delivery_options') { $djlUtil = new DejalaUtils(); $response = $djlUtil->setStoreCalendar($this->dejalaConfig, $_POST); if ($response['status'] != 200) - $errors[] = $this->l('An error occurred while updating products'); + $errors[] = $this->l('An error occurred while updating products'); $m_attributes['nb_days_displayed'] = htmlentities(Tools::getValue('nb_days'), ENT_COMPAT, 'UTF-8'); $m_attributes['delivery_delay'] = htmlentities(Tools::getValue('delivery_delay'), ENT_COMPAT, 'UTF-8'); @@ -361,15 +352,15 @@ class Dejala extends CarrierModule $response = $djlUtil->setStoreAttributes($this->dejalaConfig, $m_attributes); if ($response['status'] != 200) - $errors[] = $this->l('An error occurred while updating products'); + $errors[] = $this->l('An error occurred while updating products'); } - else if ($method == 'golive') + elseif ($method == 'golive') { $djlUtil = new DejalaUtils(); $response = $djlUtil->goLive($this->dejalaConfig, $_POST); } - else if ($method == 'switchMode') + elseif ($method == 'switchMode') { $l_mode = Tools::getValue('mode'); if ( ('PROD' == $l_mode) || ('TEST' == $l_mode) ) @@ -378,7 +369,7 @@ class Dejala extends CarrierModule $this->dejalaConfig->saveConfig(); } } - else if ($method == 'switchActive') + elseif ($method == 'switchActive') { $l_active = Tools::getValue('visibility_status'); @@ -414,17 +405,18 @@ class Dejala extends CarrierModule public function getContent() { + global $smarty; - //$this->context->smarty->assign('country', $this->dejalaConfig->country); + $smarty->assign('country', $this->dejalaConfig->country); $output = $this->display(__FILE__, 'dejala_header.tpl'); if (!empty($_POST)) { $errors = $this->_postValidation(); if (!count($errors)) - $errors = $this->_postProcess(); + $errors = $this->_postProcess(); if (count($errors)) - foreach ($errors AS $err) - $output .= '
    '. $err .'
    '; + foreach ($errors AS $err) + $output .= '
    '. $err .'
    '; else { $method = Tools::getValue('method'); @@ -441,17 +433,18 @@ class Dejala extends CarrierModule public function displayForm() { + global $smarty, $cookie; $errors = array(); $outputMain = ''; - $this->context->smarty->assign("djl_mode", $this->dejalaConfig->mode); - $this->context->smarty->assign("disabled", ''); + $smarty->assign("djl_mode", $this->dejalaConfig->mode); + $smarty->assign("disabled", ''); if ($this->dejalaConfig->mode == 'PROD') - $this->context->smarty->assign("disabled", 'disabled="disabled"'); + $smarty->assign("disabled", 'disabled="disabled"'); if (true !== extension_loaded('curl')) { $errors[] = $this->l('This module requires php extension cURL to function properly. Please install the php extension "cURL" first.'); - $this->context->smarty->assign("disabled", 'disabled="disabled"'); + $smarty->assign("disabled", 'disabled="disabled"'); } $registered = TRUE; @@ -465,49 +458,49 @@ class Dejala extends CarrierModule if (200 != $responsePing['status']) { if (401 == $responsePing['status']) - $errors[] = $this->l('An error occurred while authenticating your account on Dejala.com. Your credentials were not recognized.'); + $errors[] = $this->l('An error occurred while authenticating your account on Dejala.com. Your credentials were not recognized.'); else - $errors[] = $this->l('An error occurred while authenticating your account on Dejala.com. This may be due to a temporary network or platform problem. Please try again later or contact Dejala.com'); + $errors[] = $this->l('An error occurred while authenticating your account on Dejala.com. This may be due to a temporary network or platform problem. Please try again later or contact Dejala.com'); unset($_GET['cat']); $registered= FALSE; } } - $this->context->smarty->assign("registered", $registered?"1":"0"); + $smarty->assign("registered", $registered?"1":"0"); if (!isset($_GET['cat']) || ($_GET['cat']==='home') || ($_GET['cat']==='')) - $currentTab = "home"; + $currentTab="home"; else - $currentTab = $_GET['cat']; + $currentTab=$_GET['cat']; - $this->context->smarty->assign("currentTab", $currentTab); - $this->context->smarty->assign("moduleConfigURL", 'index.php?tab=AdminModules&configure=dejala&token='.$_GET['token']); - $this->context->smarty->assign("formAction", Tools::safeOutput($_SERVER['REQUEST_URI'])); + $smarty->assign("currentTab", $currentTab); + $smarty->assign("moduleConfigURL", 'index.php?tab=AdminModules&configure=dejala&token='.$_GET['token']); + $smarty->assign("formAction", Tools::safeOutput($_SERVER['REQUEST_URI'])); $outputMenu = $this->display(__FILE__, 'dejala_menu.tpl'); if ($currentTab === 'home') { - $this->context->smarty->assign("login", html_entity_decode(Configuration::get('PS_SHOP_EMAIL'), ENT_COMPAT, 'UTF-8')); + $smarty->assign("login", html_entity_decode(Configuration::get('PS_SHOP_EMAIL'), ENT_COMPAT, 'UTF-8')); if ($registered) { - $this->context->smarty->assign("visibility_status", $this->dejalaConfig->visibility_status); - $this->context->smarty->assign("visible_users_list", $this->dejalaConfig->visible_users_list); - $this->context->smarty->assign("store_login", html_entity_decode($this->dejalaConfig->login, ENT_COMPAT, 'UTF-8')); + $smarty->assign("visibility_status", $this->dejalaConfig->visibility_status); + $smarty->assign("visible_users_list", $this->dejalaConfig->visible_users_list); + $smarty->assign("store_login", html_entity_decode($this->dejalaConfig->login, ENT_COMPAT, 'UTF-8')); $smartifyErrors = $this->smartyfyStoreAttributes(); if (isset($smartifyErrors) && count($smartifyErrors)) - $errors = $smartifyErrors; + $errors = $smartifyErrors; } else { $shopName = Configuration::get('PS_SHOP_NAME'); if (strlen($shopName) >= 15) - $shopName = substr($shopName, 0, 15); - $this->context->smarty->assign("store_name", html_entity_decode($shopName, ENT_COMPAT, 'UTF-8')); + $shopName = substr($shopName, 0, 15); + $smarty->assign("store_name", html_entity_decode($shopName, ENT_COMPAT, 'UTF-8')); } $outputMain = $this->display(__FILE__, 'dejala_home.tpl'); } - else if ($currentTab==='contacts') + elseif ($currentTab==='contacts') { $contacts = array(); $djlUtil = new DejalaUtils(); @@ -516,13 +509,13 @@ class Dejala extends CarrierModule { foreach ($contacts as $contactName=>$contactData) { foreach ($contactData as $key=>$value) { - $this->context->smarty->assign($contactName.'_'.$key, $value); + $smarty->assign($contactName.'_'.$key, $value); } } } $outputMain = $this->display(__FILE__, 'dejala_contacts.tpl'); } - else if ($currentTab === 'location') + elseif ($currentTab === 'location') { $location = array(); $djlUtil = new DejalaUtils(); @@ -530,12 +523,11 @@ class Dejala extends CarrierModule if ('200' == $responseArray['status']) { foreach ($location as $key=>$value) - $this->context->smarty->assign($key, $value); - + $smarty->assign($key, $value); $outputMain = $this->display(__FILE__, 'dejala_location.tpl'); } } - else if ($currentTab==='processes') + elseif ($currentTab==='processes') { $processes = array(); $djlUtil = new DejalaUtils(); @@ -543,12 +535,12 @@ class Dejala extends CarrierModule if ('200' == $responseArray['status']) { foreach ($processes as $key=>$value) - $this->context->smarty->assign($key, $value); + $smarty->assign($key, $value); $outputMain = $this->display(__FILE__, 'dejala_processes.tpl'); } } - else if ($currentTab==='prices') + elseif ($currentTab==='prices') { $products = array(); $djlUtil = new DejalaUtils(); @@ -564,19 +556,20 @@ class Dejala extends CarrierModule $product['public_price'] = number_format(round($product['price'] + $product['margin'], 2), 2, '.', ''); $product['public_price_notax'] = number_format(round($product['public_price']/$vat_factor, 2), 2, '.', ''); } - $this->context->smarty->assign('products', $products); + $smarty->assign('products', $products); $outputMain = $this->display(__FILE__, 'dejala_products.tpl'); } } - else if ($currentTab === 'accounting') + elseif ($currentTab === 'accounting') { $smartifyErrors = $this->smartyfyStoreAttributes(); if (isset($smartifyErrors) && count($smartifyErrors)) - $errors = $smartifyErrors; + $errors = $smartifyErrors; $djlUtil = new DejalaUtils(); $deliveries = array(); $responseArray = $djlUtil->getStoreDeliveries($this->dejalaConfig, $deliveries); + if ('200'==$responseArray['status']) { foreach ($deliveries as &$delivery) @@ -602,18 +595,18 @@ class Dejala extends CarrierModule $delivery['delivery_time'] = date('H\hi', $delivery['delivery_utc']); } } - $this->context->smarty->assign('formAction', __PS_BASE_URI__ . 'modules/' . $this->name . '/deliveries_csv.php'); - $this->context->smarty->assign('defaultDateFrom', date('01/m/Y')); - $this->context->smarty->assign('defaultDateTo', date('d/m/Y')); - $this->context->smarty->assign('deliveries', $deliveries); + $smarty->assign('formAction', __PS_BASE_URI__ . 'modules/' . $this->name . '/deliveries_csv.php'); + $smarty->assign('defaultDateFrom', date('01/m/Y')); + $smarty->assign('defaultDateTo', date('d/m/Y')); + $smarty->assign('deliveries', $deliveries); $outputMain = $this->display(__FILE__, 'dejala_deliveries.tpl'); } } - else if ($currentTab==='delivery_options') + elseif ($currentTab==='delivery_options') { $outputMain = $this->displayDeliveryOptions(); } - else if ($_GET['cat']==='technical_options') + elseif ($_GET['cat']==='technical_options') { $states = $this->getOrderStates(); $triggers = explode(',', $this->dejalaConfig->trigerringStatuses); @@ -623,21 +616,21 @@ class Dejala extends CarrierModule $m_status['id'] = (int)$status['id_order_state']; $m_status['label'] = $status['name']; if (in_array($status['id_order_state'], $triggers)) - $m_status['checked'] = '1'; + $m_status['checked'] = '1'; else - $m_status['checked'] = '0'; + $m_status['checked'] = '0'; $orderStatuses[] = $m_status; } - $this->context->smarty->assign('statuses', $orderStatuses); + $smarty->assign('statuses', $orderStatuses); - $this->context->smarty->assign('trigerringStatuses', $this->dejalaConfig->trigerringStatuses); + $smarty->assign('trigerringStatuses', $this->dejalaConfig->trigerringStatuses); $outputMain = $this->display(__FILE__, 'dejala_technical_options.tpl'); } $outputErr = ''; if (count($errors)) - foreach ($errors AS $err) - $outputErr .= '
    '. $err .'
    '; + foreach ($errors AS $err) + $outputErr .= '
    '. $err .'
    '; $output = $outputErr; $output = $output . $outputMenu; @@ -650,28 +643,31 @@ class Dejala extends CarrierModule // put in smarty context store attributes function smartyfyStoreAttributes() { + global $smarty; + $errors = array(); $djlUtil = new DejalaUtils(); $storeAttrs = array(); $response = $djlUtil->getStoreAttributes($this->dejalaConfig, $storeAttrs); if (200 != $response['status']) - $errors[] = $this->l('An error occurred while getting store, please try again later or contact Dejala.com'); + $errors[] = $this->l('An error occurred while getting store, please try again later or contact Dejala.com'); else { - $this->context->smarty->assign("account_balance", $storeAttrs['account_balance']); - $this->context->smarty->assign("store_name", $storeAttrs['name']); + $smarty->assign("account_balance", $storeAttrs['account_balance']); + $smarty->assign("store_name", $storeAttrs['name']); // Check if account exists in production $responsePing = $djlUtil->ping($this->dejalaConfig, 'PROD'); - if ('200' == $responsePing['status']) - $this->context->smarty->assign('isLiveReady', '1'); - else - { - $this->context->smarty->assign('isLiveReady', '0'); + if ('200' == $responsePing['status']) { + $smarty->assign('isLiveReady', '1'); + $smarty->assign('isLiveRequested', '0'); + } + else { + $smarty->assign('isLiveReady', '0'); if (isset($storeAttrs['attributes']) && isset($storeAttrs['attributes']['request_live']) && ($storeAttrs['attributes']['request_live']=='true')) - $this->context->smarty->assign('isLiveRequested', '1'); + $smarty->assign('isLiveRequested', '1'); else - $this->context->smarty->assign('isLiveRequested', '0'); + $smarty->assign('isLiveRequested', '0'); } } return ($errors); @@ -679,47 +675,51 @@ class Dejala extends CarrierModule function getOrderStates(){ + global $cookie; + $states = OrderState::getOrderStates($this->id_lang); return ($states); } function displayDeliveryOptions(){ - /* - Au moment du choix du créneau - Pour déterminer le créneau de départ proposé : - - Aller sur le prochain créneau libre - - Ajouter le délai de traitement de la commande - - Aller sur le prochain créneau libre + global $smarty; - - Le marchand configure l ouverture de sa boutique en weedkay (hStart-hStop) + exception (date fermeture) tous produits confondus - On fait le min au moment de l afichage des creneaux dispo - => trouver une slideBar avec deux curseurs - */ + /* + Au moment du choix du créneau + Pour déterminer le créneau de départ proposé : + - Aller sur le prochain créneau libre + - Ajouter le délai de traitement de la commande + - Aller sur le prochain créneau libre + + - Le marchand configure l ouverture de sa boutique en weedkay (hStart-hStop) + exception (date fermeture) tous produits confondus + On fait le min au moment de l afichage des creneaux dispo + => trouver une slideBar avec deux curseurs + */ $output = ''; $djlUtil = new DejalaUtils(); $response = $djlUtil->getStoreAttributes($this->dejalaConfig, $store); if ($response['status'] == 200) { - $this->context->smarty->assign('nb_days', $store['attributes']['nb_days_displayed']); - $this->context->smarty->assign('delivery_delay', $store['attributes']['delivery_delay']); + $smarty->assign('nb_days', $store['attributes']['nb_days_displayed']); + $smarty->assign('delivery_delay', $store['attributes']['delivery_delay']); if (isset($store['attributes']['delivery_partial'])) - $this->context->smarty->assign('delivery_partial', $store['attributes']['delivery_partial']); + $smarty->assign('delivery_partial', $store['attributes']['delivery_partial']); } $wday_selected = array(1, 1, 1, 1, 1, 1, 1); - $this->context->smarty->assign('timetable_css', _MODULE_DIR_.$this->name.'/timetable.css'); - $this->context->smarty->assign("timetable_js", _MODULE_DIR_.$this->name.'/timetable.js'); - $this->context->smarty->assign("weekdayLabels", $this->wday_labels); - $this->context->smarty->assign("weekdaySelected", $wday_selected); + // $smarty->assign('timetable_css', _MODULE_DIR_.$this->name.'/timetable.css'); + // $smarty->assign("timetable_js", _MODULE_DIR_.$this->name.'/timetable.js'); + $smarty->assign("weekdayLabels", $this->wday_labels); + $smarty->assign("weekdaySelected", $wday_selected); $calendar = array(); $response = $djlUtil->getStoreCalendar($this->dejalaConfig, $calendar); if ($response['status'] == 200) { - $this->context->smarty->assign("calendar", $calendar); - $this->context->smarty->assign("timetableTpl", dirname(__FILE__)."/dejala_picking_timetable.tpl"); + $smarty->assign("calendar", $calendar); + $smarty->assign("timetableTpl", dirname(__FILE__)."/dejala_picking_timetable.tpl"); } $output = $output . $this->display(__FILE__, 'dejala_delivery_options.tpl'); @@ -728,7 +728,7 @@ class Dejala extends CarrierModule /** * Retourne FALSE si un des produits du cart n'est pas en stock, retourne FALSE sinon - **/ + **/ function isCartOutOfStock($cart) { $products = $cart->getProducts(); @@ -740,19 +740,20 @@ class Dejala extends CarrierModule $orderedQuantity = (_PS_VERSION_ < "1.3.0.1" ? (int)($product['quantity']) : (int)($product['cart_quantity'])); $productQuantity = (int)($product['stock_quantity']); if ( ($productQuantity < $orderedQuantity) || ($productQuantity <= 0) ) - return (TRUE); + return (TRUE); } return (FALSE); } - /** - ** Affiche le transporteur Dejala.com dans la liste des transporteurs sur le Front Office - */ + ** Affiche le transporteur Dejala.com dans la liste des transporteurs sur le Front Office + */ public function hookExtraCarrier($params) { + global $smarty, $defaultCountry; $cart = $params['cart']; + $cookie = $params['cookie']; $this->hooklog("ExtraCarrier", $params); @@ -760,35 +761,32 @@ class Dejala extends CarrierModule if ($this->dejalaConfig->visibility_status == "invisible") return ; - if (($this->dejalaConfig->visibility_status == "visible_limited") && ((int)$this->context->customer->id > 0)) + if (($this->dejalaConfig->visibility_status == "visible_limited") && ((int)($cookie->id_customer) > 0)) { - $customer = $this->context->customer; + $customer = new Customer((int)($cookie->id_customer)); if (!in_array($customer->email, preg_split("/[\s,]+/", $this->dejalaConfig->visible_users_list))) return ; } - $djlUtil = new DejalaUtils(); - $responseGetStore = $djlUtil->getStoreAttributes($this->dejalaConfig, $store); - if ($responseGetStore['status']!='200') - return ; - - $isCartOutOfStock = '0'; - if ($this->isCartOutOfStock($cart)) - $isCartOutOfStock = '1'; + // $djlUtil = new DejalaUtils(); + // $responseGetStore = $djlUtil->getStoreAttributes($this->dejalaConfig, $store); + // if ($responseGetStore['status']!='200') + // return ; + // + $isCartOutOfStock = $this->isCartOutOfStock($cart) ; $this->mylog('isCartOutOfStock=' . $isCartOutOfStock . ''); - $acceptPartial = true; - if (!isset($store['attributes']) || !isset($store['attributes']['delivery_partial']) || ($store['attributes']['delivery_partial'] != '1')) - $acceptPartial = false; - if ( ($isCartOutOfStock == '1') && !$acceptPartial) - return ; - $electedProduct = $this->getDejalaProduct($cart) ; - // Get id zone - if (isset($cart->id_address_delivery) AND $cart->id_address_delivery) - $id_zone = (int)Address::getZoneById((int)($cart->id_address_delivery)); - else - $id_zone = (int)$this->context->country->id_zone; + $this->mylog("product$=" . $this->logValue($electedProduct,1)); + + if (is_null($electedProduct)) return "" ; + + $acceptPartial = false; + if (isset($electedProduct['store_attributes']) && isset($electedProduct['store_attributes']['delivery_partial']) && ($electedProduct['store_attributes']['delivery_partial'] == '1')) + $acceptPartial = true; + + if ($isCartOutOfStock && !$acceptPartial) + return ; $djlCarrier = DejalaCarrierUtils::getCarrierByName($this->name) ; @@ -797,166 +795,73 @@ class Dejala extends CarrierModule if ($djlCarrier == null) return null ; - // Calcul des dates dispo - $productCalendar = $electedProduct['calendar']['entries']; - // MFR090831 - add picking time : the store is open to (stop_hour - picking time), it is more natural to merchants to set opening hours instead of dejala delivery time - if ($electedProduct['pickingtime']) - $pickingtime = (int)($electedProduct['pickingtime']); - else - $pickingtime = $electedProduct['timelimit']; - $djlUtil = new DejalaUtils(); - $storeCalendar = array(); - $calendar = array(); - $response = $djlUtil->getStoreCalendar($this->dejalaConfig, $storeCalendar); - $this->mylog("productCalendar=" . $this->logValue($productCalendar,1)); - $this->mylog("storeCalendar=" . $this->logValue($storeCalendar,1)); - $this->mylog("response['status']=" . $response['status']); - if ($response['status'] == 200) - { - foreach ($storeCalendar['entries'] as $weekday=>$calEntry) - { - if (isset($productCalendar[$weekday])) - { - $calendar[$weekday]["weekday"] = $weekday; - $calendar[$weekday]["start_hour"] = max((int)($productCalendar[$weekday]["start_hour"]), (int)($calEntry["start_hour"])); - // MFR090831 - manage picking time : the store is open to (stop_hour - picking time) - $calendar[$weekday]["stop_hour"] = min((int)($productCalendar[$weekday]["stop_hour"]-1), (int)($calEntry["stop_hour"] - $pickingtime)); - if ($calendar[$weekday]["stop_hour"] < $calendar[$weekday]["start_hour"]) - unset($calendar[$weekday]); + $dates = $electedProduct['computed_calendar']['entries'] ; - } - } + // Adjust labels + foreach ($dates as $idx => $date) { + $dates[$idx]['label'] = $this->wday_labels[date('w', $date['ts'])] . " " . date("j", $date['ts']); } - // Calcul de la date de démarrage pour les créneaux : - // Avancement jusque jour dispo & ouvert - // Ajout du temps de préparation : 0.5 jour ou 1 nb de jours - // Ajustement de l'heure sur l'ouverture ou l'heure suivante xxh00 - $deliveryDelay = $store['attributes']['delivery_delay']; - $skipCurDay = false ; - $calUtils = new CalendarUtils(); - $all_exceptions = array_merge($storeCalendar['exceptions'], $electedProduct['calendar']['exceptions']); - $dateUtc = $calUtils->getNextDateAvailable(time(), $calendar, $all_exceptions); - - if ($dateUtc == NULL) - return ; - if ($deliveryDelay > 0) - { - if ($skipCurDay) - $dateUtc = $calUtils->skipCurDay($dateUtc); - - $dateUtc = $calUtils->addDelay($dateUtc, $deliveryDelay, $calendar, $all_exceptions); - } - - if ($dateUtc == NULL) - return ; - $dateUtc = $calUtils->adjustHour($dateUtc, $calendar); - $this->mylog("calendar=" . $this->logValue($calendar,1)); - $this->mylog("starting date=" . $this->logValue(date("d/m/Y - H:i:s", $dateUtc),1)); - - $today = getDate(); - $ctime = time(); - $nbDeliveryDates = $deliveryDelay = $store['attributes']['nb_days_displayed']; - $iDate = 0; - $dates = array(); - $balladUtc = $dateUtc; - - do - { - $wd = date("w", $balladUtc); - if ((int)($calendar[$wd]['stop_hour']) < (int)($calendar[$wd]['start_hour'])) continue ; - - $dates[$iDate]['value'] = date("Y/m/d", $balladUtc); - $dates[$iDate]['ts'] = $balladUtc ; - $dates[$iDate]['label'] = $this->wday_labels[$wd] . " " . date("j", $balladUtc); - $dates[$iDate]['start_hour'] = (int)($calendar[$wd]['start_hour']); - $dates[$iDate]['stop_hour'] = (int)($calendar[$wd]['stop_hour']); - $balladUtc = strtotime(date("Y-m-d", $balladUtc) . " +1 day"); - $balladUtc = mktime(0, 0, 0, date('m', $balladUtc), date('d', $balladUtc), date('Y', $balladUtc)); - $balladUtc = $calUtils->getNextDateAvailable($balladUtc, $calendar, $all_exceptions); - $iDate++; - } while (($iDate < $nbDeliveryDates) && ($balladUtc)); - // impossibilité de trouver un jour dispo - if (!isset($dates[0])) - return ; - - $now = (int)(date("H", $ctime)) ; - if ((int)($dates[0]['stop_hour']) > $now && (int)($dates[0]['start_hour']) < $now) - $dates[0]['start_hour'] = $now ; - elseif ((int)($dates[0]['ts']) == $now && (int)($dates[0]['stop_hour']) < $now) - array_shift($dates) ; - - $this->mylog("date$=" . $this->logValue($dates,1)); - $this->context->smarty->assign('nb_days', $nbDeliveryDates); - $this->context->smarty->assign('dates', $dates); - for ($i=0; $i < 24; $i++) - { + $smarty->assign('nb_days', sizeof($dates)); + $smarty->assign('dates', $dates); + for ($i=0; $i < 24; $i++) { $endHour = (($i+$electedProduct['timelimit'])%24); if ($endHour == 0) - $endHour = 24; + $endHour = 24; $hourLabels[] = $i . 'h-' . $endHour . 'h'; } - $this->context->smarty->assign('hourLabels', $hourLabels); + $smarty->assign('hourLabels', $hourLabels); - $this->context->smarty->assign('timetable_css', _MODULE_DIR_.$this->name.'/timetable.css'); - $this->context->smarty->assign("timetable_js", _MODULE_DIR_.$this->name.'/timetable.js'); + $smarty->assign('timetable_css', _MODULE_DIR_.$this->name.'/timetable.css'); $this->mylog("electedCarrier->id=" . $this->logValue($djlCarrier->id)); $mCarrier = $djlCarrier; $row['id_carrier'] = (int)($djlCarrier->id); $row['name'] = $this->l('Dejala.com'); - $row['delay'] = $this->l('When you want... Dispatch rider') . ', ' . $electedProduct['timelimit'].'H' ; $row['price'] = $cart->getOrderShippingCost($djlCarrier->id); $row['price_tax_exc'] = $cart->getOrderShippingCost($djlCarrier->id, false); $row['img'] = _MODULE_DIR_.$this->name.'/dejala_carrier.gif'; + if ($isCartOutOfStock) { + $row['info'] = $this->l('I will select my shipping date when my product is available.'); + } + else { + $row['info'] = $this->l('When you want... Dispatch rider') . ', ' . $electedProduct['timelimit'].'H' ; + } + $resultsArray[] = $row; - $this->context->smarty->assign('carriers', $resultsArray); - $this->context->smarty->assign('my_carrier_selected', (isset($cart->id_carrier) && $cart->id_carrier == $djlCarrier->id)) ; - $this->context->smarty->assign('product', $electedProduct); + $smarty->assign('djlCarriers', $resultsArray); + $smarty->assign('djlCarrierChecked', (isset($cart->id_carrier) && $cart->id_carrier == $djlCarrier->id ? $djlCarrier->id : -1)) ; + $smarty->assign('product', $electedProduct); $djlCart = new DejalaCart($cart->id); $setDefaultDate = TRUE; + + $smarty->assign("deliveryDateSelected", $dates[0]['value']); + $smarty->assign("deliveryHourSelected", $dates[0]['start_hour']); + if ($djlCart && isset($djlCart->shipping_date) && !empty($djlCart->shipping_date)) { $mShippingDate = $djlCart->shipping_date; $this->mylog("shipping_date=" . $this->logValue($mShippingDate)); - $m_day = date("d", $mShippingDate); $m_hour = date("H", $mShippingDate); $deliveryDateSelected = date("Y/m/d", $mShippingDate); $this->mylog("shipping_date=" . $this->logValue($deliveryDateSelected)); - foreach ($dates as $l_key=>$l_date) - { - if ($l_date['value'] == $deliveryDateSelected) - { - $this->context->smarty->assign("deliveryDateIndexSelected", $l_key); - $this->context->smarty->assign("deliveryDateSelected", $deliveryDateSelected); - $this->context->smarty->assign("deliveryHourSelected", $m_hour); - $setDefaultDate = FALSE; - } - } - } - if ($setDefaultDate) - { - $this->context->smarty->assign("deliveryDateIndexSelected", 0); - $this->context->smarty->assign("deliveryDateSelected", date("Y/m/d", $dateUtc)); - $this->context->smarty->assign("deliveryHourSelected", (int)(date("H", $dateUtc))); + $smarty->assign("deliveryDateSelected", $deliveryDateSelected); + $smarty->assign("deliveryHourSelected", $m_hour); + $setDefaultDate = FALSE; } - $this->context->smarty->assign("isCartOutOfStock", $isCartOutOfStock); - if (!$isCartOutOfStock) - { - $buffer = $this->display(__FILE__, 'dejala_carrier.tpl'); - $buffer = $buffer . $this->display(__FILE__, 'dejala_timetable.tpl'); - } - else - { - $this->context->smarty->assign('nostock_info', $this->l('I will select my shipping date when my product is available.')); - $buffer = $this->display(__FILE__, 'dejala_carrier_nostock.tpl'); - } +// $smarty->assign('one_page_checkout', (Configuration::get('PS_ORDER_PROCESS_TYPE') ? Configuration::get('PS_ORDER_PROCESS_TYPE') : 0)) ; + + $smarty->assign("isCartOutOfStock", $isCartOutOfStock); + + $buffer = $this->display(__FILE__, 'dejala_carrier.tpl'); + $buffer = $buffer . $this->display(__FILE__, 'dejala_timetable.tpl'); + return $buffer; } @@ -997,9 +902,9 @@ class Dejala extends CarrierModule if ($response['status'] == 200) { if ($l_delivery && $l_delivery['status'] && $l_delivery['status']['labels'] && $l_delivery['status']['labels'][Language::getIsoById((int)$this->id_lang)]) - echo $this->l('Order') . ' ' . $l_delivery['status']['labels'][Language::getIsoById((int)$this->id_lang)].'
    '; + echo $this->l('Order') . ' ' . $l_delivery['status']['labels'][Language::getIsoById((int)$this->id_lang)].'
    '; else - echo $this->l('Order sent to Dejala') . '
    '; + echo $this->l('Order sent to Dejala') . '
    '; } } else @@ -1025,6 +930,7 @@ class Dejala extends CarrierModule { foreach ($arrayOfObjectsToHide as $objectName) { + $searchPattern = '#('.$objectName.' Object\n(\s+)\().*?\n\2\)\n#s'; $replace = "$1--> HIDDEN - courtesy of wtf() <--)"; $text = preg_replace($searchPattern, $replace, $text); @@ -1042,6 +948,7 @@ class Dejala extends CarrierModule public function hookProcessCarrier($params) { // FO: Temporary. Necessary to go around the product's cart re-instanciation bug. + global $cart ; $cartParams = $params['cart']; $this->hooklog("processCarrier", $params) ; @@ -1073,7 +980,7 @@ class Dejala extends CarrierModule $shippingTime = mktime($shippingHour, 0, 0, $ship_month, $ship_day, $ship_year); // check that delivery date is in the future (5 min delay) if ($shippingTime > time() - 5 * 60) - $date_shipping = $shippingTime; + $date_shipping = $shippingTime; } $djlCart = $this->getDejalaCart($cartParams->id) ; @@ -1089,7 +996,7 @@ class Dejala extends CarrierModule } // FO: VERY DIRTY HACK.... Re-assign the global cart to what it was before. - $this->context->cart = $cartParams ; + $cart = $cartParams ; } /** @@ -1099,10 +1006,45 @@ class Dejala extends CarrierModule return ; } + // Still in development + public function hookOrderDetailDisplayed($param) + { + if (!$this->useBetaOrderDetailPatch) return "" ; + + $this->hooklog("OrderDetailDisplayed", $param); + $retStr = "" ; + $djlCart = new DejalaCart($param['order']->id_cart); + if (Validate::isLoadedObject($djlCart) && isset($djlCart->id_dejala_product) && isset($djlCart->shipping_date) && !empty($djlCart->shipping_date)) { + $retStr .= "
    +
  • '.$this->l('Modules').'
    '.$this->l('No modules installed').'
    » '.$module['name'].'
    + + + + + + + + + + +
    Dejala
    " ; + $mShippingDate = $djlCart->shipping_date; + + if (!empty($mShippingDate)) { + $retStr .= $this->l('Shipping date selected') . ' : ' .date('d/m/Y',$mShippingDate). ', ' . $this->l('starting at') . ' : ' .date('H\hi', $mShippingDate) ; + } + else { + $retStr .= $this->l('Shipping date not yet selected by the customer') ; + } + $retStr .= "
    + " ; + } + return $retStr ; + } /** - * Appelé après la modification d'une commande - **/ + * Called when an order's status changes. + **/ public function hookUpdateOrderStatus($params) { $this->hooklog("hookUpdateOrderStatus", $params); @@ -1132,7 +1074,7 @@ class Dejala extends CarrierModule $mCarrier = new Carrier($mOrder->id_carrier); $this->myLog("mCarrier->name=".$mCarrier->name); if ($mCarrier->name != $this->name) - return ; + return ; $this->myLog("placeOrder()"); $cartId = $mOrder->id_cart; @@ -1193,18 +1135,18 @@ class Dejala extends CarrierModule $delivery["receiver_firstname"]=$mDeliveryAddress->firstname; $delivery["receiver_name"]=$mDeliveryAddress->lastname; if ($mDeliveryAddress->company) - $delivery["receiver_company"]=$mDeliveryAddress->company; + $delivery["receiver_company"]=$mDeliveryAddress->company; $delivery["receiver_address"]=$mDeliveryAddress->address1; if ($mDeliveryAddress->address2) - $delivery["receiver_address2"]=$mDeliveryAddress->address2; + $delivery["receiver_address2"]=$mDeliveryAddress->address2; $delivery["receiver_zipcode"]=$mDeliveryAddress->postcode; $delivery["receiver_city"]=$mDeliveryAddress->city; if ($mDeliveryAddress->phone_mobile) - $delivery["receiver_cellphone"]=$mDeliveryAddress->phone_mobile; + $delivery["receiver_cellphone"]=$mDeliveryAddress->phone_mobile; if ($mDeliveryAddress->phone) - $delivery["receiver_phone"]=$mDeliveryAddress->phone; + $delivery["receiver_phone"]=$mDeliveryAddress->phone; if ($mDeliveryAddress->other) - $delivery["receiver_comments"]=$mDeliveryAddress->other; + $delivery["receiver_comments"]=$mDeliveryAddress->other; } $delivery["packet_reference"]=$mOrder->id; @@ -1212,7 +1154,7 @@ class Dejala extends CarrierModule $id_cart = (int)$mOrder->id_cart; /* set weight */ $cart = new Cart($id_cart); - $delivery['weight'] = (float)($cart->getTotalWeight()); + $delivery['weight'] = Configuration::get('PS_WEIGHT_UNIT') == 'g' ? (float)($cart->getTotalWeight() / 1000) : (float)($cart->getTotalWeight()); /* set dejalaProductID and sender_availability = shipping date */ $djlCart = new DejalaCart($id_cart); @@ -1223,7 +1165,6 @@ class Dejala extends CarrierModule $mShippingDate = $djlCart->shipping_date; if ( is_null($mShippingDate) || empty($mShippingDate) ) $mShippingDate = 0; - $delivery["shipping_start_utc"]=$mShippingDate; } } @@ -1238,7 +1179,13 @@ class Dejala extends CarrierModule public function getOrderShippingCost($cart, $shipping_cost) { - return $this->getDejalaProductPrice($cart) ; + $this->hooklog("getOrderShippingCost", null); + $price = $this->getDejalaProductPrice($cart) ; + if ($price < 0) { + $price = $shipping_cost ; + } + $this->mylog('returning : ' . $price); + return $price ; } @@ -1251,8 +1198,10 @@ class Dejala extends CarrierModule $djlCart = $this->getDejalaCart($cart->id) ; if (isset($djlCart->delivery_price) && $cart->date_upd <= $djlCart->cart_date_upd) return $djlCart->delivery_price ; - $product = $this->getDejalaProduct($cart) ; + if (is_null($product)) { + return -1 ; + } return $product["price"] ; } @@ -1265,19 +1214,18 @@ class Dejala extends CarrierModule if ($productId >= 0 && $djlCart->product["id"] == $productId) return $djlCart->product ; - $djlUtil = new DejalaUtils(); $responseGetStore = $djlUtil->getStoreAttributes($this->dejalaConfig, $store); if ($responseGetStore['status']!='200') return ; $isCartOutOfStock = '0'; if ($this->isCartOutOfStock($cart)) - $isCartOutOfStock = '1'; + $isCartOutOfStock = '1'; $this->mylog('isCartOutOfStock=' . $isCartOutOfStock . ''); $acceptPartial = true; if (!isset($store['attributes']) || !isset($store['attributes']['delivery_partial']) || ($store['attributes']['delivery_partial'] != '1')) - $acceptPartial = false; + $acceptPartial = false; if ( ($isCartOutOfStock == '1') && !$acceptPartial) return ; @@ -1295,7 +1243,8 @@ class Dejala extends CarrierModule $quotation["receiver_phone_mobile"] = $address->phone_mobile; $quotation["receiver_comments"] = $address->other; $quotation["timelimit"] = 10; - $quotation["weight"] = (float)($cart->getTotalWeight()); + $quotation["weight"] = Configuration::get('PS_WEIGHT_UNIT') == 'g' ? (float)($cart->getTotalWeight() / 1000) : (float)($cart->getTotalWeight()); + $quotation["price"] = $cart->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING) ; $quotation["module_version"] = $this->internal_version ; $quotation["platform"] = "PS " . _PS_VERSION_ ; @@ -1303,9 +1252,14 @@ class Dejala extends CarrierModule $this->mylog("asking for quotation=" . $this->logValue($quotation,1)); $products = array(); - $responseArray = $djlUtil->getStoreQuotation($this->dejalaConfig, $quotation, $products); - if ($responseArray['status']!='200') - return $shipping_cost; + $storeAttributes = array(); + $responseArray = $djlUtil->getStoreQuotation($this->dejalaConfig, $quotation, $products, $storeAttributes); + if ($responseArray['status']!='200') { + $djlCart->delivery_price = -1 ; + $djlCart->cart_date_upd = $cart->date_upd ; + $djlCart->save() ; + return null; + } $this->mylog("found quotation=" . $this->logValue($responseArray['response'],1)); $electedProduct = NULL; @@ -1313,8 +1267,12 @@ class Dejala extends CarrierModule if ( is_null($electedProduct) || ((int)($electedProduct['priority']) > (int)($key)) ) $electedProduct = $product; - if (is_null($electedProduct)) - return $shipping_cost; + if (is_null($electedProduct)) { + $djlCart->delivery_price = -1 ; + $djlCart->cart_date_upd = $cart->date_upd ; + $djlCart->save() ; + return null; + } $djlCart->id_dejala_product = (int)$electedProduct["id"]; $djlCart->id_delivery = NULL; @@ -1322,18 +1280,37 @@ class Dejala extends CarrierModule $vat_factor = (1+ ($electedProduct['vat'] / 100)); $priceTTC = round(($electedProduct['price']*$vat_factor) + $electedProduct['margin'], 2); - $priceHT = round($priceTTC/$vat_factor, 2); + $priceHT = round($priceTTC/$vat_factor, 5); + $productPrice = $priceHT; $djlCart->delivery_price = $priceHT ; $djlCart->cart_date_upd = $cart->date_upd ; $djlCart->product = $electedProduct ; $djlCart->save() ; - + $electedProduct['store_attributes'] = $storeAttributes ; return $electedProduct ; } + public function hookPDFInvoice($params) { + if (!$this->useAlphaPDFInvoicePatcher) return ; + $order = new Order($params['id_order']) ; + $djlCart = new DejalaCart($order->id_cart); + if (Validate::isLoadedObject($djlCart) && isset($djlCart->id_dejala_product) && isset($djlCart->shipping_date) && !empty($djlCart->shipping_date)) { + $deliveryEndDate = "" ; + + // TODO : Store the delivery timelimit in the dejalacart table at order time and use it here instead of querying something that might have changed. + $djlUtil = new DejalaUtils(); + $responseArray = $djlUtil->getStoreProductByID($this->dejalaConfig, $djlCart->id_dejala_product, $products); + if ('200' == $responseArray['status'] && is_array($products)) { + $deliveryEndDate = date('H\h', $djlCart->shipping_date + (int)$products['timelimit']*3600) ; + } + + $params['pdf']->pages[1] = str_replace($this->name . ")", $this->name . " \(" . date('d/m/Y',$djlCart->shipping_date). ', ' . date('H\h', $djlCart->shipping_date) . "-" . $deliveryEndDate . "\))", $params['pdf']->pages[1]) ; + } + } + public function mylog($msg) { if ($this->DEJALA_DEBUG) { require_once(dirname(__FILE__) . "/MyLogUtils.php"); @@ -1345,14 +1322,14 @@ class Dejala extends CarrierModule // get a string of a value for Log purposes public function logValue($mvalue, $lvl=0) { if (!$this->DEJALA_DEBUG) - return (""); + return (""); require_once(dirname(__FILE__) . "/MyLogUtils.php"); return (MyLogUtils::logValue($mvalue, $lvl)); } public function hooklog($hookname, $params) { - $this->mylog($hookname); + $this->mylog("Hook : " . $hookname); $this->mylog("\r\nparams" . $this->logValue($params), 1); } @@ -1361,10 +1338,32 @@ class Dejala extends CarrierModule { $host = (isset($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : $_SERVER['HTTP_HOST']); if ($entities) - $host = htmlspecialchars($host, ENT_COMPAT, 'UTF-8'); + $host = htmlspecialchars($host, ENT_COMPAT, 'UTF-8'); if ($http) - $host = (Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://').$host; + $host = (Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://').$host; return $host; } + +// public function hookLeftColumn($param) { +// return '
    hookLeftColumn
    ' ; +// } +// public function hookRightColumn($param) { +// return '
    hookRightColumn
    ' ; +// } +// public function hookHome($param) { +// return '
    hookHome
    ' ; +// } +// public function hookHeader($param) { +// return '
    hookHeader
    ' ; +// } +// public function hookTop($param) { +// return '
    hookTop
    ' ; +// } +// public function hookProductActions($param) { +// return '
    hookProductActions
    ' ; +// } +// public function hookProductFooter($param) { +// return '
    hookProductFooter
    ' ; +// } } diff --git a/modules/dejala/dejala_carrier.gif b/modules/dejala/dejala_carrier.gif index bde9893f6..bae58d102 100644 Binary files a/modules/dejala/dejala_carrier.gif and b/modules/dejala/dejala_carrier.gif differ diff --git a/modules/dejala/dejala_carrier.tpl b/modules/dejala/dejala_carrier.tpl index cf9eca624..c0b1cb291 100644 --- a/modules/dejala/dejala_carrier.tpl +++ b/modules/dejala/dejala_carrier.tpl @@ -1,56 +1,130 @@ - - - {literal} - {/literal} - {* - switchDay(deliveryDateSelected); - switchHours(deliveryHourSelected); - toggleShipping(); - *} - - {foreach from=$carriers item=carrier name=myLoop} + {foreach from=$djlCarriers item=carrier name=myLoop} - + - {$carrier.delay|escape:'htmlall':'UTF-8'} + {$carrier.info|escape:'htmlall':'UTF-8'} {if $carrier.price} diff --git a/modules/dejala/dejala_carrier_nostock.tpl b/modules/dejala/dejala_carrier_nostock.tpl index 831bc51d0..bf76b9912 100644 --- a/modules/dejala/dejala_carrier_nostock.tpl +++ b/modules/dejala/dejala_carrier_nostock.tpl @@ -1,9 +1,9 @@ - {foreach from=$carriers item=carrier name=myLoop} + {foreach from=$djlCarriers item=carrier name=myLoop} - +