// Refactoring of shop class with new context

This commit is contained in:
rMalie
2011-07-12 16:28:20 +00:00
parent e7ea230525
commit 2d77925e7d
28 changed files with 216 additions and 185 deletions
+28 -30
View File
@@ -140,8 +140,7 @@ class BlockCategories extends Module
public function hookLeftColumn($params)
{
global $smarty, $cookie;
$context = Context::getContext();
$id_current_shop = $this->shopID;
$id_customer = (int)($params['cookie']->id_customer);
@@ -185,35 +184,35 @@ class BlockCategories extends Module
unset($resultIds);
//TODO clean that
$res = $blockCategTree;
$shopcurrentroot = Shop::getCurrentRootCategory();
if($blockCategTree['id'] != Shop::getCurrentRootCategory())
$shopcurrentroot = $context->shop->id_category;
if ($blockCategTree['id'] != $shopcurrentroot)
$blockCategTree = $this->cleanTree($blockCategTree['children']);
$isDhtml = (Configuration::get('BLOCK_CATEG_DHTML') == 1 ? true : false);
if (Tools::isSubmit('id_category'))
{
$cookie->last_visited_category = $id_category;
$smarty->assign('currentCategoryId', $cookie->last_visited_category);
$context->cookie->last_visited_category = $id_category;
$context->controller->smarty->assign('currentCategoryId', $context->cookie->last_visited_category);
}
if (Tools::isSubmit('id_product'))
{
if (!isset($cookie->last_visited_category) OR !Product::idIsOnCategoryId($id_product, array('0' => array('id_category' => $cookie->last_visited_category))))
if (!isset($context->cookie->last_visited_category) OR !Product::idIsOnCategoryId($id_product, array('0' => array('id_category' => $context->cookie->last_visited_category))))
{
$product = new Product($id_product);
if (isset($product) AND Validate::isLoadedObject($product))
$cookie->last_visited_category = (int)($product->id_category_default);
$context->cookie->last_visited_category = (int)($product->id_category_default);
}
$smarty->assign('currentCategoryId', (int)($cookie->last_visited_category));
$context->controller->smarty->assign('currentCategoryId', (int)($context->cookie->last_visited_category));
}
$smarty->assign('blockCategTree', $blockCategTree);
$context->controller->smarty->assign('blockCategTree', $blockCategTree);
if (file_exists(_PS_THEME_DIR_.'modules/blockcategories/blockcategories.tpl'))
$smarty->assign('branche_tpl_path', _PS_THEME_DIR_.'modules/blockcategories/category-tree-branch.tpl');
$context->controller->smarty->assign('branche_tpl_path', _PS_THEME_DIR_.'modules/blockcategories/category-tree-branch.tpl');
else
$smarty->assign('branche_tpl_path', _PS_MODULE_DIR_.'blockcategories/category-tree-branch.tpl');
$smarty->assign('isDhtml', $isDhtml);
$context->controller->smarty->assign('branche_tpl_path', _PS_MODULE_DIR_.'blockcategories/category-tree-branch.tpl');
$context->controller->smarty->assign('isDhtml', $isDhtml);
}
$smarty->cache_lifetime = 31536000; // 1 Year
$context->controller->smarty->cache_lifetime = 31536000; // 1 Year
$display = $this->display(__FILE__, 'blockcategories.tpl', $smartyCacheId);
Tools::restoreCacheSettings();
return $display;
@@ -221,8 +220,7 @@ class BlockCategories extends Module
public function hookFooter($params)
{
global $smarty, $cookie;
$context = Context::getContext();
$id_current_shop = $this->shopID;
$id_customer = (int)($params['cookie']->id_customer);
@@ -262,43 +260,43 @@ class BlockCategories extends Module
$nbrColumns=3;
$numberColumn = abs(sizeof($result)/$nbrColumns);
$widthColumn= floor(100/$nbrColumns);
$smarty->assign('numberColumn', $numberColumn);
$smarty->assign('widthColumn', $widthColumn);
$context->controller->smarty->assign('numberColumn', $numberColumn);
$context->controller->smarty->assign('widthColumn', $widthColumn);
$blockCategTree = $this->getTree($resultParents, $resultIds, Configuration::get('BLOCK_CATEG_MAX_DEPTH'));
unset($resultParents);
unset($resultIds);
//TODO clean that
$res = $blockCategTree;
if($blockCategTree['id'] != Shop::getCurrentRootCategory())
if($blockCategTree['id'] != $context->shop->id_category)
$blockCategTree = $this->cleanTree($blockCategTree['children']);
$isDhtml = (Configuration::get('BLOCK_CATEG_DHTML') == 1 ? true : false);
$isDhtml = (Configuration::get('BLOCK_CATEG_DHTML') == 1 ? true : false);
if (Tools::isSubmit('id_category'))
{
$cookie->last_visited_category = $id_category;
$smarty->assign('currentCategoryId', $cookie->last_visited_category);
$context->cookie->last_visited_category = $id_category;
$context->controller->smarty->assign('currentCategoryId', $context->cookie->last_visited_category);
}
if (Tools::isSubmit('id_product'))
{
if (!isset($cookie->last_visited_category) OR !Product::idIsOnCategoryId($id_product, array('0' => array('id_category' => $cookie->last_visited_category))))
if (!isset($context->cookie->last_visited_category) OR !Product::idIsOnCategoryId($id_product, array('0' => array('id_category' => $context->cookie->last_visited_category))))
{
$product = new Product($id_product);
if (isset($product) AND Validate::isLoadedObject($product))
$cookie->last_visited_category = (int)($product->id_category_default);
$context->cookie->last_visited_category = (int)($product->id_category_default);
}
$smarty->assign('currentCategoryId', (int)($cookie->last_visited_category));
$context->controller->smarty->assign('currentCategoryId', (int)($context->cookie->last_visited_category));
}
$smarty->assign('blockCategTree', $blockCategTree);
$context->controller->smarty->assign('blockCategTree', $blockCategTree);
if (file_exists(_PS_THEME_DIR_.'modules/blockcategories/blockcategories_footer.tpl'))
$smarty->assign('branche_tpl_path', _PS_THEME_DIR_.'modules/blockcategories/category-tree-branch.tpl');
$context->controller->smarty->assign('branche_tpl_path', _PS_THEME_DIR_.'modules/blockcategories/category-tree-branch.tpl');
else
$smarty->assign('branche_tpl_path', _PS_MODULE_DIR_.'blockcategories/category-tree-branch.tpl');
$smarty->assign('isDhtml', $isDhtml);
$context->controller->smarty->assign('branche_tpl_path', _PS_MODULE_DIR_.'blockcategories/category-tree-branch.tpl');
$context->controller->smarty->assign('isDhtml', $isDhtml);
}
$smarty->cache_lifetime = 31536000; // 1 Year
$context->controller->smarty->cache_lifetime = 31536000; // 1 Year
$display = $this->display(__FILE__, 'blockcategories_footer.tpl', $smartyCacheId);
Tools::restoreCacheSettings();
return $display;
@@ -306,7 +304,7 @@ class BlockCategories extends Module
public function cleanTree($categories)
{
$id_category_root = (int)Shop::getCurrentRootCategory();
$id_category_root = Context::getContext()->shop->id_category;
foreach ($categories AS $row)
{
if ($row['id'] == $id_category_root)
+6 -7
View File
@@ -283,10 +283,10 @@ class BlockLayered extends Module
public function getProductByFilters($selectedFilters = array())
{
global $cookie;
if (!empty($this->products))
return $this->products;
$context = Context::getContext();
/* If the current category isn't defined of if it's homepage, we have nothing to display */
$id_parent = (int)Tools::getValue('id_category', Tools::getValue('id_category_layered', 1));
@@ -387,15 +387,14 @@ class BlockLayered extends Module
p.ean13, pl.available_later, pl.description_short, pl.link_rewrite, pl.name, i.id_image, il.legend, m.name manufacturer_name, p.condition, p.id_manufacturer, s.quantity,
DATEDIFF(p.`date_add`, DATE_SUB(NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY)) > 0 AS new
FROM '._DB_PREFIX_.'product p
LEFT JOIN '._DB_PREFIX_.'product_shop ps ON ps.id_product = p.id_product
LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (pl.id_product = p.id_product AND pl.id_shop = '.Shop::getCurrentShop(true).')
LEFT JOIN '._DB_PREFIX_.'product_shop ps ON ps.id_product = p.id_product AND ps.id_shop = '.$this->shopID.'
LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (pl.id_product = p.id_product AND pl.id_shop = '.$this->shopID.')
LEFT JOIN '._DB_PREFIX_.'stock s ON s.id_product = p.id_product AND s.id_product_attribute = 0 '.Shop::sqlSharedStock('s').'
LEFT JOIN '._DB_PREFIX_.'image i ON (i.id_product = p.id_product AND i.cover = 1)
LEFT JOIN '._DB_PREFIX_.'image_lang il ON (i.id_image = il.id_image AND il.id_lang = '.(int)($cookie->id_lang).')
LEFT JOIN '._DB_PREFIX_.'image_lang il ON (i.id_image = il.id_image AND il.id_lang = '.(int)$context->language->id.')
LEFT JOIN '._DB_PREFIX_.'manufacturer m ON (m.id_manufacturer = p.id_manufacturer)
WHERE p.`active` = 1
AND pl.id_lang = '.(int)$cookie->id_lang.'
AND ps.id_shop = '.Shop::getCurrentShop(true)
AND pl.id_lang = '.(int)$context->language->id
.$queryFilters.
' ORDER BY '.Tools::getProductsOrder('by', Tools::getValue('orderby')).' '.Tools::getProductsOrder('way', Tools::getValue('orderway')).
' LIMIT '.(((int)(Tools::getValue('p', 1)) - 1) * $n.','.$n);
+23 -21
View File
@@ -144,13 +144,15 @@ function submitConfirm()
function submitAccount()
{
global $cookie, $errors, $smarty;
global $errors;
$context = Context::getContext();
$email = Tools::getValue('email');
if (empty($email) OR !Validate::isEmail($email))
$errors[] = Tools::displayError('e-mail not valid');
elseif (!Validate::isPasswd(Tools::getValue('passwd')))
$errors[] = Tools::displayError('invalid password');
elseif (Customer::customerExists($email, false, true, (int)Shop::getCurrentGroupShop(), (int)Shop::getCurrentShop()))
elseif (Customer::customerExists($email))
$errors[] = Tools::displayError('someone has already registered with this e-mail address');
elseif (!@checkdate(Tools::getValue('months'), Tools::getValue('days'), Tools::getValue('years')) AND !(Tools::getValue('months') == '' AND Tools::getValue('days') == '' AND Tools::getValue('years') == ''))
$errors[] = Tools::displayError('invalid birthday');
@@ -180,15 +182,15 @@ function submitAccount()
$errors[] = Tools::displayError('an error occurred while creating your address');
else
{
if (Mail::Send((int)($cookie->id_lang), 'account', Mail::l('Welcome!'),
if (Mail::Send($context->language->id, 'account', Mail::l('Welcome!'),
array('{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{email}' => $customer->email, '{passwd}' => Tools::getValue('passwd')), $customer->email, $customer->firstname.' '.$customer->lastname))
$smarty->assign('confirmation', 1);
$cookie->id_customer = (int)($customer->id);
$cookie->customer_lastname = $customer->lastname;
$cookie->customer_firstname = $customer->firstname;
$cookie->passwd = $customer->passwd;
$cookie->logged = 1;
$cookie->email = $customer->email;
$context->controller->smarty->assign('confirmation', 1);
$context->cookie->id_customer = (int)($customer->id);
$context->cookie->customer_lastname = $customer->lastname;
$context->cookie->customer_firstname = $customer->firstname;
$context->cookie->passwd = $customer->passwd;
$context->cookie->logged = 1;
$context->cookie->email = $customer->email;
Module::hookExec('createAccount', array(
'_POST' => $_POST,
'newCustomer' => $customer
@@ -205,7 +207,7 @@ function submitAccount()
function submitLogin()
{
global $cookie, $errors;
global $errors;
$passwd = trim(Tools::getValue('passwd'));
$email = trim(Tools::getValue('email'));
@@ -222,21 +224,21 @@ function submitLogin()
else
{
$customer = new Customer();
$authentication = $customer->getByemail(trim($email), trim($passwd), (int)Shop::getCurrentGroupShop(), (int)Shop::getCurrentShop());
$authentication = $customer->getByemail(trim($email), trim($passwd));
/* Handle brute force attacks */
sleep(1);
if (!$authentication OR !$customer->id)
$errors[] = Tools::displayError('authentication failed');
else
{
$cookie->id_customer = (int)($customer->id);
$cookie->customer_lastname = $customer->lastname;
$cookie->customer_firstname = $customer->firstname;
$cookie->logged = 1;
$cookie->passwd = $customer->passwd;
$cookie->email = $customer->email;
if (Configuration::get('PS_CART_FOLLOWING') AND (empty($cookie->id_cart) OR Cart::getNbProducts($cookie->id_cart) == 0))
$cookie->id_cart = Cart::lastNoneOrderedCart($customer->id);
$context->cookie->id_customer = (int)($customer->id);
$context->cookie->customer_lastname = $customer->lastname;
$context->cookie->customer_firstname = $customer->firstname;
$context->cookie->logged = 1;
$context->cookie->passwd = $customer->passwd;
$context->cookie->email = $customer->email;
if (Configuration::get('PS_CART_FOLLOWING') AND (empty($context->cookie->id_cart) OR Cart::getNbProducts($context->cookie->id_cart) == 0))
$context->cookie->id_cart = Cart::lastNoneOrderedCart($customer->id);
Module::hookExec('authentication');
// Next !
@@ -383,7 +385,7 @@ else
unset($cookie->paypal_token);
Tools::redirect('modules/paypal/express/submit.php');
}
if (Customer::customerExists($email, false, true, (int)Shop::getCurrentGroupShop(), (int)Shop::getCurrentShop()) OR Tools::isSubmit('submitLogin'))
if (Customer::customerExists($email) OR Tools::isSubmit('submitLogin'))
displayLogin();
displayAccount();
}