how to create cart content as pdf output in PRESTASHOP - prestashop

I have to print the cart content in a pdf file and download.
I have try some code using pdfinvoicecontroller.php
I have created new controller - controllers/front/CartprintController.php
class CartprintControllerCore extends FrontController
{
protected $display_header = false;
protected $display_footer = false;
public $content_only = true;
protected $template;
public $filename;
public function postProcess()
{
if (!$this->context->customer->isLogged() && !Tools::getValue('secure_key'))
Tools::redirect('index.php?controller=authentication&back=cartprint');
}
public function display()
{
$displayproducts = $this->context->cart->getProducts();
$pdf = new PDF($displayproducts, PDF::TEMPLATE_INVOICE_CART, $this->context->smarty, $this->context->language->id);
$pdf->render();
}
public function getTemplate()
{
$template = _PS_THEME_PDF_DIR_.'/cartprint.tpl';
return $template;
}
}
Added
const TEMPLATE_INVOICE_CART = 'Cartprint';
line in classes/pdf/PDF.php
3.then created a HTML template file in pdf/cartprint.tpl
<table id="cart_summary" class="std">
<thead>
<tr>
<th class="cart_product first_item">{l s='Product'}</th>
<th class="cart_description item">{l s='Description'}</th>
<th class="cart_unit item">{l s='Unit price'}</th>
<th class="cart_quantity item">{l s='Qty'}</th>
<th class="cart_total item">{l s='Total'}</th>
</tr>
</thead>
{foreach $displayproducts item=prodpef name=prodpef }
<tr>
<td class="cart_product first_item">{$prodpef.name}</td>
<td class="cart_description item">{$prodpef.description_short}</td>
<td class="cart_unit item">{$prodpef.price}</td>>
<td class="cart_quantity item">{$prodpef.cart_quantity}</td>>
<td class="cart_total item">{$prodpef.total}</td>>
</tr>
{/foreach}
</table>
4.in shopping cart page i have created a link
<img src="{$img_dir}icon/pdf.gif" alt="{l s='Invoice'}" class="icon" />
but still i am not getting pdf output .
Any help ?

First it will be better to override PDF class and second you need to create a HTMLTemplateCartPrint.php file in classes dir or override classes dir in order to generate pdf file.
Best regards.

Related

Spring WebFlux+Thymeleaf How to display reactive collection size

I am developing a spring boot service to manage a REST server.
The service displays a reactive list on one of the forms.
It is very simple code.
Table in thymeleaf template
<table>
<thead>
<tr>
<td>ID</td>
<td>Name</td>
<td>Alive</td>
</tr>
</thead>
<tbody>
<tr th:each="item : ${items}">
<td th:text="${item.counterpartID}" />
<td th:text="${item.counterpartName}" />
<td th:text="${item.alive}"/>
</tr>
</tbody>
</table>
Controller
#GetMapping("/counterparties")
public String init(Model model) {
IReactiveDataDriverContextVariable reactiveDataDrivenMode =
new ReactiveDataDriverContextVariable(
webClient
.get()
.uri(uriBuilder -> uriBuilder
.path("/findAllCounterpart")
.build())
.retrieve()
.bodyToFlux(Counterpart.class)
, 1);
model.addAttribute("items", reactiveDataDrivenMode);
return "counterparties.html";
}
Now I want to display collection size (numbers of rows in table).
I added to the html temlate tag
<label th:text="'total rows: ' + ${#lists.size(items)}">rows number in table</label>
And I got an unexpected result
total rows: 1
How to display the real number of rows in a reactive collection ?
Thanks.
I decided to use javascript.
<script language="JavaScript">
function countLoadedRows() {
var table = document.getElementById('tableId');
var tbodyRowCount = table.tBodies[0].rows.length;
console.log('total rows: ' + tbodyRowCount);
document.getElementById('totalRowsId').textContent = tbodyRowCount
}
document.addEventListener('readystatechange', countLoadedRows)
</script>
and html tags is
<input type = "button" onclick = "countLoadedRows()" value = "Total rows: "><label id="totalRowsId">???</label>
<table id="tableId">
...
</table>

Quarkus Qute not parsing html template correctly

I am using quarkus-qute to generate html from a html template file. However, it returns a pure string. For e.g. in the template file, userNotification.html
<table width="600" cellpadding="0" cellspacing="0" border="0" class="table">
<tr>
<td width="600" bgcolor="#f2f2f2" class="logocell">
is parsed as
<table width=\"600\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" class=\"table\">\n
<tr>\n
<td width=\"600\" bgcolor=\"#f2f2f2\" class=\"logocell\">\n
The parser escaped the double quotes and added \n to the end of line.
Section of class that parses
#CheckedTemplate(requireTypeSafeExpressions = false)
static class Templates {
static native TemplateInstance userNotification(Email email);
}
.....
.....
private String getTemplateOutput( Message notificationMessage) {
return Templates.userNotification(email).render();
}
Its not a REST API call.
Any suggesstions?

Display the first row of view data in razor

I have a a ViewData with 8 rows. The ForEach loop works fine, but I need to extract the very first row before the foreach.
I need to extract only the first row to inject the default video in the iframe.
<iframe name="myFrame" width="800" height="500" src="#item.ID?wmode=transparent" allowfullscreen="True"></iframe>
Here is the foreach that works 100%
#foreach (var item in (List<VideoModel>)ViewData["Videos"])
{
<tr class="sep">
<td>#item.DisplayNumber</td>
<td>
#Html.ActionLink("Play Video", "IframeRedirect", "Home", new { ContentID = item.ID }, new { target = "someFrame", #class = "cbutton" })
</td>
<td>#item.Time #item.Hd</td>
<td><b>#item.Title</b><br />#item.Description</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td><b>Author:</b> #item.Author <br />Subscribe to youtube channel</td>
</tr>
}
you can get the first row like following:
var firstRow = ((List<VideoModel>)ViewData["Videos"]).First();
If your model is a IEnumerable
You can get the first like following:
var first = Model.First();

How to close dojox.grid.DataGrid

I have a grid that populates from a search event and I'd like the option of being able to close the grid by simply adding an X in the top right corner, similar to how you close any browser or window. I thought it would be as easy as adding the X, styling it to my liking and then creating an onclick event that would close or hide the grid... but I can't seem to get that working. Any help would be appreciated.
My JS is:
dojo.require("dojox.grid.DataGrid"); //FindTask
dojo.require("dojo.data.ItemFileReadStore"); //FindTask
dojo.require("esri.tasks.find"); //FindTask
var findTask, findParams;
var grid, store;
var searchExtent;
function doFind() {
//Show datagrid onclick of search button and resize the map div.
esri.show(datagrid);
dojo.style(dojo.byId("content"), "height", "83%");
searchExtent = new esri.geometry.Extent ({
"xmin":-9196258.30121186,"ymin":3361222.57748752,"xmax":-9073959.055955742,"ymax":3442169.390441412,"spatialReference":{"wkid":102100}
});
map.setExtent(searchExtent);
//Set the search text to the value in the box
findParams.searchText = dojo.byId("parcel").value;
grid.showMessage("Loading..."); //Shows the Loading Message until search results are returned.
findTask.execute(findParams,showResults);
}
function showResults(results) {
//This function works with an array of FindResult that the task returns
map.graphics.clear();
var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([98,194,204]), 2), new dojo.Color([98,194,204,0.5]));
//create array of attributes
var items = dojo.map(results,function(result){
var graphic = result.feature;
graphic.setSymbol(symbol);
map.graphics.add(graphic);
return result.feature.attributes;
});
//Create data object to be used in store
var data = {
identifier: "Parcel Identification Number", //This field needs to have unique values. USES THE ALIAS!!!
label: "PARCELID", //Name field for display. Not pertinent to a grid but may be used elsewhere.
items: items
};
//Create data store and bind to grid.
store = new dojo.data.ItemFileReadStore({ data:data });
var grid = dijit.byId('grid');
grid.setStore(store);
//Zoom back to the initial map extent
map.setExtent(searchExtent);
}
//Zoom to the parcel when the user clicks a row
function onRowClickHandler(evt){
var clickedTaxLotId = grid.getItem(evt.rowIndex).PARCELID;
var selectedTaxLot;
dojo.forEach(map.graphics.graphics,function(graphic){
if((graphic.attributes) && graphic.attributes.PARCELID === clickedTaxLotId){
selectedTaxLot = graphic;
return;
}
});
var taxLotExtent = selectedTaxLot.geometry.getExtent();
map.setExtent(taxLotExtent);
}
and my HTML is:
<div id ="datagrid" data-dojo-type="dijit.layout.AccordionPane" splitter="true" region="bottom"
style="width:100%; height:125px;">
<table data-dojo-type="dojox.grid.DataGrid" data-dojo-id="grid" id="grid" data-dojo-props="rowsPerPage:'5', rowSelector:'20px'">
<thead>
<tr>
<th field="Parcel Identification Number" width="10%">
Parcel ID
</th>
<th field="Assessing Neighbornood Code" width ="20%">
Neighborhood Code
</th>
<th field="Property Class Code" width="10%">
Property Class
</th>
<th field="Site Address" width="100%">
Address
</th>
</tr>
</thead>
</table>
</div>
This is my best guess at what to add:
<tr>
<td align="right">
<div class="divOk" onclick="dijit.byId('tocDiv').hide();">
OK</div>
</td>
</tr>
I wound up creating a work around for what I want by creating a new column and putting a close icon within the header. I connected it to an function so that when I click it, the grid closes and the map resizes:
function closeGrid() {
esri.hide(datagrid);
dojo.style("map", {"height": "100%"});
}
HTML
<th field="" width="2%"> <div class="GridCloseIcon" title="Close Grid" onclick="closeGrid();"></div>
How about this?
(assuming the OK line actually appears)
HTML
<tr>
<td align="right">
<div class="divOk" onclick="hideGrid();">OK</div>
</td>
</tr>
JS
function hideGrid() {
var widget = dijit.byId('datagrid');
dojo.fadeOut({
node: widget.domNode
}).play();
dojo.style(widget.domNode, 'display', 'none');
}

ASP VB. NET Highlight Row to Red color

I would like to select the row and highlight to Red if status equal to Offline.
How can i do it in ASP .NET?
I saw quite alot of example talking about protected void OnRowCreated(object sender, GridViewRowEventArgs e).
I should create the class in Controller? or View? Very confuse on the new MVC >_<
Please help
You should just reference the row values Online/Offline status from the model and change the CSS accordingly to highlight the row. Since no code has been provided I have mocked an example up:
I.e.
public class OnlineOfflineElements {
public List<Element> elements { get; set; }
}
public class Element {
public bool isOnline { get; set; }
}
Then in your View:
#foreach (var status in elements) {
if (status.isOnline) {
<tr class="Online">
} else {
<tr class="Offline">
}
// Other model content here
}
I tried the method CSS TD Class to red, but i could not get it work. Any idea?
My code as follow:-
#For Each item In Model
Dim currentItem = item
Dim status = Html.Action("showPing", New With {.ipaddress = currentItem.IP})
If status.Equals("Online") Then
#<tr>
<td>
#Html.DisplayFor(Function(modelItem) currentItem.Name)
</td>
<td>
#Html.DisplayFor(Function(modelItem) currentItem.IP)
</td>
<td>
#Html.DisplayFor(Function(modelItem) currentItem.Location)
</td>
<td>
#Html.Action("showPing", New With {.ipaddress = currentItem.IP})
</td>
</tr>
Else
#<tr>
<td class="red">
#Html.DisplayFor(Function(modelItem) currentItem.Name)
</td>
<td class="red">
#Html.DisplayFor(Function(modelItem) currentItem.IP)
</td>
<td class="red">
#Html.DisplayFor(Function(modelItem) currentItem.Location)
</td>
<td class="red">
#Html.Action("showPing", New With {.ipaddress = currentItem.IP})
</td>
</tr>
End If
Next
It showed all red. I am using ASP .NET VB MVC4
I have just been able to complete this for a gridview in my webpage. I needed to be able to change a row of data when offline to red.
Protected Sub grdName_RowDataBound(ByVal sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdName.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
If DataBinder.Eval(e.Row.DataItem, "Status").ToString() = "OffLine" Then
e.Row.BackColor = System.Drawing.Color.Red
End If
End If
End Sub
Hope this helps.
Betty