From 2a74e65fd5f1fee955399acf80fc376f55f871bc Mon Sep 17 00:00:00 2001 From: mMarinetti Date: Tue, 25 Oct 2011 16:48:15 +0000 Subject: [PATCH] // #PSFV-94 - update AdminProductsController git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@9645 b9a71923-0436-4b27-9f14-aed3839534dd --- admin-dev/themes/default/admin.css | 5 + .../themes/template/products/content.tpl | 11 + .../themes/template/products/informations.tpl | 492 ++++++++++- controllers/admin/AdminProductsController.php | 797 +++++------------- js/admin.js | 22 + 5 files changed, 747 insertions(+), 580 deletions(-) diff --git a/admin-dev/themes/default/admin.css b/admin-dev/themes/default/admin.css index ba119c21c..e31f7f89d 100644 --- a/admin-dev/themes/default/admin.css +++ b/admin-dev/themes/default/admin.css @@ -90,3 +90,8 @@ a.module_toggle_all{color: #268CCD;} .notifs_wrapper p.no_notifs {border: none;} .productTabs ol{padding:0;} .productTabs{background-color:#e0e0e0;border:1px solid #cccccc;position:absolute;top:100px;left:50px;} + +ul.cc_button {float:right;margin:0;padding:6px 0;} +ul.cc_button li {float:left;text-decoration: none;list-style: none;font-size:12px;padding:5px 0;} +.available_btn {border:2px outset black;display:block;height:50px;margin:2px;padding:3px 2px 1px 2px;width:60px;} +.available_btn span{font-size:small;margin-top:5px;text-align:center} diff --git a/admin-dev/themes/template/products/content.tpl b/admin-dev/themes/template/products/content.tpl index 8ab5e53b7..953d1974b 100644 --- a/admin-dev/themes/template/products/content.tpl +++ b/admin-dev/themes/template/products/content.tpl @@ -18,6 +18,7 @@ var toload = new Array(); var pos_select = {$pos_select}; $(document).ready(function(){ + {* submenu binding *} $(".tab-page").click(function(e){ e.preventDefault(); // currentId is the current producttab id @@ -181,8 +182,18 @@ $(document).ready(function(){ } //]]> +
{$draft_warning} +
diff --git a/admin-dev/themes/template/products/informations.tpl b/admin-dev/themes/template/products/informations.tpl index 2ce887285..9de762117 100644 --- a/admin-dev/themes/template/products/informations.tpl +++ b/admin-dev/themes/template/products/informations.tpl @@ -82,9 +82,499 @@ $('#mvt_sign').show(); } +
+
+ +{* global information *} + + + + + + + + + + + + + + + + + + + + + + + + + + +
{l s='Name:' } + {foreach from=$languages item=language} +
+ * + {l s='Invalid characters:'} <>;=#{}  + +
+ {/foreach} + +
{l s='Reference:' } + + {l s='Special characters allowed:' }.-_#\  +
{l s='Supplier Reference:' } + + {l s='Special characters allowed:' } .-_#\  +
{l s='EAN13 or JAN:' } + {l s='(Europe, Japan)'} +
{l s='UPC:' } + {l s='(US, Canada)'} +
{l s='Location (warehouse):' } + +
+{* status informations *} + + + + + + {if $feature_shop_active} + {* @todo use asso_shop from Helper *} + + + + + {/if} + active}style="display:none"{/if} > + + + + + + + + + + + + + + + +
{l s='Status:' } + active}checked="checked" {/if} /> + +
+ active}checked="checked"{/if} /> + +
{l s='Shop association:'}{$displayAssoShop}
{l s='Options:' } + available_for_order}checked="checked"{/if} /> + + +
+ show_price}checked="checked"{/if} /> + +
+ online_only}checked="checked"{/if} /> + +
{l s='Condition:' } + +
{l s='Manufacturer:' } +     + + {l s='Create'} {l s='Create'} + +
{l s='Supplier:' } +     + + {l s='Create'} {l s='Create'} + +
+
+

+{* [begin] pack product *} + + + + + + +
+ + + +
+
+ {foreach from=$product->packItems item=packItem} + {$packItem->pack_quantity} x {$packItem->name}
+ {/foreach} +
+ + + + + + +

{l s='Begin typing the first letters of the product name, then select the product from the drop-down list:'} +
{l s='You cannot add downloadable products to a pack.'}

+ + + {l s='Add an item to the pack'} +
+ +{* [end] pack product *} + +{* [begin] specific / detailled information *} + +
+ +

+ + + + + + + {$content} - diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index 72252bb55..c1bc43931 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -25,8 +25,6 @@ * International Registered Trademark & Property of PrestaShop SA */ -include_once('functions.php'); - class AdminProductsController extends AdminController { protected $maxFileSize = 20000000; @@ -1527,7 +1525,8 @@ if (false) $defaultLanguage = (int)(Configuration::get('PS_LANG_DEFAULT')); $product = new Product((int)(Tools::getValue('id_product'))); $this->initForm(); - return $this->{'initForm'.$this->action}($product, $languages, $defaultLanguage); + $this->{'initForm'.$this->action}($product, $languages, $defaultLanguage); + $this->context->smarty->assign('product',$product); } } else @@ -1719,6 +1718,7 @@ if (false) $this->context->smarty->assign('form_action', $this->context->link->getAdminLink('AdminProducts').'&id_product='.$id_product); $this->context->smarty->assign('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); if (!($obj = $this->loadObject(true))) @@ -1732,7 +1732,7 @@ if (false) $content = ''; parent::displayForm(); $this->addJs(_PS_JS_DIR_.'attributesBack.js'); - if (!($obj = $this->loadObject(true))) + if (!($product = $this->loadObject(true))) throw new Exception('object not loaded'); $smarty = $this->context->smarty; $product_tabs = array(); @@ -1761,34 +1761,90 @@ if (false) $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->_defaultFormLanguage), Category::getLinkRewrite($this->getFieldValue($product, 'id_category_default'), $this->context->language->id))); + if (!$product->active) + { + $admin_dir = dirname($_SERVER['PHP_SELF']); + $admin_dir = substr($admin_dir, strrpos($admin_dir,'/') + 1); + $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 (!($obj = $this->loadObject(true))) + if (!($product = $this->loadObject(true))) return; $currency = Tools::setCurrency($this->context->cookie); -// if ($obj->id) -// self::$currentIndex .= '&id_product='.$obj->id; +// if ($product->id) +// self::$currentIndex .= '&id_product='.$product->id; // $this->addJqueryPlugin('tabpane'); $content .= $this->initForm(); - $this->{'initForm'.$action}($obj, null); + $this->{'initForm'.$action}($product, null); /* Tabs */ /* switch ($this->action) { default: - $this->initFormInformations($obj, $currency); -// $this->initFormImages($obj, $this->token); + $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)$obj->id)); + $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)$obj->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) { @@ -2218,350 +2274,120 @@ switch ($this->action) '; } - function initFormInformations($obj, $currency) + function initFormInformations($product, $currency) { $content = ''; $smarty = $this->context->smarty; $content .= parent::displayForm(); - $has_attribute = $obj->hasAttributes(); + $has_attribute = $product->hasAttributes(); // @FIXME Stock, need to use StockManagerFactory $qty = 0; - $cover = Product::getCover($obj->id); - $this->_applyTaxToEcotax($obj); + $cover = Product::getCover($product->id); + $this->_applyTaxToEcotax($product); /* * Form for add a virtual product like software, mp3, etc... */ $productDownload = new ProductDownload(); - if ($id_product_download = $productDownload->getIdFromIdProduct($this->getFieldValue($obj, 'id'))) + if ($id_product_download = $productDownload->getIdFromIdProduct($this->getFieldValue($product, 'id'))) $productDownload = new ProductDownload($id_product_download); + $product->{'productDownload'} = $productDownload; - $hidden = $display_filename = $check = ''; $this->displayInitInformationAndAttachment(); - if(!$productDownload->id || !$productDownload->active) - $hidden = 'style="display:none;"'; - $cache_default_attribute = (int) $this->getFieldValue($obj, 'cache_default_attribute'); - $is_virtual = (int) $this->getFieldValue($obj, 'is_virtual'); - if($is_virtual && $productDownload->active) - $check = 'checked="checked"'; - - if($is_virtual) - $virtual = 1; - else - $virtual = 0; - - $preview_url = ''; - if (isset($obj->id)) + $cache_default_attribute = (int) $this->getFieldValue($product, 'cache_default_attribute'); + $languages = $this->_languages; + foreach ($languages as $k => $language) { - $preview_url = ($this->context->link->getProductLink($this->getFieldValue($obj, 'id'), $this->getFieldValue($obj, 'link_rewrite', $this->_defaultFormLanguage), Category::getLinkRewrite($this->getFieldValue($obj, 'id_category_default'), $this->context->language->id))); - if (!$obj->active) - { - $admin_dir = dirname($_SERVER['PHP_SELF']); - $admin_dir = substr($admin_dir, strrpos($admin_dir,'/') + 1); - $token = Tools::encrypt('PreviewProduct'.$obj->id); - - $preview_url .= $obj->active ? '' : '&adtoken='.$token.'&ad='.$admin_dir; - } - - $content .= ' - - '.$this->l('Delete this product').' '.$this->l('Delete this product').' - '.$this->l('View product in shop').' '.$this->l('View product in shop').''; - - if (file_exists(_PS_MODULE_DIR_.'statsproduct/statsproduct.php')) - $content .= ' - '.$this->l('View product sales').' '.$this->l('View product sales').''; + $languages[$k]['name'] = $this->getFieldValue($product, 'name', $language['id_lang']); + $languages[$k]['is_default'] = ($language['id_lang'] == $this->_defaultFormLanguage); } - $content .= ' -
-
-
+

is_virtual && $product->productDownload->active}checked="checked"{/if} /> + +

+ {* [begin] physical product infos *} +
productDownload->id && $product->productDownload->active}style="display:none"{/if} > + + +

+ + + + + + + + + +
{l s='Width ( package ) :' } + {$ps_dimension_unit} +
{l s='Height ( package ) :' } + {$ps_dimension_unit} +
+ + + + + + + + + +
{l s='Deep ( package ) :' } + {$ps_dimension_unit} +
{l s='Weight ( package ) :' } + {$ps_weight_unit} +
+
+ {* [end] of physical product *} + {* [begin] virtual product *} +
productDownload->id || $product->productDownload->active}style="display:none"{/if} > + + + + + +
+
{l s='Does this product has an associated file ?'}
+ {l s='Yes'} + {l s='No'}

+ {if $download_product_file_missing} +

+ {$download_product_file_missing} :
+ {$smarty.const._PS_DOWNLOAD_DIR_}/{$product->productDownload->filename}
+

+ {/if} +
+ +
+ + +
+
+

+ + + +

+

+ + {l s='Format: YYYY-MM-DD'} + +

+

+ + * + +

+

+ + productDownload->is_shareable}checked="checked"{/if} /> + +

+
+ {else} +
{l s='You used combinations, for this reason you can\'t edit your file here, but in the Combinations tab'}
+
+ {$error_product_download} + {/if} +
+
+ +

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
'.$this->l('Name:').''; - foreach ($this->_languages as $language) - $content .= '
- id) ? ' onkeyup="if (isArrowKey(event)) return; copy2friendlyURL();"' : '').' onkeyup="if (isArrowKey(event)) return; updateCurrentText();" onchange="updateCurrentText();" /> * - '.$this->l('Invalid characters:').' <>;=#{}  -
'; - $content .= '
'.$this->l('Reference:').' - - '.$this->l('Special characters allowed:').' .-_#\  -
'.$this->l('Supplier Reference:').' - - '.$this->l('Special characters allowed:').' .-_#\  -
'.$this->l('EAN13 or JAN:').' - '.$this->l('(Europe, Japan)').' -
'.$this->l('UPC:').' - '.$this->l('(US, Canada)').' -
'.$this->l('Location (warehouse):').' - -
'.$this->l('Width ( package ) :').' - '.Configuration::get('PS_DIMENSION_UNIT').' -
'.$this->l('Height ( package ) :').' - '.Configuration::get('PS_DIMENSION_UNIT').' -
'.$this->l('Deep ( package ) :').' - '.Configuration::get('PS_DIMENSION_UNIT').' -
'.$this->l('Weight ( package ) :').' - '.Configuration::get('PS_WEIGHT_UNIT').' -
- - - - - - - - - active ? 'style="display:none"' : '').'> - - - - - - - - - - - - - - - -
'.$this->l('Status:').' - getFieldValue($obj, 'active') ? 'checked="checked" ' : '').'/> - -
- getFieldValue($obj, 'active') ? 'checked="checked" ' : '').'/> - -
'.$this->l('Shop association:').''; - $content .= $this->displayAssoShop(); - $content .= '
'.$this->l('Options:').' - getFieldValue($obj, 'available_for_order') ? 'checked="checked" ' : '').' onclick="if ($(this).is(\':checked\')){$(\'#show_price\').attr(\'checked\', \'checked\');$(\'#show_price\').attr(\'disabled\', \'disabled\');}else{$(\'#show_price\').attr(\'disabled\', \'\');}"/> - -
- getFieldValue($obj, 'show_price') ? 'checked="checked" ' : '').' /> - -
- getFieldValue($obj, 'online_only') ? 'checked="checked" ' : '').' /> - -
'.$this->l('Condition:').' - -
'.$this->l('Manufacturer:').' -    '.$this->l('Create').' '.$this->l('Create').' -
'.$this->l('Supplier:').' -    '.$this->l('Create').' '.$this->l('Create').' -
-
- - '; - $this->displayPack($obj); - $content .= ' '; + $smarty->assign('languages', $languages); + $smarty->assign('feature_shop_active', Shop::isFeatureActive()); + $smarty->assign('displayAssoShop', $this->displayAssoShop()); + + $product_props = array(); + // global informations + array_push($product_props, 'reference', 'supplier_reference', 'ean13', 'upc', 'location', + 'available_for_order', 'show_price', 'online_only', + 'id_manufacturer', 'id_supplier' + ); + + // specific / detailled information + array_push($product_props, + // physical product + 'width', 'height', 'weight', 'active', + // virtual product + 'is_virtual', 'cache_default_attribute', + // customization + 'uploadable_files', 'text_fields' + ); + 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'} = + $this->initPack($product); /* * Form for add a virtual product like software, mp3, etc... */ $productDownload = new ProductDownload(); - if ($id_product_download = $productDownload->getIdFromIdProduct($this->getFieldValue($obj, 'id'))) - $productDownload = new ProductDownload($id_product_download); + if ($id_product_download = $productDownload->getIdFromIdProduct($this->getFieldValue($product, 'id'))) + $product->{'product_download'} = new ProductDownload($id_product_download); + $this->displayInitInformationAndAttachment(); - $content .= ' - - - - - '; $currency = $this->context->currency; - $content .= ' - - - '; $content .= ' '; @@ -2639,7 +2414,7 @@ switch ($this->action) '; @@ -2668,16 +2443,16 @@ switch ($this->action) '; foreach ($tax_rules_groups as $tax_rules_group) - $content .= ''; + $content .= ''; $content .= ' - '.$this->l('Create').' '.$this->l('Create').' + '.$this->l('Create').' '.$this->l('Create').' '; if (Tax::excludeTaxeOption()) { $content .= ''.$this->l('Taxes are currently disabled').' ('.$this->l('Tax options').')'; - $content .= ''; + $content .= ''; } $content .= ' @@ -2688,7 +2463,7 @@ switch ($this->action) '; @@ -2710,15 +2485,15 @@ switch ($this->action) @@ -2752,7 +2527,7 @@ switch ($this->action) '; @@ -2784,7 +2559,7 @@ switch ($this->action) @@ -2808,7 +2583,7 @@ switch ($this->action) foreach ($this->_languages as $language) $content .= '
+ value="'.stripslashes(htmlentities($this->getFieldValue($product, 'available_later', $language['id_lang']), ENT_COMPAT, 'UTF-8')).'" /> '.$this->l('Forbidden characters:').' <>;=#{} 
'; $content .= ' @@ -2816,7 +2591,7 @@ switch ($this->action) // 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)$obj->id); + $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) { @@ -2824,7 +2599,7 @@ switch ($this->action) '; @@ -2839,9 +2614,9 @@ switch ($this->action) @@ -2857,7 +2632,7 @@ switch ($this->action) var post_selected_cat; '; $default_category = Tools::getValue('id_category', 1); - if (!$obj->id) + if (!$product->id) { $selectedCat = Category::getCategoryInformations(Tools::getValue('categoryBox', array($default_category)), $this->_defaultFormLanguage); $content .= ' @@ -2870,12 +2645,12 @@ switch ($this->action) if (Tools::isSubmit('categoryBox')) $selectedCat = Category::getCategoryInformations(Tools::getValue('categoryBox', array($default_category)), $this->_defaultFormLanguage); else - $selectedCat = Product::getProductCategoriesFull($obj->id, $this->_defaultFormLanguage); + $selectedCat = Product::getProductCategoriesFull($product->id, $this->_defaultFormLanguage); } $content .= ' @@ -2906,7 +2681,7 @@ switch ($this->action) foreach ($this->_languages as $language) $content .= '
+ value="'.htmlentities($this->getFieldValue($product, 'meta_title', $language['id_lang']), ENT_COMPAT, 'UTF-8').'" /> '.$this->l('Forbidden characters:').' <>;=#{} 
'; $content .= '

'.$this->l('Product page title; leave blank to use product name').'

@@ -2918,7 +2693,7 @@ switch ($this->action) foreach ($this->_languages as $language) $content .= '
+ value="'.htmlentities($this->getFieldValue($product, 'meta_description', $language['id_lang']), ENT_COMPAT, 'UTF-8').'" /> '.$this->l('Forbidden characters:').' <>;=#{} 
'; $content .= '

'.$this->l('A single sentence for HTML header').'

@@ -2930,7 +2705,7 @@ switch ($this->action) foreach ($this->_languages as $language) $content .= '
+ value="'.htmlentities($this->getFieldValue($product, 'meta_keywords', $language['id_lang']), ENT_COMPAT, 'UTF-8').'" /> '.$this->l('Forbidden characters:').' <>;=#{} 
'; $content .= '

'.$this->l('Keywords for HTML header, separated by a comma').'

@@ -2943,7 +2718,7 @@ switch ($this->action) { $content .= '
* + value="'.htmlentities($this->getFieldValue($product, 'link_rewrite', $language['id_lang']), ENT_COMPAT, 'UTF-8').'" onkeyup="if (isArrowKey(event)) return ;updateFriendlyURL();" onchange="updateFriendlyURL();" /> * '.$this->l('Only letters and the "less" character are allowed').' 
'; } @@ -2960,7 +2735,7 @@ switch ($this->action) @@ -2970,12 +2745,12 @@ switch ($this->action) '; - $images = Image::getImages($this->context->language->id, $obj->id); + $images = Image::getImages($this->context->language->id, $product->id); if ($images) { $content .= ' @@ -2999,7 +2774,7 @@ switch ($this->action) $content .= '
  • '; - $urlImage = $this->context->link->getImageLink($obj->link_rewrite[$this->context->language->id], $obj->id.'-'.$image['id_image'], 'small'); + $urlImage = $this->context->link->getImageLink($product->link_rewrite[$this->context->language->id], $product->id.'-'.$image['id_image'], 'small'); $content .= '
  • '; @@ -3083,20 +2858,20 @@ switch ($this->action) '; - $accessories = Product::getAccessoriesLight($this->context->language->id, $obj->id); + $accessories = Product::getAccessoriesLight($this->context->language->id, $product->id); if ($postAccessories = Tools::getValue('inputAccessories')) { @@ -3160,7 +2935,7 @@ switch ($this->action) function getAccessorieIds() { - var ids = '. $obj->id.'+\',\'; + var ids = '. $product->id.'+\',\'; ids += $(\'#inputAccessories\').val().replace(/\\-/g,\',\').replace(/\\,$/,\'\'); ids = ids.replace(/\,$/,\'\'); @@ -3195,6 +2970,8 @@ switch ($this->action) unitPriceWithTax(\'unit\'); '; $categoryBox = Tools::getValue('categoryBox', array()); + + $smarty->assign('product', $product); $smarty->assign('content', $content); $this->content = $this->context->smarty->fetch('products/informations.tpl'); } @@ -3662,18 +3439,17 @@ switch ($this->action) $smarty->assign('attributes_groups', AttributeGroup::getAttributesGroups($this->context->language->id)); $default_country = new Country((int)Configuration::get('PS_COUNTRY_DEFAULT')); - $productDownload = new ProductDownload(); - $id_product_download = (int) $productDownload->getIdFromIdProduct($this->getFieldValue($obj, 'id')); + $product->productDownload = new ProductDownload(); + $id_product_download = (int) $product->productDownload->getIdFromIdProduct($this->getFieldValue($obj, 'id')); if (!empty($id_product_download)) - $productDownload = new ProductDownload($id_product_download); + $product->productDownload = new ProductDownload($id_product_download); - $smarty->assign('productDownload', $productDownload); + // $smarty->assign('productDownload', $productDownload); $smarty->assign('currency', $currency); $images = Image::getImages($this->context->language->id, $obj->id); if ($obj->id) { - $smarty->assign('upload_max_filesize', ini_get('upload_max_filesize')); $smarty->assign('tax_exclude_option', Tax::excludeTaxeOption()); $smarty->assign('ps_weight_unit', Configuration::get('PS_WEIGHT_UNIT')); @@ -3982,190 +3758,52 @@ switch ($this->action) return false; } - private function displayPack(Product $obj) + private function initPack(Product $product) { - $boolPack = (($obj->id && Pack::isPack($obj->id)) || Tools::getValue('ppack')) ? true : false; - $packItems = $boolPack ? Pack::getItems($obj->id, $this->context->language->id) : array(); - - $this->content .= ' - - - - - '; - // param multipleSeparator:'||' ajouté à cause de bug dans lib autocomplete - $this->content .= ''; + $smarty = $this->context->smarty; + $smarty->assign('is_pack', ($product->id && Pack::isPack($product->id)) || Tools::getValue('ppack')); + $product->packItems = Pack::getItems($product->id, $this->context->language->id); + + $input_pack_items = ''; + if(Tools::getValue('inputPackItems')) + $input_pack_items = Tools::getValue('inputPackItems'); + else + foreach ($product->packItems as $packItem) + $input_pack_items .= $packItem->pack_quantity.'x'.$packItem->id.'-'; + $smarty->assign('input_pack_items',$input_pack_items); + $input_namepack_items = ''; + if (Tools::getValue('namePackItems')) + $input_namepack_items = Tools::getValue('namePackItems'); + else + foreach ($product->packItems as $packItem) + $input_namepack_items.= $packItem->pack_quantity.' x '.$packItem->name.'¤'; + $smarty->assign('input_namepack_items',$input_namepack_items); } - private function addPackItem() - { - return ' - function addPackItem() - { - if ($(\'#curPackItemId\').val() == \'\' || $(\'#curPackItemName\').val() == \'\') - { - alert(\''.$this->l('Thanks to select at least one product.').'\'); - return false; - } - else if ($(\'#curPackItemId\').val() == \'\' || $(\'#curPackItemQty\').val() == \'\') - { - alert(\''.$this->l('Thanks to set a quantity to add a product.').'\'); - return false; - } - var lineDisplay = $(\'#curPackItemQty\').val()+ \'x \' +$(\'#curPackItemName\').val(); - - var divContent = $(\'#divPackItems\').html(); - divContent += lineDisplay; - divContent += \'
    \'; - - // QTYxID-QTYxID - var line = $(\'#curPackItemQty\').val()+ \'x\' +$(\'#curPackItemId\').val(); - - - $(\'#inputPackItems\').val($(\'#inputPackItems\').val() + line + \'-\'); - $(\'#divPackItems\').html(divContent); - $(\'#namePackItems\').val($(\'#namePackItems\').val() + lineDisplay + \'¤\'); - - $(\'#curPackItemId\').val(\'\'); - $(\'#curPackItemName\').val(\'\'); - - $(\'#curPackItemName\').setOptions({ - extraParams: {excludeIds : getSelectedIds()} - }); - } - '; - } - - private function delPackItem() - { - return ' - function delPackItem(id) - { - var reg = new RegExp(\'-\', \'g\'); - var regx = new RegExp(\'x\', \'g\'); - - var div = getE(\'divPackItems\'); - var input = getE(\'inputPackItems\'); - var name = getE(\'namePackItems\'); - var select = getE(\'curPackItemId\'); - var select_quantity = getE(\'curPackItemQty\'); - - var inputCut = input.value.split(reg); - var nameCut = name.value.split(new RegExp(\'¤\', \'g\')); - - input.value = \'\'; - name.value = \'\'; - div.innerHTML = \'\'; - - for (var i = 0; i < inputCut.length; ++i) - if (inputCut[i]) - { - var inputQty = inputCut[i].split(regx); - if (inputQty[1] != id) - { - input.value += inputCut[i] + \'-\'; - name.value += nameCut[i] + \'¤\'; - div.innerHTML += nameCut[i] + \'
    \'; - } - } - - $(\'#curPackItemName\').setOptions({ - extraParams: {excludeIds : getSelectedIds()} - }); - }'; - } public function updatePackItems($product) { Pack::deleteItems($product->id); // lines format: QTY x ID-QTY x ID - if (Tools::getValue('ppack') && $items = Tools::getValue('inputPackItems') && sizeof($lines = array_unique(explode('-', $items)))) + if (Tools::getValue('ppack')) { - foreach ($lines as $line) - { - // line format QTY x ID - list($qty, $item_id) = explode('x', $line); - if ($qty > 0 && isset($item_id)) - { - if (!Pack::addItem((int)($product->id), (int)($item_id), (int)($qty))) - return false; - } - } + $items = Tools::getValue('inputPackItems'); + $lines = array_unique(explode('-', $items)); + // lines is an array of string with format : QTYxID + if(count($lines)) + foreach ($lines as $line) + if (!empty($line)) + { + list($qty, $item_id) = explode('x', $line); + if ($qty > 0 && isset($item_id)) + { + if (!Pack::addItem((int)($product->id), (int)($item_id), (int)($qty))) + return false; + } + } } return true; } @@ -4210,6 +3848,7 @@ switch ($this->action) $this->displayErrors(); } + public function displayInitInformationAndAttachment() { $this->addJqueryPlugin('thickbox'); diff --git a/js/admin.js b/js/admin.js index 8e6585232..485b6b9ba 100644 --- a/js/admin.js +++ b/js/admin.js @@ -101,6 +101,7 @@ function strToAltImgAttr(str,encoding,ucfirst) function copy2friendlyURL() { $('#link_rewrite_' + id_language).val(str2url($('#name_' + id_language).val().replace(/^[0-9]+\./, ''), 'UTF-8')); + return; } function copyMeta2friendlyURL() @@ -927,3 +928,24 @@ function showErrorMessage(msg) $("#ajax_confirmation").show() .html("
    \"ERROR\""+msg+"
    "); } + +$(document).ready(function(){ + $(".copy2friendlyURL").live('keyup',function(e){ + if(!isArrowKey(e)) + return copy2friendlyURL() + }); + + // on live will make this binded for dynamic content + $(".updateCurrentText").live('keyup change',function(e){ + if(typeof e == KeyboardEvent) + if(isArrowKey(e)) + return; + + updateCurrentText() + }); + + $(".copyMeta2friendlyURL").live('keyup',function(e){ + if(!isArrowKey(e)) + return copyMeta2friendlyURL() + }); +});


    + // price.js is used in information + $this->addJs(_PS_JS_DIR_.'price.js'); -

    -

    -
    - -
    '.$this->l('Does this product has an associated file ?').'
    '; - - // todo handle is_virtual with the value of the product - $exists_file = realpath(_PS_DOWNLOAD_DIR_).'/'.$productDownload->filename; - - if ($productDownload->id && !empty($cache_default_attribute) && !empty($productDownload->display_filename)) + // 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)) { - $check_yes = 'checked="checked"'; - $check_no = ''; + + $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)) { - $check_yes = ''; - $check_no = 'checked="checked"'; - } - - $content .= ''. $this->l('Yes').' - '.$this->l('No').'

    '; - - if (!file_exists($exists_file) && !empty($productDownload->display_filename) && empty($cache_default_attribute)) - { - $msg = sprintf(Tools::displayError('This file "%s" is missing'), $productDownload->display_filename); - $content .= '

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

    '; - } - - if (!ProductDownload::checkWritableDir()) - { - $content .= '

    - '.$this->l('Your download repository is not writable.').'
    - '.realpath(_PS_DOWNLOAD_DIR_).' -

    '; - } - - $content .= ' -
    -

    '.$this->l('Pre-tax wholesale price:').' - '.($currency->format % 2 != 0 ? $currency->sign.' ' : '').''.($currency->format % 2 == 0 ? ' '.$currency->sign : '').' + '.($currency->format % 2 != 0 ? $currency->sign.' ' : '').''.($currency->format % 2 == 0 ? ' '.$currency->sign : '').' '.$this->l('The wholesale price at which you bought this product').'
    '.$this->l('Pre-tax retail price:').' - '.($currency->format % 2 != 0 ? $currency->sign.' ' : '').''.($currency->format % 2 == 0 ? ' '.$currency->sign : '').' * + '.($currency->format % 2 != 0 ? $currency->sign.' ' : '').''.($currency->format % 2 == 0 ? ' '.$currency->sign : '').' * '.$this->l('The pre-tax retail price to sell this product').'
    '.$this->l('Eco-tax (tax incl.):').' - '.($currency->format % 2 != 0 ? $currency->sign.' ' : '').''.($currency->format % 2 == 0 ? ' '.$currency->sign : '').' + '.($currency->format % 2 != 0 ? $currency->sign.' ' : '').''.($currency->format % 2 == 0 ? ' '.$currency->sign : '').' ('.$this->l('already included in price').')
    '.$this->l('Unit price without tax:').' - '.($currency->format % 2 != 0 ? ' '.$currency->sign : '').' '.($currency->format % 2 == 0 ? ' '.$currency->sign : '').' '.$this->l('per').' '. - (Configuration::get('PS_TAX') && $this->context->country->display_tax_label ? ''.$this->l('or').' '.($currency->format % 2 != 0 ? ' '.$currency->sign : '').'0.00'.($currency->format % 2 == 0 ? ' '.$currency->sign : '').' '.$this->l('per').' '.$this->getFieldValue($obj, 'unity').' '.$this->l('with tax') : '').' + '.($currency->format % 2 != 0 ? ' '.$currency->sign : '').' '.($currency->format % 2 == 0 ? ' '.$currency->sign : '').' '.$this->l('per').' '. + (Configuration::get('PS_TAX') && $this->context->country->display_tax_label ? ''.$this->l('or').' '.($currency->format % 2 != 0 ? ' '.$currency->sign : '').'0.00'.($currency->format % 2 == 0 ? ' '.$currency->sign : '').' '.$this->l('per').' '.$this->getFieldValue($product, 'unity').' '.$this->l('with tax') : '').'

    '.$this->l('Eg. $15 per Lb').'

      - getFieldValue($obj, 'on_sale') ? 'checked="checked"' : '').'value="1" />  + getFieldValue($product, 'on_sale') ? 'checked="checked"' : '').'value="1" /> 
    '.$this->l('Minimum quantity:').' - +

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

    '.$this->l('Additional shipping cost:').' - '.($currency->format % 2 == 0 ? ' '.$currency->sign : ''); + '.($currency->format % 2 == 0 ? ' '.$currency->sign : ''); if ($this->context->country->display_tax_label) $content .= ' ('.$this->l('tax excl.').')'; @@ -2797,7 +2572,7 @@ switch ($this->action) foreach ($this->_languages as $language) $content .= '
    + value="'.stripslashes(htmlentities($this->getFieldValue($product, 'available_now', $language['id_lang']), ENT_COMPAT, 'UTF-8')).'" /> '.$this->l('Forbidden characters:').' <>;=#{} 
    '; $content .= '
    '.$this->l('Available date:').' - +

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

    '.$this->l('When out of stock:').' - getFieldValue($obj, 'out_of_stock')) == 0 ? 'checked="checked"' : '').'/> -
    getFieldValue($obj, 'out_of_stock') == 1 ? 'checked="checked"' : '').'/> -
    getFieldValue($obj, 'out_of_stock') == 2 ? 'checked="checked"' : '').'/> + getFieldValue($product, 'out_of_stock')) == 0 ? 'checked="checked"' : '').'/> +
    getFieldValue($product, 'out_of_stock') == 1 ? 'checked="checked"' : '').'/> +
    getFieldValue($product, 'out_of_stock') == 2 ? 'checked="checked"' : '').'/>
    '; foreach ($this->_languages as $language) $content .= '
    - +
    '; $content .= '

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

    '.$this->l('Tags:').' '; - if ($obj->id) - $obj->tags = Tag::getProductTags((int)$obj->id); + if ($product->id) + $product->tags = Tag::getProductTags((int)$product->id); foreach ($this->_languages as $language) { $content .= '
    + value="'.htmlentities(Tools::getValue('tags_'.$language['id_lang'], $product->getTags($language['id_lang'], true)), ENT_COMPAT, 'UTF-8').'" /> '.$this->l('Forbidden characters:').' !<>;?=+#"°{}_$% 
    '; } $content .= '

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

    - - - -