From fe292b6b341bade8893d9de34353a32c72025097 Mon Sep 17 00:00:00 2001 From: mMarinetti Date: Fri, 21 Oct 2011 17:31:54 +0000 Subject: [PATCH] // added adminProduct - combination - #PSFV-94 bugfix on AdminProductsController --- .../themes/template/products/combinations.tpl | 323 ++++++++++++++++ .../themes/template/products/content.tpl | 80 ++-- controllers/admin/AdminProductsController.php | 357 +++--------------- 3 files changed, 436 insertions(+), 324 deletions(-) create mode 100644 admin-dev/themes/template/products/combinations.tpl diff --git a/admin-dev/themes/template/products/combinations.tpl b/admin-dev/themes/template/products/combinations.tpl new file mode 100644 index 000000000..dfbea4da5 --- /dev/null +++ b/admin-dev/themes/template/products/combinations.tpl @@ -0,0 +1,323 @@ +{l s='Add a new combination'} + + + + + + +
{l s='Add or modify combinations for this product'} {l s='or go to'} +  combinations_generator {l s='Product combinations generator'} +
+

+ + + + + + + +{$content} diff --git a/admin-dev/themes/template/products/content.tpl b/admin-dev/themes/template/products/content.tpl index 524da282b..f6e83677c 100644 --- a/admin-dev/themes/template/products/content.tpl +++ b/admin-dev/themes/template/products/content.tpl @@ -9,7 +9,7 @@
    {foreach $product_tabs key=numStep item=tab}
  1. - {$tab.name}{*todo href when nojs*} + {$tab.name}{*todo href when nojs*}
  2. {/foreach}
@@ -20,36 +20,53 @@ var pos_select = {$pos_select}; $(document).ready(function(){ $(".tab-page").click(function(e){ e.preventDefault(); + // currentId is the current producttab id + currentId = $(".productTabs a.selected").attr('id').substr(5); + // id is the wanted producttab id id = $(this).attr('id').substr(5); $(".tab-page").removeClass('selected'); - $("#product-tab-content").html("... LOADING ..."); - $("#link-"+id).addClass('selected'); - myurl = $(this).attr("href")+"&ajax=1"; - $.ajax({ - url : myurl, - async : true, - success :function(data) - { - $("#product-tab-content").html(data); - var languages = new Array(); - if (id == 3) - populate_attrs(); - if (id == 7) + $("#product-tab-content-"+currentId).hide(); + $("#product-tab-content-wait").show();; + + + if($("#product-tab-content-"+id).hasClass('not-loaded')) + { + myurl = $(this).attr("href")+"&ajax=1"; + $.ajax({ + url : myurl, + async : true, + success :function(data) { - $("#addAttachment").click(function() { - return !$("#selectAttachment1 option:selected").remove().appendTo("#selectAttachment2"); - }); - $("#removeAttachment").click(function() { - return !$("#selectAttachment2 option:selected").remove().appendTo("#selectAttachment1"); - }); - $("#product").submit(function() { - $("#selectAttachment1 option").each(function(i) { - $(this).attr("selected", "selected"); - }); - }); + $("#product-tab-content-"+id).html(data); + $("#product-tab-content-"+id).removeClass('not-loaded'); + $("#product-tab-content-"+id).show(); + $("#link-"+id).addClass('selected'); } - } - }); + }); + } + else + { + $("#product-tab-content-"+id).show(); + $("#link-"+id).addClass('selected'); + } + + var languages = new Array(); + if (id == 3) + populate_attrs(); + if (id == 7) + { + $("#addAttachment").click(function() { + return !$("#selectAttachment1 option:selected").remove().appendTo("#selectAttachment2"); + }); + $("#removeAttachment").click(function() { + return !$("#selectAttachment2 option:selected").remove().appendTo("#selectAttachment1"); + }); + $("#product").submit(function() { + $("#selectAttachment1 option").each(function(i) { + $(this).attr("selected", "selected"); + }); + }); + } }); }); @@ -169,9 +186,14 @@ $(document).ready(function(){
-
-{$content} + + {foreach $product_tabs key=numStep item=tab} +
+{if $tab.selected}{$content}{/if} +
+ {/foreach}
+
{l s='Back to list'}
diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index 8c393006d..feb4f5442 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -1705,6 +1705,11 @@ if (false) $this->context->smarty->assign('draft_warning',$content); } + /** + * initForm contains all necessary initialization needed for all tabs + * + * @return void + */ public function initForm() { $this->addJqueryUI('ui.datepicker'); @@ -1715,6 +1720,8 @@ 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('country_display_tax_label', $this->context->country->display_tax_label); + if (!($obj = $this->loadObject(true))) throw new Exception('object not loaded'); $this->_displayDraftWarning($obj->active); @@ -1725,18 +1732,31 @@ if (false) { $content = ''; parent::displayForm(); + $this->addJs(_PS_JS_DIR_.'attributesBack.js'); if (!($obj = $this->loadObject(true))) throw new Exception('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) { $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, ); } + } + $smarty->assign('product_tabs', $product_tabs); if ($id_category_back = (int)(Tools::getValue('id_category'))) @@ -1752,9 +1772,6 @@ if (false) // $this->addJqueryPlugin('tabpane'); - $action = $this->action; - if (empty($action) || !method_exists($this,'initForm'.$action)) - $action = 'informations'; $content .= $this->initForm(); $this->{'initForm'.$action}($obj, null); /* Tabs */ @@ -1973,7 +1990,6 @@ switch ($this->action) if (!($product = $this->loadObject())) return; $content = ''; - $this->context->smarty->assign('country_display_tax_label', $this->context->country->display_tax_label); $content .= '
@@ -2479,6 +2495,8 @@ switch ($this->action) } $content .= '
'; + // found in informations and combination : to merge + $smarty->assign('up_filename', strval(Tools::getValue('virtual_product_filename'))); if ($up_filename = strval(Tools::getValue('virtual_product_filename'))) $content .= ''; @@ -2737,9 +2755,9 @@ switch ($this->action)    @@ -3300,29 +3318,7 @@ switch ($this->action)
'; - $content .= ' - - '; + $smarty->assign('up_filename', strval(Tools::getValue('virtual_product_filename_attribute'))); $smarty->assign('content',$content); $this->content = $smarty->fetch('products/images.tpl'); } @@ -3665,6 +3661,7 @@ switch ($this->action) { return $this->initFormAttributes($obj, $languages, $defaultLanguage); } + public function initFormAttributes($obj, $languages, $defaultLanguage) { if (!Combination::isFeatureActive()) @@ -3672,6 +3669,8 @@ switch ($this->action) $this->displayWarning($this->l('This feature has been disabled, you can active this feature at this page:').' '.$this->l('Performances').''); return; } + + $smarty = $this->context->smarty; $content = ''; $attributeJs = array(); @@ -3679,7 +3678,8 @@ switch ($this->action) foreach ($attributes as $k => $attribute) $attributeJs[$attribute['id_attribute_group']][$attribute['id_attribute']] = $attribute['name']; $currency = $this->context->currency; - $attributes_groups = AttributeGroup::getAttributesGroups($this->context->language->id); + $smarty->assign('attributeJs', $attributeJs); + $smarty->assign('attributes_groups', AttributeGroup::getAttributesGroups($this->context->language->id)); $default_country = new Country((int)Configuration::get('PS_COUNTRY_DEFAULT')); $productDownload = new ProductDownload(); @@ -3687,275 +3687,38 @@ switch ($this->action) if (!empty($id_product_download)) $productDownload = new ProductDownload($id_product_download); + $smarty->assign('productDownload', $productDownload); + $smarty->assign('currency', $currency); + $images = Image::getImages($this->context->language->id, $obj->id); if ($obj->id) { - $content .= ' - - - - - -
'.$this->l('Add or modify combinations for this product').' - -  combinations_generator '.$this->l('Product combinations generator').' -
-

- - - - - - - - - - - - - - - - - - - - - - - - -
'.$this->l('Group:').'
'.$this->l('Attribute:').' - -
-
-
- -

'.$this->l('Reference:').' - - '.$this->l('EAN13:').' - '.$this->l('UPC:').' - '.$this->l('Special characters allowed:').' .-_#  -
'.$this->l('Supplier Reference:').' - - '.$this->l('Location:').' - '.$this->l('Special characters allowed:').' .-_#  -

- - - - - - - - - - - - - - - - - - - - - - '; - if (Configuration::get('PS_USE_ECOTAX')) - $content .= ' - - - - '; - - $content .= ' - - - - - - - - - - - - - - - - - - - - - '; + $smarty->assign('reasons', $reasons = StockMvtReason::getStockMvtReasons($this->context->language->id)); + $smarty->assign('ps_stock_mvt_reason_default', $ps_stock_mvt_reason_default = Configuration::get('PS_STOCK_MVT_REASON_DEFAULT')); + $smarty->assign('minimal_quantity', $this->getFieldValue($obj, 'minimal_quantity') ? $this->getFieldValue($obj, 'minimal_quantity') : 1); + $smarty->assign('available_date', ($this->getFieldValue($obj, 'available_date') != 0) ? stripslashes(htmlentities(Tools::displayDate($this->getFieldValue($obj, 'available_date'), $language['id_lang']))) : '0000-00-00'); // date picker include - $content .= ' - - - - - - - - - - - - - + $smarty->assign('images', $images); + $content .= ' +
+
'.$this->l('Wholesale price:').''.($currency->format % 2 != 0 ? $currency->sign.' ' : '').''.($currency->format % 2 == 0 ? ' '.$currency->sign : '').' ('.$this->l('overrides Wholesale price on Information tab').')
'.$this->l('Impact on price:').' - -   '.$this->l('of').'  '.($currency->format % 2 != 0 ? $currency->sign.' ' : '').' - '.($currency->format % 2 == 0 ? ' '.$currency->sign : ''); - if ($this->context->country->display_tax_label) - { - $content .= ' '.$this->l('(tax excl.)').' '.$this->l('or').' '.($currency->format % 2 != 0 ? $currency->sign.' ' : '').' - '.($currency->format % 2 == 0 ? ' '.$currency->sign : '').' '.$this->l('(tax incl.)').' '.$this->l('final product price will be set to').' '.($currency->format % 2 != 0 ? $currency->sign.' ' : '').'0.00'.($currency->format % 2 == 0 ? $currency->sign.' ' : ''); - } - $content .= ' - -
'.$this->l('Impact on weight:').' -   '.$this->l('of').'   - '.Configuration::get('PS_WEIGHT_UNIT').'
'.$this->l('Impact on unit price :').' -   '.$this->l('of').'  '.($currency->format % 2 != 0 ? $currency->sign.' ' : '').' - '.($currency->format % 2 == 0 ? ' '.$currency->sign : '').' / '.$this->getFieldValue($obj, 'unity').' -
'.$this->l('Eco-tax:').''.($currency->format % 2 != 0 ? $currency->sign.' ' : '').''.($currency->format % 2 == 0 ? ' '.$currency->sign : '').' ('.$this->l('overrides Eco-tax on Information tab').')
'.$this->l('Initial stock:').'
'.$this->l('Minimum quantity:').' - -

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

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

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

-

'.$this->l('Image:').' -
    '; + + $i = 0; - $imageType = ImageType::getByNameNType('small', 'products'); - $imageWidth = (isset($imageType['width']) ? (int)($imageType['width']) : 64) + 25; - foreach ($images as $image) + $smarty->assign('imageType', ImageType::getByNameNType('small', 'products')); + $smarty->assign('imageWidth', (isset($imageType['width']) ? (int)($imageType['width']) : 64) + 25); + foreach ($images as $k => $image) { - $imageObj = new Image($image['id_image']); - $content .= '
  • -
  • '; + $images[$k]['obj'] = new Image($image['id_image']); ++$i; } - $content .= '
- -
'.$this->l('Default:').'

-  '.$this->l('Make this the default combination for this product').'

-
  - - -

@@ -4071,7 +3834,7 @@ switch ($this->action) $filename = $productDownload->filename; else $filename = ''; - + // @todo : a better way to "fillCombinaison" maybe ? $content .= ' '.$this->l('Modify this combination').'action) var impact = getE(\'attribute_price_impact\'); var impact2 = getE(\'attribute_weight_impact\'); - var s_attr_group = document.getElementById(\'span_new_group\'); - var s_attr_name = document.getElementById(\'span_new_attr\'); - var s_impact = document.getElementById(\'span_impact\'); - var s_impact2 = document.getElementById(\'span_weight_impact\'); + var s_attr_group = $(\'#span_new_group\'); + var s_attr_name = $(\'#span_new_attr\'); + var s_impact = $(\'#span_impact\'); + var s_impact2 = $(\'#span_weight_impact\'); init_elems(); '; } else $content .= ''.$this->l('You must save this product before adding combinations').'.'; - $this->content = $content; + $this->context->smarty->assign('content', $content); + // @todo + $smarty->assign('up_filename', strval(Tools::getValue('virtual_product_filename_attribute'))); + + $this->content = $this->context->smarty->fetch('products/combinations.tpl'); } public function initFormFeatures($obj)