I am trying to adapt the Product Comments "add a review feature" (which is on the Product page) to work on the Products List page, but the link is only recognizing the first product in the list. There is a pencil icon link next to each product in the list, but they all link to the first product only.
Can anybody let me know why this is happening, and point me in the right direction to fixing it.
Following is the code in my custom hook:
include_once dirname(__FILE__).'/ProductComment.php';
include_once dirname(__FILE__).'/ProductCommentCriterion.php';
if(in_array($this->context->controller->php_self, array('product-list'))) $products = Product::getProducts((int) Tools::getValue('id_product'), $this->context->language->id);
{
$id_guest = (!$id_customer = (int) $this->context->cookie->id_customer) ? (int) $this->context->cookie->id_guest : false;
$customerComment = ProductComment::getByCustomer((int) (Tools::getValue('id_product')), (int) $this->context->cookie->id_customer, true, (int) $id_guest);
$average = ProductComment::getAverageGrade((int) Tools::getValue('id_product'));
$image = Product::getCover((int) Tools::getValue('id_product'));
$cover_image = $this->context->link->getImageLink($product->link_rewrite, $image['id_image'], 'medium_default');
$this->context->smarty->assign(array(
'id_product_comment_form' => (int) Tools::getValue('id_product'),
'product' => $products,
'secure_key' => $this->secure_key,
'logged' => $this->context->customer->isLogged(true),
'allow_guests' => (int) Configuration::get('PRODUCT_COMMENTS_ALLOW_GUESTS'),
'productcomment_cover' => (int) Tools::getValue('id_product').'-'.(int) $image['id_image'], // retro compat
'productcomment_cover_image' => $cover_image,
'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')),
'criterions' => ProductCommentCriterion::getByProduct((int) Tools::getValue('id_product'), $this->context->language->id),
'action_url' => '',
'averageTotal' => round($average['grade']),
'ratings' => ProductComment::getRatings((int) Tools::getValue('id_product')),
'too_early' => ($customerComment && (strtotime($customerComment['date_add']) + Configuration::get('PRODUCT_COMMENTS_MINIMAL_TIME')) > time()),
'nbComments' => (int) (ProductComment::getCommentNumber((int) Tools::getValue('id_product'))),
));
return $this->display(__FILE__, '/mytemplate.tpl');
}
This is the code in my template:
<SCRIPT>
$(document).ready(function() {
if (!!$.prototype.fancybox)
$('.open-comment-form').fancybox({
'autoSize' : false,
'width': 800,
'height': auto,
'hideOnContentClick': false,
'title' : null,
});
});
</SCRIPT>
{if (!$too_early AND ($is_logged OR ($PRODUCT_COMMENTS_ALLOW_GUESTS == 0)))}
<p class="align_center">
<a class="open-comment-form" href="#new_comment_form" title="{l s='Write your review' mod='productcomments'}!"></a>
</p>
{/if}
I am using Prestashop version 1.6.1.14. Thanks aussiecomet
Related
I have a datagrid, where for each item on the table I need to attach one or many documents. When you click the last column button, you should open a popup which then has the file uploader.
I'm trying to create the custom button in my Datagrid, which will open the custom popup that has the FileUploader widget, but the button is not rendering at all.
Instead of the button showing, this is the result.
\[%!function(){%\]\ [%DevExpress.aspnet.createComponent("dxButton",{"text":"Attach","onClick":function (e) { attachButtonClick(data) }},arguments\[0\])%\]\[%}("dx-" + new DevExpress.data.Guid())%\]
I'm imagining the same will happen even if the popup shows. Just this text which would seem to represent the file uploader.
This is my .chtml code for this part.
#(Html.DevExtreme().DataGrid<myModel>()
.ID("dataGrid")
.DataSource(ds => ds.Mvc().Controller("DataGridMaterials")
.LoadAction("Get")
.InsertAction("Insert")
.UpdateAction("Update")
.DeleteAction("Delete")
.Key("ID")
)
.Columns(columns => {
columns.AddFor(m => m.Equipment);
columns.AddFor(m => m.Client);
columns.AddFor(m => m.Number);
columns.AddFor(m => m.Address);
columns.AddFor(m => m.Phone);
columns.Add().Width(160).Alignment(HorizontalAlignment.Center).CellTemplate(#<text>
#Html.DevExtreme().Button().Text("Attach").OnClick("function (e) { attachButtonClick(data) }")
</text>);
})
.OnRowDblClick(#<text>
function MyHandler(selectedItem) {
var dataGrid = $("#dataGrid").dxDataGrid("instance");
var selectedRowsData = dataGrid.getSelectedRowsData();
var allData = selectedRowsData[0];
var id = allData.ID;
console.log(id);
$('#customPopup').dxPopup('instance').option('visible', true);
}
</text>)
.RowAlternationEnabled(true)
.Editing(editing => {
editing.Mode(GridEditMode.Row);
editing.AllowUpdating(true);
editing.AllowDeleting(true);
editing.AllowAdding(true);
})
.Selection(s => s.Mode(SelectionMode.Single))
.RemoteOperations(true)
)
#(Html.DevExtreme().Popup().ID("customPopup").Width(660).Height(540).Title("Attachments").Visible(false)
.ContentTemplate(#<text>
#(Html.DevExtreme().FileUploader()
.ID("file-uploader")
.Name("myFile")
.Multiple(true)
.Accept("*")
.UploadMode(FileUploadMode.UseButtons)
.UploadUrl(Url.Action("Upload", "FileUploader"))
.OnValueChanged("fileUploader_valueChanged")
)
</text>)
)
I based my solution on this sample app.
View
Custom popup
It's strange, I follow the sample codes you provide and it can work on my side. I am using Asp.net core 3.1 and Devextreme 20.1:
#model Order
#{
ViewBag.Title = "Index";
}
<h2>Home</h2>
#(Html.DevExtreme().DataGrid<Order>()
.ID("gridContainer")
.ShowBorders(true)
.DataSource(d => d.Mvc().Controller("Orders").LoadAction("Get").Key("OrderID").UpdateAction("Put"))
.Columns(columns => {
columns.AddFor(m => m.CustomerName);
columns.AddFor(m => m.OrderDate);
columns.AddFor(m => m.ShipCity);
columns.Add().Width(160).Alignment(HorizontalAlignment.Center).CellTemplate(#<text>
#Html.DevExtreme().Button().Text("Attach").OnClick("function (e) { attachButtonClick() }")
</text>);
})
.Selection(s => s.Mode(SelectionMode.Single))
.RemoteOperations(true)
)
#(Html.DevExtreme().Popup().ID("customPopup").Width(660).Height(540).Title("Attachments").Visible(false)
.ContentTemplate(#<text>
#(Html.DevExtreme().FileUploader()
.ID("file-uploader")
.Name("myFile")
.Multiple(true)
.Accept("*")
.UploadMode(FileUploadMode.UseButtons)
.UploadUrl(Url.Action("Upload", "FileUploader"))
)
</text>)
)
<script>
function attachButtonClick() {
$('#customPopup').dxPopup('instance').option('visible', true);
}
</script>
Can anybody help me in implementing Drupal 7 'Keep me logged in' feature and customize the error messages in login form.
In page--front.tpl.php i used <?php print front_login();?> for the login form and front_login() function is in template.php.
template.php functions are
<?php
function front_login() {
global $user;
if ($user->uid == 0) {
$form = drupal_get_form('front_login_form');
return theme('status_messages').render($form);
} else {
return '<div id="loginbar">' . t('Welcome back ') . ucwords($user->name) . '</div>';
}
}
function front_login_form($form, &$form_state) {
global $base_url;
$form['#id'] = 'login';
$haveAccount = '<div class="title"><span>Already have an account?</span><br>Log In Here</div>';
$forgot = '<div class="forgot">Forgot your password?</div>';
$form['#validate'] = user_login_default_validators();
$form['#submit'][] = 'front_login_form_submit';
$form['name'] = array(
'#type' => 'textfield',
'#id' => 'user_login',
'#prefix' => $haveAccount . '<div class="inputholder"><div class="icon glyphicon glyphicon-user"></div>',
'#suffix' => '</div>',
'#required' => TRUE,
'#attributes' => array('class' => array('footerinput'), 'placeholder' => array(t('Username'))),
);
$form['pass'] = array(
'#type' => 'password',
'#id' => 'pwd_login',
'#prefix' => '<div class="inputholder"><div class="icon"><img src="' . $base_url . '/' . drupal_get_path('theme', 'foodnet') . '/images/icon-2.png"></div>',
'#suffix' => "</div>",
'#required' => TRUE,
'#attributes' => array('class' => array('footerinput'), 'placeholder' => array(t('Password'))),
);
$form['keep_logged'] = array(
'#type' => 'checkbox',
'#title' => t('Keep me logged in'),
'#default_value' => 1,
'#prefix' => '<div class="row">
<div class="col-md-6">
<div class="checkbox"><label>',
'#suffix' => '</label></div>
</div>'
);
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
'#id' => 'but_login',
'#name' => 'but_login',
'#value' => t('Log In ยป'),
'#prefix' => '<div class="col-md-6"><div class="loginBtn">',
'#suffix' => '</div></div> </div>' . $forgot
);
$form['actions']['submit']['#attributes']['class'][] = 'btn';
$form['actions']['submit']['#attributes']['class'][] = 'btn-yellow';
$form['actions']['submit']['#attributes']['class'][] = 'btn-lg';
$form['actions']['submit']['#attributes']['class'][] = 'col-md-12';
return $form;
}
function front_login_form_submit($form, &$form_state) {
global $user;
$user = user_load($form_state['uid']);
$form_state['redirect'] = 'profile';
user_login_finalize($form_state);
if($form_state['values']['keep_logged'] ==0){
ini_set('session.cookie_lifetime', 0);
foreach ($_COOKIE as $key => $value) {
setcookie($key, $value, 0);
}
setcookie('_fnet_keepLogged', 0, time()+200000);
}else{
ini_set('session.cookie_lifetime', 2000000);
setcookie('_fnet_keepLogged', 1, time()+200000);
}
}
The login functionality works fine but I cannot customize the error messages. I have to set the errors inside the form. Please help.
When user click the 'Keep me logged in' checkbox I set '_fnet_keepLogged' cookie to 1, else to 0. I know that the default expiration of cookie in drupal is 23 days. I need to change that according to the value of '_fnet_keepLogged' cookie. Please help for this.
Thanks in advance.
I use CGridView to render a result (invoice rows) from a db query. This is done inside a <div> on html page that is later converted to a PDF using wkhtmltopdf and printed. The problem is that today I have no support for page break so if number of invoice rows are greater than 10 the remaining rows are not visible. I can't let the div flow since I have an invoice footer with an absolute position that can't move.
Is there a way to force a page break and continue rendering rows on a separate page?
Below is part of the CGridView code used.
<...plenty of html---->
<div class="invoiceRow">
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $dpRows,
'cssFile' => Yii::app()->request->baseUrl . '/css/invoice.css',
'summaryText' => '',
'enablePagination' => false,
'columns' => array(
'number',
'name',
'description',
'amount',
array (
'name'=>'value',
'header' => 'netprice',
'value' => 'number_format($data->value,2,","," ")'
),
));
?>
</div>
<---more html ----->
If wkhtml is able to parse css (it seems so) you could try:
<div style="page-break-after:always">
//X invoices here
</div>
if(!empty($model))
{
if($model->content_type==1)
{
$sentences = explode ('<div style="page-break-after: always;"><span style="display:none"> </span></div>',$model->content);
?>
<div id="datashow">
<?php
echo $sentences[0];
?>
</div>
<?php
$dummy=array();
$kcnt=preg_match_all('/page-break-after: always/', $model->content,$dummy);
// echo $model->content;
}
<script>
$("#pagebreakdiv").find(":button").click(function () {
var datashow=$('#datashow');
var a=this.value;
var bid='<?php echo $bid; ?>';
var id='<?php echo $id; ?>';
var pdata = {};
pdata["bitt"] = a;
pdata["bid"] = bid;
pdata["id"] = id;
$.ajax(
{
url : "<?php echo Yii::app()->request->baseUrl; ?>/UserSimple/Contentpagebreak",
type: "POST",
data : pdata,
success:function(data, textStatus, jqXHR)
{
datashow.html(data);
},
error: function(jqXHR, textStatus, errorThrown)
{
}
});
});
</script>
Does anyone knows how or point me in the direction to show the last guestbook entry (using the simple guestbook module) in the sidebar or homepage?
trying to have a go, I've put in HomePage.php this function
function LastGuest($nume=1) {
$guest = DataObject::get_one("Guestbook");
return ($guest) ? DataObject::get("GuestbookEntry", "", "Date DESC", "", $nume) : false;
}
and in HomePage.ss this:
<% control LastGuest %>
<div class="newsList">
<h2 class="newsTitle">$Title.XML</h2>
<article class="newsSummary">$Comment</article>
</div>
<% end_control %>
But it doesn't work. I get a 500 error. Any idea?
Thanks in advance.
This works for me. First see if you have a page of class Guestbook, grab the ID of the page. Then use that ID in the arguments to GuestbookEntry::getEntryList.
function LastGuest() {
if ($guestbook = DataObject::get_one('GuestBook')) {
$id = $guestbook->ID;
$params = array(
'filter' => 'IsActive = 1 AND IsSpam = 0 AND GuestbookID = ' . $id,
'sort' => 'Created DESC',
'limit_start' => 0,
'limit_end' => 1,
'comments' => false,
'cryptmail' => false,
'emoticons' => false,
);
$entries = GuestbookEntry::getEntryList($params);
return $entries;
}
return;
}
I want to have a add more button on clicking which i can add dynamically, textboxes in a drupal form api.. can someone help on this?
Thanks in advance
Take a look at Adding dynamic form elements using AHAH. It is a good guide to learn AHAH with Drupal's form API.
EDIT: For an example, install the Examples for Developers module, it has an AHAH example you can use to help you learn.
Here is an example how to solve this with Ajax in Drupal 7(If anyone want I can convert it also to Drupal 6 using AHAH(name before it became Ajax)).
<?php
function text_boxes_form($form, &$form_state)
{
$number = 0;
$addTextbox = false;
$form['text_lists'] = array
(
'#tree' => true,
'#theme' => 'my_list_theme',
'#prefix' => '<div id="wrapper">',
'#suffix' => '</div>',
);
if (array_key_exists('triggering_element', $form_state) &&
array_key_exists('#name', $form_state['triggering_element']) &&
$form_state['triggering_element']['#name'] == 'Add'
) {
$addTextbox = true;
}
if (array_key_exists('values', $form_state) && array_key_exists('text_lists', $form_state['values']))
{
foreach ($form_state['values']['text_lists'] as $element) {
$form['text_lists'][$number]['text'] = array(
'#type' => 'textfield',
);
$number++;
}
}
if ($addTextbox) {
$form['text_lists'][$number]['text'] = array(
'#type' => 'textfield',
);
}
$form['add_button'] = array(
'#type' => 'button',
'#name' => 'Add',
'#ajax' => array(
'callback' => 'ajax_add_textbox_callback',
'wrapper' => 'wrapper',
'method' => 'replace',
'effect' => 'fade',
),
'#value' => t('Add'),
);
return $form;
}
function ajax_add_textbox_callback($form, $form_state)
{
return $form['text_lists'];
}
function text_boxes_menu()
{
$items = array();
$items['text_boxes'] = array(
'title' => 'Text Boxes',
'description' => 'Text Boxes',
'page callback' => 'drupal_get_form',
'page arguments' => array('text_boxes_form'),
'access callback' => array(TRUE),
'type' => MENU_CALLBACK,
);
return $items;
}