diff --git a/admin-dev/ajax.php b/admin-dev/ajax.php index ee0a17dcd..31f10349d 100644 --- a/admin-dev/ajax.php +++ b/admin-dev/ajax.php @@ -737,9 +737,9 @@ if (Tools::isSubmit('updateElementEmployee') && Tools::getValue('updateElementEm if (Tools::isSubmit('syncImapMail')) { if (!$url = Configuration::get('PS_SAV_IMAP_URL') - OR !$port = Configuration::get('PS_SAV_IMAP_PORT') - OR !$user = Configuration::get('PS_SAV_IMAP_USER') - OR !$password = Configuration::get('PS_SAV_IMAP_PWD')) + || !$port = Configuration::get('PS_SAV_IMAP_PORT') + || !$user = Configuration::get('PS_SAV_IMAP_USER') + || !$password = Configuration::get('PS_SAV_IMAP_PWD')) die('{"hasError" : true, "errors" : ["Configuration is not correct"]}'); if (!function_exists('imap_open')) @@ -798,7 +798,7 @@ if (Tools::isSubmit('syncImapMail')) preg_match('/\#ct([0-9]*)/', $subject, $matches1); preg_match('/\#tc([0-9-a-z-A-Z]*)/', $subject, $matches2); - if (isset($matches1[1]) AND isset($matches2[1])) + if (isset($matches1[1]) && isset($matches2[1])) { //check if order exist in database $ct = new CustomerThread((int)$matches1[1]); @@ -822,18 +822,18 @@ if (Tools::isSubmit('syncImapMail')) /* Modify attribute position */ if (Tools::isSubmit('ajaxAttributesPositions')) { - $way = (int)(Tools::getValue('way')); - $id_attribute = (int)(Tools::getValue('id_attribute')); - $id_attribute_group = (int)(Tools::getValue('id_attribute_group')); - $positions = Tools::getValue('attribute_'.(int)(Tools::getValue('id_attribute_group'))); + $way = (int)Tools::getValue('way'); + $id_attribute = (int)Tools::getValue('id_attribute'); + $id_attribute_group = (int)Tools::getValue('id_attribute_group'); + $positions = Tools::getValue('attribute_'.(int)Tools::getValue('id_attribute_group')); if (is_array($positions)) - foreach ($positions AS $position => $value) + foreach ($positions as $position => $value) { // pos[1] = id_attribute_group, pos[2] = id_attribute, pos[3]=old position $pos = explode('_', $value); - if ((isset($pos[1]) AND isset($pos[2])) AND ($pos[1] == $id_attribute_group AND (int)$pos[2] === $id_attribute)) + if ((isset($pos[1]) && isset($pos[2])) && ($pos[1] == $id_attribute_group && (int)$pos[2] === $id_attribute)) { if ($attribute = new Attribute((int)$pos[2])) if (isset($position) && $attribute->updatePosition($way, $position)) @@ -851,8 +851,8 @@ if (Tools::isSubmit('ajaxAttributesPositions')) /* Modify group attribute position */ if (Tools::isSubmit('ajaxGroupsAttributesPositions')) { - $way = (int)(Tools::getValue('way')); - $id_attribute_group = (int)(Tools::getValue('id_attribute_group')); + $way = (int)Tools::getValue('way'); + $id_attribute_group = (int)Tools::getValue('id_attribute_group'); $positions = Tools::getValue('attribute_group'); $new_positions = array(); @@ -860,12 +860,12 @@ if (Tools::isSubmit('ajaxGroupsAttributesPositions')) if (count(explode('_', $v)) == 3) $new_positions[] = $v; - foreach ($new_positions AS $position => $value) + foreach ($new_positions as $position => $value) { // pos[1] = id_attribute_group, pos[2] = old position $pos = explode('_', $value); - if (isset($pos[1]) AND (int)$pos[1] === $id_attribute_group) + if (isset($pos[1]) && (int)$pos[1] === $id_attribute_group) { if ($group_attribute = new AttributeGroup((int)$pos[1])) if (isset($position) && $group_attribute->updatePosition($way, $position)) @@ -883,8 +883,8 @@ if (Tools::isSubmit('ajaxGroupsAttributesPositions')) /* Modify feature position */ if (Tools::isSubmit('ajaxFeaturesPositions')) { - $way = (int)(Tools::getValue('way')); - $id_feature = (int)(Tools::getValue('id_feature')); + $way = (int)Tools::getValue('way'); + $id_feature = (int)Tools::getValue('id_feature'); $positions = Tools::getValue('feature'); $new_positions = array(); @@ -892,20 +892,47 @@ if (Tools::isSubmit('ajaxFeaturesPositions')) if (!empty($v)) $new_positions[] = $v; - foreach ($new_positions AS $position => $value) + foreach ($new_positions as $position => $value) { // pos[1] = id_feature, pos[2] = old position $pos = explode('_', $value); - if (isset($pos[1]) AND (int)$pos[1] === $id_feature) + if (isset($pos[1]) && (int)$pos[1] === $id_feature) { if ($feature = new Feature((int)$pos[1])) if (isset($position) && $feature->updatePosition($way, $position)) echo "ok position $position for feature $pos[1]\r\n"; else - echo '{"hasError" : true, "errors" : "Can not update feature '. $id_attribute_group . ' to position '.$position.' "}'; + echo '{"hasError" : true, "errors" : "Can not update feature '. $id_feature . ' to position '.$position.' "}'; else - echo '{"hasError" : true, "errors" : "This feature ('.$id_attribute_group.') can t be loaded"}'; + echo '{"hasError" : true, "errors" : "This feature ('.$id_feature.') can t be loaded"}'; + + break; + } + } +} + +/* Modify carrier position */ +if (Tools::isSubmit('ajaxCarriersPositions')) +{ + $way = (int)(Tools::getValue('way')); + $id_carrier = (int)(Tools::getValue('id_carrier')); + $positions = Tools::getValue('carrier'); + + + foreach ($positions as $position => $value) + { + $pos = explode('_', $value); + + if (isset($pos[2]) && (int)$pos[2] === $id_carrier) + { + if ($carrier = new Carrier((int)$pos[2])) + if (isset($position) && $carrier->updatePosition($way, $position)) + echo "ok position $position for carrier $pos[1]\r\n"; + else + echo '{"hasError" : true, "errors" : "Can not update carrier '. $id_carrier . ' to position '.$position.' "}'; + else + echo '{"hasError" : true, "errors" : "This carrier ('.$id_carrier.') can t be loaded"}'; break; } diff --git a/admin-dev/tabs/AdminCarriers.php b/admin-dev/tabs/AdminCarriers.php index 673c92905..d9816cf2c 100644 --- a/admin-dev/tabs/AdminCarriers.php +++ b/admin-dev/tabs/AdminCarriers.php @@ -45,7 +45,8 @@ class AdminCarriers extends AdminTab 'logo' => array('title' => $this->l('Logo'), 'align' => 'center', 'image' => 's', 'orderby' => false, 'search' => false), 'delay' => array('title' => $this->l('Delay'), 'width' => 300, 'orderby' => false), 'active' => array('title' => $this->l('Status'), 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false), - 'is_free' => array('title' => $this->l('Is Free'), 'align' => 'center', 'icon' => array(0 => 'disabled.gif', 1 => 'enabled.gif', 'default' => 'disabled.gif'), 'type' => 'bool', 'orderby' => false) + 'is_free' => array('title' => $this->l('Is Free'), 'align' => 'center', 'icon' => array(0 => 'disabled.gif', 1 => 'enabled.gif', 'default' => 'disabled.gif'), 'type' => 'bool', 'orderby' => false), + 'position' => array('title' => $this->l('Position'), 'width' => 40,'filter_key' => 'cp!position', 'align' => 'center', 'position' => 'position') ); $this->optionsList = array( @@ -81,7 +82,7 @@ class AdminCarriers extends AdminTab
'; } - + public function displayForm($isMainTab = true) { parent::displayForm(); @@ -163,7 +164,7 @@ class AdminCarriers extends AdminTab getValue('SELECT id_group FROM '._DB_PREFIX_.'carrier_group - WHERE id_carrier='.(int)($obj->id).' AND id_group='.(int)($group['id_group'])) || (!isset($obj->id))) ? 'checked="checked" ' : '').'/> + WHERE id_carrier='.(int)$obj->id.' AND id_group='.(int)$group['id_group']) || (!isset($obj->id))) ? 'checked="checked" ' : '').'/> '.$group['id_group'].' '; @@ -290,7 +291,7 @@ class AdminCarriers extends AdminTab $this->validateRules(); if (!count($this->_errors)) { - $id = (int)(Tools::getValue('id_'.$this->table)); + $id = (int)Tools::getValue('id_'.$this->table); /* Object update */ if (isset($id) && !empty($id)) @@ -303,22 +304,23 @@ class AdminCarriers extends AdminTab Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'carrier_group WHERE id_carrier = '.(int)$id); $object->deleted = 1; $object->update(); - $objectNew = new $this->className(); - $this->copyFromPost($objectNew, $this->table); - $result = $objectNew->add(); - if (Validate::isLoadedObject($objectNew)) + $object_new = new $this->className(); + $this->copyFromPost($object_new, $this->table); + $object_new->position = $object->position; + $result = $object_new->add(); + if (Validate::isLoadedObject($object_new)) { - $this->afterDelete($objectNew, $object->id); - Hook::updateCarrier((int)($object->id), $objectNew); + $this->afterDelete($object_new, $object->id); + Hook::updateCarrier((int)$object->id, $object_new); } - $this->changeGroups($objectNew->id); + $this->changeGroups($object_new->id); if (!$result) $this->_errors[] = Tools::displayError('An error occurred while updating object.').' '.$this->table.''; - else if ($this->postImage($objectNew->id)) - { - $this->changeZones($objectNew->id); - Tools::redirectAdmin(self::$currentIndex.'&id_'.$this->table.'='.$object->id.'&conf=4'.'&token='.$this->token); - } + else if ($this->postImage($object_new->id)) + { + $this->changeZones($object_new->id); + Tools::redirectAdmin(self::$currentIndex.'&id_'.$this->table.'='.$object->id.'&conf=4&token='.$this->token); + } } else $this->_errors[] = Tools::displayError('An error occurred while updating object.').' '.$this->table.' '.Tools::displayError('(cannot load object)'); @@ -334,6 +336,7 @@ class AdminCarriers extends AdminTab { $object = new $this->className(); $this->copyFromPost($object, $this->table); + $object->position = Carrier::getHigherPosition() + 1; if (!$object->add()) $this->_errors[] = Tools::displayError('An error occurred while creating object.').' '.$this->table.''; else if (($_POST['id_'.$this->table] = $object->id /* voluntary */) && $this->postImage($object->id) && $this->_redirect) @@ -348,7 +351,7 @@ class AdminCarriers extends AdminTab } } } - elseif ((isset($_GET['status'.$this->table]) OR isset($_GET['status'])) AND Tools::getValue($this->identifier)) + else if ((isset($_GET['status'.$this->table]) || isset($_GET['status'])) && Tools::getValue($this->identifier)) { if ($this->tabAccess['edit'] === '1') { @@ -395,4 +398,13 @@ class AdminCarriers extends AdminTab $this->_list[$key]['name'] = Configuration::get('PS_SHOP_NAME'); parent::displayListContent($token); } + + /** + * Modifying initial getList method to display position feature (drag and drop) + */ + public function getList($id_lang, $order_by = null, $order_way = null, $start = 0, $limit = null, $id_lang_shop = false) + { + $order_by = ($order_by && $this->context->cookie->__get($this->table.'Orderby')) ? $this->context->cookie->__get($this->table.'Orderby'): 'position'; + parent::getList($id_lang, $order_by, $order_way, $start, $limit, $id_lang_shop); + } } \ No newline at end of file diff --git a/cache/class_index.php b/cache/class_index.php index d41e50e7f..7c4b229ca 100644 --- a/cache/class_index.php +++ b/cache/class_index.php @@ -1,10 +1,10 @@ 'classes/AbstractLogger.php', 'AbstractLogger' => 'override/classes/AbstractLogger.php', - 'AddressCore' => 'classes/Address.php', - 'Address' => 'override/classes/Address.php', 'AddressFormatCore' => 'classes/AddressFormat.php', 'AddressFormat' => 'override/classes/AddressFormat.php', + 'AddressCore' => 'classes/Address.php', + 'Address' => 'override/classes/Address.php', 'AdminControllerCore' => 'classes/AdminController.php', 'AdminController' => 'override/classes/AdminController.php', 'AdminTabCore' => 'classes/AdminTab.php', @@ -13,29 +13,39 @@ 'Alias' => 'override/classes/Alias.php', 'AttachmentCore' => 'classes/Attachment.php', 'Attachment' => 'override/classes/Attachment.php', - 'AttributeCore' => 'classes/Attribute.php', - 'Attribute' => 'override/classes/Attribute.php', 'AttributeGroupCore' => 'classes/AttributeGroup.php', 'AttributeGroup' => 'override/classes/AttributeGroup.php', + 'AttributeCore' => 'classes/Attribute.php', + 'Attribute' => 'override/classes/Attribute.php', 'Autoload' => 'classes/Autoload.php', 'BackupCore' => 'classes/Backup.php', 'Backup' => 'override/classes/Backup.php', 'BlowfishCore' => 'classes/Blowfish.php', 'Blowfish' => 'override/classes/Blowfish.php', - 'CMSCore' => 'classes/CMS.php', - 'CMS' => 'override/classes/CMS.php', - 'CMSCategoryCore' => 'classes/CMSCategory.php', - 'CMSCategory' => 'override/classes/CMSCategory.php', - 'CarrierCore' => 'classes/Carrier.php', - 'Carrier' => 'override/classes/Carrier.php', + 'CacheApcCore' => 'classes/cache/CacheApc.php', + 'CacheApc' => 'override/classes/cache/CacheApc.php', + 'CacheFsCore' => 'classes/cache/CacheFs.php', + 'CacheFs' => 'override/classes/cache/CacheFs.php', + 'CacheMemcacheCore' => 'classes/cache/CacheMemcache.php', + 'CacheMemcache' => 'override/classes/cache/CacheMemcache.php', + 'CacheCore' => 'classes/cache/Cache.php', + 'Cache' => 'override/classes/cache/Cache.php', + 'CacheXcacheCore' => 'classes/cache/CacheXcache.php', + 'CacheXcache' => 'override/classes/cache/CacheXcache.php', 'CarrierModuleCore' => 'classes/CarrierModule.php', 'CarrierModule' => 'override/classes/CarrierModule.php', + 'CarrierCore' => 'classes/Carrier.php', + 'Carrier' => 'override/classes/Carrier.php', 'CartCore' => 'classes/Cart.php', 'Cart' => 'override/classes/Cart.php', 'CategoryCore' => 'classes/Category.php', 'Category' => 'override/classes/Category.php', 'ChartCore' => 'classes/Chart.php', 'Chart' => 'override/classes/Chart.php', + 'CMSCategoryCore' => 'classes/CMSCategory.php', + 'CMSCategory' => 'override/classes/CMSCategory.php', + 'CMSCore' => 'classes/CMS.php', + 'CMS' => 'override/classes/CMS.php', 'CombinationCore' => 'classes/Combination.php', 'Combination' => 'override/classes/Combination.php', 'CompareProductCore' => 'classes/CompareProduct.php', @@ -52,10 +62,10 @@ 'Contact' => 'override/classes/Contact.php', 'ContextCore' => 'classes/Context.php', 'Context' => 'override/classes/Context.php', - 'ControllerCore' => 'classes/Controller.php', - 'Controller' => 'override/classes/Controller.php', 'ControllerFactoryCore' => 'classes/ControllerFactory.php', 'ControllerFactory' => 'override/classes/ControllerFactory.php', + 'ControllerCore' => 'classes/Controller.php', + 'Controller' => 'override/classes/Controller.php', 'CookieCore' => 'classes/Cookie.php', 'Cookie' => 'override/classes/Cookie.php', 'CountryCore' => 'classes/Country.php', @@ -64,16 +74,26 @@ 'County' => 'override/classes/County.php', 'CurrencyCore' => 'classes/Currency.php', 'Currency' => 'override/classes/Currency.php', - 'CustomerCore' => 'classes/Customer.php', - 'Customer' => 'override/classes/Customer.php', 'CustomerMessageCore' => 'classes/CustomerMessage.php', 'CustomerMessage' => 'override/classes/CustomerMessage.php', + 'CustomerCore' => 'classes/Customer.php', + 'Customer' => 'override/classes/Customer.php', 'CustomerThreadCore' => 'classes/CustomerThread.php', 'CustomerThread' => 'override/classes/CustomerThread.php', 'CustomizationCore' => 'classes/Customization.php', 'Customization' => 'override/classes/Customization.php', 'DateRangeCore' => 'classes/DateRange.php', 'DateRange' => 'override/classes/DateRange.php', + 'DbMySQLiCore' => 'classes/db/DbMySQLi.php', + 'DbMySQLi' => 'override/classes/db/DbMySQLi.php', + 'DbPDOCore' => 'classes/db/DbPDO.php', + 'DbPDO' => 'override/classes/db/DbPDO.php', + 'DbCore' => 'classes/db/Db.php', + 'Db' => 'override/classes/db/Db.php', + 'DbQueryCore' => 'classes/db/DbQuery.php', + 'DbQuery' => 'override/classes/db/DbQuery.php', + 'MySQLCore' => 'classes/db/MySQL.php', + 'MySQL' => 'override/classes/db/MySQL.php', 'DeliveryCore' => 'classes/Delivery.php', 'Delivery' => 'override/classes/Delivery.php', 'DiscountCore' => 'classes/Discount.php', @@ -82,6 +102,14 @@ 'Dispatcher' => 'override/classes/Dispatcher.php', 'EmployeeCore' => 'classes/Employee.php', 'Employee' => 'override/classes/Employee.php', + 'PrestashopDatabaseExceptionCore' => 'classes/exception/PrestashopDatabaseException.php', + 'PrestashopDatabaseException' => 'override/classes/exception/PrestashopDatabaseException.php', + 'PrestashopExceptionCore' => 'classes/exception/PrestashopException.php', + 'PrestashopException' => 'override/classes/exception/PrestashopException.php', + 'PrestashopModuleExceptionCore' => 'classes/exception/PrestashopModuleException.php', + 'PrestashopModuleException' => 'override/classes/exception/PrestashopModuleException.php', + 'PrestashopPaymentExceptionCore' => 'classes/exception/PrestashopPaymentException.php', + 'PrestashopPaymentException' => 'override/classes/exception/PrestashopPaymentException.php', 'FeatureCore' => 'classes/Feature.php', 'Feature' => 'override/classes/Feature.php', 'FeatureValueCore' => 'classes/FeatureValue.php', @@ -102,12 +130,12 @@ 'Guest' => 'override/classes/Guest.php', 'HelpAccessCore' => 'classes/HelpAccess.php', 'HelpAccess' => 'override/classes/HelpAccess.php', - 'HelperCore' => 'classes/Helper.php', - 'Helper' => 'override/classes/Helper.php', 'HelperFormCore' => 'classes/HelperForm.php', 'HelperForm' => '', 'HelperListCore' => 'classes/HelperList.php', 'HelperList' => '', + 'HelperCore' => 'classes/Helper.php', + 'Helper' => 'override/classes/Helper.php', 'HookCore' => 'classes/Hook.php', 'Hook' => 'override/classes/Hook.php', 'ImageCore' => 'classes/Image.php', @@ -134,22 +162,20 @@ 'Message' => 'override/classes/Message.php', 'MetaCore' => 'classes/Meta.php', 'Meta' => 'override/classes/Meta.php', - 'ModuleCore' => 'classes/Module.php', - 'Module' => 'override/classes/Module.php', - 'ModuleGraphCore' => 'classes/ModuleGraph.php', - 'ModuleGraph' => 'override/classes/ModuleGraph.php', 'ModuleGraphEngineCore' => 'classes/ModuleGraphEngine.php', 'ModuleGraphEngine' => 'override/classes/ModuleGraphEngine.php', - 'ModuleGridCore' => 'classes/ModuleGrid.php', - 'ModuleGrid' => 'override/classes/ModuleGrid.php', + 'ModuleGraphCore' => 'classes/ModuleGraph.php', + 'ModuleGraph' => 'override/classes/ModuleGraph.php', 'ModuleGridEngineCore' => 'classes/ModuleGridEngine.php', 'ModuleGridEngine' => 'override/classes/ModuleGridEngine.php', + 'ModuleGridCore' => 'classes/ModuleGrid.php', + 'ModuleGrid' => 'override/classes/ModuleGrid.php', + 'ModuleCore' => 'classes/Module.php', + 'Module' => 'override/classes/Module.php', 'NotificationCore' => 'classes/Notification.php', 'Notification' => 'override/classes/Notification.php', 'ObjectModelCore' => 'classes/ObjectModel.php', 'ObjectModel' => 'override/classes/ObjectModel.php', - 'OrderCore' => 'classes/Order.php', - 'Order' => 'override/classes/Order.php', 'OrderDetailCore' => 'classes/OrderDetail.php', 'OrderDetail' => 'override/classes/OrderDetail.php', 'OrderDiscountCore' => 'classes/OrderDiscount.php', @@ -158,6 +184,8 @@ 'OrderHistory' => 'override/classes/OrderHistory.php', 'OrderMessageCore' => 'classes/OrderMessage.php', 'OrderMessage' => 'override/classes/OrderMessage.php', + 'OrderCore' => 'classes/Order.php', + 'Order' => 'override/classes/Order.php', 'OrderReturnCore' => 'classes/OrderReturn.php', 'OrderReturn' => 'override/classes/OrderReturn.php', 'OrderReturnStateCore' => 'classes/OrderReturnState.php', @@ -166,8 +194,6 @@ 'OrderSlip' => 'override/classes/OrderSlip.php', 'OrderStateCore' => 'classes/OrderState.php', 'OrderState' => 'override/classes/OrderState.php', - 'PDFCore' => 'classes/PDF.php', - 'PDF' => 'override/classes/PDF.php', 'PackCore' => 'classes/Pack.php', 'Pack' => 'override/classes/Pack.php', 'PageCore' => 'classes/Page.php', @@ -176,10 +202,12 @@ 'PaymentCC' => 'override/classes/PaymentCC.php', 'PaymentModuleCore' => 'classes/PaymentModule.php', 'PaymentModule' => 'override/classes/PaymentModule.php', - 'ProductCore' => 'classes/Product.php', - 'Product' => 'override/classes/Product.php', + 'PDFCore' => 'classes/PDF.php', + 'PDF' => 'override/classes/PDF.php', 'ProductDownloadCore' => 'classes/ProductDownload.php', 'ProductDownload' => 'override/classes/ProductDownload.php', + 'ProductCore' => 'classes/Product.php', + 'Product' => 'override/classes/Product.php', 'ProductSaleCore' => 'classes/ProductSale.php', 'ProductSale' => 'override/classes/ProductSale.php', 'ProfileCore' => 'classes/Profile.php', @@ -198,20 +226,34 @@ 'Rijndael' => 'override/classes/Rijndael.php', 'SceneCore' => 'classes/Scene.php', 'Scene' => 'override/classes/Scene.php', - 'SearchCore' => 'classes/Search.php', - 'Search' => 'override/classes/Search.php', 'SearchEngineCore' => 'classes/SearchEngine.php', 'SearchEngine' => 'override/classes/SearchEngine.php', + 'SearchCore' => 'classes/Search.php', + 'Search' => 'override/classes/Search.php', + 'GroupShopCore' => 'classes/shop/GroupShop.php', + 'GroupShop' => 'override/classes/shop/GroupShop.php', + 'ShopCore' => 'classes/shop/Shop.php', + 'Shop' => 'override/classes/shop/Shop.php', + 'ShopUrlCore' => 'classes/shop/ShopUrl.php', + 'ShopUrl' => 'override/classes/shop/ShopUrl.php', 'SpecificPriceCore' => 'classes/SpecificPrice.php', 'SpecificPrice' => 'override/classes/SpecificPrice.php', 'StateCore' => 'classes/State.php', 'State' => 'override/classes/State.php', - 'StockCore' => 'classes/Stock.php', - 'Stock' => 'override/classes/Stock.php', + 'StockManagerFactoryCore' => 'classes/stock/StockManagerFactory.php', + 'StockManagerFactory' => '', + 'StockManagerInterface' => 'classes/stock/StockManagerInterface.php', + 'StockManagerModule' => 'classes/stock/StockManagerModule.php', + 'StockManagerCore' => 'classes/stock/StockManager.php', + 'StockManager' => '', + 'WarehouseCore' => 'classes/stock/Warehouse.php', + 'Warehouse' => '', 'StockMvtCore' => 'classes/StockMvt.php', 'StockMvt' => 'override/classes/StockMvt.php', 'StockMvtReasonCore' => 'classes/StockMvtReason.php', 'StockMvtReason' => 'override/classes/StockMvtReason.php', + 'StockCore' => 'classes/Stock.php', + 'Stock' => 'override/classes/Stock.php', 'StoreCore' => 'classes/Store.php', 'Store' => 'override/classes/Store.php', 'SubDomainCore' => 'classes/SubDomain.php', @@ -222,6 +264,21 @@ 'Tab' => 'override/classes/Tab.php', 'TagCore' => 'classes/Tag.php', 'Tag' => 'override/classes/Tag.php', + 'TaxCalculatorCore' => 'classes/tax/TaxCalculator.php', + 'TaxCalculator' => 'override/classes/tax/TaxCalculator.php', + 'TaxManagerFactoryCore' => 'classes/tax/TaxManagerFactory.php', + 'TaxManagerFactory' => 'override/classes/tax/TaxManagerFactory.php', + 'TaxManagerInterface' => 'classes/tax/TaxManagerInterface.php', + 'TaxManagerModuleCore' => 'classes/tax/TaxManagerModule.php', + 'TaxManagerModule' => 'override/classes/tax/TaxManagerModule.php', + 'TaxCore' => 'classes/tax/Tax.php', + 'Tax' => 'override/classes/tax/Tax.php', + 'TaxRuleCore' => 'classes/tax/TaxRule.php', + 'TaxRule' => 'override/classes/tax/TaxRule.php', + 'TaxRulesGroupCore' => 'classes/tax/TaxRulesGroup.php', + 'TaxRulesGroup' => 'override/classes/tax/TaxRulesGroup.php', + 'TaxRulesTaxManagerCore' => 'classes/tax/TaxRulesTaxManager.php', + 'TaxRulesTaxManager' => 'override/classes/tax/TaxRulesTaxManager.php', 'ThemeCore' => 'classes/Theme.php', 'Theme' => 'override/classes/Theme.php', 'ToolsCore' => 'classes/Tools.php', @@ -232,65 +289,6 @@ 'Upgrader' => 'override/classes/Upgrader.php', 'ValidateCore' => 'classes/Validate.php', 'Validate' => 'override/classes/Validate.php', - 'ZoneCore' => 'classes/Zone.php', - 'Zone' => 'override/classes/Zone.php', - 'CacheCore' => 'classes/cache/Cache.php', - 'Cache' => 'override/classes/cache/Cache.php', - 'CacheApcCore' => 'classes/cache/CacheApc.php', - 'CacheApc' => 'override/classes/cache/CacheApc.php', - 'CacheFsCore' => 'classes/cache/CacheFs.php', - 'CacheFs' => 'override/classes/cache/CacheFs.php', - 'CacheMemcacheCore' => 'classes/cache/CacheMemcache.php', - 'CacheMemcache' => 'override/classes/cache/CacheMemcache.php', - 'CacheXcacheCore' => 'classes/cache/CacheXcache.php', - 'CacheXcache' => 'override/classes/cache/CacheXcache.php', - 'DbCore' => 'classes/db/Db.php', - 'Db' => 'override/classes/db/Db.php', - 'DbMySQLiCore' => 'classes/db/DbMySQLi.php', - 'DbMySQLi' => 'override/classes/db/DbMySQLi.php', - 'DbPDOCore' => 'classes/db/DbPDO.php', - 'DbPDO' => 'override/classes/db/DbPDO.php', - 'DbQueryCore' => 'classes/db/DbQuery.php', - 'DbQuery' => 'override/classes/db/DbQuery.php', - 'MySQLCore' => 'classes/db/MySQL.php', - 'MySQL' => 'override/classes/db/MySQL.php', - 'PrestashopDatabaseExceptionCore' => 'classes/exception/PrestashopDatabaseException.php', - 'PrestashopDatabaseException' => 'override/classes/exception/PrestashopDatabaseException.php', - 'PrestashopExceptionCore' => 'classes/exception/PrestashopException.php', - 'PrestashopException' => 'override/classes/exception/PrestashopException.php', - 'PrestashopModuleExceptionCore' => 'classes/exception/PrestashopModuleException.php', - 'PrestashopModuleException' => 'override/classes/exception/PrestashopModuleException.php', - 'PrestashopPaymentExceptionCore' => 'classes/exception/PrestashopPaymentException.php', - 'PrestashopPaymentException' => 'override/classes/exception/PrestashopPaymentException.php', - 'GroupShopCore' => 'classes/shop/GroupShop.php', - 'GroupShop' => 'override/classes/shop/GroupShop.php', - 'ShopCore' => 'classes/shop/Shop.php', - 'Shop' => 'override/classes/shop/Shop.php', - 'ShopUrlCore' => 'classes/shop/ShopUrl.php', - 'ShopUrl' => 'override/classes/shop/ShopUrl.php', - 'StockManagerCore' => 'classes/stock/StockManager.php', - 'StockManager' => '', - 'StockManagerFactoryCore' => 'classes/stock/StockManagerFactory.php', - 'StockManagerFactory' => '', - 'StockManagerInterface' => 'classes/stock/StockManagerInterface.php', - 'StockManagerModule' => 'classes/stock/StockManagerModule.php', - 'WarehouseCore' => 'classes/stock/Warehouse.php', - 'Warehouse' => '', - 'TaxCore' => 'classes/tax/Tax.php', - 'Tax' => 'override/classes/tax/Tax.php', - 'TaxCalculatorCore' => 'classes/tax/TaxCalculator.php', - 'TaxCalculator' => 'override/classes/tax/TaxCalculator.php', - 'TaxManagerFactoryCore' => 'classes/tax/TaxManagerFactory.php', - 'TaxManagerFactory' => 'override/classes/tax/TaxManagerFactory.php', - 'TaxManagerInterface' => 'classes/tax/TaxManagerInterface.php', - 'TaxManagerModuleCore' => 'classes/tax/TaxManagerModule.php', - 'TaxManagerModule' => 'override/classes/tax/TaxManagerModule.php', - 'TaxRuleCore' => 'classes/tax/TaxRule.php', - 'TaxRule' => 'override/classes/tax/TaxRule.php', - 'TaxRulesGroupCore' => 'classes/tax/TaxRulesGroup.php', - 'TaxRulesGroup' => 'override/classes/tax/TaxRulesGroup.php', - 'TaxRulesTaxManagerCore' => 'classes/tax/TaxRulesTaxManager.php', - 'TaxRulesTaxManager' => 'override/classes/tax/TaxRulesTaxManager.php', 'WebserviceExceptionCore' => 'classes/webservice/WebserviceException.php', 'WebserviceException' => 'override/classes/webservice/WebserviceException.php', 'WebserviceKeyCore' => 'classes/webservice/WebserviceKey.php', @@ -307,6 +305,8 @@ 'WebserviceSpecificManagementInterface' => 'classes/webservice/WebserviceSpecificManagementInterface.php', 'WebserviceSpecificManagementSearchCore' => 'classes/webservice/WebserviceSpecificManagementSearch.php', 'WebserviceSpecificManagementSearch' => 'override/classes/webservice/WebserviceSpecificManagementSearch.php', + 'ZoneCore' => 'classes/Zone.php', + 'Zone' => 'override/classes/Zone.php', 'FB' => 'override/classes/fb.php', 'AdminAddressesControllerCore' => 'controllers/admin/AdminAddressesController.php', 'AdminAddressesController' => '', @@ -324,8 +324,6 @@ 'AdminShopUrlController' => '', 'AdminStatesControllerCore' => 'controllers/admin/AdminStatesController.php', 'AdminStatesController' => '', - 'AdminTaxRulesGroupControllerCore' => 'controllers/admin/AdminTaxRulesGroupController.php', - 'AdminTaxRulesGroupController' => '', 'AdminToolsControllerCore' => 'controllers/admin/AdminToolsController.php', 'AdminToolsController' => 'override/controllers/admin/AdminToolsController.php', 'AdminTrackingController' => 'controllers/admin/AdminTrackingController.php', diff --git a/classes/AdminTab.php b/classes/AdminTab.php index ab66595d1..2544cd14d 100644 --- a/classes/AdminTab.php +++ b/classes/AdminTab.php @@ -149,7 +149,7 @@ abstract class AdminTabCore public $smarty; - protected $identifiersDnd = array('id_product' => 'id_product', 'id_category' => 'id_category_to_move','id_cms_category' => 'id_cms_category_to_move', 'id_cms' => 'id_cms', 'id_attribute' => 'id_attribute', 'id_attribute_group' => 'id_attribute_group', 'id_feature' => 'id_feature'); + protected $identifiersDnd = array('id_product' => 'id_product', 'id_category' => 'id_category_to_move','id_cms_category' => 'id_cms_category_to_move', 'id_cms' => 'id_cms', 'id_attribute' => 'id_attribute', 'id_attribute_group' => 'id_attribute_group', 'id_feature' => 'id_feature', 'id_carrier' => 'id_carrier'); /** @var bool Redirect or not ater a creation */ protected $_redirect = true; @@ -592,6 +592,8 @@ abstract class AdminTabCore { $object->deleteImage(); $object->deleted = 1; + if(method_exists($object, 'cleanPositions')) + $object->cleanPositions(); if ($object->update()) Tools::redirectAdmin(self::$currentIndex.'&conf=1&token='.$token); } @@ -673,6 +675,8 @@ abstract class AdminTabCore Tools::redirectAdmin(self::$currentIndex.'&conf=2&token='.$token); $this->_errors[] = Tools::displayError('An error occurred while deleting selection.'); } + // clean carriers positions + Carrier::cleanPositions(); } else $this->_errors[] = Tools::displayError('You must select at least one element to delete.'); diff --git a/classes/Attribute.php b/classes/Attribute.php index 31e1a0914..e6ad4364d 100644 --- a/classes/Attribute.php +++ b/classes/Attribute.php @@ -28,25 +28,25 @@ class AttributeCore extends ObjectModel { /** @var integer Group id which attribute belongs */ - public $id_attribute_group; + public $id_attribute_group; /** @var string Name */ - public $name; - public $color; - public $position; - public $default; + public $name; + public $color; + public $position; + public $default; - protected $fieldsRequired = array('id_attribute_group'); - protected $fieldsValidate = array('id_attribute_group' => 'isUnsignedId', 'color' => 'isColor', 'position' => 'isInt'); - protected $fieldsRequiredLang = array('name'); - protected $fieldsSizeLang = array('name' => 64); - protected $fieldsValidateLang = array('name' => 'isGenericName'); + protected $fieldsRequired = array('id_attribute_group'); + protected $fieldsValidate = array('id_attribute_group' => 'isUnsignedId', 'color' => 'isColor', 'position' => 'isInt'); + protected $fieldsRequiredLang = array('name'); + protected $fieldsSizeLang = array('name' => 64); + protected $fieldsValidateLang = array('name' => 'isGenericName'); - protected $table = 'attribute'; - protected $identifier = 'id_attribute'; + protected $table = 'attribute'; + protected $identifier = 'id_attribute'; protected $image_dir = _PS_COL_IMG_DIR_; - protected $webserviceParameters = array( + protected $webserviceParameters = array( 'objectsNodeName' => 'product_option_values', 'objectNodeName' => 'product_option_value', 'fields' => array( @@ -56,7 +56,7 @@ class AttributeCore extends ObjectModel public function __construct() { - $this->image_dir = _PS_COL_IMG_DIR_; + $this->image_dir = _PS_COL_IMG_DIR_; parent::__construct(); } @@ -85,16 +85,23 @@ class AttributeCore extends ObjectModel public function delete() { - if (($result = Db::getInstance()->executeS('SELECT `id_product_attribute` FROM `'._DB_PREFIX_.'product_attribute_combination` WHERE `'.$this->identifier.'` = '.(int)$this->id)) === false) + if (($result = Db::getInstance()->executeS(' + SELECT `id_product_attribute` + FROM `'._DB_PREFIX_.'product_attribute_combination` + WHERE `'.$this->identifier.'` = '.(int)$this->id)) === false) return false; - $combinationIds = array(); + $combination_ids = array(); if (Db::getInstance()->numRows()) { - foreach ($result AS $row) - $combinationIds[] = (int)$row['id_product_attribute']; - if (Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'product_attribute_combination` WHERE `'.$this->identifier.'` = '.(int)$this->id) === false) + foreach ($result as $row) + $combination_ids[] = (int)$row['id_product_attribute']; + if (Db::getInstance()->execute(' + DELETE FROM `'._DB_PREFIX_.'product_attribute_combination` + WHERE `'.$this->identifier.'` = '.(int)$this->id) === false) return false; - if (Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'product_attribute` WHERE `id_product_attribute` IN ('.implode(', ', $combinationIds).')') === false) + if (Db::getInstance()->execute(' + DELETE FROM `'._DB_PREFIX_.'product_attribute` + WHERE `id_product_attribute` IN ('.implode(', ', $combination_ids).')') === false) return false; } @@ -107,17 +114,17 @@ class AttributeCore extends ObjectModel return $return; } - public function update($nullValues = false) + public function update($null_values = false) { - $return = parent::update($nullValues); + $return = parent::update($null_values); if ($return) Module::hookExec('afterSaveAttribute', array('id_attribute' => $this->id)); return $return; } - public function add($autodate = true, $nullValues = false) + public function add($autodate = true, $null_values = false) { - $return = parent::add($autodate, $nullValues); + $return = parent::add($autodate, $null_values); if ($return) Module::hookExec('afterSaveAttribute', array('id_attribute' => $this->id)); return $return; @@ -130,7 +137,7 @@ class AttributeCore extends ObjectModel * @param boolean $notNull Get only not null fields if true * @return array Attributes */ - public static function getAttributes($id_lang, $notNull = false) + public static function getAttributes($id_lang, $not_null = false) { if (!Combination::isFeatureActive()) return array(); @@ -140,7 +147,7 @@ class AttributeCore extends ObjectModel LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl ON (ag.`id_attribute_group` = agl.`id_attribute_group` AND agl.`id_lang` = '.(int)$id_lang.') LEFT JOIN `'._DB_PREFIX_.'attribute` a ON a.`id_attribute_group` = ag.`id_attribute_group` LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON (a.`id_attribute` = al.`id_attribute` AND al.`id_lang` = '.(int)$id_lang.') - '.($notNull ? 'WHERE a.`id_attribute` IS NOT NULL AND al.`name` IS NOT NULL' : '').' + '.($not_null ? 'WHERE a.`id_attribute` IS NOT NULL AND al.`name` IS NOT NULL' : '').' ORDER BY agl.`name` ASC, a.`position` ASC'); } @@ -152,7 +159,7 @@ class AttributeCore extends ObjectModel * @param integer $qty Quantity needed * @return boolean Quantity is available or not */ - static public function checkAttributeQty($id_product_attribute, $qty, Shop $shop = null) + public static function checkAttributeQty($id_product_attribute, $qty, Shop $shop = null) { if (!$shop) $shop = Context::getContext()->shop; @@ -163,7 +170,7 @@ class AttributeCore extends ObjectModel .$shop->sqlRestriction(Shop::SHARE_STOCK); $result = (int)Db::getInstance()->getValue($sql); - return ($result AND $qty <= $result); + return ($result && $qty <= $result); } /** @@ -182,7 +189,7 @@ class AttributeCore extends ObjectModel FROM `'._DB_PREFIX_.'product_attribute` WHERE `id_product` = '.(int)$id_product); - if ($row['quantity'] !== NULL) + if ($row['quantity'] !== null) return (int)$row['quantity']; return false; } @@ -260,11 +267,11 @@ class AttributeCore extends ObjectModel )) return false; - foreach ($res AS $attribute) + foreach ($res as $attribute) if ((int)$attribute['id_attribute'] == (int)$this->id) - $movedAttribute = $attribute; + $moved_attribute = $attribute; - if (!isset($movedAttribute) || !isset($position)) + if (!isset($moved_attribute) || !isset($position)) return false; // < and > statements rather than BETWEEN operator @@ -274,14 +281,14 @@ class AttributeCore extends ObjectModel SET `position`= `position` '.($way ? '- 1' : '+ 1').' WHERE `position` '.($way - ? '> '.(int)$movedAttribute['position'].' AND `position` <= '.(int)$position - : '< '.(int)$movedAttribute['position'].' AND `position` >= '.(int)$position).' - AND `id_attribute_group`='.(int)$movedAttribute['id_attribute_group']) - AND Db::getInstance()->execute(' + ? '> '.(int)$moved_attribute['position'].' AND `position` <= '.(int)$position + : '< '.(int)$moved_attribute['position'].' AND `position` >= '.(int)$position).' + AND `id_attribute_group`='.(int)$moved_attribute['id_attribute_group']) + && Db::getInstance()->execute(' UPDATE `'._DB_PREFIX_.'attribute` SET `position` = '.(int)$position.' - WHERE `id_attribute` = '.(int)$movedAttribute['id_attribute'].' - AND `id_attribute_group`='.(int)$movedAttribute['id_attribute_group'])); + WHERE `id_attribute` = '.(int)$moved_attribute['id_attribute'].' + AND `id_attribute_group`='.(int)$moved_attribute['id_attribute_group'])); } /** @@ -301,7 +308,7 @@ class AttributeCore extends ObjectModel FROM `'._DB_PREFIX_.'attribute` WHERE `id_attribute_group` = '.(int)$id_attribute_group; // when delete, you must use $use_last_attribute - if($use_last_attribute) + if ($use_last_attribute) $sql .= ' AND `id_attribute` != '.(int)$this->id; $sql .= ' diff --git a/classes/Carrier.php b/classes/Carrier.php index 7b078e198..79148a2e3 100644 --- a/classes/Carrier.php +++ b/classes/Carrier.php @@ -83,12 +83,16 @@ class CarrierCore extends ObjectModel /** @var boolean Need Range */ public $need_range = 0; + /** @var int Position */ + public $position; + protected $langMultiShop = true; protected $fieldsRequired = array('name', 'active'); protected $fieldsSize = array('name' => 64); protected $fieldsValidate = array('id_tax_rules_group' => 'isInt', 'name' => 'isCarrierName', 'active' => 'isBool', - 'is_free' => 'isBool', 'url' => 'isAbsoluteUrl', 'shipping_handling' => 'isBool', 'range_behavior' => 'isBool', 'shipping_method' => 'isUnsignedInt'); + 'is_free' => 'isBool', 'url' => 'isAbsoluteUrl', 'shipping_handling' => 'isBool', 'range_behavior' => 'isBool', + 'shipping_method' => 'isUnsignedInt'); protected $fieldsRequiredLang = array('delay'); protected $fieldsSizeLang = array('delay' => 128); protected $fieldsValidateLang = array('delay' => 'isGenericName'); @@ -96,12 +100,12 @@ class CarrierCore extends ObjectModel protected $table = 'carrier'; protected $identifier = 'id_carrier'; - protected static $priceByWeight = array(); - protected static $priceByWeight2 = array(); - protected static $priceByPrice = array(); - protected static $priceByPrice2 = array(); + protected static $price_by_weight = array(); + protected static $price_by_weight2 = array(); + protected static $price_by_price = array(); + protected static $price_by_price2 = array(); - protected static $_cache_tax_rule = array(); + protected static $cache_tax_rule = array(); protected $webserviceParameters = array( 'fields' => array( @@ -114,19 +118,20 @@ class CarrierCore extends ObjectModel public function getFields() { $this->validateFields(); - $fields['id_tax_rules_group'] = (int)($this->id_tax_rules_group); + $fields['id_tax_rules_group'] = (int)$this->id_tax_rules_group; $fields['name'] = pSQL($this->name); $fields['url'] = pSQL($this->url); - $fields['active'] = (int)($this->active); - $fields['deleted'] = (int)($this->deleted); - $fields['shipping_handling'] = (int)($this->shipping_handling); - $fields['range_behavior'] = (int)($this->range_behavior); - $fields['shipping_method'] = (int)($this->shipping_method); - $fields['is_module'] = (int)($this->is_module); - $fields['is_free'] = (int)($this->is_free); - $fields['shipping_external'] = (int)($this->shipping_external); + $fields['active'] = (int)$this->active; + $fields['deleted'] = (int)$this->deleted; + $fields['shipping_handling'] = (int)$this->shipping_handling; + $fields['range_behavior'] = (int)$this->range_behavior; + $fields['shipping_method'] = (int)$this->shipping_method; + $fields['is_module'] = (int)$this->is_module; + $fields['is_free'] = (int)$this->is_free; + $fields['shipping_external'] = (int)$this->shipping_external; $fields['external_module_name'] = $this->external_module_name; $fields['need_range'] = $this->need_range; + $fields['position'] = (int)$this->position; return $fields; } @@ -149,20 +154,20 @@ class CarrierCore extends ObjectModel return $this->getTranslationsFields(array('delay')); } - public function add($autodate = true, $nullValues = false) + public function add($autodate = true, $null_values = false) { - if (!parent::add($autodate, $nullValues) || !Validate::isLoadedObject($this)) + if (!parent::add($autodate, $null_values) || !Validate::isLoadedObject($this)) return false; if (!Db::getInstance()->executeS('SELECT `id_carrier` FROM `'._DB_PREFIX_.$this->table.'` WHERE `deleted` = 0')) return false; - if (!$numRows = Db::getInstance()->NumRows()) + if (!$num_rows = Db::getInstance()->NumRows()) return false; - if ((int)($numRows) == 1) - Configuration::updateValue('PS_CARRIER_DEFAULT', (int)($this->id)); - + if ((int)$num_rows == 1) + Configuration::updateValue('PS_CARRIER_DEFAULT', (int)$this->id); + // Register reference Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.$this->table.'` SET `id_reference` = '.$this->id.' WHERE `id_carrier` = '.$this->id); - + return true; } @@ -173,7 +178,7 @@ class CarrierCore extends ObjectModel */ public function setConfiguration($id_old) { - Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'delivery` SET `id_carrier` = '.(int)($this->id).' WHERE `id_carrier` = '.(int)($id_old)); + Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'delivery` SET `id_carrier` = '.(int)$this->id.' WHERE `id_carrier` = '.(int)$id_old); } /** @@ -183,47 +188,47 @@ class CarrierCore extends ObjectModel * @param integer $id_zone Zone id (for customer delivery address) * @return float Delivery price */ - public function getDeliveryPriceByWeight($totalWeight, $id_zone, Shop $shop = null) + public function getDeliveryPriceByWeight($total_weight, $id_zone, Shop $shop = null) { - $cache_key = $this->id.'_'.$totalWeight.'_'.$id_zone; - if (!isset(self::$priceByWeight[$cache_key])) + $cache_key = $this->id.'_'.$total_weight.'_'.$id_zone; + if (!isset(self::$price_by_weight[$cache_key])) { $sql = 'SELECT d.`price` FROM `'._DB_PREFIX_.'delivery` d LEFT JOIN `'._DB_PREFIX_.'range_weight` w ON (d.`id_range_weight` = w.`id_range_weight`) - WHERE d.`id_zone` = '.(int)($id_zone).' - AND '.(float)$totalWeight.' >= w.`delimiter1` - AND '.(float)$totalWeight.' < w.`delimiter2` + WHERE d.`id_zone` = '.(int)$id_zone.' + AND '.(float)$total_weight.' >= w.`delimiter1` + AND '.(float)$total_weight.' < w.`delimiter2` AND d.`id_carrier` = '.(int)$this->id.' '.Carrier::sqlDeliveryRangeShop('range_weight', $shop).' ORDER BY w.`delimiter1` ASC'; $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql); if (!isset($result['price'])) - self::$priceByWeight[$cache_key] = $this->getMaxDeliveryPriceByWeight($id_zone); + self::$price_by_weight[$cache_key] = $this->getMaxDeliveryPriceByWeight($id_zone); else - self::$priceByWeight[$cache_key] = $result['price']; + self::$price_by_weight[$cache_key] = $result['price']; } - return self::$priceByWeight[$cache_key]; + return self::$price_by_weight[$cache_key]; } - public static function checkDeliveryPriceByWeight($id_carrier, $totalWeight, $id_zone, Shop $shop = null) + public static function checkDeliveryPriceByWeight($id_carrier, $total_weight, $id_zone, Shop $shop = null) { - $cache_key = $id_carrier.'_'.$totalWeight.'_'.$id_zone; - if (!isset(self::$priceByWeight2[$cache_key])) + $cache_key = $id_carrier.'_'.$total_weight.'_'.$id_zone; + if (!isset(self::$price_by_weight2[$cache_key])) { $sql = 'SELECT d.`price` FROM `'._DB_PREFIX_.'delivery` d LEFT JOIN `'._DB_PREFIX_.'range_weight` w ON d.`id_range_weight` = w.`id_range_weight` WHERE d.`id_zone` = '.(int)$id_zone.' - AND '.(float)$totalWeight.' >= w.`delimiter1` - AND '.(float)$totalWeight.' < w.`delimiter2` + AND '.(float)$total_weight.' >= w.`delimiter1` + AND '.(float)$total_weight.' < w.`delimiter2` AND d.`id_carrier` = '.(int)$id_carrier.' '.Carrier::sqlDeliveryRangeShop('range_weight', $shop).' ORDER BY w.`delimiter1` ASC'; $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql); - self::$priceByWeight2[$cache_key] = (isset($result['price'])); + self::$price_by_weight2[$cache_key] = (isset($result['price'])); } - return self::$priceByWeight2[$cache_key]; + return self::$price_by_weight2[$cache_key]; } public function getMaxDeliveryPriceByWeight($id_zone, Shop $shop = null) @@ -248,30 +253,30 @@ class CarrierCore extends ObjectModel * @param integer $id_zone Zone id (for customer delivery address) * @return float Delivery price */ - public function getDeliveryPriceByPrice($orderTotal, $id_zone, $id_currency = null, Shop $shop = null) + public function getDeliveryPriceByPrice($order_total, $id_zone, $id_currency = null, Shop $shop = null) { - $cache_key = $this->id.'_'.$orderTotal.'_'.$id_zone.'_'.$id_currency; - if (!isset(self::$priceByPrice[$cache_key])) + $cache_key = $this->id.'_'.$order_total.'_'.$id_zone.'_'.$id_currency; + if (!isset(self::$price_by_price[$cache_key])) { if (!empty($id_currency)) - $orderTotal = Tools::convertPrice($orderTotal, $id_currency, false); + $order_total = Tools::convertPrice($order_total, $id_currency, false); $sql = 'SELECT d.`price` FROM `'._DB_PREFIX_.'delivery` d LEFT JOIN `'._DB_PREFIX_.'range_price` r ON d.`id_range_price` = r.`id_range_price` - WHERE d.`id_zone` = '.(int)($id_zone).' - AND '.(float)$orderTotal.' >= r.`delimiter1` - AND '.(float)$orderTotal.' < r.`delimiter2` - AND d.`id_carrier` = '.(int)($this->id).' + WHERE d.`id_zone` = '.(int)$id_zone.' + AND '.(float)$order_total.' >= r.`delimiter1` + AND '.(float)$order_total.' < r.`delimiter2` + AND d.`id_carrier` = '.(int)$this->id.' '.Carrier::sqlDeliveryRangeShop('range_price', $shop).' ORDER BY r.`delimiter1` ASC'; $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql); if (!isset($result['price'])) - self::$priceByPrice[$cache_key] = $this->getMaxDeliveryPriceByPrice($id_zone); + self::$price_by_price[$cache_key] = $this->getMaxDeliveryPriceByPrice($id_zone); else - self::$priceByPrice[$cache_key] = $result['price']; + self::$price_by_price[$cache_key] = $result['price']; } - return self::$priceByPrice[$cache_key]; + return self::$price_by_price[$cache_key]; } /** @@ -283,27 +288,27 @@ class CarrierCore extends ObjectModel * @param integer $id_currency * @return float Delivery price */ - public static function checkDeliveryPriceByPrice($id_carrier, $orderTotal, $id_zone, $id_currency = null, Shop $shop = null) + public static function checkDeliveryPriceByPrice($id_carrier, $order_total, $id_zone, $id_currency = null, Shop $shop = null) { - $cache_key = $id_carrier.'_'.$orderTotal.'_'.$id_zone.'_'.$id_currency; - if (!isset(self::$priceByPrice2[$cache_key])) + $cache_key = $id_carrier.'_'.$order_total.'_'.$id_zone.'_'.$id_currency; + if (!isset(self::$price_by_price2[$cache_key])) { if (!empty($id_currency)) - $orderTotal = Tools::convertPrice($orderTotal, $id_currency, false); + $order_total = Tools::convertPrice($order_total, $id_currency, false); $sql = 'SELECT d.`price` FROM `'._DB_PREFIX_.'delivery` d LEFT JOIN `'._DB_PREFIX_.'range_price` r ON d.`id_range_price` = r.`id_range_price` - WHERE d.`id_zone` = '.(int)($id_zone).' - AND '.(float)$orderTotal.' >= r.`delimiter1` - AND '.(float)$orderTotal.' < r.`delimiter2` + WHERE d.`id_zone` = '.(int)$id_zone.' + AND '.(float)$order_total.' >= r.`delimiter1` + AND '.(float)$order_total.' < r.`delimiter2` AND d.`id_carrier` = '.(int)$id_carrier.' '.Carrier::sqlDeliveryRangeShop('range_price', $shop).' ORDER BY r.`delimiter1` ASC'; $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql); - self::$priceByPrice2[$cache_key] = (isset($result['price'])); + self::$price_by_price2[$cache_key] = (isset($result['price'])); } - return self::$priceByPrice2[$cache_key]; + return self::$price_by_price2[$cache_key]; } public function getMaxDeliveryPriceByPrice($id_zone, Shop $shop = null) @@ -327,16 +332,16 @@ class CarrierCore extends ObjectModel * @param string $rangeTable Table name (price or weight) * @return array Delivery prices */ - public static function getDeliveryPriceByRanges($rangeTable, $id_carrier, Shop $shop = null) + public static function getDeliveryPriceByRanges($range_table, $id_carrier, Shop $shop = null) { - $rangeTable = pSQL($rangeTable); - $sql = 'SELECT d.id_'.$rangeTable.', d.id_carrier, d.id_zone, d.price + $range_table = pSQL($range_table); + $sql = 'SELECT d.id_'.$range_table.', d.id_carrier, d.id_zone, d.price FROM '._DB_PREFIX_.'delivery d - LEFT JOIN '._DB_PREFIX_.$rangeTable.' r ON r.id_'.$rangeTable.' = d.id_'.$rangeTable.' + LEFT JOIN '._DB_PREFIX_.$range_table.' r ON r.id_'.$range_table.' = d.id_'.$range_table.' WHERE d.id_carrier = '.(int)$id_carrier.' - AND d.id_'.$rangeTable.' IS NOT NULL - AND d.id_'.$rangeTable.' != 0 - '.Carrier::sqlDeliveryRangeShop($rangeTable, $shop).' + AND d.id_'.$range_table.' IS NOT NULL + AND d.id_'.$range_table.' != 0 + '.Carrier::sqlDeliveryRangeShop($range_table, $shop).' ORDER BY r.delimiter1'; return Db::getInstance()->executeS($sql); } @@ -362,7 +367,7 @@ class CarrierCore extends ObjectModel { $ids = ''; foreach ($ids_group as $id) - $ids .= (int)($id).', '; + $ids .= (int)$id.', '; $ids = rtrim($ids, ', '); if ($ids == '') return array(); @@ -397,7 +402,8 @@ class CarrierCore extends ObjectModel } $sql .= ($ids_group ? ' AND c.id_carrier IN (SELECT id_carrier FROM '._DB_PREFIX_.'carrier_group WHERE id_group IN ('.$ids.')) ' : '').' - GROUP BY c.`id_carrier`'; + GROUP BY c.`id_carrier` + ORDER BY c.`position` ASC'; $carriers = Db::getInstance()->executeS($sql); @@ -413,9 +419,9 @@ class CarrierCore extends ObjectModel return $carriers; } - public static function getDeliveredCountries($id_lang, $activeCountries = false, $activeCarriers = false, $containStates = null) + public static function getDeliveredCountries($id_lang, $active_countries = false, $active_carriers = false, $contain_states = null) { - if (!Validate::isBool($activeCountries) || !Validate::isBool($activeCarriers)) + if (!Validate::isBool($active_countries) || !Validate::isBool($active_carriers)) die(Tools::displayError()); $states = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' @@ -426,12 +432,12 @@ class CarrierCore extends ObjectModel $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT cl.*,c.*, cl.`name` AS country, zz.`name` AS zone FROM `'._DB_PREFIX_.'country` c LEFT JOIN `'._DB_PREFIX_.'country_lang` cl ON (c.`id_country` = cl.`id_country` AND cl.`id_lang` = 1) - INNER JOIN (`'._DB_PREFIX_.'carrier_zone` cz INNER JOIN `'._DB_PREFIX_.'carrier` cr ON ( cr.id_carrier = cz.id_carrier AND cr.deleted = 0 '.($activeCarriers ? - 'AND cr.active = 1) ' : ') ').' + INNER JOIN (`'._DB_PREFIX_.'carrier_zone` cz INNER JOIN `'._DB_PREFIX_.'carrier` cr ON ( cr.id_carrier = cz.id_carrier AND cr.deleted = 0 '. + ($active_carriers ? 'AND cr.active = 1) ' : ') ').' LEFT JOIN `'._DB_PREFIX_.'zone` zz ON cz.id_zone = zz.id_zone) ON zz.`id_zone` = c.`id_zone` WHERE 1 - '.($activeCountries ? 'AND c.active = 1' : '').' - '.(!is_null($containStates) ? 'AND c.`contains_states` = '.(int)($containStates) : '').' + '.($active_countries ? 'AND c.active = 1' : '').' + '.(!is_null($contain_states) ? 'AND c.`contains_states` = '.(int)$contain_states : '').' ORDER BY cl.name ASC'); $countries = array(); @@ -451,22 +457,22 @@ class CarrierCore extends ObjectModel * @param array $defaultCarrier the last carrier selected * @return number the id of the default carrier */ - public static function getDefaultCarrierSelection($carriers, $defaultCarrier = 0) + public static function getDefaultCarrierSelection($carriers, $default_carrier = 0) { - if(empty($carriers)) + if (empty($carriers)) return 0; - - if ((int)$defaultCarrier != 0) - foreach ($carriers AS $carrier) - if ($carrier['id_carrier'] == (int)$defaultCarrier) + + if ((int)$default_carrier != 0) + foreach ($carriers as $carrier) + if ($carrier['id_carrier'] == (int)$default_carrier) return (int)$carrier['id_carrier']; - foreach ($carriers AS $carrier) + foreach ($carriers as $carrier) if ($carrier['id_carrier'] == (int)Configuration::get('PS_CARRIER_DEFAULT')) return (int)$carrier['id_carrier']; - + return (int)$carriers[0]['id_carrier']; } - + /** * * @param int $id_zone @@ -484,44 +490,45 @@ class CarrierCore extends ObjectModel $result = Carrier::getCarriers($id_lang, true, false, (int)$id_zone, $groups, self::PS_CARRIERS_AND_CARRIER_MODULES_NEED_RANGE); else $result = Carrier::getCarriers($id_lang, true, false, (int)$id_zone, array(1), self::PS_CARRIERS_AND_CARRIER_MODULES_NEED_RANGE); - $resultsArray = array(); + $results_array = array(); foreach ($result as $k => $row) { $carrier = new Carrier((int)$row['id_carrier']); - $shippingMethod = $carrier->getShippingMethod(); - if ($shippingMethod != Carrier::SHIPPING_METHOD_FREE) + $shipping_method = $carrier->getShippingMethod(); + if ($shipping_method != Carrier::SHIPPING_METHOD_FREE) { - // Get only carriers that are compliant with shipping method - if (($shippingMethod == Carrier::SHIPPING_METHOD_WEIGHT && $carrier->getMaxDeliveryPriceByWeight($id_zone) === false) - || ($shippingMethod == Carrier::SHIPPING_METHOD_PRICE && $carrier->getMaxDeliveryPriceByPrice($id_zone) === false)) - { - unset($result[$k]); - continue; - } + // Get only carriers that are compliant with shipping method + if (($shipping_method == Carrier::SHIPPING_METHOD_WEIGHT && $carrier->getMaxDeliveryPriceByWeight($id_zone) === false) + || ($shipping_method == Carrier::SHIPPING_METHOD_PRICE && $carrier->getMaxDeliveryPriceByPrice($id_zone) === false)) + { + unset($result[$k]); + continue; + } - // If out-of-range behavior carrier is set on "Desactivate carrier" - if ($row['range_behavior']) - { - // Get id zone - if (!$id_zone) - $id_zone = Country::getIdZone(Country::getDefaultCountryId()); + // If out-of-range behavior carrier is set on "Desactivate carrier" + if ($row['range_behavior']) + { + // Get id zone + if (!$id_zone) + $id_zone = Country::getIdZone(Country::getDefaultCountryId()); - // Get only carriers that have a range compatible with cart - if (($shippingMethod == Carrier::SHIPPING_METHOD_WEIGHT && (!Carrier::checkDeliveryPriceByWeight($row['id_carrier'], $cart->getTotalWeight(), $id_zone))) - || ($shippingMethod == Carrier::SHIPPING_METHOD_PRICE + // Get only carriers that have a range compatible with cart + if (($shipping_method == Carrier::SHIPPING_METHOD_WEIGHT + && (!Carrier::checkDeliveryPriceByWeight($row['id_carrier'], $cart->getTotalWeight(), $id_zone))) + || ($shipping_method == Carrier::SHIPPING_METHOD_PRICE && (!Carrier::checkDeliveryPriceByPrice($row['id_carrier'], $cart->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING), $id_zone, $id_currency)))) { unset($result[$k]); continue; } - } + } } $row['name'] = (strval($row['name']) != '0' ? $row['name'] : Configuration::get('PS_SHOP_NAME')); - $row['price'] = ($shippingMethod == Carrier::SHIPPING_METHOD_FREE ? 0 : $cart->getOrderShippingCost((int)$row['id_carrier'])); - $row['price_tax_exc'] = ($shippingMethod == Carrier::SHIPPING_METHOD_FREE ? 0 : $cart->getOrderShippingCost((int)$row['id_carrier'], false)); - $row['img'] = file_exists(_PS_SHIP_IMG_DIR_.(int)($row['id_carrier']).'.jpg') ? _THEME_SHIP_DIR_.(int)($row['id_carrier']).'.jpg' : ''; + $row['price'] = ($shipping_method == Carrier::SHIPPING_METHOD_FREE ? 0 : $cart->getOrderShippingCost((int)$row['id_carrier'])); + $row['price_tax_exc'] = ($shipping_method == Carrier::SHIPPING_METHOD_FREE ? 0 : $cart->getOrderShippingCost((int)$row['id_carrier'], false)); + $row['img'] = file_exists(_PS_SHIP_IMG_DIR_.(int)$row['id_carrier']).'.jpg' ? _THEME_SHIP_DIR_.(int)$row['id_carrier'].'.jpg' : ''; // If price is false, then the carrier is unavailable (carrier module) if ($row['price'] === false) @@ -529,10 +536,9 @@ class CarrierCore extends ObjectModel unset($result[$k]); continue; } - - $resultsArray[] = $row; + $results_array[] = $row; } - return $resultsArray; + return $results_array; } public static function checkCarrierZone($id_carrier, $id_zone) @@ -541,11 +547,11 @@ class CarrierCore extends ObjectModel SELECT c.`id_carrier` FROM `'._DB_PREFIX_.'carrier` c LEFT JOIN `'._DB_PREFIX_.'carrier_zone` cz ON (cz.`id_carrier` = c.`id_carrier`) - LEFT JOIN `'._DB_PREFIX_.'zone` z ON (z.`id_zone` = '.(int)($id_zone).') - WHERE c.`id_carrier` = '.(int)($id_carrier).' + LEFT JOIN `'._DB_PREFIX_.'zone` z ON (z.`id_zone` = '.(int)$id_zone.') + WHERE c.`id_carrier` = '.(int)$id_carrier.' AND c.`deleted` = 0 AND c.`active` = 1 - AND cz.`id_zone` = '.(int)($id_zone).' + AND cz.`id_zone` = '.(int)$id_zone.' AND z.`active` = 1' ); } @@ -561,7 +567,7 @@ class CarrierCore extends ObjectModel SELECT * FROM `'._DB_PREFIX_.'carrier_zone` cz LEFT JOIN `'._DB_PREFIX_.'zone` z ON cz.`id_zone` = z.`id_zone` - WHERE cz.`id_carrier` = '.(int)($this->id)); + WHERE cz.`id_carrier` = '.(int)$this->id); } /** @@ -574,8 +580,8 @@ class CarrierCore extends ObjectModel return Db::getInstance()->executeS(' SELECT * FROM `'._DB_PREFIX_.'carrier_zone` - WHERE `id_carrier` = '.(int)($this->id).' - AND `id_zone` = '.(int)($id_zone)); + WHERE `id_carrier` = '.(int)$this->id.' + AND `id_zone` = '.(int)$id_zone); } /** @@ -585,7 +591,7 @@ class CarrierCore extends ObjectModel { return Db::getInstance()->execute(' INSERT INTO `'._DB_PREFIX_.'carrier_zone` (`id_carrier` , `id_zone`) - VALUES ('.(int)($this->id).', '.(int)($id_zone).')'); + VALUES ('.(int)$this->id.', '.(int)$id_zone.')'); } /** @@ -595,8 +601,8 @@ class CarrierCore extends ObjectModel { return Db::getInstance()->execute(' DELETE FROM `'._DB_PREFIX_.'carrier_zone` - WHERE `id_carrier` = '.(int)($this->id).' - AND `id_zone` = '.(int)($id_zone).' LIMIT 1'); + WHERE `id_carrier` = '.(int)$this->id.' + AND `id_zone` = '.(int)$id_zone.' LIMIT 1'); } /** @@ -605,20 +611,20 @@ class CarrierCore extends ObjectModel * @param string $rangeTable Table name to clean (weight or price according to shipping method) * @return boolean Deletion result */ - public function deleteDeliveryPrice($rangeTable, Shop $shop = null) + public function deleteDeliveryPrice($range_table, Shop $shop = null) { - $where = '`id_carrier` = '.(int)$this->id.' AND (`id_'.$rangeTable.'` IS NOT NULL OR `id_'.$rangeTable.'` = 0) '; + $where = '`id_carrier` = '.(int)$this->id.' AND (`id_'.$range_table.'` IS NOT NULL OR `id_'.$range_table.'` = 0) '; if (!$shop) $shop = Context::getContext()->shop; - $shopID = $shop->getID(); - $shopGroupID = $shop->getGroupID(); - if (!$shopID && !$shopGroupID) + $shop_id = $shop->getID(); + $shop_group_id = $shop->getGroupID(); + if (!$shop_id && !$shop_group_id) $where .= 'AND id_shop IS NULL AND id_group_shop IS NULL'; - else if (!$shopID) - $where .= 'AND id_shop IS NULL AND id_group_shop = '.$shopGroupID; + else if (!$shop_id) + $where .= 'AND id_shop IS NULL AND id_group_shop = '.$shop_group_id; else - $where .= 'AND id_shop = '.$shopID; + $where .= 'AND id_shop = '.$shop_id; return Db::getInstance()->delete(_DB_PREFIX_.'delivery', $where); } @@ -629,12 +635,12 @@ class CarrierCore extends ObjectModel * @param array $priceList Prices list in multiple arrays (changed to array since 1.5.0) * @return boolean Insertion result */ - public function addDeliveryPrice($priceList, Shop $shop = null) + public function addDeliveryPrice($price_list, Shop $shop = null) { - if (!$priceList) + if (!$price_list) return false; - $keys = array_keys($priceList[0]); + $keys = array_keys($price_list[0]); if (!in_array('id_shop', $keys)) $keys[] = 'id_shop'; if (!in_array('id_group_shop', $keys)) @@ -642,16 +648,16 @@ class CarrierCore extends ObjectModel if (!$shop) $shop = Context::getContext()->shop; - $shopID = $shop->getID(); - $shopGroupID = $shop->getGroupID(); + $shop_id = $shop->getID(); + $shop_group_id = $shop->getGroupID(); $sql = 'INSERT INTO `'._DB_PREFIX_.'delivery` ('.implode(', ', $keys).') VALUES '; - foreach ($priceList as $values) + foreach ($price_list as $values) { if (!isset($values['id_shop'])) - $values['id_shop'] = ($shopID) ? $shopID : null; + $values['id_shop'] = ($shop_id) ? $shop_id : null; if (!isset($values['id_group_shop'])) - $values['id_group_shop'] = ($shopGroupID) ? $shopGroupID : null; + $values['id_group_shop'] = ($shop_group_id) ? $shop_group_id : null; $sql .= '('; foreach ($values as $v) @@ -675,36 +681,36 @@ class CarrierCore extends ObjectModel * * @param integer $oldId Old id carrier (copy from that id) */ - public function copyCarrierData($oldId) + public function copyCarrierData($old_id) { - if (!Validate::isUnsignedId($oldId)) + if (!Validate::isUnsignedId($old_id)) die(Tools::displayError()); if (!$this->id) return false; - $oldLogo = _PS_SHIP_IMG_DIR_.'/'.(int)$oldId.'.jpg'; - if (file_exists($oldLogo)) - copy($oldLogo, _PS_SHIP_IMG_DIR_.'/'.$this->id.'.jpg'); + $old_logo = _PS_SHIP_IMG_DIR_.'/'.(int)$old_id.'.jpg'; + if (file_exists($old_logo)) + copy($old_logo, _PS_SHIP_IMG_DIR_.'/'.$this->id.'.jpg'); // Copy existing ranges price foreach (array('range_price', 'range_weight') as $range) { $sql = 'SELECT id_'.$range.' id_range, delimiter1, delimiter2 FROM `'._DB_PREFIX_.$range.'` - WHERE id_carrier = '.(int)$oldId; + WHERE id_carrier = '.(int)$old_id; $res = Db::getInstance()->executeS($sql); foreach ($res as $val) { $sql = 'INSERT INTO `'._DB_PREFIX_.$range.'` (`id_carrier`, `delimiter1`, `delimiter2`) VALUES ('.$this->id.','.(float)$val['delimiter1'].','.(float)$val['delimiter2'].')'; Db::getInstance()->execute($sql); - $rangeID = (int)Db::getInstance()->Insert_ID(); + $range_id = (int)Db::getInstance()->Insert_ID(); - $rangePriceID = ($range == 'range_price') ? $rangeID : 'NULL'; - $rangeWeightID = ($range == 'range_weight') ? $rangeID : 'NULL'; + $range_price_id = ($range == 'range_price') ? $range_id : 'NULL'; + $range_weight_id = ($range == 'range_weight') ? $range_id : 'NULL'; $sql = 'INSERT INTO '._DB_PREFIX_.'delivery (id_carrier, id_range_price, id_range_weight, id_zone, price) - SELECT '.$this->id.', '.$rangePriceID.', '.$rangeWeightID.', id_zone, price FROM '._DB_PREFIX_.'delivery - WHERE id_carrier = '.(int)$oldId.' AND '.(($range == 'range_price') ? 'id_range_price' : 'id_range_weight').' = '.$val['id_range']; + SELECT '.$this->id.', '.$range_price_id.', '.$range_weight_id.', id_zone, price FROM '._DB_PREFIX_.'delivery + WHERE id_carrier = '.(int)$old_id.' AND '.(($range == 'range_price') ? 'id_range_price' : 'id_range_weight').' = '.$val['id_range']; Db::getInstance()->execute($sql); } @@ -712,18 +718,18 @@ class CarrierCore extends ObjectModel // Copy existing zones $res = Db::getInstance()->executeS('SELECT * FROM `'._DB_PREFIX_.'carrier_zone` - WHERE id_carrier = '.(int)$oldId); + WHERE id_carrier = '.(int)$old_id); foreach ($res as $val) Db::getInstance()->execute(' INSERT INTO `'._DB_PREFIX_.'carrier_zone` (`id_carrier`, `id_zone`) VALUES ('.$this->id.','.(int)$val['id_zone'].')'); //Copy default carrier - if ((int)(Configuration::get('PS_CARRIER_DEFAULT')) == $oldId) - Configuration::updateValue('PS_CARRIER_DEFAULT', (int)($this->id)); - + if ((int)Configuration::get('PS_CARRIER_DEFAULT') == $old_id) + Configuration::updateValue('PS_CARRIER_DEFAULT', (int)$this->id); + // Copy reference - $id_reference = Db::getInstance()->getValue('SELECT `id_reference` FROM `'._DB_PREFIX_.$this->table.'` WHERE id_carrier = '.$oldId); + $id_reference = Db::getInstance()->getValue('SELECT `id_reference` FROM `'._DB_PREFIX_.$this->table.'` WHERE id_carrier = '.$old_id); Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.$this->table.'` SET `id_reference` = '.$id_reference.' WHERE `id_carrier` = '.$this->id); @@ -741,7 +747,7 @@ class CarrierCore extends ObjectModel return false; return new Carrier($id_carrier); } - + /** * Check if carrier is used (at least one order placed) * @@ -752,9 +758,9 @@ class CarrierCore extends ObjectModel $row = Db::getInstance()->getRow(' SELECT COUNT(`id_carrier`) AS total FROM `'._DB_PREFIX_.'orders` - WHERE `id_carrier` = '.(int)($this->id)); + WHERE `id_carrier` = '.(int)$this->id); - return (int)($row['total']); + return (int)$row['total']; } public function getShippingMethod() @@ -778,20 +784,20 @@ class CarrierCore extends ObjectModel public function getRangeTable() { - $shippingMethod = $this->getShippingMethod(); - if ($shippingMethod == Carrier::SHIPPING_METHOD_WEIGHT) + $shipping_method = $this->getShippingMethod(); + if ($shipping_method == Carrier::SHIPPING_METHOD_WEIGHT) return 'range_weight'; - else if ($shippingMethod == Carrier::SHIPPING_METHOD_PRICE) + else if ($shipping_method == Carrier::SHIPPING_METHOD_PRICE) return 'range_price'; return false; } public function getRangeObject() { - $shippingMethod = $this->getShippingMethod(); - if ($shippingMethod == Carrier::SHIPPING_METHOD_WEIGHT) + $shipping_method = $this->getShippingMethod(); + if ($shipping_method == Carrier::SHIPPING_METHOD_WEIGHT) return new RangeWeight(); - else if ($shippingMethod == Carrier::SHIPPING_METHOD_PRICE) + else if ($shipping_method == Carrier::SHIPPING_METHOD_PRICE) return new RangePrice(); return false; } @@ -808,15 +814,15 @@ class CarrierCore extends ObjectModel public static function getIdTaxRulesGroupByIdCarrier($id_carrier) { - if (!isset(self::$_cache_tax_rule[(int)$id_carrier])) + if (!isset(self::$cache_tax_rule[(int)$id_carrier])) { - self::$_cache_tax_rule[$id_carrier] = Db::getInstance()->getValue(' + self::$cache_tax_rule[$id_carrier] = Db::getInstance()->getValue(' SELECT `id_tax_rules_group` FROM `'._DB_PREFIX_.'carrier` WHERE `id_carrier` = '.(int)$id_carrier); } - return self::$_cache_tax_rule[$id_carrier]; + return self::$cache_tax_rule[$id_carrier]; } @@ -841,31 +847,113 @@ class CarrierCore extends ObjectModel * @param Shop $shop * @return string */ - public static function sqlDeliveryRangeShop($rangeTable, Shop $shop = null, $alias = 'd') + public static function sqlDeliveryRangeShop($range_table, Shop $shop = null, $alias = 'd') { if (!$shop) $shop = Context::getContext()->shop; - $shopID = $shop->getID(); - $shopGroupID = $shop->getGroupID(); + $shop_id = $shop->getID(); + $shop_group_id = $shop->getGroupID(); $where = ''; - if (!$shopID && !$shopGroupID) + if (!$shop_id && !$shop_group_id) $where = 'AND d2.id_shop IS NULL AND d2.id_group_shop IS NULL'; - else if (!$shopID) - $where = 'AND ((d2.id_group_shop IS NULL OR d2.id_group_shop = '.$shopGroupID.') AND d2.id_shop IS NULL)'; + else if (!$shop_id) + $where = 'AND ((d2.id_group_shop IS NULL OR d2.id_group_shop = '.$shop_group_id.') AND d2.id_shop IS NULL)'; else - $where = 'AND (d2.id_shop = '.$shopID.' OR (d2.id_group_shop = '.$shopGroupID.' AND d2.id_shop IS NULL) OR (d2.id_group_shop IS NULL AND d2.id_shop IS NULL))'; + $where = 'AND (d2.id_shop = '.$shop_id.' OR (d2.id_group_shop = '.$shop_group_id.' + AND d2.id_shop IS NULL) OR (d2.id_group_shop IS NULL AND d2.id_shop IS NULL))'; $sql = 'AND '.$alias.'.id_delivery = ( SELECT d2.id_delivery FROM '._DB_PREFIX_.'delivery d2 WHERE d2.id_carrier = '.$alias.'.id_carrier AND d2.id_zone = '.$alias.'.id_zone - AND d2.id_'.$rangeTable.' = '.$alias.'.id_'.$rangeTable.' + AND d2.id_'.$range_table.' = '.$alias.'.id_'.$range_table.' '.$where.' ORDER BY d2.id_shop DESC, d2.id_group_shop DESC LIMIT 1 )'; return $sql; } + + /** + * Move a carrier + * @param boolean $way Up (1) or Down (0) + * @param integer $position + * @return boolean Update result + */ + public function updatePosition($way, $position) + { + if (!$res = Db::getInstance()->executeS(' + SELECT `id_carrier`, `position` + FROM `'._DB_PREFIX_.'carrier` + WHERE `deleted` = 0 + ORDER BY `position` ASC' + )) + return false; + + foreach ($res as $carrier) + if ((int)$carrier['id_carrier'] == (int)$this->id) + $moved_carrier = $carrier; + + if (!isset($moved_carrier) || !isset($position)) + return false; + + // < and > statements rather than BETWEEN operator + // since BETWEEN is treated differently according to databases + return (Db::getInstance()->execute(' + UPDATE `'._DB_PREFIX_.'carrier` + SET `position`= `position` '.($way ? '- 1' : '+ 1').' + WHERE `position` + '.($way + ? '> '.(int)$moved_carrier['position'].' AND `position` <= '.(int)$position + : '< '.(int)$moved_carrier['position'].' AND `position` >= '.(int)$position.' + AND `deleted` = 0')) + && Db::getInstance()->execute(' + UPDATE `'._DB_PREFIX_.'carrier` + SET `position` = '.(int)$position.' + WHERE `id_carrier` = '.(int)$moved_carrier['id_carrier'])); + } + + /** + * Reorder carrier position. + * Call it after deleting a carrier. + * + * @return bool $return + */ + public static function cleanPositions() + { + $return = true; + + $sql = ' + SELECT `id_carrier` + FROM `'._DB_PREFIX_.'carrier` + WHERE `deleted` = 0 + ORDER BY `position` ASC'; + $result = Db::getInstance()->executeS($sql); + + $i = 0; + foreach ($result as $value) + $return = Db::getInstance()->execute(' + UPDATE `'._DB_PREFIX_.'carrier` + SET `position` = '.(int)$i++.' + WHERE `id_carrier` = '.(int)$value['id_carrier']); + return $return; + } + + /** + * getHigherPosition + * + * Get the higher carrier position + * + * @return integer $position + */ + public static function getHigherPosition() + { + $sql = 'SELECT MAX(`position`) + FROM `'._DB_PREFIX_.'carrier` + WHERE `deleted` = 0'; + $position = DB::getInstance()->getValue($sql); + return ($position !== false) ? $position : -1; + } } diff --git a/classes/Product.php b/classes/Product.php index 42710e3f6..db9f59c75 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -315,7 +315,7 @@ class ProductCore extends ObjectModel if (!$context) $context = Context::getContext(); - if ($full AND $this->id) + if ($full && $this->id) { $this->isFullyLoaded = $full; $this->tax_name = 'deprecated'; // The applicable tax may be BOTH the product one AND the state one (moreover this variable is some deadcode) @@ -330,7 +330,7 @@ class ProductCore extends ObjectModel $this->tax_rate = $this->getTaxesRate(new Address($address)); $this->new = $this->isNew(); - $this->price = Product::getPriceStatic((int)($this->id), false, null, 6, null, false, true, 1, false, null, null, null, $this->specificPrice); + $this->price = Product::getPriceStatic((int)$this->id, false, null, 6, null, false, true, 1, false, null, null, null, $this->specificPrice); $this->unit_price = ($this->unit_price_ratio != 0 ? $this->price / $this->unit_price_ratio : 0); if ($this->id) $this->tags = Tag::getProductTags((int)$this->id); @@ -346,45 +346,45 @@ class ProductCore extends ObjectModel { $this->validateFields(); if (isset($this->id)) - $fields['id_product'] = (int)($this->id); - $fields['id_tax_rules_group'] = (int)($this->id_tax_rules_group); - $fields['id_manufacturer'] = (int)($this->id_manufacturer); - $fields['id_supplier'] = (int)($this->id_supplier); - $fields['id_category_default'] = (int)($this->id_category_default); - $fields['quantity'] = (int)($this->quantity); - $fields['minimal_quantity'] = (int)($this->minimal_quantity); - $fields['price'] = (float)($this->price); - $fields['additional_shipping_cost'] = (float)($this->additional_shipping_cost); - $fields['wholesale_price'] = (float)($this->wholesale_price); - $fields['on_sale'] = (int)($this->on_sale); - $fields['online_only'] = (int)($this->online_only); - $fields['ecotax'] = (float)($this->ecotax); + $fields['id_product'] = (int)$this->id; + $fields['id_tax_rules_group'] = (int)$this->id_tax_rules_group; + $fields['id_manufacturer'] = (int)$this->id_manufacturer; + $fields['id_supplier'] = (int)$this->id_supplier; + $fields['id_category_default'] = (int)$this->id_category_default; + $fields['quantity'] = (int)$this->quantity; + $fields['minimal_quantity'] = (int)$this->minimal_quantity; + $fields['price'] = (float)$this->price; + $fields['additional_shipping_cost'] = (float)$this->additional_shipping_cost; + $fields['wholesale_price'] = (float)$this->wholesale_price; + $fields['on_sale'] = (int)$this->on_sale; + $fields['online_only'] = (int)$this->online_only; + $fields['ecotax'] = (float)$this->ecotax; $fields['unity'] = pSQL($this->unity); - $fields['unit_price_ratio'] = (float)($this->unit_price > 0 ? $this->price / $this->unit_price : 0); + $fields['unit_price_ratio'] = (float)$this->unit_price > 0 ? $this->price / $this->unit_price : 0; $fields['ean13'] = pSQL($this->ean13); $fields['upc'] = pSQL($this->upc); $fields['reference'] = pSQL($this->reference); $fields['supplier_reference'] = pSQL($this->supplier_reference); $fields['location'] = pSQL($this->location); - $fields['width'] = (float)($this->width); - $fields['height'] = (float)($this->height); - $fields['depth'] = (float)($this->depth); - $fields['weight'] = (float)($this->weight); + $fields['width'] = (float)$this->width; + $fields['height'] = (float)$this->height; + $fields['depth'] = (float)$this->depth; + $fields['weight'] = (float)$this->weight; $fields['out_of_stock'] = pSQL($this->out_of_stock); - $fields['quantity_discount'] = (int)($this->quantity_discount); - $fields['customizable'] = (int)($this->customizable); - $fields['uploadable_files'] = (int)($this->uploadable_files); - $fields['text_fields'] = (int)($this->text_fields); - $fields['active'] = (int)($this->active); - $fields['available_for_order'] = (int)($this->available_for_order); + $fields['quantity_discount'] = (int)$this->quantity_discount; + $fields['customizable'] = (int)$this->customizable; + $fields['uploadable_files'] = (int)$this->uploadable_files; + $fields['text_fields'] = (int)$this->text_fields; + $fields['active'] = (int)$this->active; + $fields['available_for_order'] = (int)$this->available_for_order; $fields['available_date'] = pSQL($this->available_date); $fields['condition'] = pSQL($this->condition); - $fields['show_price'] = (int)($this->show_price); + $fields['show_price'] = (int)$this->show_price; $fields['indexed'] = 0; // Reset indexation every times - $fields['cache_is_pack'] = (int)($this->cache_is_pack); - $fields['cache_has_attachments'] = (int)($this->cache_has_attachments); - $fields['is_virtual'] = (int)($this->is_virtual); - $fields['cache_default_attribute'] = (int)($this->cache_default_attribute); + $fields['cache_is_pack'] = (int)$this->cache_is_pack; + $fields['cache_has_attachments'] = (int)$this->cache_has_attachments; + $fields['is_virtual'] = (int)$this->is_virtual; + $fields['cache_default_attribute'] = (int)$this->cache_default_attribute; $fields['date_add'] = pSQL($this->date_add); $fields['date_upd'] = pSQL($this->date_upd); @@ -432,10 +432,10 @@ class ProductCore extends ObjectModel { if ($id_customer) { - $customer = new Customer((int)($id_customer)); + $customer = new Customer((int)$id_customer); if (!Validate::isLoadedObject($customer)) die(Tools::displayError()); - self::$_taxCalculationMethod = Group::getPriceDisplayMethod((int)($customer->id_default_group)); + self::$_taxCalculationMethod = Group::getPriceDisplayMethod((int)$customer->id_default_group); } else if (Validate::isLoadedObject(Context::getContext()->customer)) self::$_taxCalculationMethod = Group::getPriceDisplayMethod(Context::getContext()->customer->id_default_group); @@ -446,8 +446,8 @@ class ProductCore extends ObjectModel public static function getTaxCalculationMethod($id_customer = null) { if ($id_customer) - self::initPricesComputation((int)($id_customer)); - return (int)(self::$_taxCalculationMethod); + self::initPricesComputation((int)$id_customer); + return (int)self::$_taxCalculationMethod; } /** @@ -461,13 +461,13 @@ class ProductCore extends ObjectModel if (!$res = Db::getInstance()->executeS(' SELECT cp.`id_product`, cp.`position`, cp.`id_category` FROM `'._DB_PREFIX_.'category_product` cp - WHERE cp.`id_category` = '.(int)(Tools::getValue('id_category', 1)).' + WHERE cp.`id_category` = '.(int)Tools::getValue('id_category', 1).' ORDER BY cp.`position` ASC' )) return false; foreach ($res as $product) - if ((int)($product['id_product']) == (int)($this->id)) + if ((int)$product['id_product'] == (int)$this->id) $movedProduct = $product; if (!isset($movedProduct) || !isset($position)) @@ -480,14 +480,14 @@ class ProductCore extends ObjectModel SET `position`= `position` '.($way ? '- 1' : '+ 1').' WHERE `position` '.($way - ? '> '.(int)($movedProduct['position']).' AND `position` <= '.(int)($position) - : '< '.(int)($movedProduct['position']).' AND `position` >= '.(int)($position)).' - AND `id_category`='.(int)($movedProduct['id_category'])) + ? '> '.(int)$movedProduct['position'].' AND `position` <= '.(int)$position + : '< '.(int)$movedProduct['position'].' AND `position` >= '.(int)$position).' + AND `id_category`='.(int)$movedProduct['id_category']) AND Db::getInstance()->execute(' UPDATE `'._DB_PREFIX_.'category_product` - SET `position` = '.(int)($position).' - WHERE `id_product` = '.(int)($movedProduct['id_product']).' - AND `id_category`='.(int)($movedProduct['id_category']))); + SET `position` = '.(int)$position.' + WHERE `id_product` = '.(int)$movedProduct['id_product'].' + AND `id_category`='.(int)$movedProduct['id_category'])); } /* @@ -503,16 +503,16 @@ class ProductCore extends ObjectModel $result = Db::getInstance()->executeS(' SELECT `id_product` FROM `'._DB_PREFIX_.'category_product` - WHERE `id_category` = '.(int)($id_category).' + WHERE `id_category` = '.(int)$id_category.' ORDER BY `position`'); $sizeof = count($result); for ($i = 0; $i < $sizeof; $i++) $return &= Db::getInstance()->execute(' UPDATE `'._DB_PREFIX_.'category_product` - SET `position` = '.(int)($i).' - WHERE `id_category` = '.(int)($id_category).' - AND `id_product` = '.(int)($result[$i]['id_product'])); + SET `position` = '.(int)$i.' + WHERE `id_category` = '.(int)$id_category.' + AND `id_product` = '.(int)$result[$i]['id_product']); return $return; } @@ -566,7 +566,7 @@ class ProductCore extends ObjectModel public static function updateDefaultAttribute($id_product) { $id_product_attribute = self::getDefaultAttribute($id_product); - Db::getInstance()->execute('UPDATE '._DB_PREFIX_.'product SET cache_default_attribute = '.(int)($id_product_attribute).' WHERE id_product = '.(int)($id_product).' LIMIT 1'); + Db::getInstance()->execute('UPDATE '._DB_PREFIX_.'product SET cache_default_attribute = '.(int)$id_product_attribute.' WHERE id_product = '.(int)$id_product.' LIMIT 1'); } public function validateFieldsLang($die = true, $errorReturn = false) @@ -601,7 +601,7 @@ class ProductCore extends ObjectModel !$this->deleteAttributesImpacts() OR !$this->deleteAttachments() OR !$this->deleteCustomization() OR - !SpecificPrice::deleteByProductId((int)($this->id)) OR + !SpecificPrice::deleteByProductId((int)$this->id) OR !$this->deletePack() OR !$this->deleteProductSale() OR !$this->deleteSceneProducts() OR @@ -620,7 +620,7 @@ class ProductCore extends ObjectModel $return = 1; foreach ($products as $id_product) { - $product = new Product((int)($id_product)); + $product = new Product((int)$id_product); $return &= $product->delete(); } return $return; @@ -712,8 +712,8 @@ class ProductCore extends ObjectModel */ public function deleteCategory($id_category, $cleanPositions = true) { - $result = Db::getInstance()->executeS('SELECT `id_category` FROM `'._DB_PREFIX_.'category_product` WHERE `id_product` = '.(int)($this->id).' AND id_category = '.(int)$id_category.''); - $return = Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'category_product` WHERE `id_product` = '.(int)($this->id).' AND id_category = '.(int)$id_category.''); + $result = Db::getInstance()->executeS('SELECT `id_category` FROM `'._DB_PREFIX_.'category_product` WHERE `id_product` = '.(int)$this->id.' AND id_category = '.(int)$id_category.''); + $return = Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'category_product` WHERE `id_product` = '.(int)$this->id.' AND id_category = '.(int)$id_category.''); if ($cleanPositions === true) foreach ($result as $row) $this->cleanPositions((int)$row['id_category']); @@ -728,12 +728,12 @@ class ProductCore extends ObjectModel */ public function deleteCategories($cleanPositions = false) { - $return = Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'category_product` WHERE `id_product` = '.(int)($this->id)); + $return = Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'category_product` WHERE `id_product` = '.(int)$this->id); if ($cleanPositions === true) { - $result = Db::getInstance()->executeS('SELECT `id_category` FROM `'._DB_PREFIX_.'category_product` WHERE `id_product` = '.(int)($this->id)); + $result = Db::getInstance()->executeS('SELECT `id_category` FROM `'._DB_PREFIX_.'category_product` WHERE `id_product` = '.(int)$this->id); foreach ($result as $row) - $this->cleanPositions((int)($row['id_category'])); + $this->cleanPositions((int)$row['id_category']); } return $return; } @@ -745,7 +745,7 @@ class ProductCore extends ObjectModel */ public function deleteTags() { - return (Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'product_tag` WHERE `id_product` = '.(int)($this->id)) + return (Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'product_tag` WHERE `id_product` = '.(int)$this->id) AND Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'tag` WHERE `id_tag` NOT IN (SELECT `id_tag` FROM `'._DB_PREFIX_.'product_tag`)')); } @@ -756,7 +756,7 @@ class ProductCore extends ObjectModel */ public function deleteCartProducts() { - return Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'cart_product` WHERE `id_product` = '.(int)($this->id)); + return Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'cart_product` WHERE `id_product` = '.(int)$this->id); } /** @@ -769,7 +769,7 @@ class ProductCore extends ObjectModel $result = Db::getInstance()->executeS(' SELECT `id_image` FROM `'._DB_PREFIX_.'image` - WHERE `id_product` = '.(int)($this->id)); + WHERE `id_product` = '.(int)$this->id); $status = true; if ($result) @@ -786,7 +786,7 @@ class ProductCore extends ObjectModel $rq = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' SELECT `price` FROM `'._DB_PREFIX_.'product_attribute` - WHERE `id_product_attribute` = '.(int)($id_product_attribute)); + WHERE `id_product_attribute` = '.(int)$id_product_attribute); return $rq['price']; } @@ -845,7 +845,7 @@ class ProductCore extends ObjectModel FROM `'._DB_PREFIX_.'product` p '.$context->shop->sqlAsso('product', 'p', false).' LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` '.$context->shop->sqlLang('pl').') - WHERE pl.`id_lang` = '.(int)($id_lang).' + WHERE pl.`id_lang` = '.(int)$id_lang.' ORDER BY pl.`name`'; return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); } @@ -855,7 +855,7 @@ class ProductCore extends ObjectModel $result = Db::getInstance()->executeS(' SELECT id_product FROM `'._DB_PREFIX_.'product` p WHERE 1 - AND id_product = '.(int)($this->id).' + AND id_product = '.(int)$this->id.' AND DATEDIFF(p.`date_add`, DATE_SUB(NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY)) > 0 '); @@ -3000,9 +3000,9 @@ class ProductCore extends ObjectModel if (isset($customizedDatas[$productId][$productAttributeId])) foreach ($customizedDatas[$productId][$productAttributeId] as $customization) { - $customizationQuantity += (int)($customization['quantity']); - $customizationQuantityRefunded += (int)($customization['quantity_refunded']); - $customizationQuantityReturned += (int)($customization['quantity_returned']); + $customizationQuantity += (int)$customization['quantity']; + $customizationQuantityRefunded += (int)$customization['quantity_refunded']; + $customizationQuantityReturned += (int)$customization['quantity_returned']; } $productUpdate['customizationQuantityTotal'] = $customizationQuantity; $productUpdate['customizationQuantityRefunded'] = $customizationQuantityRefunded; @@ -3034,32 +3034,32 @@ class ProductCore extends ObjectModel protected function _deleteOldLabels() { - $max = array(Product::CUSTOMIZE_FILE => (int)(Tools::getValue('uploadable_files')), Product::CUSTOMIZE_TEXTFIELD => (int)(Tools::getValue('text_fields'))); + $max = array(Product::CUSTOMIZE_FILE => (int)Tools::getValue('uploadable_files'), Product::CUSTOMIZE_TEXTFIELD => (int)Tools::getValue('text_fields')); /* Get customization field ids */ - if (($result = Db::getInstance()->executeS('SELECT `id_customization_field`, `type` FROM `'._DB_PREFIX_.'customization_field` WHERE `id_product` = '.(int)($this->id).' + if (($result = Db::getInstance()->executeS('SELECT `id_customization_field`, `type` FROM `'._DB_PREFIX_.'customization_field` WHERE `id_product` = '.(int)$this->id.' ORDER BY `id_customization_field`')) === false) return false; if (empty($result)) return true; $customizationFields = array(Product::CUSTOMIZE_FILE => array(), Product::CUSTOMIZE_TEXTFIELD => array()); foreach ($result as $row) - $customizationFields[(int)($row['type'])][] = (int)($row['id_customization_field']); + $customizationFields[(int)$row['type']][] = (int)$row['id_customization_field']; $extraFile = count($customizationFields[Product::CUSTOMIZE_FILE]) - $max[Product::CUSTOMIZE_FILE]; $extraText = count($customizationFields[Product::CUSTOMIZE_TEXTFIELD]) - $max[Product::CUSTOMIZE_TEXTFIELD]; /* If too much inside the database, deletion */ if ($extraFile > 0 && count($customizationFields[Product::CUSTOMIZE_FILE]) - $extraFile >= 0 && (!Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'customization_field` - WHERE `id_product` = '.(int)($this->id).' AND `type` = '.Product::CUSTOMIZE_FILE.' - AND `id_customization_field` >= '.(int)($customizationFields[Product::CUSTOMIZE_FILE][count($customizationFields[Product::CUSTOMIZE_FILE]) - $extraFile])) + WHERE `id_product` = '.(int)$this->id.' AND `type` = '.Product::CUSTOMIZE_FILE.' + AND `id_customization_field` >= '.(int)$customizationFields[Product::CUSTOMIZE_FILE][count($customizationFields[Product::CUSTOMIZE_FILE]) - $extraFile]) || !Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'customization_field_lang` WHERE `id_customization_field` NOT IN (SELECT `id_customization_field` FROM `'._DB_PREFIX_.'customization_field`)'))) return false; if ($extraText > 0 && count($customizationFields[Product::CUSTOMIZE_TEXTFIELD]) - $extraText >= 0 && (!Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'customization_field` - WHERE `id_product` = '.(int)($this->id).' AND `type` = '.Product::CUSTOMIZE_TEXTFIELD.' - AND `id_customization_field` >= '.(int)($customizationFields[Product::CUSTOMIZE_TEXTFIELD][count($customizationFields[Product::CUSTOMIZE_TEXTFIELD]) - $extraText])) + WHERE `id_product` = '.(int)$this->id.' AND `type` = '.Product::CUSTOMIZE_TEXTFIELD.' + AND `id_customization_field` >= '.(int)$customizationFields[Product::CUSTOMIZE_TEXTFIELD][count($customizationFields[Product::CUSTOMIZE_TEXTFIELD]) - $extraText]) || !Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'customization_field_lang` WHERE `id_customization_field` NOT IN (SELECT `id_customization_field` FROM `'._DB_PREFIX_.'customization_field`)'))) return false; @@ -3075,14 +3075,14 @@ class ProductCore extends ObjectModel // Label insertion if (!Db::getInstance()->execute(' INSERT INTO `'._DB_PREFIX_.'customization_field` (`id_product`, `type`, `required`) - VALUES ('.(int)$this->id.', '.(int)($type).', 0)') || - !$id_customization_field = (int)(Db::getInstance()->Insert_ID())) + VALUES ('.(int)$this->id.', '.(int)$type.', 0)') || + !$id_customization_field = (int)Db::getInstance()->Insert_ID()) return false; // Multilingual label name creation $values = ''; foreach ($languages as $language) - $values .= '('.(int)($id_customization_field).', '.(int)($language['id_lang']).', \'\'), '; + $values .= '('.(int)$id_customization_field.', '.(int)$language['id_lang'].', \'\'), '; $values = rtrim($values, ', '); if (!Db::getInstance()->execute(' INSERT INTO `'._DB_PREFIX_.'customization_field_lang` (`id_customization_field`, `id_lang`, `name`) @@ -3098,12 +3098,12 @@ class ProductCore extends ObjectModel public function createLabels($uploadableFiles, $textFields) { $languages = Language::getLanguages(); - if ((int)($uploadableFiles) > 0) - for ($i = 0; $i < (int)($uploadableFiles); $i++) + if ((int)$uploadableFiles > 0) + for ($i = 0; $i < (int)$uploadableFiles; $i++) if (!$this->_createLabel($languages, Product::CUSTOMIZE_FILE)) return false; - if ((int)($textFields) > 0) - for ($i = 0; $i < (int)($textFields); $i++) + if ((int)$textFields > 0) + for ($i = 0; $i < (int)$textFields; $i++) if (!$this->_createLabel($languages, Product::CUSTOMIZE_TEXTFIELD)) return false; return true; @@ -3121,16 +3121,16 @@ class ProductCore extends ObjectModel /* Multilingual label name update */ if (!Db::getInstance()->execute(' INSERT INTO `'._DB_PREFIX_.'customization_field_lang` - (`id_customization_field`, `id_lang`, `name`) VALUES ('.(int)($tmp[2]).', '.(int)($tmp[3]).', \''.pSQL($value).'\') + (`id_customization_field`, `id_lang`, `name`) VALUES ('.(int)$tmp[2].', '.(int)$tmp[3].', \''.pSQL($value).'\') ON DUPLICATE KEY UPDATE `name` = \''.pSQL($value).'\'')) return false; - $isRequired = isset($_POST['require_'.(int)($tmp[1]).'_'.(int)($tmp[2])]) ? 1 : 0; + $isRequired = isset($_POST['require_'.(int)$tmp[1].'_'.(int)$tmp[2]]) ? 1 : 0; $hasRequiredFields |= $isRequired; /* Require option update */ - if (!Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'customization_field` SET `required` = '.(int)($isRequired).' WHERE `id_customization_field` = '.(int)($tmp[2]))) + if (!Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'customization_field` SET `required` = '.(int)$isRequired.' WHERE `id_customization_field` = '.(int)$tmp[2])) return false; } - if ($hasRequiredFields && !Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'product` SET `customizable` = 2 WHERE `id_product` = '.(int)($this->id))) + if ($hasRequiredFields && !Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'product` SET `customizable` = 2 WHERE `id_product` = '.(int)$this->id)) return false; if (!$this->_deleteOldLabels()) return false; @@ -3145,14 +3145,14 @@ class ProductCore extends ObjectModel SELECT cf.`id_customization_field`, cf.`type`, cf.`required`, cfl.`name`, cfl.`id_lang` FROM `'._DB_PREFIX_.'customization_field` cf NATURAL JOIN `'._DB_PREFIX_.'customization_field_lang` cfl - WHERE cf.`id_product` = '.(int)($this->id).($id_lang ? ' AND cfl.`id_lang` = '.(int)($id_lang) : '').' + WHERE cf.`id_product` = '.(int)$this->id.($id_lang ? ' AND cfl.`id_lang` = '.(int)$id_lang : '').' ORDER BY cf.`id_customization_field`')) return false; if ($id_lang) return $result; $customizationFields = array(); foreach ($result as $row) - $customizationFields[(int)($row['type'])][(int)($row['id_customization_field'])][(int)($row['id_lang'])] = $row; + $customizationFields[(int)$row['type']][(int)$row['id_customization_field']][(int)$row['id_lang']] = $row; return $customizationFields; } @@ -3163,7 +3163,7 @@ class ProductCore extends ObjectModel return Db::getInstance()->executeS(' SELECT `id_customization_field`, `type` FROM `'._DB_PREFIX_.'customization_field` - WHERE `id_product` = '.(int)($this->id)); + WHERE `id_product` = '.(int)$this->id); } public function getRequiredCustomizableFields() @@ -3173,7 +3173,7 @@ class ProductCore extends ObjectModel return Db::getInstance()->executeS(' SELECT `id_customization_field`, `type` FROM `'._DB_PREFIX_.'customization_field` - WHERE `id_product` = '.(int)($this->id).' + WHERE `id_product` = '.(int)$this->id.' AND `required` = 1' ); } @@ -3210,9 +3210,9 @@ class ProductCore extends ObjectModel { if (!((int)$id_product > 0) || !is_array($categories) || empty($categories)) return false; - $sql = 'SELECT id_product FROM `'._DB_PREFIX_.'category_product` WHERE `id_product`='.(int)($id_product).' AND `id_category` IN('; + $sql = 'SELECT id_product FROM `'._DB_PREFIX_.'category_product` WHERE `id_product`='.(int)$id_product.' AND `id_category` IN('; foreach ($categories as $category) - $sql .= (int)($category['id_category']).','; + $sql .= (int)$category['id_category'].','; $sql = rtrim($sql, ',').')'; if (isset(self::$_incat[md5($sql)])) @@ -3451,7 +3451,7 @@ class ProductCore extends ObjectModel */ public function getWsCombinations() { - $result = Db::getInstance()->executeS('SELECT `id_product_attribute` as id FROM `'._DB_PREFIX_.'product_attribute` WHERE `id_product` = '.(int)($this->id)); + $result = Db::getInstance()->executeS('SELECT `id_product_attribute` as id FROM `'._DB_PREFIX_.'product_attribute` WHERE `id_product` = '.(int)$this->id); return $result; } @@ -3468,7 +3468,7 @@ class ProductCore extends ObjectModel $ids_new[] = (int)$combination['id']; $ids_orig = array(); - $original = Db::getInstance()->executeS('SELECT `id_product_attribute` as id FROM `'._DB_PREFIX_.'product_attribute` WHERE `id_product` = '.(int)($this->id)); + $original = Db::getInstance()->executeS('SELECT `id_product_attribute` as id FROM `'._DB_PREFIX_.'product_attribute` WHERE `id_product` = '.(int)$this->id); if (is_array($original)) foreach ($original as $id) $ids_orig[] = $id['id']; @@ -3527,8 +3527,8 @@ class ProductCore extends ObjectModel { $result = Db::getInstance()->executeS('SELECT position FROM `'._DB_PREFIX_.'category_product` - WHERE id_category = '.(int)($this->id_category_default).' - AND id_product = '.(int)($this->id)); + WHERE id_category = '.(int)$this->id_category_default.' + AND id_product = '.(int)$this->id); if (count($result) > 0) return $result[0]['position']; return ''; @@ -3553,10 +3553,10 @@ class ProductCore extends ObjectModel public function setCoverWs($id_image) { Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'image` - SET `cover` = 0 WHERE `id_product` = '.(int)($this->id).' + SET `cover` = 0 WHERE `id_product` = '.(int)$this->id.' '); Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'image` - SET `cover` = 1 WHERE `id_product` = '.(int)($this->id).' AND `id_image` = '.(int)$id_image); + SET `cover` = 1 WHERE `id_product` = '.(int)$this->id.' AND `id_image` = '.(int)$id_image); return true; } @@ -3570,7 +3570,7 @@ class ProductCore extends ObjectModel return Db::getInstance()->executeS(' SELECT `id_image` as id FROM `'._DB_PREFIX_.'image` - WHERE `id_product` = '.(int)($this->id).' + WHERE `id_product` = '.(int)$this->id.' ORDER BY `position`'); } @@ -3579,7 +3579,7 @@ class ProductCore extends ObjectModel return Db::getInstance()->executeS(' SELECT `id_tag` as id FROM `'._DB_PREFIX_.'product_tag` - WHERE `id_product` = '.(int)($this->id)); + WHERE `id_product` = '.(int)$this->id); } diff --git a/install-dev/sql/db.sql b/install-dev/sql/db.sql index b3aa54022..89acfa474 100644 --- a/install-dev/sql/db.sql +++ b/install-dev/sql/db.sql @@ -138,6 +138,7 @@ CREATE TABLE `PREFIX_carrier` ( `need_range` tinyint(1) unsigned NOT NULL DEFAULT '0', `external_module_name` varchar(64) DEFAULT NULL, `shipping_method` int(2) NOT NULL DEFAULT '0', + `position` int(10) unsigned NOT NULL default '0', PRIMARY KEY (`id_carrier`), KEY `deleted` (`deleted`,`active`), KEY `id_tax_rules_group` (`id_tax_rules_group`) diff --git a/install-dev/sql/db_settings_extends.sql b/install-dev/sql/db_settings_extends.sql index 63ad0308c..d648e6b28 100644 --- a/install-dev/sql/db_settings_extends.sql +++ b/install-dev/sql/db_settings_extends.sql @@ -1,7 +1,7 @@ SET NAMES 'utf8'; /* Carrier */ -INSERT INTO `PREFIX_carrier` (`id_carrier`, `id_reference`, `id_tax_rules_group`, `name`, `active`, `deleted`, `shipping_handling`, `is_free`) VALUES (2, 2, 1, 'My carrier', 1, 0, 1, 0); +INSERT INTO `PREFIX_carrier` (`id_carrier`, `id_reference`, `id_tax_rules_group`, `name`, `active`, `deleted`, `shipping_handling`, `is_free`, `position`) VALUES (2, 2, 1, 'My carrier', 1, 0, 1, 0, 1); INSERT INTO `PREFIX_carrier_group` (`id_carrier`, `id_group`) VALUES (2, 1); INSERT INTO `PREFIX_carrier_shop` (`id_carrier`, `id_shop`) VALUES (2, 1); INSERT INTO `PREFIX_carrier_lang` (`id_carrier`, `id_lang`, `delay`) VALUES (2, 1, 'Delivery next day!'),(2, 2, 'Livraison le lendemain !'),(2, 3, '¡Entrega día siguiente!'),(2, 4, 'Zustellung am nächsten Tag!'),(2, 5, 'Consegna il giorno dopo!'); diff --git a/install-dev/sql/db_settings_lite.sql b/install-dev/sql/db_settings_lite.sql index 3499baf1a..1e9af6644 100644 --- a/install-dev/sql/db_settings_lite.sql +++ b/install-dev/sql/db_settings_lite.sql @@ -1177,7 +1177,7 @@ INSERT INTO `PREFIX_cms_category_lang` (`id_cms_category`, `id_lang`, `name`, `d INSERT INTO `PREFIX_cms_category` (`id_cms_category`, `id_parent`, `level_depth`, `active`, `date_add`, `date_upd`) VALUES(1, 0, 0, 1, NOW(), NOW()); /* Carrier */ -INSERT INTO `PREFIX_carrier` (`id_carrier`, `id_reference`, `id_tax_rules_group`, `name`, `active`, `deleted`, `shipping_handling`) VALUES (1, 1, 0, 0, 1, 0, 0); +INSERT INTO `PREFIX_carrier` (`id_carrier`, `id_reference`, `id_tax_rules_group`, `name`, `active`, `deleted`, `shipping_handling`, `position`) VALUES (1, 1, 0, 0, 1, 0, 0, 0); INSERT INTO `PREFIX_carrier_group` (`id_carrier`, `id_group`) VALUES (1, 1); diff --git a/install-dev/sql/upgrade/1.5.0.1.sql b/install-dev/sql/upgrade/1.5.0.1.sql index 0679a8f32..a4599f060 100644 --- a/install-dev/sql/upgrade/1.5.0.1.sql +++ b/install-dev/sql/upgrade/1.5.0.1.sql @@ -215,5 +215,6 @@ UPDATE `PREFIX_module_access` SET `id_profile` = 2 WHERE `id_profile` = 1; INSERT INTO `PREFIX_module_access` (`id_profile`, `id_module`, `configure`, `view`) (SELECT 1, `id_module`, 1, 1 FROM `PREFIX_module`); +ALTER TABLE `PREFIX_carrier` ADD `position` INT( 10 ) UNSIGNED NOT NULL DEFAULT '0'; - +/* PHP:add_carrier_position();*/ diff --git a/js/admin-dnd.js b/js/admin-dnd.js index 314ea79ac..ba076d6b7 100644 --- a/js/admin-dnd.js +++ b/js/admin-dnd.js @@ -119,6 +119,15 @@ $(document).ready(function() { } } + if (table.id == 'carrier') { + params = { + ajaxCarriersPositions: true, + id_carrier : ids[2], + way: way, + token: token + } + } + $.ajax({ type: 'POST', async: false, diff --git a/modules/cashondelivery/config.xml b/modules/cashondelivery/config.xml index 6ee431f63..d214915a3 100755 --- a/modules/cashondelivery/config.xml +++ b/modules/cashondelivery/config.xml @@ -2,7 +2,7 @@ cashondelivery - +