I have a custom admin page in prestashop and i would like to add a URL link at the bottom of that page. However, i am very new to prestashop and can not figure out how to do this.
I have an admin controller file for the module that creates the custom page with a form on it and was wondering how i can add a link at the bottom of the page that simply goes to another static page on the site or even an external page.
AdminFedeltaSchoolsController.php content
<?php
class AdminFedeltaSchoolsController extends ModuleAdminController {
public function __construct() {
// Configure admin controller with table, model, language and bootstrap theme
$this->table = 'fedeltapos_school';
$this->className = 'FedeltaposModel';
$this->lang = true;
$this->bootstrap = true;
// Generat action on list
$this->addRowAction('edit');
$this->addRowAction('delete');
// This adds a multiple deletion button
$this->bulk_actions = array(
'delete' => array(
'text' => $this->l('Delete selected'),
'confirm' => $this->l('Delete selected items?')
)
);
// Generat list
$this->fields_list = array(
'id_fedeltapos_school' => array(
'title' => $this->l('ID'),
'align' => 'center',
'width' => 25
),
'school_name' => array(
'title' => $this->l('School Name'),
'width' => 'auto'
),
'delivery' => array(
'title' => $this->l('Delivery'),
'width' => 'auto'
),
'pickup' => array(
'title' => $this->l('Pickup'),
'width' => 'auto'
),
'pricelevel' => array(
'title' => $this->l('Price Level'),
'width' => 'auto',
),
);
parent::__construct();
}
// This method generates the Add/Edit form
public function renderForm() {
// Building the Add/Edit form
$this->fields_form = array(
'legend' => array(
'title' => $this->l('Schools'),
'icon' => 'icon-envelope-alt'
),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('School Name:'),
'name' => 'school_name',
'lang' => true,
'size' => 33,
'required' => true,
), array(
'type' => 'text',
'label' => $this->l('Delivery:'),
'name' => 'delivery',
'size' => 33,
'required' => true,
),
array(
'type' => 'text',
'label' => $this->l('Pickup:'),
'name' => 'pickup',
'size' => 33,
'required' => true,
),
array(
'type' => 'text',
'label' => $this->l('Price Level:'),
'name' => 'pricelevel',
'size' => 33,
'required' => true,
),
),
'submit' => array(
'title' => $this->l('Save')
)
);
return parent::renderForm();
}
}
I would like the link at the bottom of the page (see screenshot):
http://awesomescreenshot.com/08252wdh8a
Any assistance will be appreciated.
Override the default content admin template file of your admin controller.
Create /your-admin-folder/themes/default/template/controllers/fedelta_schools/content.tpl
{if isset($content)}
{$content}
{/if}
{block name="override_tpl_schools"}
<div class="row">
<div class="col-lg-12">
<div class="panel">
<h3>
<i class="icon-info"></i>
{l s='Help'}
</h3>
<p>{l s='You can find answer of your question here :'} <a href='#'>{l s='FAQ'}</a> </p>
</div>
</div>
</div>
{/block}
Related
I am working on a custom Magento extension. Version: 1.9.0.1.
I have a custom Adminhtml form, here it is:
Here is the Form code:
<?php
class VivasIndustries_SmsNotification_Block_Adminhtml_Sms_Status_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
{
protected function _prepareForm()
{
$form = new Varien_Data_Form(array(
'id' => 'edit_form',
'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
'method' => 'post',
));
$fieldset = $form->addFieldset('edit_form', array('legend'=>Mage::helper('smsnotification')->__('SMS Information')));
$statuses = Mage::getResourceModel('sales/order_status_collection')
->toOptionArray();
$statuses = array_merge(array('' => ''), $statuses);
$fieldset->addField('state', 'select',
array(
'name' => 'state',
'label' => Mage::helper('smsnotification')->__('Order Status'),
'class' => 'required-entry',
'values' => $statuses,
'required' => true,
)
);
$fieldset->addField('smstext', 'textarea', array(
'label' => Mage::helper('smsnotification')->__('SMS Text'),
'class' => 'required-entry',
'required' => true,
'name' => 'smstext',
'onclick' => "",
'onchange' => "",
'after_element_html' => '<br><small>SMS text must <b>NOT</b> be longer then 160 characters!</small>',
'tabindex' => 1
));
if ( Mage::getSingleton('adminhtml/session')->getsmsnotificationData() )
{
$form->setValues(Mage::getSingleton('adminhtml/session')->getsmsnotificationData());
Mage::getSingleton('adminhtml/session')->setsmsnotificationData(null);
} elseif ( Mage::registry('smsnotification_data') ) {
$form->setValues(Mage::registry('smsnotification_data')->getData());
}
// Add these two lines
$form->setUseContainer(true);
$this->setForm($form);
////
return parent::_prepareForm();
}
}
I use this code to get the customer name from the order:
$CustomerName = $observer->getOrder()->getBillingAddress()->getName();
How can I check the whole text and if it finds CustomVariable_CustomerName to replace it with the real customer name ?
Im new to this, I have downloaded Yii-Booster Widgets for use of TBRelationalColumn.
I have downloaded the extensions from yiibooster.clevertech.biz yiibooster-4.0.1.zip file and extracted under
protected/extensions/booster
Configuration
protected/config/local.php and main.php
<?php
Yii::setPathOfAlias('booster', dirname(__FILE__).'/../extensions/booster');
Yii::setPathOfAlias('bootstrap', dirname(__FILE__).'/../extensions/bootstrap');
return array(
'components'=>array(
'db' => array(
),
'mongodb' => array(
'class' => 'EMongoDB',
),
'booster'=>array(
'class'=>'booster.components.Booster',
'coreCss' => true,
'responsiveCss' => true,
'yiiCss' => true,
),
'bootstrap'=>array(
'class'=>'bootstrap.components.bootstrap',
'coreCss' => true,
'responsiveCss' => true,
'yiiCss' => true,
),
'cache'=>array(
'class' => 'CFileCache',
),
),
);
When Im using this widget im getting the grid structure but js is Not Enable
index.php
$this->widget('booster.widgets.TbExtendedGridView', array(
'id' => 'invite-grid',
'type' => 'striped condensed',
'dataProvider' => $arrayDataProvider,
'columns' => array(
'id',
'username',
'email',
array(
'class' => 'booster.widgets.TbRelationalColumn',
'name' => 'test',
'value' => '"grid"',
'url' => $this->createUrl('site/relational'),
'afterAjaxUpdate' => 'js:function(tr,rowid,data){
bootbox.alert("I have afterAjax events too!<br/>This will only happen once for row with id: "+rowid);
}'
),
)
));
When Click on Grid i cannt get the Alert Message. Please anyone help me to resolve this problem
You are not loading it. If you are using boostrap across all pages, preload it from the config,
return array(
'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'name'=>'My Site',
'preload'=>array(
'log',
'bootstrap', //preload bootsrtap
),
Else, you can add it separately for each controller using filter
public function filters()
{
return array(
'accessControl',
array('ext.booster.filters.BootstrapFilter') //load bootstrap
);
there are 2 columns check box in cgridViewtable and two bootstrap widgets TbButton in view page.
I can not get value of my checkbox very good. My value in checkboxs transfer into controller but changed id of checkboxs After a period of timeand , and controller don't knew checkbox,
View:
$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
'id' => 'profile-information-form',
'enableAjaxValidation' => false,
));
$this->widget('bootstrap.widgets.TbButton', array('buttonType' => 'submit', 'type' => 'primary', 'label' => Yii::t('fa_ir', 'First validation'),));
$this->widget('bootstrap.widgets.TbButton', array('buttonType' => 'submit', 'type' => 'primary', 'label' => Yii::t('fa_ir', 'End validation'),));
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'profile-information-grid',
'dataProvider' => $model->children(),
'filter' => $model,
'columns' => array(
array(
'header' => '',
'value' => '$this->grid->dataProvider->pagination->offset + $row+1', // row is zero based
),
array(
'name' => 'ProfileInformation.user.scope',
'value' => 'CHtml::encode($data->user->scope->name)',
'filter' => Scope::model()->options,
),
array(
'name' => 'id',
'value' => 'CHtml::encode($data->id)',
),
array(
'name' => 'center',
'value' => 'CHtml::encode($data->center)',
),
array(
'name' => 'sendCount',
'value' => 'CHtml::encode($data->sendCount)',
'filter' => '',
),
// Use CCheckbox column with selectableRows = 2 for Select All
array('class' => 'CCheckBoxColumn', 'selectableRows' => 2, 'visible' => (Lookup::isUser2(Yii::app()->user->id) or Lookup::isAdmin(Yii::app()->user->id))),
array('class' => 'CCheckBoxColumn', 'selectableRows' => 2, 'visible' => (Lookup::isUser1(Yii::app()->user->id) or Lookup::isAdmin(Yii::app()->user->id))),
),
));
// action button
$this->endWidget();
Controller:
if (isset($_POST['profile-information-grid_c10']) & isset($_POST['yt0'])) {
////Do action1
}
if (isset($_POST['profile-information-grid_c12']) & isset($_POST['yt1'])) {
////Do action2
}
}
my problem is in $_POST['profile-information-grid_c10'] and _POST['profile-information-grid_c12'] , before id were $_POST['profile-information-grid_c8'] and $_POST['profile-information-grid_c10'] , and now is $_POST['profile-information-grid_c12'] and $_POST['profile-information-grid_c14'].
my problem is very involved. I cannot explain very good.
I want to have a fix id.
I donto why change id of check box?
Can I assign ids for checkboxs?
Can I assign ids for checkboxs? Sure, you better explicitly set checkbox column id:
'class' => 'CCheckBoxColumn', 'id'=>'column1', ... see these docs.
This way you firmly set it and you'll have no things like these yt0, yt2...
The same you can do for the buttons. See TButton docs.
Also you need to use double && in logical condition:
isset($_POST['profile-information-grid_c12']) & isset($_POST['yt1'])
I have a weird problem. I copied my website into production environment (from windows to ubuntu). I correct few big/small letter issues and app started to work fine. Until I entered one page that looks like it's being rendered without layout. There is no error.
Also - firebug shows no css styles or anything. At HTML source there is lack of layout code too.
What could be the reason of that?
EDIT:
controller part:
$dataProvider = Projects::model()->getInviteProjectsProvider();
$this->render('invite', array(
'dataProvider' => $dataProvider
));
It returns CActiveDataProvider.
View:
<?php
$this->breadcrumbs=array(
'Projekty' => array('admin'),
'Zapraszanie',
);
$this->renderPartial('_allMenu');
?>
<link rel="stylesheet" type="text/css" href="<?php echo $this->module->assetsUrl; ?>/css/projects.css"/>
<h1>Projekty aktywne - zapraszanie</h1>
<?php
$this->widget('bootstrap.widgets.TbExtendedGridView', array(
'id' => 'invite-grid',
'type' => 'striped condensed',
'dataProvider' => $dataProvider,
'rowCssClassExpression' => '($data->leftCustomers<100) ? "error":""',
'columns' => array(
array(
'name' => 'idProject',
'htmlOptions' => array('width' => '60px', 'style' => 'text-align: right;', 'class' => 'gridIdColumn'),
),
'name',
array(
'name' => 'leftCustomers',
'header' => 'Pozostało <i class="icon-info-sign" rel="tooltipbootstrap" data-original-title="Gdy wartość ta jest mniejsza niż 100 - rekord jest podświetlony na czerwono"/>',
),
'confirmStart',
'presentationDate',
array(
'class' => 'bootstrap.widgets.TbRelationalColumn',
'name' => 'Statystyki',
'value' => '"Pokaż"',
'url' => $this->createUrl('dynamicProjectStats')
),
array(
'header' => 'Postęp <i class="icon-info-sign" rel="tooltipbootstrap" data-original-title="Liczba zaproszeń / Limit zaproszeń"/>',
'value' => function($data)
{
$prc = round(($data->projectMaxInvites > 0) ? ($data->projectInvites)/ $data->projectMaxInvites * 100 : 0, 2);
Controller::widget('bootstrap.widgets.TbProgress', array(
'percent' => $prc,
'htmlOptions' => array(
'style' => 'height: 20px; margin-bottom: -20px',
'rel' => 'tooltipbootstrap',
'data-original-title' => $prc." %",
),
));
},
),
array(
'class' => 'bootstrap.widgets.TbButtonColumn',
'template' => '{view}{update}{delete}',
'htmlOptions' => array(
'style' => 'width: 40px;',
),
),
array(
'header' => '',
'htmlOptions' => array('style' => 'width: 43px'),
'value' => function($data)
{
$this->renderPartial('partials/_actionMenu', array('idProject' => $data->idProject, 'activated' => true, 'afterAction' => 'removeActiveProject'));
}
),
array(
'header' => '',
'value' => function($data)
{
$this->renderPartial('partials/_statMenu', array('idProject' => $data->idProject, 'showIcon' => true));
}
),
)
));
?>
I noticed that if I comment out the columns where function($data) is used - it shows fine. When I leave it - there is no layout displayed.
EDIT2:
Maybe I should notice the fact that inside partials/_statMenu and partials/_actionMenu there is a bootstrap.widgets.TbButtonGroup widget rendered.
Try:
Yii::app()->controller->renderPartial(...)
Instead of:
$this->renderPartial(...)
Having just arrived at Prestashop 1.5, I am making a very simple module: a video of the week, associated with multiple products that need to appear right next to it.
I decided to start from the Backoffice. Right now, I can view, add, edit and remove all the Video entries but I'm a bit lost on how to map the N-N association between a video and its related products... The lack of documentation isn't helping either.
Any ideas how to pull this off?
Here's a bit of my code, the Video class is defined by:
class Video extends ObjectModel {
public $id_video;
public $title;
public $url;
public $active;
public static $definition = array(
'table' => 'video',
'primary' => 'id_video',
'multilang' => false,
'fields' => array(
'id_video' => array(
'type' => ObjectModel :: TYPE_INT
),
'title' => array(
'type' => ObjectModel :: TYPE_STRING,
'required' => true
),
'url' => array(
'type' => ObjectModel :: TYPE_STRING,
'required' => true
),
'active' => array(
'type' => ObjectModel :: TYPE_BOOL,
'required' => true
)
),
);
(...)
and the AdminVideo class is here:
class AdminVideoController extends ModuleAdminController {
public function __construct()
{
$this->table = 'video';
$this->className = 'Video';
$this->lang = false;
$this->fields_list['id_video'] = array(
'title' => $this->l('ID'),
'align' => 'center',
);
$this->fields_list['title'] = array(
'title' => $this->l('Title'),
'width' => 'auto'
);
$this->fields_list['url'] = array(
'title' => $this->l('URL'),
'width' => 'auto'
);
$this->fields_list['active'] = array(
'title' => $this->l('Active'),
'width' => '70',
'align' => 'center',
'active' => 'status',
'type' => 'bool',
'orderby' => false
);
parent::__construct();
}
public function postProcess()
{
parent::postProcess();
}
public function renderList()
{
$this->addRowAction('edit');
$this->addRowAction('delete');
$this->addRowAction('details');
return parent::renderList();
}
public function renderForm()
{
if (!($obj = $this->loadObject(true)))
return;
$this->fields_form = array(
'legend' => array(
'title' => $this->l('This weeks video'),
'image' => '../img/admin/world.gif'
),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Nome'),
'name' => 'title',
'size' => 33,
'required' => true,
'desc' => $this->l('Title')
),
array(
'type' => 'text',
'label' => $this->l('URL'),
'name' => 'url',
'size' => 33,
'required' => true,
'desc' => $this->l('Video URL')
),
array(
'type' => 'radio',
'label' => $this->l('Active:'),
'name' => 'active',
'required' => false,
'class' => 't',
'is_bool' => true,
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled')
)
),
'desc' => $this->l('Only one video can be active at any given time')
),
)
);
if (Shop::isFeatureActive())
{
$this->fields_form['input'][] = array(
'type' => 'shop',
'label' => $this->l('Shop association:'),
'name' => 'checkBoxShopAsso',
);
}
$this->fields_form['submit'] = array(
'title' => $this->l(' Save '),
'class' => 'button'
);
if (!($obj = $this->loadObject(true)))
return;
return parent::renderForm();
}
}
One other thing: would it be possible to add a preview of the video inside the backoffice? I tried to echo YouTube's embed code, but it gets inserted even before the header. Is there a clean way of doing this or do I have to use some jQuery trickery? I was basically doing an echo of YT's embed code just before the end of postProcess().
Thanks in advance!
The simplest way to associate the videos to the products is by adding a "products" text field in your "video" table to store a comma separated list of the ids of the associated products (eg.: 1,10,27). Even if it's a bit rudimentary, it should work.
Alternatively, you could use a table like this:
create table video_product (
id_association int not null auto_increment,
id_video int,
id_product int,
primary key (id_association)
);
The problem with this solution is that the PrestaShop ObjectModel core does not provide any method to automatically update or delete the related tables (at least as far as I know), so you have to insert the code to manage the "video_product" table in your "Video" class.
If you want an example of how to do this, you should look at the classes/Product.php script, which manages the product table and all its related tables (categories, tags, features, attachments, etc.).
To have an idea of how the Prestashop database is structured, have a look at the docs/dbmodel.mwb file, which contains the schema of the database; this file can be viewed by using the MySQL Workbench application.