From 9963c84fd9fdc5b3d6fabe3fac52057fea9b4241 Mon Sep 17 00:00:00 2001 From: mMarinetti Date: Thu, 10 Nov 2011 14:57:54 +0000 Subject: [PATCH] // norms on AdminProductController // bugfix addfeaturestodb custom values // uses of smartyV3 features (createTemplate, createData) in AdminProducts + admin products forms now extends base form.tpl [+] BO : now tiny_mce can be loaded 'onclick' instead of 'onload' // improvement in adminproduct pages git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@10040 b9a71923-0436-4b27-9f14-aed3839534dd --- admin-dev/themes/template/footer.tpl | 39 +- .../themes/template/helper/form/form.tpl | 39 +- admin-dev/themes/template/products/form.tpl | 264 +++ admin-dev/themes/template/products/images.tpl | 133 +- .../themes/template/products/informations.tpl | 283 ++- .../template/products/input_text_lang.tpl | 10 + admin-dev/themes/template/products/prices.tpl | 55 +- .../template/products/textarea_lang.tpl | 16 + classes/AdminController.php | 57 +- classes/Helper.php | 4 +- controllers/admin/AdminProductsController.php | 2075 +++++++---------- js/jquery/ui/jquery.ui.datepicker.min.js | 2 +- js/tinymce.inc.js | 16 +- 13 files changed, 1626 insertions(+), 1367 deletions(-) create mode 100644 admin-dev/themes/template/products/form.tpl create mode 100644 admin-dev/themes/template/products/input_text_lang.tpl create mode 100644 admin-dev/themes/template/products/textarea_lang.tpl diff --git a/admin-dev/themes/template/footer.tpl b/admin-dev/themes/template/footer.tpl index a2079f88e..0b0ad5d3f 100644 --- a/admin-dev/themes/template/footer.tpl +++ b/admin-dev/themes/template/footer.tpl @@ -56,32 +56,39 @@ diff --git a/admin-dev/themes/template/helper/form/form.tpl b/admin-dev/themes/template/helper/form/form.tpl index 492f1902f..f3e77b01d 100644 --- a/admin-dev/themes/template/helper/form/form.tpl +++ b/admin-dev/themes/template/helper/form/form.tpl @@ -27,19 +27,23 @@ {if $firstCall} - + {/if} {block name="other_fieldsets"}{/block} +{/block} + + diff --git a/admin-dev/themes/template/products/form.tpl b/admin-dev/themes/template/products/form.tpl new file mode 100644 index 000000000..fefe7b3d6 --- /dev/null +++ b/admin-dev/themes/template/products/form.tpl @@ -0,0 +1,264 @@ +{* +* 2007-2011 PrestaShop +* +* NOTICE OF LICENSE +* +* This source file is subject to the Academic Free License (AFL 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/afl-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 +* @copyright 2007-2011 PrestaShop SA +* @version Release: $Revision$ +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} +{extends file="helper/form/form.tpl"} +{block name="script"} + + + + + + + +{***********************************************} +{********** TO CHECK !!!!!!!!!!!!!!! ***********} + + + +
+ + +
+{if !$product->active} +
+

+ + {l s='Your product will be saved as draft'} + {l s='Save and preview'} + +
+

+
+{/if} +{* all input are here *} + + {if !$newproduct} + {foreach $product_tabs key=numStep item=tab} +
+ {if $tab.selected}{$custom_form}{/if} +
+ {/foreach} + {else} +
{$custom_form}
+ {/if} +
+ +
+ +
+{/block} +{*a href="{$link->getAdminLink('AdminCatalog')}">{l s='Back to list'}
+*} + diff --git a/admin-dev/themes/template/products/images.tpl b/admin-dev/themes/template/products/images.tpl index 4909b9d56..20d74293e 100644 --- a/admin-dev/themes/template/products/images.tpl +++ b/admin-dev/themes/template/products/images.tpl @@ -1,25 +1,26 @@
-

2. {l s='Images'} ({$countImages})

- +

2. {l s='Images'} ({$countImages})

+
-
{if isset($id_image)}{l s='Edit this product image'}{else}{l s='Add a new image to this product'}{/if}
-

- - - - + + + + + + + + +
-
- -
-
- -
    - - + {firebug value=$product} + -{$content} +

    + {l s='Format:'} JPG, GIF, PNG. {l s='Filesize:'} {$max_image_size / 1000}{l s='Kb max.'} +

    +
    + + {if Tools::getValue('id_image')}{/if} +
    + + + + + + + + {if $shops} + + {foreach from=$shops item=shop} + + {/foreach} + {/if} + + + + + {foreach from=$images item=image} + + + + + {foreach from=$shops item=shop} + + {/foreach} + + + + +{/foreach} +
    {l s='Image'} {l s='Position'}{$shop.name}{l s='Cover'}{l s='Action'}
    + + {$image->id} - {$image->legend|htmlentitiesUTF8} + + {$image->position} + position}style="display: none;"{/if} href="{$currentIndex}&id_image={$image->id_image}&imgPosition={$image->position -1}&imgDirection=0&token={$token}"> + + + position} == $imagesTotal} style="display: none;"{/if} href="{$currentIndex}&id_image={$image->id_image}&imgPosition={$image->position+1}&imgDirection=1&token={$token}"> + + + + isAssociatedToShop($shop.id_shop)}checked="checked"{/if} /> + + e + + + {l s='Delete this image'} + +
    +
    +
    + diff --git a/admin-dev/themes/template/products/informations.tpl b/admin-dev/themes/template/products/informations.tpl index fe58d7c48..ec52ca08d 100644 --- a/admin-dev/themes/template/products/informations.tpl +++ b/admin-dev/themes/template/products/informations.tpl @@ -92,7 +92,7 @@
    * + value="{$product->name[$language.id_lang]|htmlentitiesUTF8|default:''}"/> * {l s='Invalid characters:'} <>;=#{} 
    @@ -683,8 +683,287 @@ $(document).ready(function(){ {* [end] prices *} + +
    + {if !$ps_stock_management} + + {l s='The stock management is disabled'} + + {/if} + {if !$has_attribute} + + + + +

    {l s='The minimum quantity to buy this product (set to 1 to disable this feature)'}

    + + + {/if} +
    + + + {$currency->prefix}{$currency->suffix} + {if $country_display_tax_label}{l s='tax excl.'}{/if} +

    {l s='Carrier tax will be applied.'}

    + + + + + + {include file="products/input_text_lang.tpl" + languages=$languages + input_value=$product->available_now + input_name='available_now'} + {l s='Forbidden characters:'} <>;=#{}  + + + + + + {include file="products/input_text_lang.tpl" + languages=$languages + input_value=$product->available_later + input_name='available_later'} + {l s='Forbidden characters:'} <>;=#{}  + + + {if $countAttributes} + +{* .(($this->getFieldValue($product, 'available_date') != 0) ? stripslashes(htmlentities(Tools::displayDate($this->getFieldValue($product, 'available_date'), $language['id_lang']))) : '0000-00-00').'" *} + + + + +

    {l s='The available date when this product is out of stock'}

    + + + {/if} + + + + + out_of_stock == 0}checked="checked"{/if} /> + +
    out_of_stock == 1}checked="checked"{/if} /> + +
    out_of_stock == 2}checked="checked"{/if} /> + + + + + +
    + + + + + + + + + + + + {$category_tree} +
    +{************** DESCRIPTION *****************************} + + {l s='SEO'}{l s='Click here to improve product\'s rank in search engines (SEO)'}
    + + +
    + + + + {include file="products/textarea_lang.tpl" + languages=$languages + input_name='description_short' + input_value=$product->description_short} + +

    + + + + + + {include file="products/textarea_lang.tpl" languages=$languages + input_name='description' + input_value=$product->description + } +

    + + + +{if $images} + + + + +
    + {l s='Do you want an image associated with the product in your description?'} + {l s='Click here'}. + + + + + + + + + + + + + + + + + + + + + + +
    +

    + + + + +{/if} +{$last_content} + + + diff --git a/admin-dev/themes/template/products/input_text_lang.tpl b/admin-dev/themes/template/products/input_text_lang.tpl new file mode 100644 index 000000000..4508c1e96 --- /dev/null +++ b/admin-dev/themes/template/products/input_text_lang.tpl @@ -0,0 +1,10 @@ +
    +{foreach from=$languages item=language} +
    + +
    +{/foreach} +
    diff --git a/admin-dev/themes/template/products/prices.tpl b/admin-dev/themes/template/products/prices.tpl index 9246b35ac..d2d7c9b83 100644 --- a/admin-dev/themes/template/products/prices.tpl +++ b/admin-dev/themes/template/products/prices.tpl @@ -18,8 +18,8 @@ var product_prices = new Array(); > > @@ -66,7 +66,8 @@ var product_prices = new Array(); }); $('.datepicker').datepicker({ prevText: '', - nextText: '' + nextText: '', + dateFormat: 'yy-mm-dd' }); }); @@ -76,4 +77,50 @@ var product_prices = new Array(); {l s='(tax excl.):'} {/if} -{$content} +
    + {$currency->prefix} + + {$currency->suffix} + ({l s='Current:'} '.Tools::displayPrice((float)($product->price), $defaultCurrency).' ) +
    + {l s='You can set this value at 0 in order to apply the default price'} +
    +
    + + +
    + + + {l s='(if set to "amount", the tax is included)'} +
    + +
    + +
    + +
    +
    +

    {l s='Current specific prices'}

    + + + + + + + + + + + + + + + + + + {$specificPriceModificationForm} + diff --git a/admin-dev/themes/template/products/textarea_lang.tpl b/admin-dev/themes/template/products/textarea_lang.tpl new file mode 100644 index 000000000..7a8e05cc2 --- /dev/null +++ b/admin-dev/themes/template/products/textarea_lang.tpl @@ -0,0 +1,16 @@ +
    +{foreach from=$languages item=language} +
    + + {$hint|default:''}  +
    +{/foreach} +
    + diff --git a/classes/AdminController.php b/classes/AdminController.php index dd371bd36..1dc387abc 100644 --- a/classes/AdminController.php +++ b/classes/AdminController.php @@ -832,54 +832,6 @@ class AdminControllerCore extends Controller $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); } - /** - * Display form - */ - public function displayForm($first_call = true) - { - $content = ''; - $content .= $this->initForm(); - $allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0; - - if ($allow_employee_form_lang && !$this->context->cookie->employee_form_lang) - $this->context->cookie->employee_form_lang = (int)Configuration::get('PS_LANG_DEFAULT'); - - $use_lang_from_cookie = false; - $this->_languages = Language::getLanguages(false); - - if ($allow_employee_form_lang) - foreach ($this->_languages as $lang) - if ($this->context->cookie->employee_form_lang == $lang['id_lang']) - $use_lang_from_cookie = true; - - if (!$use_lang_from_cookie) - $this->_defaultFormLanguage = (int)Configuration::get('PS_LANG_DEFAULT'); - else - $this->_defaultFormLanguage = (int)$this->context->cookie->employee_form_lang; - - // Only if it is the first call to displayForm, otherwise it has already been defined - if ($first_call) - { - // language related - $content .= ' - '; - } - return $content; - } /** * assign default action in toolbar_btn smarty var, if they are not set. @@ -1384,6 +1336,7 @@ class AdminControllerCore extends Controller $helper->identifier = $this->identifier; $helper->override_folder = $this->tpl_folder; $helper->token = $this->token; + $helper->languages = $this->_languages; $helper->specificConfirmDelete = $this->specificConfirmDelete; $helper->imageType = $this->imageType; $helper->no_link = $this->list_no_link; @@ -1411,7 +1364,6 @@ class AdminControllerCore extends Controller $helper = new HelperForm($this); $helper->override_folder = $this->tpl_folder; $this->setHelperDisplay($helper); - $helper->languages = $this->_languages; $helper->default_form_language = $this->default_form_language; $helper->allow_employee_form_lang = $this->allow_employee_form_lang; $helper->fields_value = $this->getFieldsValue($this->object); @@ -1891,6 +1843,11 @@ class AdminControllerCore extends Controller $this->default_form_language = (int)Configuration::get('PS_LANG_DEFAULT'); else $this->default_form_language = (int)$cookie->employee_form_lang; + + foreach ($this->_languages as $k => $language) + $this->_languages[$k]['is_default'] = (int)($language['id_lang'] == $this->default_form_language); + + return $this->_languages; } public function getFieldsValue($obj) @@ -2332,7 +2289,7 @@ EOF; return false; // Check image validity - $max_size = isset($this->maxImageSize) ? $this->maxImageSize : 0; + $max_size = isset($this->max_image_size) ? $this->max_image_size : 0; if ($error = checkImage($_FILES[$name], Tools::getMaxUploadSize($max_size))) $this->_errors[] = $error; else if (!$tmp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS') || !move_uploaded_file($_FILES[$name]['tmp_name'], $tmp_name)) diff --git a/classes/Helper.php b/classes/Helper.php index a90825194..f3e04f9e0 100755 --- a/classes/Helper.php +++ b/classes/Helper.php @@ -66,10 +66,10 @@ class HelperCore $this->context = Context::getContext(); } - /*public function setTpl($tpl) + public function setTpl($tpl) { $this->tpl = $this->createTemplate($tpl); - }*/ + } /** * Create a template from the override file, else from the base file. diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index c8b3f1694..25b137e0a 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -27,22 +27,22 @@ class AdminProductsController extends AdminController { - protected $maxFileSize = 20000000; + protected $max_file_size = 20000000; /** @var integer Max image size for upload * As of 1.5 it is recommended to not set a limit to max image size **/ - protected $maxImageSize; + protected $max_image_size; private $_category; protected $available_tabs = array( - 'Informations', - 'Images', - 'Prices', - 'Combinations', - 'Features', - 'Customization', - 'Attachments', + 'Informations', + 'Images', + 'Prices', + 'Combinations', + 'Features', + 'Customization', + 'Attachments', 'Quantities', 'Accounting'); @@ -60,14 +60,19 @@ class AdminProductsController extends AdminController $this->fieldsDisplay = array( 'id_product' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 20), - 'image' => array('title' => $this->l('Photo'), 'align' => 'center', 'image' => 'p', 'width' => 70, 'orderby' => false, 'filter' => false, 'search' => false), + 'image' => array('title' => $this->l('Photo'), 'align' => 'center', 'image' => 'p', + 'width' => 70, 'orderby' => false, 'filter' => false, 'search' => false), 'name' => array('title' => $this->l('Name'), 'filter_key' => 'b!name'), 'reference' => array('title' => $this->l('Reference'), 'align' => 'center', 'width' => 80), 'name_category' => array('title' => $this->l('Category'), 'width' => 100, 'filter_key' => 'cl!name'), - 'price' => array('title' => $this->l('Base price'), 'width' => 70, 'type' => 'price', 'align' => 'right', 'filter_key' => 'a!price'), - 'price_final' => array('title' => $this->l('Final price'), 'width' => 70, 'type' => 'price', 'align' => 'right', 'havingFilter' => true, 'orderby' => false), - 'active' => array('title' => $this->l('Displayed'), 'width' => 70, 'active' => 'status', 'filter_key' => 'a!active', 'align' => 'center', 'type' => 'bool', 'orderby' => false), - 'position' => array('title' => $this->l('Position'), 'width' => 70,'filter_key' => 'cp!position', 'align' => 'center', 'position' => 'position'), + 'price' => array('title' => $this->l('Base price'), 'width' => 70, + 'type' => 'price', 'align' => 'right', 'filter_key' => 'a!price'), + 'price_final' => array('title' => $this->l('Final price'), 'width' => 70, + 'type' => 'price', 'align' => 'right', 'havingFilter' => true, 'orderby' => false), + 'active' => array('title' => $this->l('Displayed'), 'width' => 70, 'active' => 'status', + 'filter_key' => 'a!active', 'align' => 'center', 'type' => 'bool', 'orderby' => false), + 'position' => array('title' => $this->l('Position'), 'width' => 70,'filter_key' => 'cp!position', + 'align' => 'center', 'position' => 'position'), ); /* Join categories table */ @@ -80,9 +85,10 @@ class AdminProductsController extends AdminController LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (a.`id_category_default` = cl.`id_category` AND b.`id_lang` = cl.`id_lang`) LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = a.`id_product` AND i.`cover` = 1) LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_product` = a.`id_product`) - LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (a.`id_tax_rules_group` = tr.`id_tax_rules_group` AND tr.`id_country` = '.(int)$this->context->country->id.' AND tr.`id_state` = 0) + LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (a.`id_tax_rules_group` = tr.`id_tax_rules_group` + AND tr.`id_country` = '.(int)$this->context->country->id.' AND tr.`id_state` = 0) LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`)'; - $this->_filter = 'AND cp.`id_category` = '.(int)($this->_category->id); + $this->_filter = 'AND cp.`id_category` = '.(int)$this->_category->id; $this->_select = 'cl.name `name_category`, cp.`position`, i.`id_image`, (a.`price` * ((100 + (t.`rate`))/100)) AS price_final'; parent::__construct(); @@ -116,7 +122,8 @@ class AdminProductsController extends AdminController 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']])); + $_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']); @@ -127,8 +134,8 @@ class AdminProductsController extends AdminController $object->unit_price = str_replace(',', '.', $_POST['unit_price']); if (array_key_exists('ecotax', $_POST) && $_POST['ecotax'] != null) $object->ecotax = str_replace(',', '.', $_POST['ecotax']); - $object->available_for_order = (int)(Tools::isSubmit('available_for_order')); - $object->show_price = $object->available_for_order ? 1 : (int)(Tools::isSubmit('show_price')); + $object->available_for_order = (int)Tools::isSubmit('available_for_order'); + $object->show_price = $object->available_for_order ? 1 : (int)Tools::isSubmit('show_price'); $object->on_sale = Tools::isSubmit('on_sale'); $object->online_only = Tools::isSubmit('online_only'); } @@ -483,8 +490,6 @@ class AdminProductsController extends AdminController if (isset($image->legend[$language['id_lang']])) $_POST['legend_'.$language['id_lang']] = $image->legend[$language['id_lang']]; $_POST['id_image'] = $image->id; - // @todo in postProcess, we should avoid displayForm - $this->content .= $this->displayForm(); } /* Choose product cover image */ @@ -723,7 +728,7 @@ class AdminProductsController extends AdminController { if ($default_value = $this->checkFeatures($languages, $match[1])) { - $id_value = $product->addFeaturesToDB($match[1], 0, 1, (int)$language['id_lang']); + $id_value = $product->addFeaturesToDB($match[1], 0, 1); foreach ($languages as $language) { if ($cust = Tools::getValue('custom_'.$match[1].'_'.(int)$language['id_lang'])) @@ -732,6 +737,8 @@ class AdminProductsController extends AdminController $product->addFeaturesCustomToDB($id_value, (int)$language['id_lang'], $default_value); } } + else + $id_value = $product->addFeaturesToDB($match[1], 0, 1); } } } @@ -931,7 +938,7 @@ class AdminProductsController extends AdminController self::$currentIndex = 'index.php?tab=AdminProducts'; $allowedExtensions = array("jpeg", "gif", "png", "jpg"); // max file size in bytes - $sizeLimit = $this->maxFileSize; + $sizeLimit = $this->max_file_size; $uploader = new FileUploader($allowedExtensions, $sizeLimit); $result = $uploader->handleUpload(); if (isset($result['success'])) @@ -1527,22 +1534,48 @@ if (false) { if (Tools::getValue('id_product') || ((Tools::isSubmit('submitAddproduct') OR Tools::isSubmit('submitAddproductAndPreview') OR Tools::isSubmit('submitAddproductAndStay') OR Tools::isSubmit('submitSpecificPricePriorities') OR Tools::isSubmit('submitPriceAddition') OR Tools::isSubmit('submitPricesModification')) AND sizeof($this->_errors)) OR Tools::isSubmit('updateproduct') OR Tools::isSubmit('addproduct')) { + $this->fields_form = array(); + if (empty($this->action) || !method_exists($this, 'initForm'.$this->action)) + $this->action = 'Informations'; + + $this->tpl_form = 'products/'.strtolower($this->action).'.tpl'; if ($this->ajax) { - if ($this->action && method_exists($this, 'initForm'.$this->action)) - { - $this->template = 'products/'.strtolower($this->action).'.tpl'; - $this->content_only = true; - $languages = Language::getLanguages(false); - $defaultLanguage = (int)(Configuration::get('PS_LANG_DEFAULT')); - $product = new Product((int)(Tools::getValue('id_product'))); - $this->initForm(); - $this->{'initForm'.$this->action}($product, $languages, $defaultLanguage); - $this->context->smarty->assign('product', $product); - } + $this->display = 'edit'; + $this->content_only = true; } else - $this->displayForm(); + { + $product_tabs = array(); + // action defines which tab to display first + $action = $this->action; + if (empty($action) || !method_exists($this, 'initForm'.$action)) + $action = 'Informations'; + if(Tools::getValue('id_product')) + { + // i is used as producttab id + $i = 0; + foreach($this->available_tabs as $product_tab) + { + $product_tabs[$product_tab] = array( + 'id' => ++$i, + 'selected' => (strtolower($product_tab) == strtolower($action)), + // @todo $this->l() instead of product_tab + 'name' => $product_tab, + 'href' => $this->context->link->getAdminLink('AdminProducts').'&id_product='.Tools::getValue('id_product').'&action='.$product_tab, + ); + } + $this->tpl_form_vars['newproduct'] = 0; + } + else + $this->tpl_form_vars['newproduct'] = 1; + + $this->tpl_form_vars['product_tabs'] = $product_tabs; + } + + + $languages = Language::getLanguages(false); + $defaultLanguage = (int)(Configuration::get('PS_LANG_DEFAULT')); } else { @@ -1567,20 +1600,9 @@ if (false) $category_tree[] = $categ; } $this->tpl_list_vars['category_tree'] = $category_tree; - $this->content .= ' - '; - //////////////////////// - $this->l('in category').' "'.stripslashes($this->_category->getName()).'"'; - $this->content .= '
    '; - // $this->displayList($token); -// $this->display = 'list'; - $this->content .= '
    '; } + // @todo module free + $this->tpl_form_vars['vat_number'] = file_exists(_PS_MODULE_DIR_.'vatnumber/ajax.php'); parent::initContent(); } @@ -1704,7 +1726,7 @@ if (false)

    '; - $this->context->smarty->assign('draft_warning',$content); + $this->tpl_form_vars['draft_warning'] = $content; } public function initToolbar() @@ -1754,6 +1776,8 @@ if (false) ); } parent::initToolbar(); + $this->context->smarty->assign('toolbar_fix', 1); + $this->context->smarty->assign('show_toolbar', 1); $this->context->smarty->assign('toolbar_btn', $this->toolbar_btn); } @@ -1764,63 +1788,54 @@ if (false) */ public function initForm() { + $product = $this->object = new Product((int)(Tools::getValue('id_product'))); + // getLanguages init this->_languages + $this->getLanguages(); + $languages = $this->_languages; + $defaultLanguage = (int)(Configuration::get('PS_LANG_DEFAULT')); + + $this->tpl_form_vars['currentIndex'] = self::$currentIndex; + $this->fields_form = array("pouet"=>"eh oui"); + $this->addJs(_PS_JS_DIR_.'attributesBack.js'); $this->display = 'edit'; $this->addJqueryUI('ui.datepicker'); - $this->context->smarty->assign('pos_select', (($tab = Tools::getValue('tabs')) ? $tab : '0')); - $this->context->smarty->assign('token',$this->token); - $this->context->smarty->assign('combinationImagesJs', $this->getCombinationImagesJs()); + $this->tpl_form_vars['pos_select'] = ($tab = Tools::getValue('tabs')) ? $tab : '0'; + $this->tpl_form_vars['token'] = $this->token; + $this->tpl_form_vars['combinationImagesJs'] = $this->getCombinationImagesJs(); $id_product = Tools::getvalue('id_product'); - $this->context->smarty->assign('form_action', $this->context->link->getAdminLink('AdminProducts').'&id_product='.$id_product); - $this->context->smarty->assign('id_product',$id_product); + $this->tpl_form_vars['form_action'] = $this->context->link->getAdminLink('AdminProducts').'&id_product='.$id_product; + $this->tpl_form_vars['id_product'] = $id_product; - $this->context->smarty->assign('upload_max_filesize', ini_get('upload_max_filesize')); - $this->context->smarty->assign('country_display_tax_label', $this->context->country->display_tax_label); + $this->tpl_form_vars['upload_max_filesize'] = ini_get('upload_max_filesize'); + $this->tpl_form_vars['country_display_tax_label'] = $this->context->country->display_tax_label; // let's calculate this once for all if (!($obj = $this->loadObject(true))) throw new PrestashopException('object not loaded'); $this->_displayDraftWarning($obj->active); + $this->{'initForm'.$this->action}($this->object, $languages, $defaultLanguage); + $this->tpl_form_vars['product'] = $this->object; + if ($this->ajax) + if (empty($this->tpl_form_vars['custom_form'])) + throw new PrestashopException('custom_form empty for action '.$this->action); + else + return $this->tpl_form_vars['custom_form']; return parent::initForm(); } - public function displayForm($isMainTab = true) + public function getPreviewUrl(Product $product) { - $content = ''; - parent::displayForm(); - $this->addJs(_PS_JS_DIR_.'attributesBack.js'); - if (!($product = $this->loadObject(true))) - throw new PrestashopException('object not loaded'); - $smarty = $this->context->smarty; - $product_tabs = array(); - // action defines which tab to display first - $action = $this->action; - if (empty($action) || !method_exists($this,'initForm'.$action)) - $action = 'Informations'; - if(Tools::getValue('id_product')) - { - // i is used as producttab id - $i = 0; - foreach($this->available_tabs as $product_tab) - { - $endurl = '&id_product='.Tools::getValue('id_product').'&action='.$product_tab; - $product_tabs[$product_tab] = array( - 'id' => ++$i, - 'selected' => (strtolower($product_tab) == strtolower($action)), - // @todo $this->l() instead of product_tab - 'name' => $product_tab, - 'href' => $this->context->link->getAdminLink('AdminProducts').$endurl, - ); - } - $smarty->assign('newproduct', 0); - } - else - $smarty->assign('newproduct', 1); - - $smarty->assign('product_tabs', $product_tabs); - - $preview_url = ''; - if (isset($product->id)) + $preview_url = $this->context->link->getProductLink( + $this->getFieldValue($product, 'id'), + $this->getFieldValue($product, 'link_rewrite', $this->context->language->id), + Category::getLinkRewrite($product->id_category_default, $this->context->language->id), null, null, Context::getContext()->shop->getID()); + if (!$product->active) { + $admin_dir = dirname($_SERVER['PHP_SELF']); + $admin_dir = substr($admin_dir, strrpos($admin_dir,'/') + 1); + $token = Tools::encrypt('PreviewProduct'.$product->id); + if (strpos($preview_url, '?') === false) + $preview_url .= '?'; $preview_url = ($this->context->link->getProductLink($this->getFieldValue($product, 'id'), $this->getFieldValue($product, 'link_rewrite', $this->_defaultFormLanguage), Category::getLinkRewrite($this->getFieldValue($product, 'id_category_default'), $this->context->language->id))); if (!$product->active) { @@ -1829,93 +1844,10 @@ if (false) $token = Tools::encrypt('PreviewProduct'.$product->id); $preview_url .= $product->active ? '' : '&adtoken='.$token.'&ad='.$admin_dir; - $smarty->assign('preview_url', $preview_url); } } - if($this->tabAccess['delete']) - $available_btn['delete'] = array( - 'short' => 'Delete', - 'href' => $this->context->link->getAdminLink('AdminProducts').'&id_product='.$product->id.'&deleteproduct', - 'desc' => $this->l('Delete this product'), - 'confirm' => 1); - - if($this->tabAccess['add']) - $available_btn['duplicate'] = array( - 'short' => 'Duplicate', - 'href' => '#todo'.$this->context->link->getAdminLink('AdminProducts').'&id_product='.$product->id, 'desc' => $this->l('Duplicate this product'), - 'confirm' => 1 - ); -// @TODO navigation - $available_btn['preview'] = array( - 'short' => 'Preview', - 'href' => $preview_url, 'desc' => 'prevdesc', - ); - if (file_exists(_PS_MODULE_DIR_.'statsproduct/statsproduct.php')) - $available_btn['stats'] = array( - 'short' => 'Statistics', - 'href' => $this->context->link->getAdminLink('AdminStats').'&module=statsproduct&id_product='.$product->id, - 'desc' => $this->l('View product sales'), - ); - - $available_btn['cancel'] = array( - 'short' => 'Close', - 'href' => '#todo'.$this->context->link->getAdminLink('AdminProducts').'&id_product='.$product->id, 'desc' => $this->l('Cancel modification'), - 'confirm' => 1); - if($this->tabAccess['add']) - $available_btn['new'] = array( - 'short' => 'Create', - 'href' => '#todo'.$this->context->link->getAdminLink('AdminProducts').'&id_product='.$product->id, 'desc' => $this->l('Create new product'), - ); - if($this->tabAccess['edit']) - $available_btn['save'] = array( - 'short' => 'Save', - 'href' => '#todo'.$this->context->link->getAdminLink('AdminProducts').'&id_product='.$product->id, 'desc' => $this->l('Save your modifications'), - ); - - $smarty->assign('available_btn', $available_btn); - - if ($id_category_back = (int)(Tools::getValue('id_category'))) - self::$currentIndex .= '&id_category='.$id_category_back; - - if (!($product = $this->loadObject(true))) - return; - - $currency = Tools::setCurrency($this->context->cookie); -// if ($product->id) -// self::$currentIndex .= '&id_product='.$product->id; - - - // $this->addJqueryPlugin('tabpane'); - - $content .= $this->initForm(); - $this->{'initForm'.$action}($product, null); - /* Tabs */ -/* -switch ($this->action) - { - default: - $this->initFormInformations($product, $currency); -// $this->initFormImages($product, $this->token); - } - */ - if (Combination::isFeatureActive()) - $smarty->assign('countAttributes', Db::getInstance()->getValue('SELECT COUNT(id_product) FROM '._DB_PREFIX_.'product_attribute WHERE id_product = '.(int)$product->id)); - - $smarty->assign('countAttachments', Db::getInstance()->getValue('SELECT COUNT(id_product) FROM '._DB_PREFIX_.'product_attachment WHERE id_product = '.(int)$product->id)); - - if (Tools::getValue('id_category') > 1) - { - $productIndex = preg_replace('/(&id_product=[0-9]*)/', '', self::$currentIndex); -/** @TODO - $this->content .= ' -

    - - '.$this->l('Back to the category').' -
    '; -*/ - } + return $preview_url; } - /** * Post traitment for accounting */ @@ -1983,15 +1915,16 @@ switch ($this->action) public function initFormPrices($obj, $languages, $defaultLanguage) { - $content = ''; - if ($obj->id) + $data = $this->context->smarty->createData(); + + if ($this->object->id) { $shops = Shop::getShops(); $countries = Country::getCountries($this->context->language->id); $groups = Group::getGroups($this->context->language->id); $currencies = Currency::getCurrencies(); $currency = - $attributes = $obj->getAttributesGroups((int)$this->context->language->id); + $attributes = $this->object->getAttributesGroups((int)$this->context->language->id); $combinations = array(); foreach($attributes as $attribute) { @@ -2000,28 +1933,29 @@ switch ($this->action) $combinations[$attribute['id_product_attribute']]['attributes'] = ''; $combinations[$attribute['id_product_attribute']]['attributes'] .= $attribute['attribute_name'].' - '; - $combinations[$attribute['id_product_attribute']]['price'] = Tools::displayPrice(Tools::convertPrice(Product::getPriceStatic((int)$obj->id, false, $attribute['id_product_attribute']), $this->context->currency), $this->context->currency); + $combinations[$attribute['id_product_attribute']]['price'] = Tools::displayPrice(Tools::convertPrice(Product::getPriceStatic((int)$this->object->id, false, $attribute['id_product_attribute']), $this->context->currency), $this->context->currency); } foreach ($combinations as &$combination) $combination['attributes'] = rtrim($combination['attributes'], ' - '); - $this->context->smarty->assign(array( - 'shops' => $shops, - 'currencies' => $currencies, - 'countries' => $countries, - 'groups' => $groups, - 'combinations' => $combinations, - 'product' => $obj - ) - ); + $data->assign(array( + 'shops' => $shops, + 'currencies' => $currencies, + 'countries' => $countries, + 'groups' => $groups, + 'combinations' => $combinations, + 'product' => $this->object + )); - $content .= $this->_displaySpecificPriceAdditionForm($this->context->currency, $shops, $currencies, $countries, $groups); - $content .= $this->_displaySpecificPriceModificationForm($this->context->currency, $shops, $currencies, $countries, $groups); + $data->assign('country_display_tax_label', $this->context->country->display_tax_label); + $data->assign('specificPriceModificationForm', $this->_displaySpecificPriceModificationForm($this->context->currency, $shops, $currencies, $countries, $groups)); } else - $content .= ''.$this->l('You must save this product before adding specific prices').'.'; - $this->context->smarty->assign('content',$content); - $this->content = $this->context->smarty->fetch('products/prices.tpl'); + $data->assign('content', ''.$this->l('You must save this product before adding specific prices').'.'); + + $data->assign('currency', $this->context->currency); + + $this->tpl_form_vars['custom_form'] = $this->context->smarty->createTemplate($this->tpl_form, $data)->fetch(); } private function _getFinalPrice($specificPrice, $productPrice, $taxRate) @@ -2061,26 +1995,6 @@ switch ($this->action) $tmp[$group['id_group']] = $group; $groups = $tmp; - $content .= ' -

    '.$this->l('Current specific prices').'

    - -
    {l s='Combination'}{l s='Shop'}{l s='Currency'}{l s='Country'}{l s='Group'}{l s='Price'} {if $country_display_tax_label}{l s='(tax excl)'}{/if}{l s='Reduction'}{l s='Period'}{l s='From (quantity)'}{l s='Final price'} {if $country_display_tax_label}{l s='(tax excl.)'}{/if}{l s='Action'}
    - - - - - - - - - - - - - - - - '; if (!is_array($specificPrices) || !sizeof($specificPrices)) $content .= ' @@ -2200,42 +2114,6 @@ switch ($this->action) return $content; } - protected function _displaySpecificPriceAdditionForm($defaultCurrency, $shops, $currencies, $countries, $groups) - { - if (!($product = $this->loadObject())) - return; - $content = ''; - - $content .= ' -
    - '.($defaultCurrency->format == 1 ? ' '.$defaultCurrency->sign : '').' - - '.($defaultCurrency->format == 2 ? ' '.$defaultCurrency->sign : '').' - ('.$this->l('Current:').' '.Tools::displayPrice((float)($product->price), $defaultCurrency).' ) -
    - '.$this->l('You can set this value at 0 in order to apply the default price').' -
    -
    - - -
    - - - '.$this->l('(if set to "amount", the tax is included)').' -
    - -
    - -
    - -
    - '; - return $content; - } private function _getCustomizationFieldIds($labels, $alreadyGenerated, $obj) { @@ -2257,46 +2135,50 @@ switch ($this->action) private function _displayLabelField(&$label, $languages, $defaultLanguage, $type, $fieldIds, $id_customization_field) { + $content = ''; $fieldsName = 'label_'.$type.'_'.(int)($id_customization_field); $fieldsContainerName = 'labelContainer_'.$type.'_'.(int)($id_customization_field); - $this->content .= '
    '; + $content .= '
    '; foreach ($languages as $language) { $fieldName = 'label_'.$type.'_'.(int)($id_customization_field).'_'.(int)($language['id_lang']); $text = (isset($label[(int)($language['id_lang'])])) ? $label[(int)($language['id_lang'])]['name'] : ''; - $this->content .= '
    + $content .= '
    #'.(int)($id_customization_field).'
    '; } $required = (isset($label[(int)($language['id_lang'])])) ? $label[(int)($language['id_lang'])]['required'] : false; - $this->content .= '
    + $content .= '
    '; + return $content; } private function _displayLabelFields(&$obj, &$labels, $languages, $defaultLanguage, $type) { + $content = ''; $type = (int)($type); $labelGenerated = array(Product::CUSTOMIZE_FILE => (isset($labels[Product::CUSTOMIZE_FILE]) ? count($labels[Product::CUSTOMIZE_FILE]) : 0), Product::CUSTOMIZE_TEXTFIELD => (isset($labels[Product::CUSTOMIZE_TEXTFIELD]) ? count($labels[Product::CUSTOMIZE_TEXTFIELD]) : 0)); $fieldIds = $this->_getCustomizationFieldIds($labels, $labelGenerated, $obj); if (isset($labels[$type])) foreach ($labels[$type] as $id_customization_field => $label) - $this->_displayLabelField($label, $languages, $defaultLanguage, $type, $fieldIds, (int)($id_customization_field)); + $content .= $this->_displayLabelField($label, $languages, $defaultLanguage, $type, $fieldIds, (int)($id_customization_field)); + return $content; } - function initFormCustomization($obj, $languages, $defaultLanguage) + public function initFormCustomization($obj, $languages, $defaultLanguage) { - $this->content .= parent::displayForm(); + $content = ''; $labels = $obj->getCustomizationFields(); $defaultIso = Language::getIsoById($defaultLanguage); $hasFileLabels = (int)($this->getFieldValue($obj, 'uploadable_files')); $hasTextLabels = (int)($this->getFieldValue($obj, 'text_fields')); - $this->content .= ' + $content .= '
    '.$this->l('Combination').''.$this->l('Shop').''.$this->l('Currency').''.$this->l('Country').''.$this->l('Group').''.$this->l('Price').' '.($this->context->country->display_tax_label ? $this->l('(tax excl.)') : '').''.$this->l('Reduction').''.$this->l('Period').''.$this->l('From (quantity)').''.$this->l('Final price').' '.($this->context->country->display_tax_label ? $this->l('(tax excl.)') : '').''.$this->l('Action').'
    @@ -2326,69 +2208,71 @@ switch ($this->action) if ($hasFileLabels) { - $this->content .= ' + $content .= ' '; } if ($hasTextLabels) { - $this->content .= ' + $content .= ' '; } - $this->content .= ' + $content .= '
    '.$this->l('Add or modify customizable properties').'
    '.$this->l('Files fields:').' '; - $this->_displayLabelFields($obj, $labels, $languages, $defaultLanguage, Product::CUSTOMIZE_FILE); - $this->content .= ' + $content .= $this->_displayLabelFields($obj, $labels, $languages, $defaultLanguage, Product::CUSTOMIZE_FILE); + $content .= '
    '.$this->l('Text fields:').' '; - $this->_displayLabelFields($obj, $labels, $languages, $defaultLanguage, Product::CUSTOMIZE_TEXTFIELD); - $this->content .= ' + $content .= $this->_displayLabelFields($obj, $labels, $languages, $defaultLanguage, Product::CUSTOMIZE_TEXTFIELD); + $content .= '
    '; if ($hasFileLabels || $hasTextLabels) - $this->content .= ''; - $this->content .= ' + $content .= ''; + $content .= '
    '; + $this->tpl_form_vars['custom_form'] = $content; } - function initFormAttachments($obj, $languages, $defaultLanguage) + public function initFormAttachments($obj, $languages, $defaultLanguage) { + $content = ''; if (!($obj = $this->loadObject(true))) return; $languages = Language::getLanguages(false); $attach1 = Attachment::getAttachments($this->context->language->id, $obj->id, true); $attach2 = Attachment::getAttachments($this->context->language->id, $obj->id, false); - $this->content .= ' + $content .= ' '.($obj->id ? '' : '').'
    '.$this->l('Attachment').'
    '; foreach ($languages as $language) - $this->content .= '
    + $content .= '
    *
    '; - $this->content .= $this->getTranslationsFlags($languages, $defaultLanguage, 'attachment_name¤attachment_description', 'attachment_name'); - $this->content .= '
    + $content .= $this->getTranslationsFlags($languages, $defaultLanguage, 'attachment_name¤attachment_description', 'attachment_name'); + $content .= '
     
    '; foreach ($languages as $language) - $this->content .= '
    + $content .= '
    '; - $this->content .= $this->getTranslationsFlags($languages, $defaultLanguage, 'attachment_name¤attachment_description', 'attachment_description'); - $this->content .= '
    + $content .= $this->getTranslationsFlags($languages, $defaultLanguage, 'attachment_name¤attachment_description', 'attachment_description'); + $content .= '
     
    @@ -2408,8 +2292,8 @@ switch ($this->action)

    '.$this->l('Attachments for this product:').'



    + $content .= ''; + $content .= '

    '.$this->l('Remove').' >> @@ -2418,8 +2302,8 @@ switch ($this->action)

    '.$this->l('Available attachments:').'



    + $content .= ''; + $content .= '

    << '.$this->l('Add').' @@ -2429,13 +2313,19 @@ switch ($this->action)
     
    '; + $this->tpl_form_vars['custom_form'] = $content; } - function initFormInformations($product, $currency) + public function initFormInformations($product, $languages, $defaultLanguage) { + $data = $this->context->smarty->createData(); + + $currency = $this->context->currency; + + $data->assign('languages',$languages); + $this->object = $product; + $this->display = 'edit'; $content = ''; - $smarty = $this->context->smarty; - $content .= parent::displayForm(); $has_attribute = $product->hasAttributes(); // @FIXME Stock, need to use StockManagerFactory @@ -2454,16 +2344,9 @@ switch ($this->action) $this->displayInitInformationAndAttachment(); - $cache_default_attribute = (int) $this->getFieldValue($product, 'cache_default_attribute'); - $languages = $this->_languages; - foreach ($languages as $k => $language) - { - $languages[$k]['name'] = $this->getFieldValue($product, 'name', $language['id_lang']); - $languages[$k]['is_default'] = ($language['id_lang'] == $this->_defaultFormLanguage); - } - $smarty->assign('languages', $languages); - $smarty->assign('feature_shop_active', Shop::isFeatureActive()); - $smarty->assign('displayAssoShop', $this->displayAssoShop()); + $cache_default_attribute = (int) $this->getFieldValue($product, 'cache_default_attribute'); + $data->assign('feature_shop_active', Shop::isFeatureActive()); + $data->assign('displayAssoShop', $this->displayAssoShop()); $product_props = array(); // global informations @@ -2484,7 +2367,8 @@ switch ($this->action) // prices array_push($product_props, 'price', 'wholesale_price', 'id_tax_rules_group', 'unit_price_ratio', 'on_sale', - 'unity' + 'unity', 'minimum_quantity', 'additional_shipping_cost', + 'available_now', 'available_later', 'available_date', 'out_of_stock' ); if(Configuration::get('PS_USE_ECOTAX')) @@ -2492,558 +2376,265 @@ switch ($this->action) foreach($product_props as $prop) $product->$prop = $this->getFieldValue($product, $prop); -$product->manufacturer_name = Manufacturer::getNameById($product->id_manufacturer); -$product->supplier_name = Supplier::getNameById($product->id_supplier); - $smarty->assign('ps_dimension_unit', Configuration::get('PS_DIMENSION_UNIT')); - $smarty->assign('ps_weight_unit', Configuration::get('PS_WEIGHT_UNIT')); - //$product->{'pack_info'} = + $product->name['class'] = 'updateCurrentText'; + if (!$product->id) + $product->name['class'] .= ' copy2friendlyUrl'; + + $product->manufacturer_name = Manufacturer::getNameById($product->id_manufacturer); + $product->supplier_name = Supplier::getNameById($product->id_supplier); + + $data->assign('ps_dimension_unit', Configuration::get('PS_DIMENSION_UNIT')); + $data->assign('ps_weight_unit', Configuration::get('PS_WEIGHT_UNIT')); + // @todo : initPack should not be called like this $this->initPack($product); -/* - * Form for add a virtual product like software, mp3, etc... - */ - $productDownload = new ProductDownload(); - if ($id_product_download = $productDownload->getIdFromIdProduct($this->getFieldValue($product, 'id'))) - $product->{'product_download'} = new ProductDownload($id_product_download); + /* + * Form for add a virtual product like software, mp3, etc... + */ + $productDownload = new ProductDownload(); + if ($id_product_download = $productDownload->getIdFromIdProduct($this->getFieldValue($product, 'id'))) + $product->{'product_download'} = new ProductDownload($id_product_download); - $this->displayInitInformationAndAttachment(); - // price.js is used in information - $this->addJs(_PS_JS_DIR_.'price.js'); + $this->displayInitInformationAndAttachment(); + // @todo price.js is used in information .. for now + $this->addJs(_PS_JS_DIR_.'price.js'); - // todo handle is_virtual with the value of the product - $exists_file = realpath(_PS_DOWNLOAD_DIR_).'/'.$product->productDownload->filename; - $smarty->assign('product_downloaded', - $product->productDownload->id - // it seems the following is not used - // && !empty($product->cache_default_attribute) - && !empty($product->productDownload->display_filename)); - if (!file_exists($exists_file) - && !empty($product->productDownload->display_filename) - && !empty($product->cache_default_attribute)) - { + // @todo handle is_virtual with the value of the product + $exists_file = realpath(_PS_DOWNLOAD_DIR_).'/'.$product->productDownload->filename; + $data->assign('product_downloaded', $product->productDownload->id && !empty($product->productDownload->display_filename)); - $msg = sprintf(Tools::displayError('This file "%s" is missing'), $product->productDownload->display_filename); - } - else - $msg = ''; - - $smarty->assign('download_product_file_missing', $msg); - $smarty->assign('download_dir_writable', ProductDownload::checkWritableDir()); - - if (empty($product->cache_default_attribute)) - { - $smarty->assign('show_file_input', !strval(Tools::getValue('virtual_product_filename')) OR $product->productDownload->id > 0); - // found in informations and combination : to merge - $smarty->assign('up_filename', strval(Tools::getValue('virtual_product_filename'))); - $display_filename = ($product->productDownload->id > 0) ? $product->productDownload->display_filename : htmlentities(Tools::getValue('virtual_product_name'), ENT_COMPAT, 'UTF-8'); - - if (!$product->productDownload->id || !$product->productDownload->active) - $hidden = 'display:none;'; - else $hidden =''; - - $product->productDownload->nb_downloadable = ($product->productDownload->id > 0) ? $product->productDownload->nb_downloadable : htmlentities(Tools::getValue('virtual_product_nb_downloable'), ENT_COMPAT, 'UTF-8'); - $product->productDownload->date_expiration = ($product->productDownload->id > 0) ? ((!empty($product->productDownload->date_expiration) && $product->productDownload->date_expiration != '0000-00-00 00:00:00') ? date('Y-m-d', strtotime($product->productDownload->date_expiration)) : '' ) : htmlentities(Tools::getValue('virtual_product_expiration_date'), ENT_COMPAT, 'UTF-8'); - $product->productDownload->nb_days_accessible = ($product->productDownload->id > 0) ? $product->productDownload->nb_days_accessible : htmlentities(Tools::getValue('virtual_product_nb_days'), ENT_COMPAT, 'UTF-8'); - $product->productDownload->is_shareable = $product->productDownload->id > 0 && $product->productDownload->is_shareable; - } - else - { - $error =''; - $product_attribute = ProductDownload::getAttributeFromIdProduct($this->getFieldValue($product, 'id')); - foreach ($product_attribute as $p) - { - $productDownloadAttribute = new ProductDownload($p['id_product_download']); - $exists_file2 = realpath(_PS_DOWNLOAD_DIR_).'/'.$productDownloadAttribute->filename; - if (!file_exists($exists_file2) && !empty($productDownloadAttribute->id_product_attribute)) - { - $msg = sprintf(Tools::displayError('This file "%s" is missing'), $productDownloadAttribute->display_filename); - $error .= '

    - '.$msg.' :
    - '.realpath(_PS_DOWNLOAD_DIR_) .'/'. $productDownloadAttribute->filename.'
    -

    '; - } - } - $smarty->assign('error_product_download', $error); - } - - // prices part - $smarty->assign('currency', $currency = $this->context->currency); - $smarty->assign('tax_rules_groups', TaxRulesGroup::getTaxRulesGroups(true)); - $smarty->assign('taxesRatesByGroup', TaxRulesGroup::getAssociatedTaxRatesByIdCountry($this->context->country->id)); - $smarty->assign('ecotaxTaxRate', Tax::getProductEcotaxRate()); - $smarty->assign('tax_exclude_taxe_option', Tax::excludeTaxeOption()); - - $smarty->assign('ps_use_ecotax', Configuration::get('PS_USE_ECOTAX')); - if ($product->unit_price_ratio != 0) - $smarty->assign('unit_price', Tools::ps_round($product->price)/$product->unit_price_ratio); - else - $smarty->assign('unit_price', 0); - - $smarty->assign('ps_tax', Configuration::get('PS_TAX')); - - - if ((int)Configuration::get('PS_STOCK_MANAGEMENT')) - { - if (!$has_attribute) - { - $content .= ' -
    - - - - -

    '.$this->l('The minimum quantity to buy this product (set to 1 to disable this feature)').'

    - - '; - } - } - else - { - $content .= ' -
    - - '.$this->l('The stock management is disabled').' - '; - if (!$has_attribute) - { - $content .= ' - - - - -

    '.$this->l('The minimum quantity to buy this product (set to 1 to disable this feature)').'

    - - - '; - } - } - - $content .= ' -
    - - - - '.($currency->format % 2 == 0 ? ' '.$currency->sign : ''); - if ($this->context->country->display_tax_label) - $content .= ' ('.$this->l('tax excl.').')'; - - $content .= '

    '.$this->l('Carrier tax will be applied.').'

    - - - - - '; - foreach ($this->_languages as $language) - $content .= '
    - - '.$this->l('Forbidden characters:').' <>;=#{}  -
    '; - $content .= ' - - - - '; - foreach ($this->_languages as $language) - $content .= '
    - - '.$this->l('Forbidden characters:').' <>;=#{}  -
    '; - $content .= ' - '; - - // Check if product has combination, to display the available date only for the product or for each combination - if (Combination::isFeatureActive()) - $countAttributes = (int)Db::getInstance()->getValue('SELECT COUNT(id_product) FROM '._DB_PREFIX_.'product_attribute WHERE id_product = '.(int)$product->id); - - if (isset($countAttributes) && $countAttributes == 0) - { - $content .= ' - - - - -

    '.$this->l('The available date when this product is out of stock').'

    - - '; - // date picker include - } - - $content .= ' - - - - - - getFieldValue($product, 'out_of_stock')) == 0 ? 'checked="checked"' : '').'/> -
    getFieldValue($product, 'out_of_stock') == 1 ? 'checked="checked"' : '').'/> -
    getFieldValue($product, 'out_of_stock') == 2 ? 'checked="checked"' : '').'/> - - - - -
    - - - - - - - '; - $default_category = Tools::getValue('id_category', 1); - if (!$product->id) - { - $selectedCat = Category::getCategoryInformations(Tools::getValue('categoryBox', array($default_category)), $this->_defaultFormLanguage); - $content .= ' - '; - } - else - { - if (Tools::isSubmit('categoryBox')) - $selectedCat = Category::getCategoryInformations(Tools::getValue('categoryBox', array($default_category)), $this->_defaultFormLanguage); - else - $selectedCat = Product::getProductCategoriesFull($product->id, $this->_defaultFormLanguage); - } - - $content .= ' - - - - - '; - // Translations are not automatic for the moment ;) - $trads = array( - 'Home' => $this->l('Home'), - 'selected' => $this->l('selected'), - 'Collapse All' => $this->l('Collapse All'), - 'Expand All' => $this->l('Expand All'), - 'Check All' => $this->l('Check All'), - 'Uncheck All' => $this->l('Uncheck All'), - 'search' => $this->l('Search a category') - ); - $content .= Helper::renderAdminCategorieTree($trads, $selectedCat, 'categoryBox', false, true).' - - -
    - - '.$this->l('SEO').''.$this->l('Click here to improve product\'s rank in search engines (SEO)').'
    - - -
    - - - '; - foreach ($this->_languages as $language) - $content .= '
    - -
    '; - $content .= '

    - - - - - '; - foreach ($this->_languages as $language) - $content .= '
    - -
    '; - $content .= '

    + else + $msg = ''; + + $data->assign('download_product_file_missing', $msg); + $data->assign('download_dir_writable', ProductDownload::checkWritableDir()); + + if (empty($product->cache_default_attribute)) + { + $data->assign('show_file_input', !strval(Tools::getValue('virtual_product_filename')) OR $product->productDownload->id > 0); + // found in informations and combination : to merge + $data->assign('up_filename', strval(Tools::getValue('virtual_product_filename'))); + $display_filename = ($product->productDownload->id > 0) ? $product->productDownload->display_filename : htmlentities(Tools::getValue('virtual_product_name'), ENT_COMPAT, 'UTF-8'); + + if (!$product->productDownload->id || !$product->productDownload->active) + $hidden = 'display:none;'; + else $hidden =''; + + $product->productDownload->nb_downloadable = ($product->productDownload->id > 0) ? $product->productDownload->nb_downloadable : htmlentities(Tools::getValue('virtual_product_nb_downloable'), ENT_COMPAT, 'UTF-8'); + $product->productDownload->date_expiration = ($product->productDownload->id > 0) ? ((!empty($product->productDownload->date_expiration) && $product->productDownload->date_expiration != '0000-00-00 00:00:00') ? date('Y-m-d', strtotime($product->productDownload->date_expiration)) : '' ) : htmlentities(Tools::getValue('virtual_product_expiration_date'), ENT_COMPAT, 'UTF-8'); + $product->productDownload->nb_days_accessible = ($product->productDownload->id > 0) ? $product->productDownload->nb_days_accessible : htmlentities(Tools::getValue('virtual_product_nb_days'), ENT_COMPAT, 'UTF-8'); + $product->productDownload->is_shareable = $product->productDownload->id > 0 && $product->productDownload->is_shareable; + } + else + { + $error =''; + $product_attribute = ProductDownload::getAttributeFromIdProduct($this->getFieldValue($product, 'id')); + foreach ($product_attribute as $p) + { + $productDownloadAttribute = new ProductDownload($p['id_product_download']); + $exists_file2 = realpath(_PS_DOWNLOAD_DIR_).'/'.$productDownloadAttribute->filename; + if (!file_exists($exists_file2) && !empty($productDownloadAttribute->id_product_attribute)) + { + $msg = sprintf(Tools::displayError('This file "%s" is missing'), $productDownloadAttribute->display_filename); + $error .= '

    + '.$msg.' :
    + '.realpath(_PS_DOWNLOAD_DIR_) .'/'. $productDownloadAttribute->filename.'
    +

    '; + } + } + $data->assign('error_product_download', $error); + } + + // prices part + $data->assign('currency', $currency = $this->context->currency); + $data->assign('tax_rules_groups', TaxRulesGroup::getTaxRulesGroups(true)); + $data->assign('taxesRatesByGroup', TaxRulesGroup::getAssociatedTaxRatesByIdCountry($this->context->country->id)); + $data->assign('ecotaxTaxRate', Tax::getProductEcotaxRate()); + $data->assign('tax_exclude_taxe_option', Tax::excludeTaxeOption()); + + $data->assign('ps_use_ecotax', Configuration::get('PS_USE_ECOTAX')); + if ($product->unit_price_ratio != 0) + $data->assign('unit_price', Tools::ps_round($product->price)/$product->unit_price_ratio); + else + $data->assign('unit_price', 0); + + $data->assign('ps_tax', Configuration::get('PS_TAX')); + $data->assign('ps_stock_management', Configuration::get('PS_STOCK_MANAGEMENT')); + $data->assign('has_attribute', $has_attribute); + // Check if product has combination, to display the available date only for the product or for each combination + if (Combination::isFeatureActive()) + $data->assign('countAttributes', (int)Db::getInstance()->getValue('SELECT COUNT(id_product) FROM '._DB_PREFIX_.'product_attribute WHERE id_product = '.(int)$product->id)); + + $data->assign('ps_order_out_of_stock', Configuration::get('PS_ORDER_OUT_OF_STOCK')); + + $default_category = Tools::getValue('id_category', 1); + $data->assign('default_category', $default_category); + if (!$product->id) + { + $selectedCat = Category::getCategoryInformations(Tools::getValue('categoryBox', array($default_category)), $this->default_form_language); + } + else + { + if (Tools::isSubmit('categoryBox')) + $selectedCat = Category::getCategoryInformations(Tools::getValue('categoryBox', array($default_category)), $this->default_form_language); + else + $selectedCat = Product::getProductCategoriesFull($product->id, $this->default_form_language); + } + $data->assign('selected_cat_ids', implode(',', array_keys($selectedCat))); + $data->assign('selected_cat', $selectedCat); + + $trads = array( + 'Home' => $this->l('Home'), + 'selected' => $this->l('selected'), + 'Collapse All' => $this->l('Collapse All'), + 'Expand All' => $this->l('Expand All'), + 'Check All' => $this->l('Check All'), + 'Uncheck All' => $this->l('Uncheck All'), + 'search' => $this->l('Search a category') + ); + $data->assign('category_tree', Helper::renderAdminCategorieTree($trads, $selectedCat, 'categoryBox', false, true)); + + $images = Image::getImages($this->context->language->id, $product->id); + + foreach($images as $k => $image) + $images[$k]['src'] = $this->context->link->getImageLink($product->link_rewrite[$this->context->language->id], $product->id.'-'.$image['id_image'], 'small'); + $data->assign('ps_ssl_enabled', Configuration::get('PS_SSL_ENABLED')); + $data->assign('images', $images); + $data->assign('imagesTypes', ImageType::getImagesTypes('products')); + + $content .= ' + + + '; + if ($product->id) + $product->tags = Tag::getProductTags((int)$product->id); + foreach ($this->_languages as $language) + { + $content .= '
    + + '.$this->l('Forbidden characters:').' !<>;?=+#"°{}_$%  +
    '; + } + $content .= '

    '.$this->l('Tags separated by commas (e.g., dvd, dvd player, hifi)').'

    - '; - $images = Image::getImages($this->context->language->id, $product->id); - if ($images) - { - $content .= ' - - - -
    - '.$this->l('Do you want an image associated with the product in your description?').' - '.$this->l('Click here').'. - - - - - - - - '; - $content .= ' - - - - '; - $content .= ' - - - - '; - $content .= ' - - - - - -
    -

    - - '; - $content .= ' - '; - } $content .= ' - - - '; - if ($product->id) - $product->tags = Tag::getProductTags((int)$product->id); - foreach ($this->_languages as $language) - { - $content .= '
    - - '.$this->l('Forbidden characters:').' !<>;?=+#"°{}_$%  -
    '; - } - $content .= '

    '.$this->l('Tags separated by commas (e.g., dvd, dvd player, hifi)').'

    - - '; - $accessories = Product::getAccessoriesLight($this->context->language->id, $product->id); + + + +
    '; + foreach ($accessories as $accessory) + $content .= htmlentities($accessory['name'], ENT_COMPAT, 'UTF-8').(!empty($accessory['reference']) ? ' ('.$accessory['reference'].')' : '').'
    '; + $content .= '
    + + + '; - $content .= ' - - - -
    '; - foreach ($accessories as $accessory) - $content .= htmlentities($accessory['name'], ENT_COMPAT, 'UTF-8').(!empty($accessory['reference']) ? ' ('.$accessory['reference'].')' : '').'
    '; - $content .= '
    - - - '; - - $this->addJqueryPlugin('autocomplete'); - - $content .= ' -
    -

    '.$this->l('Begin typing the first letters of the product name, then select the product from the drop-down list:').'

    - - '.$this->l('Add an accessory').' -
    - - - -
    - - - -   - - -
    -
    '; - // TinyMCE - $iso = $this->context->language->iso_code; - $isoTinyMCE = (file_exists(_PS_JS_DIR_.'tiny_mce/langs/'.$iso.'.js') ? $iso : 'en'); - $ad = dirname($_SERVER["PHP_SELF"]); + return ids; + } + + + +
    + + + +   + + +
    +
    '; + // TinyMCE + $iso_tiny_mce = $this->context->language->iso_code; + $iso_tiny_mce = (file_exists(_PS_JS_DIR_.'tiny_mce/langs/'.$iso_tiny_mce.'.js') ? $iso_tiny_mce : 'en'); + $data->assign('ad', dirname($_SERVER["PHP_SELF"])); + $data->assign('iso_tiny_mce', $iso_tiny_mce); $content .= ' - - - '; $categoryBox = Tools::getValue('categoryBox', array()); - - $smarty->assign('product', $product); - $smarty->assign('content', $content); - $this->content = $this->context->smarty->fetch('products/informations.tpl'); + $data->assign('product', $product); + $data->assign('last_content', $content); + $data->assign('token', $this->token); + $data->assign($this->tpl_form_vars); + $data->assign('link', $this->context->link); + $this->tpl_form_vars['product'] = $product; + $this->tpl_form_vars['custom_form'] = $this->context->smarty->createTemplate($this->tpl_form, $data)->fetch(); } - function initFormImages($obj, $token = null) + public function initFormImages($obj, $token = null) { - $smarty = $this->context->smarty; + $this->addJs('admin-dnd'); + $this->addJqueryPlugin('tablednd'); + + $data = $this->context->smarty->createData(); + $data->assign('product', $this->loadObject()); $content = ''; if (!Tools::getValue('id_product')) return ''; // TEMPO @@ -3052,438 +2643,30 @@ $product->supplier_name = Supplier::getNameById($product->id_supplier); if (Shop::isFeatureActive()) $shops = Shop::getShops(); + $data->assign('shops', $shops); $countImages = Db::getInstance()->getValue('SELECT COUNT(id_product) FROM '._DB_PREFIX_.'image WHERE id_product = '.(int)$obj->id); - $smarty->assign('countImages', $countImages); + $data->assign('countImages', $countImages); $images = Image::getImages($this->context->language->id, $obj->id); $imagesTotal = Image::getImagesTotal($obj->id); - $smarty->assign('id_product', (int)Tools::getValue('id_product')); - $smarty->assign('id_category_default', (int)$this->_category->id); + $data->assign('id_product', (int)Tools::getValue('id_product')); + $data->assign('id_category_default', (int)$this->_category->id); - $content .= ' -

    - '.$this->l('Format:').' JPG, GIF, PNG. '.$this->l('Filesize:').' '.($this->maxImageSize / 1000).''.$this->l('Kb max.').' -

    - - - - - - '.(Tools::getValue('id_image') ? '' : '').' - - -
    - - - - - - - - - - - '; - if ($shops) - { - $content .= ''; - foreach ($shops as $shop) - $content .= ''; - } - $content .= ' - - - '; - foreach ($images as $k => $image) - $content .= $this->getLineTableImage($image, $imagesTotal, $token, $shops); - $content .= ' -
    '.$this->l('Image').' '.$this->l('Position').''.$shop['name'].''.$this->l('Cover').''.$this->l('Action').'
    - - - - '; - $smarty->assign('up_filename', strval(Tools::getValue('virtual_product_filename_attribute'))); - $smarty->assign('content',$content); - $this->content = $smarty->fetch('products/images.tpl'); - } - function initFormQuantities($obj) - { + foreach ($images as $k => $image) + $images[$k] = new Image($image['id_image']); + + $data->assign('images', $images); + $data->assign('token', $token); + $data->assign($this->tpl_form_vars); + $data->assign('table', $this->table); + $data->assign('max_image_size', $this->max_image_size); - // Get all id_product_atribute - $attributes = $obj->getAttributesResume($this->context->language->id); - if (empty($attributes)) - $attributes[] = array( - 'id_product_attribute' => 0, - 'attribute_designation' => '' - ); + $data->assign('up_filename', strval(Tools::getValue('virtual_product_filename_attribute'))); + $data->assign('currency', $this->context->currency); - // Get physical quantities & available quantities - $totalQuantity = 0; - $physicalQuantity = array(); - $availableQuantity = array(); - $productDesignation = array(); - foreach ($attributes as $attribute) - { - $physicalQuantity[$attribute['id_product_attribute']] = (int)StockManagerFactory::getManager()->getProductPhysicalQuantities((int)$obj->id, $attribute['id_product_attribute']); - $totalQuantity += $physicalQuantity[$attribute['id_product_attribute']]; - - // @TODO - $availableQuantity[$attribute['id_product_attribute']] = StockAvailable::getStockAvailableForProduct((int)$obj->id, $attribute['id_product_attribute']); - - // Get all product designation - $productDesignation[$attribute['id_product_attribute']] = rtrim($obj->name[$this->context->language->id].' - '.$attribute['attribute_designation'], ' - '); - } - - $return = ' -
    -

    8. '.$this->l('Quantities').'

    - - - - - - -
    - '.$this->l('Available stock in warehouses').' -
    -
    -

    '.sprintf($this->l('There is %s quantities available in stock for this product'), ''.$totalQuantity.'').'

    - - - - - - -
    - - - - - - - - '; - foreach ($attributes as $attribute) - $return .= ' - - - - '; - $return .= ' - -
    '.$this->l('Quantity').''.$this->l('Designation').'
    '.$physicalQuantity[$attribute['id_product_attribute']].''.$productDesignation[$attribute['id_product_attribute']].'
    -
    -
    - - - - - - -
    - '.$this->l('Available quantities for sale').' -
    -
    - - - - '; - $return .= ' - - - - - - - - - - - - - - - -
    - depends_on_stock) ? 'checked="checked"' : '' ).' type="radio" name="depends_on_stock" class="depends_on_stock" id="depends_on_stock_1" value="1"/> - -

    -
    - depends_on_stock) ? 'checked="checked"' : '' ).' type="radio" name="depends_on_stock" class="depends_on_stock" id="depends_on_stock_0" value="0"/> - -

    -
    - - - - - - - - '; - foreach ($attributes as $attribute) - $return .= ' - - - - '; - $return .= ' - -
    '.$this->l('Quantity').''.$this->l('Designation').'
    - '.$availableQuantity[$attribute['id_product_attribute']].' - - '.$productDesignation[$attribute['id_product_attribute']].'
    -
    - - - - - - - -
    - out_of_stock == 0) ? 'checked="checked"' : '' ).' id="out_of_stock_1" type="radio" checked="checked" value="0" class="out_of_stock" name="out_of_stock"> - -
    - out_of_stock == 1) ? 'checked="checked"' : '' ).' id="out_of_stock_2" type="radio" value="1" class="out_of_stock" name="out_of_stock"> - -
    - out_of_stock == 2) ? 'checked="checked"' : '' ).' id="out_of_stock_3" type="radio" value="2" class="out_of_stock" name="out_of_stock"> - -
    -
    '; - $return .= ' -
    - '; - - $this->content = $return; - return $return; - } - - public function ajaxProcessProductQuantity() - { - if(!Tools::getValue('actionQty')) - return Tools::jsonEncode(array('error' => 'Undefined action')); - - $product = new Product((int)(Tools::getValue('id_product'))); - switch(Tools::getValue('actionQty')) - { - case 'depends_on_stock': - if (Tools::getValue('value') === false) - return Tools::jsonEncode(array('error' => 'Undefined value')); - if ((int)Tools::getValue('value') != 0 && (int)Tools::getValue('value') != 1) - return Tools::jsonEncode(array('error' => 'Uncorrect value')); - - StockAvailable::setProductDependsOnStock((int)Tools::getValue('value'), $product->id); - break; - - case 'out_of_stock': - if (Tools::getValue('value') === false) - return Tools::jsonEncode(array('error' => 'Undefined value')); - if (!in_array((int)Tools::getValue('value'), array(0, 1, 2))) - return Tools::jsonEncode(array('error' => 'Uncorrect value')); - - StockAvailable::setProductOutOfStock((int)Tools::getValue('value'), $product->id); - break; - - case 'set_qty': - if (Tools::getValue('value') === false) - return Tools::jsonEncode(array('error' => 'Undefined value')); - if (Tools::getValue('id_product_attribute') === false) - return Tools::jsonEncode(array('error' => 'Undefined id product attribute')); - // @todo : Product class should handle that - $stock_available = new StockAvailable(StockAvailable::getIdStockAvailable($product->id, (int)Tools::getValue('id_product_attribute'))); - if (!$stock_available->id) - { - $stock_available->id_product = $product->id; - $stock_available->id_shop = Context::getContext()->shop->getID(true); - $stock_available->id_product_attribute = Tools::getValue('id_product_attribute'); - } - $stock_available->quantity = (int)Tools::getValue('value'); - $stock_available->save(); - break; - } - die(Tools::jsonEncode(array('error' => false))); - } - - public function getLineTableImage($image, $imagesTotal, $token, $shops) - { - if (Shop::isFeatureActive()) - $imgObj = new Image((int)$image['id_image']); - $image_obj = new Image($image['id_image']); - $img_path = $image_obj->getExistingImgPath(); - $html = ' - - - '.htmlentities(stripslashes($image['legend']), ENT_COMPAT, 'UTF-8').' - - '.(int)($image['position']).' - '; - - $html .= ' - - '; - $html .= ' - '; - if (Shop::isFeatureActive()) - foreach ($shops as $shop) - $html .= ' - isAssociatedToShop($shop['id_shop']) ? 'checked="1"' : '').' />'; - $html .= ' - - - '.$this->l('Delete this image').' - - '; - return $html; - } - - public function getCombinationImagesJS() - { - if (!($obj = $this->loadObject(true))) - return; - - $content = 'var combination_images = new Array();'; - if (!$allCombinationImages = $obj->getCombinationImages($this->context->language->id)) - return $content; - foreach ($allCombinationImages as $id_product_attribute => $combinationImages) - { - $i = 0; - $content .= 'combination_images['.(int)($id_product_attribute).'] = new Array();'; - foreach ($combinationImages as $combinationImage) - $content .= 'combination_images['.(int)($id_product_attribute).']['.$i++.'] = '.(int)($combinationImage['id_image']).';'; - } - return $content; - // $this->context->smarty->assign('co mbinationImagesJs', $content); + $this->tpl_form_vars['custom_form'] = $this->context->smarty->createTemplate($this->tpl_form, $data)->fetch(); } public function initFormCombinations($obj, $languages, $defaultLanguage) @@ -3707,18 +2890,281 @@ $product->supplier_name = Supplier::getNameById($product->id_supplier); 'id_category' => $product->id_category_default, 'token_generator' => Tools::getAdminTokenLite('AdminAttributeGenerator') )); - $this->content = $this->context->smarty->fetch('products/combinations.tpl'); + $this->tpl_form_vars['custom_form'] = $this->context->smarty->fetch('products/combinations.tpl'); + } + + + + + + + public function initFormQuantities($obj) + { + + // Get all id_product_atribute + $attributes = $obj->getAttributesResume($this->context->language->id); + if (empty($attributes)) + $attributes[] = array( + 'id_product_attribute' => 0, + 'attribute_designation' => '' + ); + + // Get physical quantities & available quantities + $totalQuantity = 0; + $physicalQuantity = array(); + $availableQuantity = array(); + $productDesignation = array(); + foreach ($attributes as $attribute) + { + $physicalQuantity[$attribute['id_product_attribute']] = (int)StockManagerFactory::getManager()->getProductPhysicalQuantities((int)$obj->id, $attribute['id_product_attribute']); + $totalQuantity += $physicalQuantity[$attribute['id_product_attribute']]; + + // @TODO + $availableQuantity[$attribute['id_product_attribute']] = StockAvailable::getStockAvailableForProduct((int)$obj->id, $attribute['id_product_attribute']); + + // Get all product designation + $productDesignation[$attribute['id_product_attribute']] = rtrim($obj->name[$this->context->language->id].' - '.$attribute['attribute_designation'], ' - '); + } + + $content = ' +
    +

    8. '.$this->l('Quantities').'

    + + + + + + +
    + '.$this->l('Available stock in warehouses').' +
    +
    +

    '.sprintf($this->l('There is %s quantities available in stock for this product'), ''.$totalQuantity.'').'

    + + + + + + +
    + + + + + + + + '; + foreach ($attributes as $attribute) + $content .= ' + + + + '; + $content .= ' + +
    '.$this->l('Quantity').''.$this->l('Designation').'
    '.$physicalQuantity[$attribute['id_product_attribute']].''.$productDesignation[$attribute['id_product_attribute']].'
    +
    +
    + + + + + + +
    + '.$this->l('Available quantities for sale').' +
    +
    + + + + '; + $content .= ' + + + + + + + + + + + + + + + +
    + depends_on_stock) ? 'checked="checked"' : '' ).' type="radio" name="depends_on_stock" class="depends_on_stock" id="depends_on_stock_1" value="1"/> + +

    +
    + depends_on_stock) ? 'checked="checked"' : '' ).' type="radio" name="depends_on_stock" class="depends_on_stock" id="depends_on_stock_0" value="0"/> + +

    +
    + + + + + + + + '; + foreach ($attributes as $attribute) + $content .= ' + + + + '; + $content .= ' + +
    '.$this->l('Quantity').''.$this->l('Designation').'
    + '.$availableQuantity[$attribute['id_product_attribute']].' + + '.$productDesignation[$attribute['id_product_attribute']].'
    +
    + + + + + + + +
    + out_of_stock == 0) ? 'checked="checked"' : '' ).' id="out_of_stock_1" type="radio" checked="checked" value="0" class="out_of_stock" name="out_of_stock"> + +
    + out_of_stock == 1) ? 'checked="checked"' : '' ).' id="out_of_stock_2" type="radio" value="1" class="out_of_stock" name="out_of_stock"> + +
    + out_of_stock == 2) ? 'checked="checked"' : '' ).' id="out_of_stock_3" type="radio" value="2" class="out_of_stock" name="out_of_stock"> + +
    +
    '; + $content .= ' +
    + '; + + $this->tpl_form_vars['custom_form'] = $content; } public function initFormFeatures($obj) { if (!Feature::isFeatureActive()) { - $this->displayWarning($this->l('This feature has been disabled, you can active this feature at this page:').' '.$this->l('Performances').''); + $this->content .= $this->displayWarning($this->l('This feature has been disabled, you can active this feature at this page:').' '.$this->l('Performances').''); return; } - $this->content .= parent::displayForm(); + $content = ''; if ($obj->id) { @@ -3728,7 +3174,7 @@ $product->supplier_name = Supplier::getNameById($product->id_supplier); $ctab .= 'ccustom_'.$tab['id_feature'].'¤'; $ctab = rtrim($ctab, '¤'); - $this->content .= ' + $content .= ' '; + $content .= '
    @@ -3743,7 +3189,7 @@ $product->supplier_name = Supplier::getNameById($product->id_supplier);

    '; // Header $nb_feature = Feature::nbFeatures($this->context->language->id); - $this->content .= ' + $content .= ' '; if (!$nb_feature) - $this->content .= ''; - $this->content .= '
    '.$this->l('Feature').' @@ -3751,13 +3197,13 @@ $product->supplier_name = Supplier::getNameById($product->id_supplier); '.$this->l('or').' '.$this->l('Customized value').'
    '.$this->l('No features defined').'
    '; + $content .= '
    '.$this->l('No features defined').'
    '; // Listing if ($nb_feature) { - $this->content .= ' + $content .= ' '; foreach ($feature as $tab_features) @@ -3770,14 +3216,14 @@ $product->supplier_name = Supplier::getNameById($product->id_supplier); $featureValues = FeatureValue::getFeatureValuesWithLang($this->context->language->id, (int)$tab_features['id_feature']); - $this->content .= ' + $content .= ' '; } - $this->content .= ' + $content .= ' '; } - $this->content .= '
    '.$tab_features['name'].' '; if (sizeof($featureValues)) { - $this->content .= ' + $content .= ' '; + $content .= ''; } else - $this->content .= ''.$this->l('N/A').' - '.$this->l('Add pre-defined values first').''; + $content .= ''.$this->l('N/A').' - '.$this->l('Add pre-defined values first').''; - $this->content .= ' + $content .= ' '; $tab_customs = ($custom ? FeatureValue::getFeatureValueLang($current_item) : array()); foreach ($this->_languages as $language) - $this->content .= ' -
    + $content .= ' +
    '; - $this->content .= ' + $content .= '
    + $content .= '
    new_features '.$this->l('Add a new feature').'
    '; } else - $this->content .= ''.$this->l('You must save this product before adding features').'.'; + $content .= ''.$this->l('You must save this product before adding features').'.'; + + $content .= ''; + $this->tpl_form_vars['custom_form'] = $content; + } + + public function ajaxProcessProductQuantity() + { + if(!Tools::getValue('actionQty')) + return Tools::jsonEncode(array('error' => 'Undefined action')); + + $product = new Product((int)(Tools::getValue('id_product'))); + switch(Tools::getValue('actionQty')) + { + case 'depends_on_stock': + if (Tools::getValue('value') === false) + return Tools::jsonEncode(array('error' => 'Undefined value')); + if ((int)Tools::getValue('value') != 0 && (int)Tools::getValue('value') != 1) + return Tools::jsonEncode(array('error' => 'Uncorrect value')); + + StockAvailable::setProductDependsOnStock((int)Tools::getValue('value'), $product->id); + break; + + case 'out_of_stock': + if (Tools::getValue('value') === false) + return Tools::jsonEncode(array('error' => 'Undefined value')); + if (!in_array((int)Tools::getValue('value'), array(0, 1, 2))) + return Tools::jsonEncode(array('error' => 'Uncorrect value')); + + StockAvailable::setProductOutOfStock((int)Tools::getValue('value'), $product->id); + break; + + case 'set_qty': + if (Tools::getValue('value') === false) + return Tools::jsonEncode(array('error' => 'Undefined value')); + if (Tools::getValue('id_product_attribute') === false) + return Tools::jsonEncode(array('error' => 'Undefined id product attribute')); + // @todo : Product class should handle that + $stock_available = new StockAvailable(StockAvailable::getIdStockAvailable($product->id, (int)Tools::getValue('id_product_attribute'))); + if (!$stock_available->id) + { + $stock_available->id_product = $product->id; + $stock_available->id_shop = Context::getContext()->shop->getID(true); + $stock_available->id_product_attribute = Tools::getValue('id_product_attribute'); + } + $stock_available->quantity = (int)Tools::getValue('value'); + $stock_available->save(); + break; + } + die(Tools::jsonEncode(array('error' => false))); + } + + public function getLineTableImage($image, $imagesTotal, $token, $shops) + { + if (Shop::isFeatureActive()) + $imgObj = new Image((int)$image['id_image']); + $image_obj = new Image($image['id_image']); + $img_path = $image_obj->getExistingImgPath(); + $html = ' + + + '.htmlentities(stripslashes($image['legend']), ENT_COMPAT, 'UTF-8').' + + '.(int)($image['position']).' + '; + + $html .= ' + + '; + $html .= ' + '; + if (Shop::isFeatureActive()) + foreach ($shops as $shop) + $html .= ' + isAssociatedToShop($shop['id_shop']) ? 'checked="1"' : '').' />'; + $html .= ' + + + '.$this->l('Delete this image').' + + '; + return $html; + } + + public function getCombinationImagesJS() + { + if (!($obj = $this->loadObject(true))) + return; + + $content = 'var combination_images = new Array();'; + if (!$allCombinationImages = $obj->getCombinationImages($this->context->language->id)) + return $content; + foreach ($allCombinationImages as $id_product_attribute => $combinationImages) + { + $i = 0; + $content .= 'combination_images['.(int)($id_product_attribute).'] = new Array();'; + foreach ($combinationImages as $combinationImage) + $content .= 'combination_images['.(int)($id_product_attribute).']['.$i++.'] = '.(int)($combinationImage['id_image']).';'; + } + return $content; } public function haveThisAccessory($accessoryId, $accessories) @@ -3833,8 +3381,7 @@ $product->supplier_name = Supplier::getNameById($product->id_supplier); private function initPack(Product $product) { - $smarty = $this->context->smarty; - $smarty->assign('is_pack', ($product->id && Pack::isPack($product->id)) || Tools::getValue('ppack')); + $this->tpl_form_vars['is_pack'] = ($product->id && Pack::isPack($product->id)) || Tools::getValue('ppack'); $product->packItems = Pack::getItems($product->id, $this->context->language->id); $input_pack_items = ''; @@ -3843,7 +3390,7 @@ $product->supplier_name = Supplier::getNameById($product->id_supplier); else foreach ($product->packItems as $packItem) $input_pack_items .= $packItem->pack_quantity.'x'.$packItem->id.'-'; - $smarty->assign('input_pack_items',$input_pack_items); + $this->tpl_form_vars['input_pack_items'] = $input_pack_items; $input_namepack_items = ''; if (Tools::getValue('namePackItems')) @@ -3851,7 +3398,7 @@ $product->supplier_name = Supplier::getNameById($product->id_supplier); else foreach ($product->packItems as $packItem) $input_namepack_items.= $packItem->pack_quantity.' x '.$packItem->name.'¤'; - $smarty->assign('input_namepack_items',$input_namepack_items); + $this->tpl_form_vars['input_namepack_items'] = $input_namepack_items; } diff --git a/js/jquery/ui/jquery.ui.datepicker.min.js b/js/jquery/ui/jquery.ui.datepicker.min.js index 07c83968e..a73be85d0 100755 --- a/js/jquery/ui/jquery.ui.datepicker.min.js +++ b/js/jquery/ui/jquery.ui.datepicker.min.js @@ -12,7 +12,7 @@ */ (function(d,C){function M(){this.debug=false;this._curInst=null;this._keyEvent=false;this._disabledInputs=[];this._inDialog=this._datepickerShowing=false;this._mainDivId="ui-datepicker-div";this._inlineClass="ui-datepicker-inline";this._appendClass="ui-datepicker-append";this._triggerClass="ui-datepicker-trigger";this._dialogClass="ui-datepicker-dialog";this._disableClass="ui-datepicker-disabled";this._unselectableClass="ui-datepicker-unselectable";this._currentClass="ui-datepicker-current-day";this._dayOverClass= "ui-datepicker-days-cell-over";this.regional=[];this.regional[""]={closeText:"Done",prevText:"Prev",nextText:"Next",currentText:"Today",monthNames:["January","February","March","April","May","June","July","August","September","October","November","December"],monthNamesShort:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],dayNames:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],dayNamesShort:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],dayNamesMin:["Su", -"Mo","Tu","We","Th","Fr","Sa"],weekHeader:"Wk",dateFormat:"mm/dd/yy",firstDay:0,isRTL:false,showMonthAfterYear:false,yearSuffix:""};this._defaults={showOn:"focus",showAnim:"fadeIn",showOptions:{},defaultDate:null,appendText:"",buttonText:"...",buttonImage:"",buttonImageOnly:false,hideIfNoPrevNext:false,navigationAsDateFormat:false,gotoCurrent:false,changeMonth:false,changeYear:false,yearRange:"c-10:c+10",showOtherMonths:false,selectOtherMonths:false,showWeek:false,calculateWeek:this.iso8601Week,shortYearCutoff:"+10", +"Mo","Tu","We","Th","Fr","Sa"],weekHeader:"Wk",dateFormat:"yy-mm-dd",firstDay:0,isRTL:false,showMonthAfterYear:false,yearSuffix:""};this._defaults={showOn:"focus",showAnim:"fadeIn",showOptions:{},defaultDate:null,appendText:"",buttonText:"...",buttonImage:"",buttonImageOnly:false,hideIfNoPrevNext:false,navigationAsDateFormat:false,gotoCurrent:false,changeMonth:false,changeYear:false,yearRange:"c-10:c+10",showOtherMonths:false,selectOtherMonths:false,showWeek:false,calculateWeek:this.iso8601Week,shortYearCutoff:"+10", minDate:null,maxDate:null,duration:"fast",beforeShowDay:null,beforeShow:null,onSelect:null,onChangeMonthYear:null,onClose:null,numberOfMonths:1,showCurrentAtPos:0,stepMonths:1,stepBigMonths:12,altField:"",altFormat:"",constrainInput:true,showButtonPanel:false,autoSize:false,disabled:false};d.extend(this._defaults,this.regional[""]);this.dpDiv=N(d('
    '))}function N(a){return a.bind("mouseout", function(b){b=d(b.target).closest("button, .ui-datepicker-prev, .ui-datepicker-next, .ui-datepicker-calendar td a");b.length&&b.removeClass("ui-state-hover ui-datepicker-prev-hover ui-datepicker-next-hover")}).bind("mouseover",function(b){b=d(b.target).closest("button, .ui-datepicker-prev, .ui-datepicker-next, .ui-datepicker-calendar td a");if(!(d.datepicker._isDisabledDatepicker(J.inline?a.parent()[0]:J.input[0])||!b.length)){b.parents(".ui-datepicker-calendar").find("a").removeClass("ui-state-hover"); b.addClass("ui-state-hover");b.hasClass("ui-datepicker-prev")&&b.addClass("ui-datepicker-prev-hover");b.hasClass("ui-datepicker-next")&&b.addClass("ui-datepicker-next-hover")}})}function H(a,b){d.extend(a,b);for(var c in b)if(b[c]==null||b[c]==C)a[c]=b[c];return a}d.extend(d.ui,{datepicker:{version:"1.8.16"}});var B=(new Date).getTime(),J;d.extend(M.prototype,{markerClassName:"hasDatepicker",maxRows:4,log:function(){this.debug&&console.log.apply("",arguments)},_widgetDatepicker:function(){return this.dpDiv}, diff --git a/js/tinymce.inc.js b/js/tinymce.inc.js index 1a43ddcd5..a72620c69 100644 --- a/js/tinymce.inc.js +++ b/js/tinymce.inc.js @@ -1,4 +1,9 @@ - tinyMCE.init({ +function tinySetup(config) +{ + if(!config) + config = {}; + + default_config = { mode : "specific_textareas", theme : "advanced", skin:"cirkuit", @@ -25,7 +30,16 @@ convert_urls : false, language : iso + } + + $.each(default_config, function(index, el) + { + if (config[index] === undefined ) + config[index] = el; }); + tinyMCE.init(config); +}; + function ajaxfilemanager(field_name, url, type, win) { var ajaxfilemanagerurl = ad+"/ajaxfilemanager/ajaxfilemanager.php";