/controllers/admin/AdminProductsController.php
PHP | 4756 lines | 3910 code | 545 blank | 301 comment | 831 complexity | 89cdea2af3e401ff2a074e05f8a33493 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, LGPL-2.1, LGPL-3.0
Large files files are truncated, but you can click here to view the full file
- <?php
- /*
- * 2007-2014 PrestaShop
- *
- * NOTICE OF LICENSE
- *
- * This source file is subject to the Open Software License (OSL 3.0)
- * that is bundled with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://opensource.org/licenses/osl-3.0.php
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to license@prestashop.com so we can send you a copy immediately.
- *
- * DISCLAIMER
- *
- * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
- * versions in the future. If you wish to customize PrestaShop for your
- * needs please refer to http://www.prestashop.com for more information.
- *
- * @author PrestaShop SA <contact@prestashop.com>
- * @copyright 2007-2014 PrestaShop SA
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
- * International Registered Trademark & Property of PrestaShop SA
- */
- class AdminProductsControllerCore extends AdminController
- {
- /** @var integer Max image size for upload
- * As of 1.5 it is recommended to not set a limit to max image size
- */
- protected $max_file_size = null;
- protected $max_image_size = null;
- protected $_category;
- /**
- * @var string name of the tab to display
- */
- protected $tab_display;
- protected $tab_display_module;
- /**
- * The order in the array decides the order in the list of tab. If an element's value is a number, it will be preloaded.
- * The tabs are preloaded from the smallest to the highest number.
- * @var array Product tabs.
- */
- protected $available_tabs = array();
- protected $default_tab = 'Informations';
- protected $available_tabs_lang = array();
- protected $position_identifier = 'id_product';
- protected $submitted_tabs;
-
- protected $id_current_category;
- public function __construct()
- {
- $this->bootstrap = true;
- $this->table = 'product';
- $this->className = 'Product';
- $this->lang = true;
- $this->explicitSelect = true;
- $this->bulk_actions = array(
- 'delete' => array(
- 'text' => $this->l('Delete selected'),
- 'icon' => 'icon-trash',
- 'confirm' => $this->l('Delete selected items?')
- )
- );
- if (!Tools::getValue('id_product'))
- $this->multishop_context_group = false;
- parent::__construct();
- $this->imageType = 'jpg';
- $this->_defaultOrderBy = 'position';
- $this->max_file_size = (int)(Configuration::get('PS_LIMIT_UPLOAD_FILE_VALUE') * 1000000);
- $this->max_image_size = (int)Configuration::get('PS_PRODUCT_PICTURE_MAX_SIZE');
- $this->allow_export = true;
- // @since 1.5 : translations for tabs
- $this->available_tabs_lang = array(
- 'Informations' => $this->l('Information'),
- 'Pack' => $this->l('Pack'),
- 'VirtualProduct' => $this->l('Virtual Product'),
- 'Prices' => $this->l('Prices'),
- 'Seo' => $this->l('SEO'),
- 'Images' => $this->l('Images'),
- 'Associations' => $this->l('Associations'),
- 'Shipping' => $this->l('Shipping'),
- 'Combinations' => $this->l('Combinations'),
- 'Features' => $this->l('Features'),
- 'Customization' => $this->l('Customization'),
- 'Attachments' => $this->l('Attachments'),
- 'Quantities' => $this->l('Quantities'),
- 'Suppliers' => $this->l('Suppliers'),
- 'Warehouses' => $this->l('Warehouses'),
- );
- $this->available_tabs = array('Quantities' => 6, 'Warehouses' => 14);
- if ($this->context->shop->getContext() != Shop::CONTEXT_GROUP)
- $this->available_tabs = array_merge($this->available_tabs, array(
- 'Informations' => 0,
- 'Pack' => 7,
- 'VirtualProduct' => 8,
- 'Prices' => 1,
- 'Seo' => 2,
- 'Associations' => 3,
- 'Images' => 9,
- 'Shipping' => 4,
- 'Combinations' => 5,
- 'Features' => 10,
- 'Customization' => 11,
- 'Attachments' => 12,
- 'Suppliers' => 13,
- ));
- // Sort the tabs that need to be preloaded by their priority number
- asort($this->available_tabs, SORT_NUMERIC);
- /* Adding tab if modules are hooked */
- $modules_list = Hook::getHookModuleExecList('displayAdminProductsExtra');
- if (is_array($modules_list) && count($modules_list) > 0)
- foreach ($modules_list as $m)
- {
- $this->available_tabs['Module'.ucfirst($m['module'])] = 23;
- $this->available_tabs_lang['Module'.ucfirst($m['module'])] = Module::getModuleName($m['module']);
- }
- if (Tools::getValue('reset_filter_category'))
- $this->context->cookie->id_category_products_filter = false;
- if (Shop::isFeatureActive() && $this->context->cookie->id_category_products_filter)
- {
- $category = new Category((int)$this->context->cookie->id_category_products_filter);
- if (!$category->inShop())
- {
- $this->context->cookie->id_category_products_filter = false;
- Tools::redirectAdmin($this->context->link->getAdminLink('AdminProducts'));
- }
- }
- /* Join categories table */
- if ($id_category = (int)Tools::getValue('productFilter_cl!name'))
- {
- $this->_category = new Category((int)$id_category);
- $_POST['productFilter_cl!name'] = $this->_category->name[$this->context->language->id];
- }
- else
- {
- if ($id_category = (int)Tools::getValue('id_category'))
- {
- $this->id_current_category = $id_category;
- $this->context->cookie->id_category_products_filter = $id_category;
- }
- elseif ($id_category = $this->context->cookie->id_category_products_filter)
- $this->id_current_category = $id_category;
- if ($this->id_current_category)
- $this->_category = new Category((int)$this->id_current_category);
- else
- $this->_category = new Category();
- }
-
- $join_category = false;
- if (Validate::isLoadedObject($this->_category) && empty($this->_filter))
- $join_category = true;
- $this->_join .= '
- LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = a.`id_product`)
- LEFT JOIN `'._DB_PREFIX_.'stock_available` sav ON (sav.`id_product` = a.`id_product` AND sav.`id_product_attribute` = 0
- '.StockAvailable::addSqlShopRestriction(null, null, 'sav').') ';
-
- $alias = 'sa';
- $alias_image = 'image_shop';
-
- $id_shop = Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP? (int)$this->context->shop->id : 'a.id_shop_default';
- $this->_join .= ' JOIN `'._DB_PREFIX_.'product_shop` sa ON (a.`id_product` = sa.`id_product` AND sa.id_shop = '.$id_shop.')
- LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON ('.$alias.'.`id_category_default` = cl.`id_category` AND b.`id_lang` = cl.`id_lang` AND cl.id_shop = '.$id_shop.')
- LEFT JOIN `'._DB_PREFIX_.'shop` shop ON (shop.id_shop = '.$id_shop.')
- LEFT JOIN `'._DB_PREFIX_.'image_shop` image_shop ON (image_shop.`id_image` = i.`id_image` AND image_shop.`cover` = 1 AND image_shop.id_shop = '.$id_shop.')
- LEFT JOIN `'._DB_PREFIX_.'product_download` pd ON (pd.`id_product` = a.`id_product`)';
-
- $this->_select .= 'shop.name as shopname, a.id_shop_default, ';
- $this->_select .= 'MAX('.$alias_image.'.id_image) id_image, cl.name `name_category`, '.$alias.'.`price`, 0 AS price_final, a.`is_virtual`, pd.`nb_downloadable`, sav.`quantity` as sav_quantity, '.$alias.'.`active`, IF(sav.`quantity`<=0, 1, 0) badge_danger';
-
- if ($join_category)
- {
- $this->_join .= ' INNER JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_product` = a.`id_product` AND cp.`id_category` = '.(int)$this->_category->id.') ';
- $this->_select .= ' , cp.`position`, ';
- }
- $this->_group = 'GROUP BY '.$alias.'.id_product';
- $this->fields_list = array();
- $this->fields_list['id_product'] = array(
- 'title' => $this->l('ID'),
- 'align' => 'center',
- 'class' => 'fixed-width-xs',
- 'type' => 'int'
- );
- $this->fields_list['image'] = array(
- 'title' => $this->l('Photo'),
- 'align' => 'center',
- 'image' => 'p',
- 'orderby' => false,
- 'filter' => false,
- 'search' => false
- );
- $this->fields_list['name'] = array(
- 'title' => $this->l('Name'),
- 'filter_key' => 'b!name'
- );
- $this->fields_list['reference'] = array(
- 'title' => $this->l('Reference'),
- 'align' => 'left',
- );
- if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_SHOP)
- $this->fields_list['shopname'] = array(
- 'title' => $this->l('Default shop'),
- 'filter_key' => 'shop!name',
- );
- else
- $this->fields_list['name_category'] = array(
- 'title' => $this->l('Category'),
- 'filter_key' => 'cl!name',
- );
- $this->fields_list['price'] = array(
- 'title' => $this->l('Base price'),
- 'type' => 'price',
- 'align' => 'text-right',
- 'filter_key' => 'a!price'
- );
- $this->fields_list['price_final'] = array(
- 'title' => $this->l('Final price'),
- 'type' => 'price',
- 'align' => 'text-right',
- 'havingFilter' => true,
- 'orderby' => false,
- 'search' => false
- );
- if (Configuration::get('PS_STOCK_MANAGEMENT'))
- $this->fields_list['sav_quantity'] = array(
- 'title' => $this->l('Quantity'),
- 'type' => 'int',
- 'align' => 'text-right',
- 'filter_key' => 'sav!quantity',
- 'orderby' => true,
- 'badge_danger' => true,
- //'hint' => $this->l('This is the quantity available in the current shop/group.'),
- );
- $this->fields_list['active'] = array(
- 'title' => $this->l('Status'),
- 'active' => 'status',
- 'filter_key' => $alias.'!active',
- 'align' => 'text-center',
- 'type' => 'bool',
- 'class' => 'fixed-width-sm',
- 'orderby' => false
- );
- if ($join_category && (int)$this->id_current_category)
- $this->fields_list['position'] = array(
- 'title' => $this->l('Position'),
- 'filter_key' => 'cp!position',
- 'align' => 'center',
- 'position' => 'position'
- );
- }
- public static function getQuantities($echo, $tr)
- {
- if ((int)$tr['is_virtual'] == 1 && $tr['nb_downloadable'] == 0)
- return '∞';
- else
- return $echo;
- }
- public function setMedia()
- {
- parent::setMedia();
- $bo_theme = ((Validate::isLoadedObject($this->context->employee)
- && $this->context->employee->bo_theme) ? $this->context->employee->bo_theme : 'default');
- if (!file_exists(_PS_BO_ALL_THEMES_DIR_.$bo_theme.DIRECTORY_SEPARATOR
- .'template'))
- $bo_theme = 'default';
- $this->addJs(__PS_BASE_URI__.$this->admin_webpath.'/themes/'.$bo_theme.'/js/jquery.iframe-transport.js');
- $this->addJs(__PS_BASE_URI__.$this->admin_webpath.'/themes/'.$bo_theme.'/js/jquery.fileupload.js');
- $this->addJs(__PS_BASE_URI__.$this->admin_webpath.'/themes/'.$bo_theme.'/js/jquery.fileupload-process.js');
- $this->addJs(__PS_BASE_URI__.$this->admin_webpath.'/themes/'.$bo_theme.'/js/jquery.fileupload-validate.js');
- $this->addJs(__PS_BASE_URI__.'js/vendor/spin.js');
- $this->addJs(__PS_BASE_URI__.'js/vendor/ladda.js');
- }
-
- protected function _cleanMetaKeywords($keywords)
- {
- if (!empty($keywords) && $keywords != '')
- {
- $out = array();
- $words = explode(',', $keywords);
- foreach ($words as $word_item)
- {
- $word_item = trim($word_item);
- if (!empty($word_item) && $word_item != '')
- $out[] = $word_item;
- }
- return ((count($out) > 0) ? implode(',', $out) : '');
- }
- else
- return '';
- }
- protected function copyFromPost(&$object, $table)
- {
- parent::copyFromPost($object, $table);
- if (get_class($object) != 'Product')
- return;
- /* Additional fields */
- $languages = Language::getLanguages(false);
- foreach ($languages as $language)
- if (isset($_POST['meta_keywords_'.$language['id_lang']]))
- {
- $_POST['meta_keywords_'.$language['id_lang']] = $this->_cleanMetaKeywords(Tools::strtolower($_POST['meta_keywords_'.$language['id_lang']]));
- // preg_replace('/ *,? +,* /', ',', strtolower($_POST['meta_keywords_'.$language['id_lang']]));
- $object->meta_keywords[$language['id_lang']] = $_POST['meta_keywords_'.$language['id_lang']];
- }
- $_POST['width'] = empty($_POST['width']) ? '0' : str_replace(',', '.', $_POST['width']);
- $_POST['height'] = empty($_POST['height']) ? '0' : str_replace(',', '.', $_POST['height']);
- $_POST['depth'] = empty($_POST['depth']) ? '0' : str_replace(',', '.', $_POST['depth']);
- $_POST['weight'] = empty($_POST['weight']) ? '0' : str_replace(',', '.', $_POST['weight']);
- if (Tools::getIsset('unit_price') != null)
- $object->unit_price = str_replace(',', '.', Tools::getValue('unit_price'));
- if (Tools::getIsset('ecotax') != null)
- $object->ecotax = str_replace(',', '.', Tools::getValue('ecotax'));
- $object->available_for_order = (int)Tools::getValue('available_for_order');
- $object->show_price = $object->available_for_order ? 1 : (int)Tools::getValue('show_price');
- $object->on_sale = (int)Tools::getValue('on_sale');
- $object->online_only = (int)Tools::getValue('online_only');
- }
- public function getList($id_lang, $orderBy = null, $orderWay = null, $start = 0, $limit = null, $id_lang_shop = null)
- {
- $orderByPriceFinal = (empty($orderBy) ? ($this->context->cookie->__get($this->table.'Orderby') ? $this->context->cookie->__get($this->table.'Orderby') : 'id_'.$this->table) : $orderBy);
- $orderWayPriceFinal = (empty($orderWay) ? ($this->context->cookie->__get($this->table.'Orderway') ? $this->context->cookie->__get($this->table.'Orderby') : 'ASC') : $orderWay);
- if ($orderByPriceFinal == 'price_final')
- {
- $orderBy = 'id_'.$this->table;
- $orderWay = 'ASC';
- }
- parent::getList($id_lang, $orderBy, $orderWay, $start, $limit, $this->context->shop->id);
- /* update product quantity with attributes ...*/
- $nb = count($this->_list);
- if ($this->_list)
- {
- $context = $this->context->cloneContext();
- $context->shop = clone($context->shop);
- /* update product final price */
- for ($i = 0; $i < $nb; $i++)
- {
- if (Context::getContext()->shop->getContext() != Shop::CONTEXT_SHOP)
- $context->shop = new Shop((int)$this->_list[$i]['id_shop_default']);
- // convert price with the currency from context
- $this->_list[$i]['price'] = Tools::convertPrice($this->_list[$i]['price'], $this->context->currency, true, $this->context);
- $this->_list[$i]['price_tmp'] = Product::getPriceStatic($this->_list[$i]['id_product'], true, null, 2, null, false, true, 1, true, null, null, null, $nothing, true, true, $context);
- }
- }
- if ($orderByPriceFinal == 'price_final')
- {
- if (strtolower($orderWayPriceFinal) == 'desc')
- uasort($this->_list, 'cmpPriceDesc');
- else
- uasort($this->_list, 'cmpPriceAsc');
- }
- for ($i = 0; $this->_list && $i < $nb; $i++)
- {
- $this->_list[$i]['price_final'] = $this->_list[$i]['price_tmp'];
- unset($this->_list[$i]['price_tmp']);
- }
- }
- protected function loadObject($opt = false)
- {
- $result = parent::loadObject($opt);
- if ($result && Validate::isLoadedObject($this->object))
- {
- if (Shop::getContext() == Shop::CONTEXT_SHOP && Shop::isFeatureActive() && !$this->object->isAssociatedToShop())
- {
- $default_product = new Product((int)$this->object->id, false, null, (int)$this->object->id_shop_default);
- $def = ObjectModel::getDefinition($this->object);
- foreach ($def['fields'] as $field_name => $row)
- {
- if (is_array($default_product->$field_name))
- foreach ($default_product->$field_name as $key => $value)
- $this->object->{$field_name}[$key] = $value;
- else
- $this->object->$field_name = $default_product->$field_name;
- }
- }
- $this->object->loadStockData();
- }
- return $result;
- }
- public function ajaxProcessGetCountriesOptions()
- {
- if (!$res = Country::getCountriesByIdShop((int)Tools::getValue('id_shop'), (int)$this->context->language->id))
- return ;
- $tpl = $this->createTemplate('specific_prices_shop_update.tpl');
- $tpl->assign(array(
- 'option_list' => $res,
- 'key_id' => 'id_country',
- 'key_value' => 'name'
- )
- );
- $this->content = $tpl->fetch();
- }
-
- public function ajaxProcessGetCurrenciesOptions()
- {
- if (!$res = Currency::getCurrenciesByIdShop((int)Tools::getValue('id_shop')))
- return ;
- $tpl = $this->createTemplate('specific_prices_shop_update.tpl');
- $tpl->assign(array(
- 'option_list' => $res,
- 'key_id' => 'id_currency',
- 'key_value' => 'name'
- )
- );
- $this->content = $tpl->fetch();
- }
-
- public function ajaxProcessGetGroupsOptions()
- {
- if (!$res = Group::getGroups((int)$this->context->language->id, (int)Tools::getValue('id_shop')))
- return ;
- $tpl = $this->createTemplate('specific_prices_shop_update.tpl');
- $tpl->assign(array(
- 'option_list' => $res,
- 'key_id' => 'id_group',
- 'key_value' => 'name'
- )
- );
- $this->content = $tpl->fetch();
- }
- public function processDeleteVirtualProduct()
- {
- if (!($id_product_download = ProductDownload::getIdFromIdProduct((int)Tools::getValue('id_product'))))
- $this->errors[] = Tools::displayError('Cannot retrieve file');
- else
- {
- $product_download = new ProductDownload((int)$id_product_download);
- if (!$product_download->deleteFile((int)$id_product_download))
- $this->errors[] = Tools::displayError('Cannot delete file');
- else
- $this->redirect_after = self::$currentIndex.'&id_product='.(int)Tools::getValue('id_product').'&updateproduct&key_tab=VirtualProduct&conf=1&token='.$this->token;
- }
- $this->display = 'edit';
- $this->tab_display = 'VirtualProduct';
- }
- public function ajaxProcessAddAttachment()
- {
- if (isset($_FILES['attachment_file']))
- {
- if ((int)$_FILES['attachment_file']['error'] === 1)
- {
- $_FILES['attachment_file']['error'] = array();
- $max_upload = (int)ini_get('upload_max_filesize');
- $max_post = (int)ini_get('post_max_size');
- $upload_mb = min($max_upload, $max_post);
- $_FILES['attachment_file']['error'][] = sprintf(
- $this->l('File %1$s exceeds the size allowed by the server. The limit is set to %2$d MB.'),
- '<b>'.$_FILES['attachment_file']['name'].'</b> ',
- '<b>'.$upload_mb.'</b>'
- );
- }
- $_FILES['attachment_file']['error'] = array();
- $is_attachment_name_valid = false;
- $attachment_names = Tools::getValue('attachment_name');
- $attachment_descriptions = Tools::getValue('attachment_description');
- if (!isset($attachment_names) || !$attachment_names)
- $attachment_names = array();
- if (!isset($attachment_descriptions) || !$attachment_descriptions)
- $attachment_descriptions = array();
- foreach ($attachment_names as $lang => $name)
- {
- $language = Language::getLanguage((int)$lang);
- if (Tools::strlen($name) > 0)
- $is_attachment_name_valid = true;
- if (!Validate::isGenericName($name))
- $_FILES['attachment_file']['error'][] = sprintf(Tools::displayError('Invalid name for %s language'), $language['name']);
- elseif (Tools::strlen($name) > 32)
- $_FILES['attachment_file']['error'][] = sprintf(Tools::displayError('The name for %1s language is too long (%2d chars max).'), $language['name'], 32);
- }
- foreach ($attachment_descriptions as $lang => $description)
- {
- $language = Language::getLanguage((int)$lang);
- if (!Validate::isCleanHtml($description))
- $_FILES['attachment_file']['error'][] = sprintf(Tools::displayError('Invalid description for %s language'), $language['name']);
- }
- if (!$is_attachment_name_valid)
- $_FILES['attachment_file']['error'][] = Tools::displayError('An attachment name is required.');
- if (empty($_FILES['attachment_file']['error']))
- {
- if (is_uploaded_file($_FILES['attachment_file']['tmp_name']))
- {
- if ($_FILES['attachment_file']['size'] > (Configuration::get('PS_ATTACHMENT_MAXIMUM_SIZE') * 1024 * 1024))
- $_FILES['attachment_file']['error'][] = sprintf(
- $this->l('The file is too large. Maximum size allowed is: %1$d kB. The file you\'re trying to upload is: %2$d kB.'),
- (Configuration::get('PS_ATTACHMENT_MAXIMUM_SIZE') * 1024),
- number_format(($_FILES['attachment_file']['size'] / 1024), 2, '.', '')
- );
- else
- {
- do $uniqid = sha1(microtime());
- while (file_exists(_PS_DOWNLOAD_DIR_.$uniqid));
- if (!copy($_FILES['attachment_file']['tmp_name'], _PS_DOWNLOAD_DIR_.$uniqid))
- $_FILES['attachment_file']['error'][] = $this->l('File copy failed');
- @unlink($_FILES['attachment_file']['tmp_name']);
- }
- }
- else
- $_FILES['attachment_file']['error'][] = Tools::displayError('The file is missing.');
- if (empty($_FILES['attachment_file']['error']) && isset($uniqid))
- {
- $attachment = new Attachment();
- foreach ($attachment_names as $lang => $name)
- $attachment->name[(int)$lang] = $name;
- foreach ($attachment_descriptions as $lang => $description)
- $attachment->description[(int)$lang] = $description;
- $attachment->file = $uniqid;
- $attachment->mime = $_FILES['attachment_file']['type'];
- $attachment->file_name = $_FILES['attachment_file']['name'];
- if (empty($attachment->mime) || Tools::strlen($attachment->mime) > 128)
- $_FILES['attachment_file']['error'][] = Tools::displayError('Invalid file extension');
- if (!Validate::isGenericName($attachment->file_name))
- $_FILES['attachment_file']['error'][] = Tools::displayError('Invalid file name');
- if (Tools::strlen($attachment->file_name) > 128)
- $_FILES['attachment_file']['error'][] = Tools::displayError('The file name is too long.');
- if (empty($this->errors))
- {
- $res = $attachment->add();
- if (!$res)
- $_FILES['attachment_file']['error'][] = Tools::displayError('This attachment was unable to be loaded into the database.');
- else
- {
- $_FILES['attachment_file']['id_attachment'] = $attachment->id;
- $_FILES['attachment_file']['filename'] = $attachment->name[$this->context->employee->id_lang];
- $id_product = (int)Tools::getValue($this->identifier);
- $res = $attachment->attachProduct($id_product);
- if (!$res)
- $_FILES['attachment_file']['error'][] = Tools::displayError('We were unable to associate this attachment to a product.');
- }
- }
- else
- $_FILES['attachment_file']['error'][] = Tools::displayError('Invalid file');
- }
- }
- die(Tools::jsonEncode($_FILES));
- }
- }
- /**
- * Attach an existing attachment to the product
- *
- * @return void
- */
- public function processAttachments()
- {
- if ($id = (int)Tools::getValue($this->identifier))
- {
- $attachments = trim(Tools::getValue('arrayAttachments'), ',');
- $attachments = explode(',', $attachments);
- if (!Attachment::attachToProduct($id, $attachments))
- $this->errors[] = Tools::displayError('An error occurred while saving product attachments.');
- }
- }
- public function processDuplicate()
- {
- if (Validate::isLoadedObject($product = new Product((int)Tools::getValue('id_product'))))
- {
- $id_product_old = $product->id;
- if (empty($product->price) && Shop::getContext() == Shop::CONTEXT_GROUP)
- {
- $shops = ShopGroup::getShopsFromGroup(Shop::getContextShopGroupID());
- foreach ($shops as $shop)
- if ($product->isAssociatedToShop($shop['id_shop']))
- {
- $product_price = new Product($id_product_old, false, null, $shop['id_shop']);
- $product->price = $product_price->price;
- }
- }
- unset($product->id);
- unset($product->id_product);
- $product->indexed = 0;
- $product->active = 0;
- if ($product->add()
- && Category::duplicateProductCategories($id_product_old, $product->id)
- && ($combination_images = Product::duplicateAttributes($id_product_old, $product->id)) !== false
- && GroupReduction::duplicateReduction($id_product_old, $product->id)
- && Product::duplicateAccessories($id_product_old, $product->id)
- && Product::duplicateFeatures($id_product_old, $product->id)
- && Product::duplicateSpecificPrices($id_product_old, $product->id)
- && Pack::duplicate($id_product_old, $product->id)
- && Product::duplicateCustomizationFields($id_product_old, $product->id)
- && Product::duplicateTags($id_product_old, $product->id)
- && Product::duplicateDownload($id_product_old, $product->id))
- {
- if ($product->hasAttributes())
- Product::updateDefaultAttribute($product->id);
- if (!Tools::getValue('noimage') && !Image::duplicateProductImages($id_product_old, $product->id, $combination_images))
- $this->errors[] = Tools::displayError('An error occurred while copying images.');
- else
- {
- Hook::exec('actionProductAdd', array('product' => $product));
- if (in_array($product->visibility, array('both', 'search')) && Configuration::get('PS_SEARCH_INDEXATION'))
- Search::indexation(false, $product->id);
- $this->redirect_after = self::$currentIndex.(Tools::getIsset('id_category') ? '&id_category='.(int)Tools::getValue('id_category') : '').'&conf=19&token='.$this->token;
- }
- }
- else
- $this->errors[] = Tools::displayError('An error occurred while creating an object.');
- }
- }
- public function processDelete()
- {
- if (Validate::isLoadedObject($object = $this->loadObject()) && isset($this->fieldImageSettings))
- {
- // check if request at least one object with noZeroObject
- if (isset($object->noZeroObject) && count($taxes = call_user_func(array($this->className, $object->noZeroObject))) <= 1)
- $this->errors[] = Tools::displayError('You need at least one object.').' <b>'.$this->table.'</b><br />'.Tools::displayError('You cannot delete all of the items.');
- else
- {
- /*
- * @since 1.5.0
- * It is NOT possible to delete a product if there are currently:
- * - physical stock for this product
- * - supply order(s) for this product
- */
- if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $object->advanced_stock_management)
- {
- $stock_manager = StockManagerFactory::getManager();
- $physical_quantity = $stock_manager->getProductPhysicalQuantities($object->id, 0);
- $real_quantity = $stock_manager->getProductRealQuantities($object->id, 0);
- if ($physical_quantity > 0 || $real_quantity > $physical_quantity)
- $this->errors[] = Tools::displayError('You cannot delete this product because there\'s physical stock left.');
- }
- if (!count($this->errors))
- {
- if ($object->delete())
- {
- $id_category = (int)Tools::getValue('id_category');
- $category_url = empty($id_category) ? '' : '&id_category='.(int)$id_category;
- PrestaShopLogger::addLog(sprintf($this->l('%s deletion', 'AdminTab', false, false), $this->className), 1, null, $this->className, (int)$object->id, true, (int)$this->context->employee->id);
- $this->redirect_after = self::$currentIndex.'&conf=1&token='.$this->token.$category_url;
- }
- else
- $this->errors[] = Tools::displayError('An error occurred during deletion.');
- }
- }
- }
- else
- $this->errors[] = Tools::displayError('An error occurred while deleting the object.').' <b>'.$this->table.'</b> '.Tools::displayError('(cannot load object)');
- }
- public function processImage()
- {
- $id_image = (int)Tools::getValue('id_image');
- $image = new Image((int)$id_image);
- if (Validate::isLoadedObject($image))
- {
- /* Update product image/legend */
- // @todo : move in processEditProductImage
- if (Tools::getIsset('editImage'))
- {
- if ($image->cover)
- $_POST['cover'] = 1;
- $_POST['id_image'] = $image->id;
- }
- /* Choose product cover image */
- elseif (Tools::getIsset('coverImage'))
- {
- Image::deleteCover($image->id_product);
- $image->cover = 1;
- if (!$image->update())
- $this->errors[] = Tools::displayError('You cannot change the product\'s cover image.');
- else
- {
- $productId = (int)Tools::getValue('id_product');
- @unlink(_PS_TMP_IMG_DIR_.'product_'.$productId.'.jpg');
- @unlink(_PS_TMP_IMG_DIR_.'product_mini_'.$productId.'_'.$this->context->shop->id.'.jpg');
- $this->redirect_after = self::$currentIndex.'&id_product='.$image->id_product.'&id_category='.(Tools::getIsset('id_category') ? '&id_category='.(int)Tools::getValue('id_category') : '').'&action=Images&addproduct'.'&token='.$this->token;
- }
- }
- /* Choose product image position */
- elseif (Tools::getIsset('imgPosition') && Tools::getIsset('imgDirection'))
- {
- $image->updatePosition(Tools::getValue('imgDirection'), Tools::getValue('imgPosition'));
- $this->redirect_after = self::$currentIndex.'&id_product='.$image->id_product.'&id_category='.(Tools::getIsset('id_category') ? '&id_category='.(int)Tools::getValue('id_category') : '').'&add'.$this->table.'&action=Images&token='.$this->token;
- }
- }
- else
- $this->errors[] = Tools::displayError('The image could not be found. ');
- }
- protected function processBulkDelete()
- {
- if ($this->tabAccess['delete'] === '1')
- {
- if (is_array($this->boxes) && !empty($this->boxes))
- {
- $object = new $this->className();
-
- if (isset($object->noZeroObject) &&
- // Check if all object will be deleted
- (count(call_user_func(array($this->className, $object->noZeroObject))) <= 1 || count($_POST[$this->table.'Box']) == count(call_user_func(array($this->className, $object->noZeroObject)))))
- $this->errors[] = Tools::displayError('You need at least one object.').' <b>'.$this->table.'</b><br />'.Tools::displayError('You cannot delete all of the items.');
- else
- {
- $success = 1;
- $products = Tools::getValue($this->table.'Box');
- if (is_array($products) && ($count = count($products)))
- {
- // Deleting products can be quite long on a cheap server. Let's say 1.5 seconds by product (I've seen it!).
- if (intval(ini_get('max_execution_time')) < round($count * 1.5))
- ini_set('max_execution_time', round($count * 1.5));
- if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'))
- $stock_manager = StockManagerFactory::getManager();
-
- foreach ($products as $id_product)
- {
- $product = new Product((int)$id_product);
- /*
- * @since 1.5.0
- * It is NOT possible to delete a product if there are currently:
- * - physical stock for this product
- * - supply order(s) for this product
- */
- if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $product->advanced_stock_management)
- {
- $physical_quantity = $stock_manager->getProductPhysicalQuantities($product->id, 0);
- $real_quantity = $stock_manager->getProductRealQuantities($product->id, 0);
- if ($physical_quantity > 0 || $real_quantity > $physical_quantity)
- $this->errors[] = sprintf(Tools::displayError('You cannot delete the product #%d because there is physical stock left.'), $product->id);
- }
- if (!count($this->errors))
- {
- if ($product->delete())
- PrestaShopLogger::addLog(sprintf($this->l('%s deletion', 'AdminTab', false, false), $this->className), 1, null, $this->className, (int)$product->id, true, (int)$this->context->employee->id);
- else
- $success = false;
- }
- else
- $success = 0;
- }
- }
-
- if ($success)
- {
- $id_category = (int)Tools::getValue('id_category');
- $category_url = empty($id_category) ? '' : '&id_category='.(int)$id_category;
- $this->redirect_after = self::$currentIndex.'&conf=2&token='.$this->token.$category_url;
- }
- else
- $this->errors[] = Tools::displayError('An error occurred while deleting this selection.');
- }
- }
- else
- $this->errors[] = Tools::displayError('You must select at least one element to delete.');
- }
- else
- $this->errors[] = Tools::displayError('You do not have permission to delete this.');
- }
- public function processProductAttribute()
- {
- // Don't process if the combination fields have not been submitted
- if (!Combination::isFeatureActive() || !Tools::getValue('attribute_combination_list'))
- return;
- if (Validate::isLoadedObject($product = $this->object))
- {
- if ($this->isProductFieldUpdated('attribute_price') && (!Tools::getIsset('attribute_price') || Tools::getIsset('attribute_price') == null))
- $this->errors[] = Tools::displayError('The price attribute is required.');
- if (!Tools::getIsset('attribute_combination_list') || Tools::isEmpty(Tools::getValue('attribute_combination_list')))
- $this->errors[] = Tools::displayError('You must add at least one attribute.');
-
- $array_checks = array(
- 'reference' => 'isReference',
- 'supplier_reference' => 'isReference',
- 'location' => 'isReference',
- 'ean13' => 'isEan13',
- 'upc' => 'isUpc',
- 'wholesale_price' => 'isPrice',
- 'price' => 'isPrice',
- 'ecotax' => 'isPrice',
- 'quantity' => 'isInt',
- 'weight' => 'isUnsignedFloat',
- 'unit_price_impact' => 'isPrice',
- 'default_on' => 'isBool',
- 'minimal_quantity' => 'isUnsignedInt',
- 'available_date' => 'isDateFormat'
- );
- foreach ($array_checks as $property => $check)
- if (Tools::getValue('attribute_'.$property) !== false && !call_user_func(array('Validate', $check), Tools::getValue('attribute_'.$property)))
- $this->errors[] = sprintf(Tools::displayError('Field %s is not valid'), $property);
- if (!count($this->errors))
- {
- if (!isset($_POST['attribute_wholesale_price'])) $_POST['attribute_wholesale_price'] = 0;
- if (!isset($_POST['attribute_price_impact'])) $_POST['attribute_price_impact'] = 0;
- if (!isset($_POST['attribute_weight_impact'])) $_POST['attribute_weight_impact'] = 0;
- if (!isset($_POST['attribute_ecotax'])) $_POST['attribute_ecotax'] = 0;
- if (Tools::getValue('attribute_default'))
- $product->deleteDefaultAttributes();
- // Change existing one
- if (($id_product_attribute = (int)Tools::getValue('id_product_attribute')) || ($id_product_attribute = $product->productAttributeExists(Tools::getValue('attribute_combination_list'), false, null, true, true)))
- {
- if ($this->tabAccess['edit'] === '1')
- {
- if ($this->isProductFieldUpdated('available_date_attribute') && (Tools::getValue('available_date_attribute') != '' &&!Validate::isDateFormat(Tools::getValue('available_date_attribute'))))
- $this->errors[] = Tools::displayError('Invalid date format.');
- else
- {
- $product->updateAttribute((int)$id_product_attribute,
- $this->isProductFieldUpdated('attribute_wholesale_price') ? Tools::getValue('attribute_wholesale_price') : null,
- $this->isProductFieldUpdated('attribute_price_impact') ? Tools::getValue('attribute_price') * Tools::getValue('attribute_price_impact') : null,
- $this->isProductFieldUpdated('attribute_weight_impact') ? Tools::getValue('attribute_weight') * Tools::getValue('attribute_weight_impact') : null,
- $this->isProductFieldUpdated('attribute_unit_impact') ? Tools::getValue('attribute_unity') * Tools::getValue('attribute_unit_impact') : null,
- $this->isProductFieldUpdated('attribute_ecotax') ? Tools::getValue('attribute_ecotax') : null,
- Tools::getValue('id_image_attr'),
- Tools::getValue('attribute_reference'),
- Tools::getValue('attribute_ean13'),
- $this->isProductFieldUpdated('attribute_default') ? Tools::getValue('attribute_default') : null,
- Tools::getValue('attribute_location'),
- Tools::getValue('attribute_upc'),
- $this->isProductFieldUpdated('attribute_minimal_quantity') ? Tools::getValue('attribute_minimal_quantity') : null,
- $this->isProductFieldUpdated('available_date_attribute') ? Tools::getValue('available_date_attribute') : null, false);
- StockAvailable::setProductDependsOnStock((int)$product->id, $product->depends_on_stock, null, (int)$id_product_attribute);
- StockAvailable::setProductOutOfStock((int)$product->id, $product->out_of_stock, null, (int)$id_product_attribute);
- }
- }
- else
- $this->errors[] = Tools::displayError('You do not have permission to add this.');
- }
- // Add new
- else
- {
- if ($this->tabAccess['add'] === '1')
- {
- if ($product->productAttributeExists(Tools::getValue('attribute_combination_list')))
- $this->errors[] = Tools::displayError('This combination already exists.');
- else
- {
- $id_product_attribute = $product->addCombinationEntity(
- Tools::getValue('attribute_wholesale_price'),
- Tools::getValue('attribute_price') * Tools::getValue('attribute_price_impact'),
- Tools::getValue('attribute_weight') * Tools::getValue('attribute_weight_impact'),
- Tools::getValue('attribute_unity') * Tools::getValue('attribute_unit_impact'),
- Tools::getValue('attribute_ecotax'),
- 0,
- Tools::getValue('id_image_attr'),
- Tools::getValue('attribute_reference'),
- null,
- Tools::getValue('attribute_ean13'),
- Tools::getValue('attribute_default'),
- Tools::getValue('attribute_location'),
- Tools::getValue('attribute_upc'),
- Tools::getValue('attribute_minimal_quantity'),
- Array(),
- Tools::getValue('available_date_attribute')
- );
- StockAvailable::setProductDependsOnStock((int)$product->id, $product->depends_on_stock, null, (int)$id_product_attribute);
- StockAvailable::setProductOutOfStock((int)$product->id, $product->out_of_stock, null, (int)$id_product_attribute);
- }
- }
- else
- $this->errors[] = Tools::displayError('You do not have permission to').'<hr>'.Tools::displayError('edit here.');
- }
- if (!count($this->errors))
- {
- $combination = new Combination((int)$id_product_attribute);
- $combination->setAttributes(Tools::getValue('attribute_combination_list'));
- // images could be deleted before
- $id_images = Tools::getValue('id_image_attr');
- if (!empty($id_images))
- $combination->setImages($id_images);
- $product->checkDefaultAttributes();
- if (Tools::getValue('attribute_default'))
- {
- Product::updateDefaultAttribute((int)$product->id);
- if(isset($id_product_attribute))
- $product->cache_default_attribute = (int)$id_product_attribute;
- if ($available_date = Tools::getValue('available_date_attribute'))
- $product->setAvailableDate($available_date);
- }
- }
- }
- }
- }
- public function processFeatures()
- {
- if (!Feature::isFeatureActive())
- return;
- if (Validate::isLoadedObject($product = new Product((int)Tools::getValue('id_product'))))
- {
- // delete all objects
- $product->deleteFeatures();
- // add new objects
- $languages = Language::getLanguages(false);
- foreach ($_POST as $key => $val)
- {
- if (preg_match('/^feature_([0-9]+)_value/i', $key, $match))
- {
- if ($val)
- $product->addFeaturesToDB($match[1], $val);
- else
- {
- if ($default_value = $this->checkFeatures($languages, $match[1]))
- {
- $id_value = $product->addFeaturesToDB($match[1], 0, 1);
- foreach ($languages as $language)
- {
- if ($cust = Tools::getValue('custom_'.$match[1].'_'.(int)$language['id_lang']))
- $product->addFeaturesCustomToDB($id_value, (int)$language['id_lang'], $cust);
- else
- $product->addFeaturesCustomToDB($id_value, (int)$language['id_lang'], $default_value);
- }
- }
- }
- }
- }
- }
- else
- $this->errors[] = Tools::displayError('A product must be created before adding features.');
- }
- /**
- * This function is never called at the moment (specific prices cannot be edited)
- */
- public function processPricesModification()
- {
- $id_specific_prices = Tools::getValue('spm_id_specific_price');
- $id_combinations = Tools::getValue('spm_id_product_attribute');
- $id_shops = Tools::getValue('spm_id_shop');
- $id_currencies = Tools::getValue('spm_id_currency');
- $id_countries = Tools::getValue('spm_id_country');
- $id_groups = Tools::getValue('spm_id_group');
- $id_customers = Tools::getValue('spm_id_customer');
- $prices = Tools::getValue('spm_price');
- $from_quantities = Tools::getValue('spm_from_quantity');
- $reductions = Tools::getValue('spm_reduction');
- $reduction_types = Tools::getValue('spm_reduction_type');
- $froms = Tools::getValue('spm_from');
- $tos = Tools::getValue('spm_to');
- foreach ($id_specific_prices as $key => $id_specific_price)
- if ($reduction_types[$key] == 'percentage' && ((float)$reductions[$key] <= 0 || (float)$reductions[$key] > 100))
- $this->errors[] = Tools::displayError('Submitted reduction value (0-100) is out-of-range');
- elseif ($this->_validateSpecificPrice($id_shops[$key], $id_currencies[$key], $id_countries[$key], $id_groups[$key], $id_customers[$key], $prices[$key], $from_quantities[$key], $reductions[$key], $reduction_types[$key], $froms[$key], $tos[$key], $id_combinations[$key]))
- {
- $specific_price = new SpecificPrice((int)($id_specific_price));
- $specific_price->id_shop = (int)$id_shops[$key];
- $specific_price->id_product_attribute = (int)$id_combinations[$key];
- $specific_price->id_currency = (int)($id_currencies[$key]);
- $specific_price->id_country = (int)($id_countries[$key]);
- $specific_price->id_group = (int)($id_groups[$key]);
- $specific_price->id_customer = (int)$id_customers[$key];
- $specific_price->price = (float)($prices[$key]);
- $specific_price->from_quantity = (int)($from_quantities[$key]);
- $specific_price->reduction = (float)($reduction_types[$key] == 'percentage' ? ($reductions[$key] / 100) : $reductions[$key]);
- $specific_price->reduction_type = !$reductions[$key] ? 'amount' : $reduction_types[$key];
- $specific_price->from = !$froms[$key] ? '0000-00-00 00:00:00' : $froms[$key];
- $specific_price->to = !$tos[$key] ? '0000-00-00 00:00:00' : $tos[$key];
- if (!$specific_price->update())
- $this->errors[] = Tools::displayError('An error occurred while updating the specific price.');
- }
- if (!count($this->errors))
- $this->redirect_after = self::$currentIndex.'&id_product='.(int)(Tools::getValue('id_product')).(Tools::getIsset('id_category') ? '&id_category='.(int)Tools::getValue('id_category') : '').'&update'.$this->table.'&action=Prices&token='.$this->token;
- }
- public function processPriceAddition()
- {
- // Check if a specific price has been submitted
- if (!Tools::getIsset('submitPriceAddition'))
- return;
- $id_product = Tools::getValue('id_product');
- $id_product_attribute = Tools::getValue('sp_id_product_attribute');
- $id_shop = Tools::getValue('sp_id_shop');
- $id_currency = Tools::getValue('sp_id_currency');
- $id_country = Tools::getValue('sp_id_country');
- $id_group = Tools::getValue('sp_id_group');
- $id_customer = Tools::getValue('sp_id_customer');
- $price = Tools::getValue('leave_bprice') ? '-1' : Tools::getValue('sp_price');
- $from_quantity = Tools::getValue('sp_from_quantity');
- $reduction = (float)(Tools::getValue('sp_reduction'));
- $reduction_type = !$reduction ? 'amount' : Tools::getValue('sp_reduction_type');
- $from = Tools::getValue('sp_from');
- if (!$from)
- $from = '0000-00-00 00:00:00';
- $to = Tools::getValue('sp_to');
- if (!$to)
- $to = '0000-00-00 00:00:00';
-
- if ($reduction_type == 'percentage' && ((float)$reduction <= 0 || (float)$reduction > 100))
- $this->errors[] = Tools::displayError('Submitted reduction value (0-100) is out-of-range');
- elseif ($this->_validateSpecificPrice($id_shop, $id_currency, $id_country, $id_group, $id_customer, $price, $from_quantity, $reduction, $reduction_type, $from, $to, $id_product_attribute))
- {
- $specificPrice = new SpecificPrice();
- $specificPrice->id_product = (int)$id_product;
- $specificPrice->id_product_attribute = (int)$id_product_attribute;
- $specificPrice->id_shop = (int)$id_shop;
- $specificPrice->id_currency = (int)($id_currency);
- $specificPrice->id_country = (int)($id_country);
- $specificPrice->id_group = (int)($id_group);
- $specificPrice->id_customer = (int)$id_customer;
- $specificPrice->price = (float)($price);
- $specificPrice->from_quantity = (int)($from_quantity);
- $specificPrice->reduction = (float)($reduction_type == 'percentage' ? $reduction / 100 : $reduction);
- $specificPrice->reduction_type = $reduction_type;
- $specificPrice->from = $from;
- $specificPrice->to = $to;
- if (!$specificPrice->add())
- $this->errors[] = Tools::displayError('An error occurred while updating the specific price.');
- }
- }
- public function ajaxProcessDeleteSpecificPrice()
- {
- if ($this->tabAccess['delete'] === '1')
- {
- $id_specific_price = (int)Tools::getValue('id_specific_price');
- if (!$id_specific_price || !Validate::isUnsignedId($id_specific_price))
- $error = Tools::displayError('The specific price ID is invalid.');
- else
- {
- $specificPrice = new SpecificPrice((int)$id_specific_price);
- if (!$specificPrice->delete())
- $error = Tools::displayError('An error occurred while attempting to delete the specific price.');
- }
- }
- else
- $error = Tools::displayError('You do not have permission to delete this.');
- if (isset($error))
- $json = array(
- 'status' => 'error',
- 'message'=> $error
- );
- else
- $json = array(
- 'status' => 'ok',
- 'message'=> $this->_conf[1]
- );
- die(Tools::jsonEncode($json));
- }
- public function processSpecificPricePriorities()
- {
- if (!($obj = $this->loadObject()))
- return;
- if (!$priorities = Tools::getValue('specificPricePriority'))
- $this->errors[] = Tools::displayError('Please specify priorities.');
- elseif (Tools::isSubmit('specificPricePriorityToAll'))
- {
- if (!SpecificPrice::setPriorities($priorities))
- $this->errors[] = Tools::displayError('An error occurred while updating priorities.');
- else
- $this->confirmations[] = $this->l('The price rule has successfully updated');
- }
- elseif (!SpecificPrice::setSpecificPriority((int)$obj->id, $priorities))
- $this->errors[] = Tools::displayError('An error occurred while setting priorities.');
- }
- public function processCustomizationConfiguration()
- {
- $product = $this->object;
- // Get the number of existing customization fields ($product->text_fields is the updated value, not the existing value)
- $current_customization = $product->getCustomizationFieldIds();
- $files_count = 0;
- $text_count = 0;
- if (is_array($current_customization))
- {
- foreach ($current_customization as $field)
- {
- if ($field['type'] == 1)
- $text_count++;
- else
- $files_count++;
- }
- }
- if (!$product->createLabels((int)$product->uploadable_files - $files_count, (int)$product->text_fields - $text_count))
- $this->errors[] = Tools::displayError('An error occurred while creating customization fields.');
- if (!count($this->errors) && !$product->updateLabels())
- $this->errors[] = Tools::displayError('An error occurred while updating customization fields.');
- $product->customizable = ($product->uploadable_files > 0 || $product->text_fields > 0) ? 1 : 0;
- if (!count($this->errors) && !$product->update())
- $this->errors[] = Tools::displayError('An error occurred while updating the custom configuration.');
- }
- public function processProductCustomization()
- {
- if (Validate::isLoadedObject($product = new Product((int)Tools::getValue('id_product'))))
- {
- foreach ($_POST as $field => $value)
- if (strncmp($field, 'label_', 6) == 0 && !Validate::isLabel($value))
- $this->errors[] = Tools::displayError('The label fields defined are invalid.');
- if (empty($this->errors) && !$product->updateLabels())
- $this->errors[] = Tools::displayError('An error occurred while updating customization fields.');
- if (empty($this->errors))
- $this->confirmations[] = $this->l('Update successful');
- }
- else
- $this->errors[] = Tools::displayError('A product must be created before adding customization.');
- }
- /**
- * Overrides parent for custom redirect link
- */
- public function processPosition()
- {
- if (!Validate::isLoadedObject($object = $this->loadObject()))
- {
- $this->errors[] = Tools::displayError('An error occurred while updating the status for an object.').
- ' <b>'.$this->table.'</b> '.Tools::displayError('(cannot load object)');
- }
- elseif (!$object->updatePosition((int)Tools::getValue('way'), (int)Tools::getValue('position')))
- $this->errors[] = Tools::displayError('Failed to update the position.');
- else
- {
- $category = new Category((int)Tools::getValue('id_category'));
- if (Validate::isLoadedObject($category))
- Hook::exec('actionCategoryUpdate', array('category' => $category));
- $this->redirect_after = self::$currentIndex.'&'.$this->table.'Orderby=position&'.$this->table.'Orderway=asc&action=Customization&conf=5'.(($id_category = (Tools::getIsset('id_category') ? (int)Tools::getValue('id_category') : '')) ? ('&id_category='.$id_category) : '').'&token='.Tools::getAdminTokenLite('AdminProducts');
- }
- }
- public function initProcess()
- {
- if (Tools::isSubmit('submitAddproductAndStay') || Tools::isSubmit('submitAddproduct'))
- {
- $this->id_object = (int)Tools::getValue('id_product');
- $this->object = new Product($this->id_object);
- if ((bool)$this->object->is_virtual && (int)Tools::getValue('type_product') != 2)
- {
- if (!($id_product_download = ProductDownload::getIdFromIdProduct($this->id_object)))
- $this->errors[] = Tools::displayError('Cannot retrieve file');
- else
- {
- $product_download = new ProductDownload((int)$id_product_download);
- if (!$product_download->deleteFile((int)$id_product_download))
- $this->errors[] = Tools::displayError('Cannot delete file');
- }
- }
- }
- // Delete a product in the download folder
- if (Tools::getValue('deleteVirtualProduct'))
- {
- if ($this->tabAccess['delete'] === '1')
- $this->action = 'deleteVirtualProduct';
- else
- $this->errors[] = Tools::displayError('You do not have permission to delete this.');
- }
- // Product preview
- elseif (Tools::isSubmit('submitAddProductAndPreview'))
- {
- $this->display = 'edit';
- $this->action = 'save';
- if (Tools::getValue('id_product'))
- {
- $this->id_object = Tools::getValue('id_product');
- $this->object = new Product((int)Tools::getValue('id_product'));
- }
- }
- elseif (Tools::isSubmit('submitAttachments'))
- {
- if ($this->tabAccess['edit'] === '1')
- {
- $this->action = 'attachments';
- $this->tab_display = 'attachments';
- }
- else
- $this->errors[] = Tools::displayError('You do not have permission to edit this.');
- }
- // Product duplication
- elseif (Tools::getIsset('duplicate'.$this->table))
- {
- if ($this->tabAccess['add'] === '1')
- $this->action = 'duplicate';
- else
- $this->errors[] = Tools::displayError('You do not have permission to add this.');
- }
- // Pro…
Large files files are truncated, but you can click here to view the full file