magento 2 empty attribute hide in product details page - attributes

Magento 2 experts,
Can you please help me, to hide empty/NA attribute in magento 2 products details page ?
Thanks a lot

Well, This is magento core issue: https://github.com/magento/magento2/issues/9961 , But you can use following solution for now.
Get to attributes.phtml file from :/vendor/magento/module-catalog/view/frontend/templates/product/view/attributes.phtml
Copy this file and paste in your theme : /app/design/frontend/[YOUR PACKAGE]/[YOUR THEME]/template/catalog/product/view/attributes.phtml.
Search following code:
<tr>
<th class="label"><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th>
<td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
</tr>
Replace above code by the following code:
<?php
$_attribute = $_product->getResource()->getAttribute($_data['code']);
if (!$_attribute->getFrontend()->getValue($_product)) {
continue;
}
?>
<tr>
<th class="label"><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th>
<td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
</tr>
Above solution is working perfectly in Magento 2.2

Related

GSP Pagination and Checkboxes

I am wondering if it is possible to have checkbox states transfer over to the next page on a GSP, I am new to web development so I was wondering if anyone could provide me with any advice.
Currently, this is how I am utilizing my checkboxes:
<table>
<thead>
<tr></tr>
</thead>
<tbody>
<g:each in="${itemList}" status="i" var="instance">
<tr class="${(i % 2) == 0 ? 'even' : 'odd'}">
<td>
<g:checkBox name="selected"value="${instance.id}" checked="false" />
</td>
</tr>
</g:each>
</tbody>
And this is the pagination I am utilizing:
<div class="pagination">
<g:paginate total="${total}" params="${params}"/>
</div>
My issue is that the checkboxes do not persist while traversing the pages - is there a simple way I could solve this?

how to find parent element that has specific child using By.xpath()?

Recently i've been scrapping by using selenium-webdriver in nodejs for a few days.
so i have to find element has specific child element but i don't know how find it.
i have used following operator but it doesn't work
By.xPath("tr[contains(#class, 'datetime2')]")
following html
<table>
<tbody>
<tr style="bacrgound-color:#eee">
<td class="datetime2">
20:00
</td>
<tr>
<tr></tr>
<tr style="bacrgound-color:#eee">
<td class="datetime2">
21:00
</td>
<tr>
<tr style="bacrgound-color:#eee">
<td class="datetime2">
22:00
</td>
<tr>
<tr></tr>
</tbody>
</table>
i need to find only 'tr' that include element <td class="datetime2">. not <tr></tr>
how find this element By using By.xpath()?? please help me
please try with following x-path.
//tr[td[#class='datetime2']]

I am trying to scrape a page with BeautifulSoup in Python 3

I am trying to scrape this page: http://sports.williamhill.com/bet/en-gb/results///E/10337992/today//////+England+v+Ukraine.html
I am using requests and BeautifulSoup in Python 3. I am specifically trying to extract the text that says 'Draw (13/5)' within the tag. I have tried to navigate to that spot with BeautifulSoup in many different ways, and it is like BS4 cannot 'see' it...
When I search for all within , it only gives me the first row.
<tbody>
<tr>
<th width="41%" scope="col">Market</th>
<th width="3%"></th>
<th width="45%" scope="col">Result</th>
<th width="10%" scope="col" style="text-align: center">Settled</th>
</tr>
<tr class="rowGroup top bottom">
<td style="padding-top: 0pt;" class="borderBottom" rowspan="1">Match Betting</td>
<td>
</td>
<td>
Draw (13/5)
</td>
<td style="padding-top: 0pt; text-align: center" class="borderBottom" rowspan="1">Y</td>
</tr>
How could I best retrieve that information with BeautifulSoup? Thank you in advanced.

Laravel 5 - Download Excel file of a View

I'm working on adding an export/downloading feature to a Laravel 5 application. I found the Laravel-Excel library (http://www.maatwebsite.nl/laravel-excel/docs), which seems perfect -- ideally, I will be able to take a Laravel View or html and make a downloadable Excel file.
So far, I've gotten the creation and storage to work. I can create an Excel file, and it's okay (it's the right data and View), and on the server in storage/exports/ I see "Report.xls" - which is right save path. The issue I'm having is I cannot seem to download the file through the browser after creating it.
The Laravel-Excel library has ->download('xls') and ->export('xls') methods, but these only seems to return the raw content, which is visible in the developer's console:
On the right, you can see the file was created and stored as "Report.xls", and presumably the raw content is the right content - but I don't know why it's just spitting raw content into the console. I can open the Report.xls file in Excel, so I know it's not corrupted.
I also tried to use the Laravel 5 Response::download() function and set headers for the download, but it also spit out raw content in the console instead of downloading the file:
The code I'm using is an AJAX call that hits a Controller method, and the controller method just triggers a Service method called "downloadReportFile()":
public function downloadReportFile($requestData, $fileType) {
$configJSON = \Report::loadConfigFile($requestData['reportName']);
$today = Carbon::today()->format('Y-m-d');
$FileViewdata = array(
'config' => $configJSON,
'html' => $requestData['report_html']
);
\Excel::create("Report", function($excel) use ($FileViewdata) {
$excel->setTitle($FileViewdata['config']['title']);
$excel->setDescription($FileViewdata['config']['description']);
$excel->sheet("page 1", function($sheet) {
$sheet->loadView("reports.sample");
});
})->store('xls', storage_path('exports')); // ->export('xls');
$report_excelFilepath = storage_path('exports') . "/Report.xls";
return response()->download($report_excelFilepath, "Report.xls", [
'Content-Type' => 'application/vnd.ms-excel',
'Content-Disposition' => "attachment; filename='Report.xls'"
]);
}
The View being made into the Excel file is a simple table - the same table as in the screenshots. Here's the template/HTML of the View:
<div class="container full-width-container">
<link href="http://192.168.33.10/css/reports.css" rel="stylesheet">
<div id="results" class="row">
<div class="col-xs-12">
<h2 class="report-title">Active Products </h2>
<br>
<div class="row">
<div class="col-xs-12">
<div class="table-responsive report-component" name="table" template="table">
<table id="report-table" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<td class="report-table-th">ENGINE</td>
<td class="report-table-th">PRODUCT COUNT</td>
<td class="report-table-th">PRODUCT PRICE</td>
</tr>
</thead>
<tbody>
<tr class="results-cell">
<td class="report-table-cell">
<p>Meows</p>
</td>
<td class="report-table-cell">
<p>1,234</p>
</td>
<td class="report-table-cell">
<p>781230.00</p>
</td>
</tr>
</tbody>
<tbody>
<tr class="results-cell">
<td class="report-table-cell">
<p>Paws</p>
</td>
<td class="report-table-cell">
<p>10,777</p>
</td>
<td class="report-table-cell">
<p>3919823.00</p>
</td>
</tr>
</tbody>
<tbody>
<tr class="results-cell">
<td class="report-table-cell">
<p>Meow Mobile</p>
</td>
<td class="report-table-cell">
<p>177</p>
</td>
<td class="report-table-cell">
<p>334323.00</p>
</td>
</tr>
</tbody>
<tbody>
<tr class="results-cell">
<td class="report-table-cell">
<p>Tails Cloud</p>
</td>
<td class="report-table-cell">
<p>335</p>
</td>
<td class="report-table-cell">
<p>378918923.00</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
Does anyone see what I might be missing to download an XLS file?
Thanks for your time!
EDIT
After doing some more research, it seems that my original workflow for downloading -- using an AJAX call to trigger -- is part of the problem. For example Download a file from Servlet using Ajax talks about AJAX storing results in JavaScript memory, which would explain why I get content in my console and not a file.
Try to add code below before Excel::create():
ob_end_clean();
ob_start();
Example code:
ob_end_clean();
ob_start();
Excel::create($filename, function($excel) use($records, $sheetname, $data) {}
This works for me.

pagination content

I am trying to do pagination for my forum. I am trying to get the results to show from the db, although everything is everywhere.
here is my code:
<!-- start with the table -->
<table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td width="53%" align="center" bgcolor="#E6E6E6" style="padding:5px;"><strong>Topic / Thread Starter</strong></td>
<td width="15%" align="center" bgcolor="#E6E6E6" style="padding:5px;"><strong>Replies/Views</strong></td>
<td width="13%" align="center" bgcolor="#E6E6E6" style="padding:5px;"><strong>Last Post By</strong></td>
</tr>
<div id="p1" class="pagedemo _current" style="">
<?php
$sql="SELECT * FROM forum ORDER BY datetime DESC";
$result=mysql_query($sql);
$i = 1;
$z = 1;
while($rows = mysql_fetch_array($result)){ // Start looping table row
if(($i % 4) != 0)
{ ?>
<tr>
<td bgcolor="#FFFFFF" style="padding:5px;"><a class="normal" href="view_topic.php?id=<? echo $rows['id']; ?>"><? echo $rows['topic']; ?></a><br /><span style="color:#666; font-size:12px;">Started By <?php echo "<a class='normal' href='http://www.example.com/view_profile.php?user=".getID($rows[username])."'>"; ?> <? echo $rows['username']; ?></a></span></td>
<td align="center" bgcolor="#FFFFFF">Replies: <? echo $rows['reply']; ?><br />Views: <? echo $rows['view']; ?></td>
<td align="center" background="http://example.com/images/forum_fade_bckg.png"><span style="color:#666; font-size:12px;">
<?php echo "<a class='normal' href='http://www.example.com/view_profile.php?user=".getID($rows[lastPoster])."'>"; ?> <?php echo $rows['lastPoster']; ?></a><br /><?php $date = substr($rows['datetime'],0,12);
if($date == date("M d, Y")) {
echo "Today, " . substr($rows['datetime'],-8);
} else {
echo $rows['datetime'];
}?> </span></td>
</tr>
<?php
// do whatever for the page... (this is inside the div)
$message = $row['message'];
echo $i . " " . $message. "<br>";
$i+=1;
}
else
{
$z+=1;
// GET ONLY NUMBERS HERE THAT ARE DIVISIBLE BY 4!!!!
// this is the end of the starting page, and the begining of the next page
echo '<br>---end---</div>
<div id="p'.$z.'" class="pagedemo" style="display:none;">---start---<br>NEXT PAGE!!!!!!!'; //
}
}
?>
</div>
The results, instead of staying in the div, are actually below the div. when I take out everything b/w the <tr> and </tr>, it all fits into the div. What am I doing wrong?
If you view the source of the page the issue should be apparent. I see a few mistakes that could be the problem.
The TABLE at the top of the snippet ends the TR tag then a DIV starts. A DIV should only reside within a TD, TH or outside the TABLE. Also in the snippet you provided there is no ending table tag. With all the other issues that is probably the one that is messing the browser up.
Please adjust structure to be similar to this:
<div>...</div>
<table>
<tr>
<td>Some tags in here(A, DIV, SPAN, etc.)</td>
</tr>
<tr>
<td>...</td>
<td>...</td>
</tr>
</table>
<div>...</div>
Also it would be worthwhile to migrate certain attributes to css properties in the style tag. For example the background, bgcolor, align, and width attributes in your snippet.
Sorry if that does not fix the issue its hard to debug without being able to see the issue.

Resources