// AdminController refactoring
This commit is contained in:
+18
-18
@@ -65,8 +65,6 @@ class AdminControllerCore extends Controller
|
||||
/** @var string Security token */
|
||||
public $token;
|
||||
|
||||
protected $_object;
|
||||
|
||||
/** @var string shop | group_shop */
|
||||
public $shopLinkType;
|
||||
|
||||
@@ -756,21 +754,22 @@ class AdminControllerCore extends Controller
|
||||
$id = (int)Tools::getValue($this->identifier);
|
||||
if ($id && Validate::isUnsignedId($id))
|
||||
{
|
||||
if (!$this->_object)
|
||||
$this->_object = new $this->className($id);
|
||||
if (Validate::isLoadedObject($this->_object))
|
||||
return $this->_object;
|
||||
if (!$this->object)
|
||||
$this->object = new $this->className($id);
|
||||
if (Validate::isLoadedObject($this->object))
|
||||
return $this->object;
|
||||
$this->_errors[] = Tools::displayError('Object cannot be loaded (not found)');
|
||||
}
|
||||
else if ($opt)
|
||||
{
|
||||
$this->_object = new $this->className();
|
||||
return $this->_object;
|
||||
$this->object = new $this->className();
|
||||
return $this->object;
|
||||
}
|
||||
else
|
||||
$this->_errors[] = Tools::displayError('Object cannot be loaded (identifier missing or invalid)');
|
||||
|
||||
$this->content = $this->displayErrors();
|
||||
return $this->object;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1084,14 +1083,15 @@ class AdminControllerCore extends Controller
|
||||
$this->initToolbar();
|
||||
if ($this->display == 'edit' || $this->display == 'add')
|
||||
{
|
||||
if (!($this->object = $this->loadObject(true)))
|
||||
if (!$this->loadObject(true))
|
||||
return;
|
||||
$this->content .= $this->initForm();
|
||||
}
|
||||
elseif ($this->display == 'view')
|
||||
{
|
||||
if (!($this->object = $this->loadObject(true)))
|
||||
return;
|
||||
// Some controllers use the view action without an object
|
||||
if ($this->className)
|
||||
$this->loadObject(true);
|
||||
$this->content .= $this->initView();
|
||||
}
|
||||
elseif (!$this->ajax)
|
||||
@@ -1104,7 +1104,7 @@ class AdminControllerCore extends Controller
|
||||
'content' => $this->content,
|
||||
'url_post' => self::$currentIndex.'&token='.$this->token,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* initialize the invalid doom page of death
|
||||
@@ -1210,7 +1210,7 @@ class AdminControllerCore extends Controller
|
||||
|
||||
// For each action, try to add the corresponding skip elements list
|
||||
$helper->list_skip_actions = $this->list_skip_actions;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2025,7 +2025,7 @@ class AdminControllerCore extends Controller
|
||||
*/
|
||||
protected function displayAssoShop($type = 'shop')
|
||||
{
|
||||
if (!Shop::isFeatureActive() || (!$this->_object && $this->context->shop->getContextType() != Shop::CONTEXT_ALL))
|
||||
if (!Shop::isFeatureActive() || (!$this->object && $this->context->shop->getContextType() != Shop::CONTEXT_ALL))
|
||||
return;
|
||||
|
||||
if ($type != 'shop' && $type != 'group_shop')
|
||||
@@ -2101,9 +2101,9 @@ EOF;
|
||||
$html .= '<tr'.(($type == 'group_shop') ? ' class="alt_row"' : '').'><td><label class="t"><input class="input_all_shop" type="checkbox" /> '.$this->l('All shops').'</label></td></tr>';
|
||||
foreach (Shop::getTree() as $groupID => $groupData)
|
||||
{
|
||||
$groupChecked = ($type == 'group_shop' && ((isset($assos[$groupID]) && in_array($this->_object->id, $assos[$groupID])) || !$this->_object->id));
|
||||
$groupChecked = ($type == 'group_shop' && ((isset($assos[$groupID]) && in_array($this->object->id, $assos[$groupID])) || !$this->object->id));
|
||||
$html .= '<tr'.(($type == 'shop') ? ' class="alt_row"' : '').'>';
|
||||
$html .= '<td><img style="vertical-align: middle;" alt="" src="../img/admin/lv2_b.gif" /><label class="t"><input class="input_group_shop" type="checkbox" name="checkBoxGroupShopAsso_'.$this->table.'_'.$this->_object->id.'_'.$groupID.'" value="'.$groupID.'" '.($groupChecked ? 'checked="checked"' : '').' /> '.$groupData['name'].'</label></td>';
|
||||
$html .= '<td><img style="vertical-align: middle;" alt="" src="../img/admin/lv2_b.gif" /><label class="t"><input class="input_group_shop" type="checkbox" name="checkBoxGroupShopAsso_'.$this->table.'_'.$this->object->id.'_'.$groupID.'" value="'.$groupID.'" '.($groupChecked ? 'checked="checked"' : '').' /> '.$groupData['name'].'</label></td>';
|
||||
$html .= '</tr>';
|
||||
|
||||
if ($type == 'shop')
|
||||
@@ -2112,10 +2112,10 @@ EOF;
|
||||
$j = 0;
|
||||
foreach ($groupData['shops'] as $shopID => $shopData)
|
||||
{
|
||||
$checked = ((isset($assos[$shopID]) && in_array($this->_object->id, $assos[$shopID])) || !$this->_object->id);
|
||||
$checked = ((isset($assos[$shopID]) && in_array($this->object->id, $assos[$shopID])) || !$this->object->id);
|
||||
$html .= '<tr>';
|
||||
$html .= '<td><img style="vertical-align: middle;" alt="" src="../img/admin/lv3_'.(($j < $total - 1) ? 'b' : 'f').'.png" /><label class="child">';
|
||||
$html .= '<input class="input_shop" type="checkbox" value="'.$groupID.'" name="checkBoxShopAsso_'.$this->table.'_'.$this->_object->id.'_'.$shopID.'" id="checkedBox_'.$shopID.'" '.($checked ? 'checked="checked"' : '').' /> ';
|
||||
$html .= '<input class="input_shop" type="checkbox" value="'.$groupID.'" name="checkBoxShopAsso_'.$this->table.'_'.$this->object->id.'_'.$shopID.'" id="checkedBox_'.$shopID.'" '.($checked ? 'checked="checked"' : '').' /> ';
|
||||
$html .= $shopData['name'].'</label></td>';
|
||||
$html .= '</tr>';
|
||||
$j++;
|
||||
|
||||
+13
-12
@@ -154,21 +154,23 @@ class HelperListCore extends Helper
|
||||
}
|
||||
|
||||
/**
|
||||
* @TODO refactor
|
||||
* Fetch the template for action enable
|
||||
*
|
||||
* @param unknown_type $token
|
||||
* @param unknown_type $id
|
||||
* @param unknown_type $value
|
||||
* @param string $token
|
||||
* @param int $id
|
||||
* @param int $value state enabled or not
|
||||
* @param unknown_type $active
|
||||
* @param unknown_type $id_category
|
||||
* @param unknown_type $id_product
|
||||
*/
|
||||
protected function displayEnableLink($token, $id, $value, $active, $id_category = null, $id_product = null)
|
||||
{
|
||||
return '<a href="'.$this->currentIndex.'&'.$this->identifier.'='.$id.'&'.$active.$this->table.
|
||||
((int)$id_category && (int)$id_product ? '&id_category='.$id_category : '').'&token='.($token != null ? $token : $this->token).'">
|
||||
<img src="../img/admin/'.($value ? 'enabled.gif' : 'disabled.gif').'"
|
||||
alt="'.($value ? $this->l('Enabled') : $this->l('Disabled')).'" title="'.($value ? $this->l('Enabled') : $this->l('Disabled')).'" /></a>';
|
||||
$this->context->smarty->assign(array(
|
||||
'enabled' => (bool)$value,
|
||||
'url_enable' => $this->currentIndex.'&'.$this->identifier.'='.$id.'&'.$active.$this->table.
|
||||
((int)$id_category && (int)$id_product ? '&id_category='.$id_category : '').'&token='.($token != null ? $token : $this->token)
|
||||
));
|
||||
return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/helper/list/list_action_enable.tpl');
|
||||
}
|
||||
|
||||
public function displayListContent($token = null)
|
||||
@@ -406,7 +408,7 @@ class HelperListCore extends Helper
|
||||
$tpl = $this->context->smarty->template_dir[0].'/helper/list/list_action_edit.tpl';
|
||||
|
||||
return $this->context->smarty->fetch($tpl);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -426,8 +428,7 @@ class HelperListCore extends Helper
|
||||
'action' => self::$cache_lang['Delete'],
|
||||
));
|
||||
|
||||
return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/helper/list/list_action_delete.tpl');
|
||||
|
||||
return $this->context->smarty->fetch('helper/list/list_action_delete.tpl');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -512,7 +513,7 @@ class HelperListCore extends Helper
|
||||
$this->context->controller->addJqueryUI('ui.datepicker');
|
||||
break;
|
||||
case 'select':
|
||||
foreach ($params['select'] as $option_value => $option_display)
|
||||
foreach ($params['list'] as $option_value => $option_display)
|
||||
{
|
||||
if (isset($_POST[$this->table.'Filter_'.$params['filter_key']])
|
||||
&& Tools::getValue($this->table.'Filter_'.$params['filter_key']) == $option_value
|
||||
|
||||
@@ -56,7 +56,7 @@ class AdminAddressesControllerCore extends AdminController
|
||||
'address1' => array('title' => $this->l('Address'), 'width' => 200),
|
||||
'postcode' => array('title' => $this->l('Postcode/ Zip Code'), 'align' => 'right', 'width' => 50),
|
||||
'city' => array('title' => $this->l('City'), 'width' => 150),
|
||||
'country' => array('title' => $this->l('Country'), 'width' => 100, 'type' => 'select', 'select' => $this->countriesArray, 'filter_key' => 'cl!id_country'));
|
||||
'country' => array('title' => $this->l('Country'), 'width' => 100, 'type' => 'select', 'list' => $this->countriesArray, 'filter_key' => 'cl!id_country'));
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ class AdminCustomersControllerCore extends AdminController
|
||||
'icon' => $genders_icon,
|
||||
'orderby' => false,
|
||||
'type' => 'select',
|
||||
'select' => $genders,
|
||||
'list' => $genders,
|
||||
'filter_key' => 'a!id_gender',
|
||||
),
|
||||
'lastname' => array(
|
||||
|
||||
@@ -60,7 +60,7 @@ class AdminEmployeesControllerCore extends AdminController
|
||||
'lastname' => array('title' => $this->l('Last name'), 'width' => 130),
|
||||
'firstname' => array('title' => $this->l('First name'), 'width' => 130),
|
||||
'email' => array('title' => $this->l('E-mail address'), 'width' => 180),
|
||||
'profile' => array('title' => $this->l('Profile'), 'width' => 90, 'type' => 'select', 'select' => $this->profiles_array, 'filter_key' => 'pl!name'),
|
||||
'profile' => array('title' => $this->l('Profile'), 'width' => 90, 'type' => 'select', 'list' => $this->profiles_array, 'filter_key' => 'pl!name'),
|
||||
'active' => array('title' => $this->l('Can log in'), 'align' => 'center', 'active' => 'status', 'type' => 'bool'),
|
||||
);
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ class AdminGendersController extends AdminController
|
||||
'width' => 100,
|
||||
'orderby' => false,
|
||||
'type' => 'select',
|
||||
'select' => array(
|
||||
'list' => array(
|
||||
0 => $this->l('Male'),
|
||||
1 => $this->l('Female'),
|
||||
2 => $this->l('Neutral')
|
||||
|
||||
@@ -175,7 +175,7 @@ class AdminGroupShopControllerCore extends AdminController
|
||||
'name' => 'useImportData',
|
||||
'value' => 1
|
||||
),
|
||||
'select' => array(
|
||||
'list' => array(
|
||||
'type' => 'select',
|
||||
'name' => 'importFromShop',
|
||||
'options' => array(
|
||||
|
||||
@@ -171,7 +171,7 @@ class AdminManufacturersControllerCore extends AdminController
|
||||
'title' => $this->l('Country'),
|
||||
'width' => 100,
|
||||
'type' => 'select',
|
||||
'select' => $this->countries_array,
|
||||
'list' => $this->countries_array,
|
||||
'filter_key' => 'cl!id_country'
|
||||
)
|
||||
);
|
||||
|
||||
@@ -66,7 +66,7 @@ class AdminOrdersControllerCore extends AdminController
|
||||
'customer' => array('title' => $this->l('Customer'), 'widthColumn' => 160, 'width' => 140, 'filter_key' => 'customer', 'tmpTableFilter' => true),
|
||||
'total_paid' => array('title' => $this->l('Total'), 'width' => 70, 'align' => 'right', 'prefix' => '<b>', 'suffix' => '</b>', 'price' => true, 'currency' => true),
|
||||
'payment' => array('title' => $this->l('Payment'), 'width' => 100),
|
||||
'osname' => array('title' => $this->l('Status'), 'widthColumn' => 230, 'type' => 'select', 'select' => $statesArray, 'filter_key' => 'os!id_order_state', 'filter_type' => 'int', 'width' => 200),
|
||||
'osname' => array('title' => $this->l('Status'), 'widthColumn' => 230, 'type' => 'select', 'list' => $statesArray, 'filter_key' => 'os!id_order_state', 'filter_type' => 'int', 'width' => 200),
|
||||
'date_add' => array('title' => $this->l('Date'), 'width' => 35, 'align' => 'right', 'type' => 'datetime', 'filter_key' => 'a!date_add'),
|
||||
'id_pdf' => array('title' => $this->l('PDF'), 'callback' => 'printPDFIcons', 'orderby' => false, 'search' => false));
|
||||
$this->shopLinkType = 'shop';
|
||||
@@ -74,7 +74,7 @@ class AdminOrdersControllerCore extends AdminController
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
public function initForm()
|
||||
{
|
||||
parent::initForm();
|
||||
@@ -438,18 +438,18 @@ class AdminOrdersControllerCore extends AdminController
|
||||
{
|
||||
$order = new Order((int)(Tools::getValue('id_order')));
|
||||
$pcc = new PaymentCC((int)Tools::getValue('id_payment_cc'));
|
||||
|
||||
|
||||
$pcc->id_order = $order->id;
|
||||
$pcc->transaction_id = (string)Tools::getValue('transaction_id');
|
||||
$pcc->id_currency = $order->id_currency;
|
||||
$pcc->amount = $order->total_paid;
|
||||
$pcc->save();
|
||||
|
||||
|
||||
unset($order, $pcc);
|
||||
}
|
||||
elseif (Tools::isSubmit('submitAddOrder') == 1 && ($id_cart = Tools::getValue('id_cart')) && ($module_name = pSQL(Tools::getValue('payment_module_name'))) && ($id_order_state = Tools::getValue('id_order_state')))
|
||||
{
|
||||
|
||||
|
||||
if ($this->tabAccess['edit'] === '1')
|
||||
{
|
||||
$payment_module = Module::getInstanceByName($module_name);
|
||||
@@ -511,7 +511,7 @@ class AdminOrdersControllerCore extends AdminController
|
||||
if (Validate::isLoadedObject($addressDelivery) AND $addressDelivery->id_state)
|
||||
$deliveryState = new State((int)($addressDelivery->id_state));
|
||||
}
|
||||
|
||||
|
||||
// Smarty assign
|
||||
$this->context->smarty->assign(array(
|
||||
'order' => $order,
|
||||
@@ -562,7 +562,7 @@ class AdminOrdersControllerCore extends AdminController
|
||||
|
||||
$this->content = Tools::jsonEncode($to_return);
|
||||
}
|
||||
|
||||
|
||||
public function ajaxProcessSearchProducts()
|
||||
{
|
||||
$currency = new Currency((int)Tools::getValue('id_currency'));
|
||||
@@ -584,10 +584,10 @@ class AdminOrdersControllerCore extends AdminController
|
||||
$combinations[$attribute['id_product_attribute']]['default_on'] = $attribute['default_on'];
|
||||
if (!isset($combinations[$attribute['id_product_attribute']]['price']))
|
||||
$combinations[$attribute['id_product_attribute']]['price'] = Tools::displayPrice(Tools::convertPrice(Product::getPriceStatic((int)$product['id_product'], true, $attribute['id_product_attribute']), $currency), $currency);
|
||||
if (!isset($combinations[$attribute['id_product_attribute']]['qty_in_stock']))
|
||||
if (!isset($combinations[$attribute['id_product_attribute']]['qty_in_stock']))
|
||||
$combinations[$attribute['id_product_attribute']]['qty_in_stock']= StockAvailable::getStockAvailableForProduct((int)$product['id_product'], $attribute['id_product_attribute'], (int)$this->context->shop->getID());
|
||||
}
|
||||
|
||||
|
||||
foreach ($combinations AS &$combination)
|
||||
$combination['attributes'] = rtrim($combination['attributes'], ' - ');
|
||||
$product['combinations'] = $combinations;
|
||||
@@ -597,13 +597,13 @@ class AdminOrdersControllerCore extends AdminController
|
||||
}
|
||||
else
|
||||
$to_return = array('found' => false);
|
||||
|
||||
|
||||
$this->content = Tools::jsonEncode($to_return);
|
||||
}
|
||||
|
||||
|
||||
public function ajaxProcessSendMailValidateOrder()
|
||||
{
|
||||
$errors = array();
|
||||
$errors = array();
|
||||
$cart = new Cart((int)Tools::getValue('id_cart'));
|
||||
if (Validate::isLoadedObject($cart))
|
||||
{
|
||||
|
||||
@@ -1712,42 +1712,42 @@ if (false)
|
||||
if($this->tabAccess['delete'])
|
||||
$this->toolbar_btn['delete'] = array(
|
||||
'short' => 'Delete',
|
||||
'href' => $this->context->link->getAdminLink('AdminProducts').'&id_product='.$product->id.'&deleteproduct',
|
||||
'href' => $this->context->link->getAdminLink('AdminProducts').'&id_product='.$product->id.'&deleteproduct',
|
||||
'desc' => $this->l('Delete this product'),
|
||||
'confirm' => 1);
|
||||
|
||||
if($this->tabAccess['add'])
|
||||
$this->toolbar_btn['duplicate'] = array(
|
||||
'short' => 'Duplicate',
|
||||
'href' => '#todo'.$this->context->link->getAdminLink('AdminProducts').'&id_product='.$product->id, 'desc' => $this->l('Duplicate'),
|
||||
'href' => '#todo'.$this->context->link->getAdminLink('AdminProducts').'&id_product='.$product->id, 'desc' => $this->l('Duplicate'),
|
||||
'confirm' => 1
|
||||
);
|
||||
// @TODO navigation
|
||||
$this->toolbar_btn['preview'] = array(
|
||||
'short' => 'Preview',
|
||||
'href' => '', 'desc' => 'prevdesc',
|
||||
'short' => 'Preview',
|
||||
'href' => '', 'desc' => 'prevdesc',
|
||||
'class' => 'previewUrl',
|
||||
);
|
||||
if (file_exists(_PS_MODULE_DIR_.'statsproduct/statsproduct.php'))
|
||||
$this->toolbar_btn['stats'] = array(
|
||||
'short' => 'Statistics',
|
||||
'href' => $this->context->link->getAdminLink('AdminStats').'&module=statsproduct&id_product='.$product->id,
|
||||
'desc' => $this->l('View product sales'),
|
||||
'href' => $this->context->link->getAdminLink('AdminStats').'&module=statsproduct&id_product='.$product->id,
|
||||
'desc' => $this->l('View product sales'),
|
||||
);
|
||||
|
||||
|
||||
$this->toolbar_btn['cancel'] = array(
|
||||
'short' => 'Close',
|
||||
'href' => '#todo'.$this->context->link->getAdminLink('AdminProducts').'&id_product='.$product->id, 'desc' => $this->l('Cancel'),
|
||||
'href' => '#todo'.$this->context->link->getAdminLink('AdminProducts').'&id_product='.$product->id, 'desc' => $this->l('Cancel'),
|
||||
'confirm' => 1);
|
||||
if($this->tabAccess['add'])
|
||||
$this->toolbar_btn['new'] = array(
|
||||
'short' => 'Create',
|
||||
'href' => '#todo'.$this->context->link->getAdminLink('AdminProducts').'&id_product='.$product->id, 'desc' => $this->l('Create'),
|
||||
'href' => '#todo'.$this->context->link->getAdminLink('AdminProducts').'&id_product='.$product->id, 'desc' => $this->l('Create'),
|
||||
);
|
||||
if($this->tabAccess['edit'])
|
||||
$this->toolbar_btn['save'] = array(
|
||||
'short' => 'Save',
|
||||
'href' => '#todo'.$this->context->link->getAdminLink('AdminProducts').'&id_product='.$product->id, 'desc' => $this->l('Save'),
|
||||
'href' => '#todo'.$this->context->link->getAdminLink('AdminProducts').'&id_product='.$product->id, 'desc' => $this->l('Save'),
|
||||
);
|
||||
}
|
||||
parent::initToolbar();
|
||||
@@ -2378,7 +2378,7 @@ switch ($this->action)
|
||||
'uploadable_files', 'text_fields'
|
||||
);
|
||||
// prices
|
||||
array_push($product_props,
|
||||
array_push($product_props,
|
||||
'price', 'wholesale_price', 'id_tax_rules_group', 'unit_price_ratio', 'on_sale',
|
||||
'unity'
|
||||
);
|
||||
@@ -3795,21 +3795,22 @@ $product->supplier_name = Supplier::getNameById($product->id_supplier);
|
||||
{
|
||||
if ($id = (int)(Tools::getValue($this->identifier)) AND Validate::isUnsignedId($id))
|
||||
{
|
||||
if (!$this->_object)
|
||||
$this->_object = new $this->className($id);
|
||||
if (Validate::isLoadedObject($this->_object))
|
||||
return $this->_object;
|
||||
if (!$this->object)
|
||||
$this->object = new $this->className($id);
|
||||
if (Validate::isLoadedObject($this->object))
|
||||
return $this->object;
|
||||
$this->_errors[] = Tools::displayError('Object cannot be loaded (not found)');
|
||||
}
|
||||
else if ($opt)
|
||||
{
|
||||
$this->_object = new $this->className();
|
||||
return $this->_object;
|
||||
$this->object = new $this->className();
|
||||
return $this->object;
|
||||
}
|
||||
else
|
||||
$this->_errors[] = Tools::displayError('Object cannot be loaded (identifier missing or invalid)');
|
||||
|
||||
$this->displayErrors();
|
||||
return $this->object;
|
||||
}
|
||||
|
||||
public function displayInitInformationAndAttachment()
|
||||
|
||||
@@ -52,7 +52,7 @@ class AdminStockMvtControllerCore extends AdminController
|
||||
'align' => 'center',
|
||||
'type' => 'select',
|
||||
'filter_key' => 'a!sign',
|
||||
'select' => array(
|
||||
'list' => array(
|
||||
'1' => $this->l('Increment'),
|
||||
'-1' => $this->l('Decrement'),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user