Skip to content

Instantly share code, notes, and snippets.

@eewee
Created March 24, 2017 20:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eewee/eaa006e6ac697f8032acee7e32274910 to your computer and use it in GitHub Desktop.
Save eewee/eaa006e6ac697f8032acee7e32274910 to your computer and use it in GitHub Desktop.
class Eewee_Aaa extends Module implements WidgetInterface
{
...
/**
* Content
* @return string
*/
public function getContent()
{
$renderList = $this->renderList();
return $renderList;
}
/**
* Toolbar
*/
public function initToolbar()
{
$this->toolbar_btn['new'] = array(
'short' => 'lorem ipsum',
'href' => AdminController::$currentIndex.'&configure='.$this->name.'&add'.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules'),
'desc' => $this->trans('Add new', array(), 'Admin.Actions')
);
$this->toolbar_btn['export'] = array(
'href' => AdminController::$currentIndex.'&configure='.$this->name.'&export'.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules'),
'desc' => $this->trans('Export', array(), 'Admin.Actions')
);
$this->toolbar_btn['import'] = array(
'href' => $this->context->link->getAdminLink('AdminImport', true).'&import_type=addresses',
'desc' => $this->trans('Import', array(), 'Admin.Actions')
);
// if (!$this->display && $this->can_import) {
// $this->toolbar_btn['import'] = array(
// 'href' => $this->context->link->getAdminLink('AdminImport', true).'&import_type=addresses',
// 'desc' => $this->trans('Import', array(), 'Admin.Actions')
// );
// }
}
/**
* http://doc.prestashop.com/display/PS15/HelperList
* http://doc.prestashop.com/display/PS16/Using+the+HelperList+class
* @return string
*/
public function renderList()
{
// @todo : $links = Db::getInstance()->ExecuteS('SELECT id_eeweearticle, name, label, link, new_window FROM ...');
// HEADER
$links = array(
array(
'id_eeweearticle' => 2,
'name' => '2017-03-20 20:30:45',
'label' => 'label_2',
'link' => 'www.ndd_2.com',
'active' => true,
),
array(
'id_eeweearticle' => 1,
'name' => '2017-01-10 21:30:45',
'label' => 'label_1',
'link' => 'www.ndd_1.com',
'active' => false,
),
array(
'id_eeweearticle' => 3,
'name' => '2017-02-15 13:30:45',
'label' => 'label_3',
'link' => 'www.ndd_3.com',
'active' => true,
),
);
// CONTENT
$fields_list = array(
'id_eeweearticle' => array(
'title' => $this->trans('ID Eewee article', array(), 'Modules.eewee_sellsy.Admin'),
'align' => 'center', // Align Col (not header)
//'width' => 50, // header search : width
'type' => 'int',
'class' => 'fixed-width-xs', // class css
'search' => false, // header search : display
'orderby' => true, // header search : order
),
'name' => array(
'title' => $this->l('Shop name'),
'type' => 'datetime',
),
'label' => array(
'title' => $this->l('Label'),
'type' => 'text',
'search' => true,
'color' => 'ff0000',
'prefix' => '$',
'suffix' => 'kg',
'hint' => 'Integer ante arcu, accumsan a, consectetuer eget, posuere ut, mauris. Phasellus viverra nulla ut metus varius laoreet. Morbi nec metus. In ac felis quis tortor malesuada pretium. Vivamus aliquet elit ac nisl.',
),
'link' => array(
'title' => $this->l('Link'),
'type' => 'select',
),
'active' => array(
'title' => $this->l('Status'),
'type' => 'bool',
'align' => 'center',
'active' => 'status',
'ajax' => true,
)
);
// TOOLBAR
$this->initToolbar();
// HELPER
$helper = new HelperList();
// NOT WORKING
$helper->orderBy = 'id_eeweearticle';
$helper->orderWay = 'DESC';
// BULD ACTIONS
$helper->bulk_actions = true; // bulk_actions
// HEADER BTN : add, refresh, ...
$helper->toolbar_btn = $this->toolbar_btn;
// OU
//$helper->toolbar_btn['new'] = array(
// 'href' => AdminController::$currentIndex.'&configure='.$this->name.'&add'.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules'),
// 'desc' => $this->trans('Add new', array(), 'Admin.Actions')
//);
// OTHER
$helper->shopLinkType = '';
$helper->no_link = false; // Content line is clickable if false
$helper->simple_header = false; // false = search header, true = not header. No filters, no paginations and no sorting.
$helper->actions = array('edit', 'delete', 'view');
$helper->show_toolbar = true;
$helper->module = $this;
$helper->identifier = 'id_eeweearticle';
$helper->title = $this->l('Eewee list');
$helper->table = 'eeweearticle';
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name;
return $helper->generateList($links, $fields_list);
}
/**
* Ajax process
* EeweeArticle => $helper->table
*/
public function ajaxProcessStatusEeweeArticle() {
$id_eeweearticle = (int)Tools::getValue('id_eeweearticle');
if (!$id_eeweearticle) {
die(json_encode(array(
'success' => false,
'error' => true,
'text' => $this->trans('Failed to update the status', array(), 'Admin.Notifications.Error')
)));
} else {
$eeweearticle = new Product((int)$id_eeweearticle);
if (Validate::isLoadedObject($eeweearticle)) {
$eeweearticle->active = $eeweearticle->active == 1 ? 0 : 1;
$res = $eeweearticle->save();
if ($res) {
die(json_encode(array(
'success' => true,
'text' => $this->trans('The status has been updated successfully', array(), 'Admin.Notifications.Success')
)));
} else {
die(json_encode(array(
'success' => false,
'error' => true,
'text' => $this->trans('Failed to update the status', array(), 'Admin.Notifications.Success')
)));
}
}//if
}
// $query = 'SELECT * FROM ps_product';
// echo json_encode(array(
// 'data'=> Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query),
// 'fields_display' => $this->fieldsDisplay
// ));
die();
}
...
}//class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment