From 2ede4caa48270c12d7660b5b605c90c3eaaf5a67 Mon Sep 17 00:00:00 2001 From: lLefevre Date: Thu, 15 Dec 2011 17:54:59 +0000 Subject: [PATCH] // added pack.tpl and virtualproduct.tpl git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@11288 b9a71923-0436-4b27-9f14-aed3839534dd --- .../themes/template/products/combinations.tpl | 2 +- admin-dev/themes/template/products/form.tpl | 54 ++--- admin-dev/themes/template/products/pack.tpl | 98 +++++++++ .../template/products/virtualproduct.tpl | 194 ++++++++++++++++++ classes/ProductDownload.php | 2 +- controllers/admin/AdminProductsController.php | 117 +++++++++++ 6 files changed, 440 insertions(+), 27 deletions(-) create mode 100644 admin-dev/themes/template/products/pack.tpl create mode 100644 admin-dev/themes/template/products/virtualproduct.tpl diff --git a/admin-dev/themes/template/products/combinations.tpl b/admin-dev/themes/template/products/combinations.tpl index 9e7aed62e..14a2fd496 100644 --- a/admin-dev/themes/template/products/combinations.tpl +++ b/admin-dev/themes/template/products/combinations.tpl @@ -166,7 +166,7 @@ {/if}

- +

diff --git a/admin-dev/themes/template/products/form.tpl b/admin-dev/themes/template/products/form.tpl index acfe137f9..abc8d3cf6 100644 --- a/admin-dev/themes/template/products/form.tpl +++ b/admin-dev/themes/template/products/form.tpl @@ -79,7 +79,36 @@ var toload = new Array(); $(document).ready(function(){ + + {if $is_pack} + $('#pack_product').attr("checked", "checked"); + $('li.tab-row a[id*="VirtualProduct"]').hide(); + {elseif $product->is_virtual} + $('#virtual_product').attr("checked", "checked"); + $('li.tab-row a[id*="Pack"]').hide(); + {else} + $('#simple_product').attr("checked", "checked"); + $('li.tab-row a[id*="Pack"]').hide(); + $('li.tab-row a[id*="VirtualProduct"]').hide(); + {/if} + + $('input[name="type_product"]').click(function() { + $('li.tab-row a[id*="Pack"]').hide(); + $('li.tab-row a[id*="VirtualProduct"]').hide(); + var val = $(this).val(); + if (val == 1) + $('li.tab-row a[id*="Pack"]').show(); + else if (val == 2) + $('li.tab-row a[id*="VirtualProduct"]').show(); + else + { + $('#is_virtual_good').removeAttr("checked"); + $('#is_virtual').val(0); + } + }); + $('#desc-product-newCombination').hide(); + {* submenu binding *} $(".tab-page").click(function(e){ e.preventDefault(); @@ -160,31 +189,6 @@ + +

{l s='Pack'}

+
+ + + + + + + +
+ + + +
+
+ {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'} +
diff --git a/admin-dev/themes/template/products/virtualproduct.tpl b/admin-dev/themes/template/products/virtualproduct.tpl new file mode 100644 index 000000000..282040f7e --- /dev/null +++ b/admin-dev/themes/template/products/virtualproduct.tpl @@ -0,0 +1,194 @@ +{* +* 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: 11204 $ +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} + + + +

{l s='Virtual Product'}

+
+ + + + +
+

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

+ {* [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} +
+
+
\ No newline at end of file diff --git a/classes/ProductDownload.php b/classes/ProductDownload.php index 76c751e5b..5df6e1fb7 100644 --- a/classes/ProductDownload.php +++ b/classes/ProductDownload.php @@ -67,7 +67,7 @@ class ProductDownloadCore extends ObjectModel 'primary' => 'id_product_download', 'fields' => array( 'id_product' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true), - 'id_product_attribute ' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), + 'id_product_attribute' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'display_filename' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 255), 'filename' => array('type' => self::TYPE_STRING, 'validate' => 'isSha1', 'size' => 255), 'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index c39e5f234..834fa4190 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -38,6 +38,8 @@ class AdminProductsControllerCore extends AdminController protected $available_tabs = array( 'Informations', + 'Pack', + 'VirtualProduct', 'Prices', 'Seo', 'Associations', @@ -57,6 +59,8 @@ class AdminProductsControllerCore extends AdminController protected $tabs_preloaded = array( 'Informations' => true, + 'Pack' => true, + 'VirtualProduct' => true, 'Prices' => true, 'Seo' => true, 'Associations' => true, @@ -157,6 +161,8 @@ class AdminProductsControllerCore extends AdminController // @since 1.5 : translations for tabs $this->available_tabs_lang = array ( 'Informations' => $this->l('Informations'), + 'Pack' => $this->l('Pack'), + 'VirtualProduct' => $this->l('Virtual Product'), 'Prices' => $this->l('Prices'), 'Seo' => $this->l('SEO'), 'Images' => $this->l('Images'), @@ -2536,6 +2542,117 @@ class AdminProductsControllerCore extends AdminController $this->tpl_form_vars['custom_form'] = $this->context->smarty->createTemplate($this->tpl_form, $data)->fetch(); } + public function initFormPack($product, $languages, $default_language) + { + $data = $this->context->smarty->createData(); + + $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 $pack_item) + $input_pack_items .= $pack_item->pack_quantity.'x'.$pack_item->id.'-'; + + $input_namepack_items = ''; + if (Tools::getValue('namePackItems')) + $input_namepack_items = Tools::getValue('namePackItems'); + else + foreach ($product->packItems as $pack_item) + $input_namepack_items .= $pack_item->pack_quantity.' x '.$pack_item->name.'¤'; + + $data->assign(array( + 'product' => $product, + 'languages' => $languages, + 'default_language' => $default_language, + 'ps_ssl_enabled' => Configuration::get('PS_SSL_ENABLED'), + 'is_pack' => ($product->id && Pack::isPack($product->id)) || Tools::getValue('ppack'), + 'input_pack_items' => $input_pack_items, + 'input_namepack_items' => $input_namepack_items + )); + + $this->tpl_form_vars['custom_form'] = $this->context->smarty->createTemplate($this->tpl_form, $data)->fetch(); + } + + public function initFormVirtualProduct($product, $languages, $default_language) + { + + $data = $this->context->smarty->createData(); + + $currency = $this->context->currency; + + /* + * Form for adding a virtual product like software, mp3, etc... + */ + $product_download = new ProductDownload(); + if ($id_product_download = $product_download->getIdFromIdProduct($this->getFieldValue($product, 'id'))) + $product_download = new ProductDownload($id_product_download); + $product->{'productDownload'} = $product_download; + + // @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)); + + if (!file_exists($exists_file) + && !empty($product->productDownload->display_filename) + && !empty($product->cache_default_attribute)) + { + $msg = sprintf(Tools::displayError('This file "%s" is missing'), $product->productDownload->display_filename); + } + 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')) || $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) + { + $product_download_attribute = new ProductDownload($p['id_product_download']); + $exists_file2 = realpath(_PS_DOWNLOAD_DIR_).'/'.$product_download_attribute->filename; + if (!file_exists($exists_file2) && !empty($product_download_attribute->id_product_attribute)) + { + $msg = sprintf(Tools::displayError('This file "%s" is missing'), $product_download_attribute->display_filename); + $error .= '

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

'; + } + } + $data->assign('error_product_download', $error); + } + + $data->assign('ad', dirname($_SERVER['PHP_SELF'])); + $data->assign('product', $product); + $data->assign('token', $this->token); + $data->assign('currency', $currency); + $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(); + } + private function _getFinalPrice($specific_price, $productPrice, $taxRate) { $price = Tools::ps_round((float)($specific_price['price']) ? $specific_price['price'] : $productPrice, 2);