// Refacto of CategoryController

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@8898 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
rMalie
2011-09-29 16:31:32 +00:00
parent 923eb2cd21
commit 227e13680b
5 changed files with 112 additions and 93 deletions
+3 -3
View File
@@ -372,6 +372,9 @@ class FrontControllerCore extends Controller
public function display()
{
Tools::safePostVars();
$this->context->smarty->assign('errors', $this->errors);
if ($this->displayHeader)
$this->context->smarty->display(_PS_THEME_DIR_.'header.tpl');
@@ -514,9 +517,6 @@ class FrontControllerCore extends Controller
// P3P Policies (http://www.w3.org/TR/2002/REC-P3P-20020416/#compact_policies)
header('P3P: CP="IDC DSP COR CURa ADMa OUR IND PHY ONL COM STA"');
Tools::safePostVars();
$this->context->smarty->assign('errors', $this->errors);
/* Hooks are volontary out the initialize array (need those variables already assigned) */
$this->context->smarty->assign(array(
'time' => time(),
+103 -84
View File
@@ -30,6 +30,9 @@ class CategoryControllerCore extends FrontController
public $php_self = 'category';
protected $category;
/**
* Set default medias for this controller
*/
public function setMedia()
{
parent::setMedia();
@@ -37,7 +40,8 @@ class CategoryControllerCore extends FrontController
_PS_CSS_DIR_.'jquery.cluetip.css' => 'all',
_THEME_CSS_DIR_.'scenes.css' => 'all',
_THEME_CSS_DIR_.'category.css' => 'all',
_THEME_CSS_DIR_.'product_list.css' => 'all'));
_THEME_CSS_DIR_.'product_list.css' => 'all',
));
if (Configuration::get('PS_COMPARATOR_MAX_ITEM') > 0)
$this->addJS(_THEME_JS_DIR_.'products-comparison.js');
@@ -49,118 +53,133 @@ class CategoryControllerCore extends FrontController
parent::canonicalRedirection($this->context->link->getCategoryLink($this->category));
}
/**
* Initialize category controller
* @see FrontController::init()
*/
public function init()
{
parent::init();
if ($id_category = (int)Tools::getValue('id_category'))
$this->category = new Category($id_category, $this->context->language->id);
if (!Validate::isLoadedObject($this->category))
// Get category ID
$id_category = (int)Tools::getValue('id_category');
if (!$id_category || !Validate::isUnsignedId($id_category))
$this->errors[] = Tools::displayError('Missing category ID');
// Instantiate category
$this->category = new Category($id_category, $this->context->language->id);
if (!Validate::isLoadedObject($this->category) || !$this->category->inShop())
{
$this->errors[] = Tools::displayError('Category does not exist');
header('HTTP/1.1 404 Not Found');
header('Status: 404 Not Found');
}
else
$this->canonicalRedirection();
if (!$this->category->checkAccess($this->context->customer->id))
$this->errors[] = Tools::displayError('You do not have access to this category.');
}
public function process()
public function initContent()
{
parent::process();
if (!($id_category = (int)Tools::getValue('id_category')) OR !Validate::isUnsignedId($id_category))
$this->errors[] = Tools::displayError('Missing category ID');
else
{
if (!Validate::isLoadedObject($this->category) || !$this->category->inShop())
$this->errors[] = Tools::displayError('Category does not exist');
elseif (!$this->category->checkAccess($this->context->customer->id))
$this->errors[] = Tools::displayError('You do not have access to this category.');
elseif (!$this->category->active)
$this->context->smarty->assign('category', $this->category);
else
{
$rewrited_url = $this->context->link->getCategoryLink((int)$this->category->id, $this->category->link_rewrite);
/* Scenes (could be externalised to another controler if you need them */
$scenes = Scene::getScenes($this->category->id, $this->context->language->id, true, false);
$this->context->smarty->assign('scenes', $scenes);
/* Scenes images formats */
if (sizeof($scenes))
{
if ($sceneImageTypes = ImageType::getImagesTypes('scenes'))
{
foreach ($sceneImageTypes AS $sceneImageType)
{
if ($sceneImageType['name'] == 'thumb_scene')
$thumbSceneImageType = $sceneImageType;
elseif ($sceneImageType['name'] == 'large_scene')
$largeSceneImageType = $sceneImageType;
}
$this->context->smarty->assign('thumbSceneImageType', isset($thumbSceneImageType) ? $thumbSceneImageType : NULL);
$this->context->smarty->assign('largeSceneImageType', isset($largeSceneImageType) ? $largeSceneImageType : NULL);
}
}
$this->category->description = Tools::nl2br($this->category->description);
$subCategories = $this->category->getSubCategories($this->context->language->id);
$this->context->smarty->assign('category', $this->category);
if (isset($subCategories) AND !empty($subCategories) AND $subCategories)
{
$this->context->smarty->assign('subcategories', $subCategories);
$this->context->smarty->assign(array(
'subcategories_nb_total' => sizeof($subCategories),
'subcategories_nb_half' => ceil(sizeof($subCategories) / 2)));
}
if ($this->category->id != 1)
$this->productListAssign();
$this->context->smarty->assign(array(
'products' => (isset($this->cat_products) AND $this->cat_products) ? $this->cat_products : NULL,
'id_category' => (int)($this->category->id),
'id_category_parent' => (int)($this->category->id_parent),
'return_category_name' => Tools::safeOutput($this->category->name),
'path' => Tools::getPath($this->category->id),
'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
'categorySize' => Image::getSize('category'),
'mediumSize' => Image::getSize('medium'),
'thumbSceneSize' => Image::getSize('thumb_scene'),
'homeSize' => Image::getSize('home')
));
if (isset($this->context->customer->id))
$this->context->smarty->assign('compareProducts', CompareProduct::getCustomerCompareProducts($this->context->customer->id));
elseif (isset($this->context->customer->id_guest))
$this->context->smarty->assign('compareProducts', CompareProduct::getGuestCompareProducts($this->context->customer->id_guest));
}
}
if (isset($this->context->customer->id))
$this->context->smarty->assign('compareProducts', CompareProduct::getCustomerCompareProducts($this->context->customer->id));
else if (isset($this->context->customer->id_guest))
$this->context->smarty->assign('compareProducts', CompareProduct::getGuestCompareProducts($this->context->customer->id_guest));
$this->productSort();
$this->context->smarty->assign(array(
'allow_oosp' => (int)(Configuration::get('PS_ORDER_OUT_OF_STOCK')),
'comparator_max_item' => (int)(Configuration::get('PS_COMPARATOR_MAX_ITEM')),
'category' => $this->category,
'products' => (isset($this->cat_products) && $this->cat_products) ? $this->cat_products : NULL,
'id_category' => (int)$this->category->id,
'id_category_parent' => (int)$this->category->id_parent,
'return_category_name' => Tools::safeOutput($this->category->name),
'path' => Tools::getPath($this->category->id),
'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
'categorySize' => Image::getSize('category'),
'mediumSize' => Image::getSize('medium'),
'thumbSceneSize' => Image::getSize('thumb_scene'),
'homeSize' => Image::getSize('home'),
'allow_oosp' => (int)Configuration::get('PS_ORDER_OUT_OF_STOCK'),
'comparator_max_item' => (int)Configuration::get('PS_COMPARATOR_MAX_ITEM'),
'suppliers' => Supplier::getSuppliers()
));
$this->assignScenes();
if ($this->category->id != 1)
$this->assignProductList();
$this->setTemplate(_PS_THEME_DIR_.'category.tpl');
}
public function productListAssign()
/**
* Assign scenes template vars
*/
protected function assignScenes()
{
// Scenes (could be externalised to another controler if you need them)
$scenes = Scene::getScenes($this->category->id, $this->context->language->id, true, false);
$this->context->smarty->assign('scenes', $scenes);
// Scenes images formats
if ($scenes && ($sceneImageTypes = ImageType::getImagesTypes('scenes')))
{
foreach ($sceneImageTypes as $sceneImageType)
{
if ($sceneImageType['name'] == 'thumb_scene')
$thumbSceneImageType = $sceneImageType;
elseif ($sceneImageType['name'] == 'large_scene')
$largeSceneImageType = $sceneImageType;
}
$this->context->smarty->assign(array(
'thumbSceneImageType' => isset($thumbSceneImageType) ? $thumbSceneImageType : null,
'largeSceneImageType' => isset($largeSceneImageType) ? $largeSceneImageType : null,
));
}
}
/**
* Assign sub categories templates vars
*/
protected function assignSubcategories()
{
if ($subCategories = $this->category->getSubCategories($this->context->language->id))
{
$this->context->smarty->assign(array(
'subcategories' => $subCategories,
'subcategories_nb_total' => count($subCategories),
'subcategories_nb_half' => ceil(count($subCategories) / 2)
));
}
}
/**
* Assign list of products template vars
*/
public function assignProductList()
{
$hookExecuted = false;
Module::hookExec('productListAssign', array('nbProducts' => &$this->nbProducts, 'catProducts' => &$this->cat_products, 'hookExecuted' => &$hookExecuted));
if (!$hookExecuted) // The hook was not executed, standard working
Module::hookExec('productListAssign', array(
'nbProducts' => &$this->nbProducts,
'catProducts' => &$this->cat_products,
'hookExecuted' => &$hookExecuted,
));
// The hook was not executed, standard working
if (!$hookExecuted)
{
$this->context->smarty->assign('categoryNameComplement', '');
$this->nbProducts = $this->category->getProducts(NULL, NULL, NULL, $this->orderBy, $this->orderWay, true);
$this->nbProducts = $this->category->getProducts(null, null, null, $this->orderBy, $this->orderWay, true);
$this->pagination((int)$this->nbProducts); // Pagination must be call after "getProducts"
$this->cat_products = $this->category->getProducts($this->context->language->id, (int)$this->p, (int)$this->n, $this->orderBy, $this->orderWay);
}
else // Hook executed, use the override
$this->pagination((int)$this->nbProducts); // Pagination must be call after "getProducts"
self::$smarty->assign('nb_products', (int)$this->nbProducts);
// Hook executed, use the override
else
// Pagination must be call after "getProducts"
$this->pagination($this->nbProducts);
$this->context->smarty->assign('nb_products', $this->nbProducts);
}
}
+1 -1
View File
@@ -644,7 +644,7 @@ class MoneyBookers extends PaymentModule
/* About the cart */
$mbParams['transaction_id'] = (int)($params['cart']->id).'_'.date('YmdHis').'_'.$params['cart']->secure_key;
$mbParams['currency'] = $currency->iso_code;
$mbParams['mb_currency'] = $currency->iso_code;
$mbParams['amount'] = number_format($params['cart']->getOrderTotal(), 2, '.', '');
/* URLs */
+4 -4
View File
@@ -1,5 +1,5 @@
{*
* 2007-2011 PrestaShop
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
@@ -49,7 +49,7 @@
{if isset($state) && !empty($state)}<input type="hidden" name="state" value="{$state}" />{/if}
<input type="hidden" name="country" value="{$country}" />
<input type="hidden" name="amount" value="{$amount}" />
<input type="hidden" name="currency" value="{$currency}" />
<input type="hidden" name="currency" value="{$mb_currency}" />
<input type="hidden" name="amount2_description" value="{if isset($amount2_description)}{$amount2_description}{/if}" />
<input type="hidden" name="amount2" value="{if isset($amount2)}{$amount2}{/if}" />
<input type="hidden" name="amount3_description" value="{if isset($amount3_description)}{$amount3_description}{/if}" />
@@ -96,7 +96,7 @@
{if isset($state) && !empty($state)}<input type="hidden" name="state" value="{$state}" />{/if}
<input type="hidden" name="country" value="{$country}" />
<input type="hidden" name="amount" value="{$amount}" />
<input type="hidden" name="currency" value="{$currency}" />
<input type="hidden" name="currency" value="{$mb_currency}" />
<input type="hidden" name="amount2_description" value="{if isset($amount2_description)}{$amount2_description}{/if}" />
<input type="hidden" name="amount2" value="{if isset($amount2)}{$amount2}{/if}" />
<input type="hidden" name="amount3_description" value="{if isset($amount3_description)}{$amount3_description}{/if}" />
@@ -138,7 +138,7 @@
{if isset($state) && (!empty($state))}<input type="hidden" name="state" value="{$state}" />{/if}
<input type="hidden" name="country" value="{$country}" />
<input type="hidden" name="amount" value="{$amount}" />
<input type="hidden" name="currency" value="{$currency}" />
<input type="hidden" name="currency" value="{$mb_currency}" />
<input type="hidden" name="amount2_description" value="{if isset($amount2_description)}{$amount2_description}{/if}" />
<input type="hidden" name="amount2" value="{if isset($amount2)}{$amount2}{/if}" />
<input type="hidden" name="amount3_description" value="{if isset($amount3_description)}{$amount3_description}{/if}" />
+1 -1
View File
@@ -53,7 +53,7 @@
{/if}
{if $category->description}
<div class="cat_desc">{$category->description}</div>
<div class="cat_desc">{$category->description|nl2br}</div>
{/if}
{if isset($subcategories)}
<!-- Subcategories -->