I want to append sku in product title in Magento using php code. Can anyone please help me on that.
<?php
//set empty title
$title = '';
if ($_product = Mage::registry('current_product'))
{
$title = $_product->getName();
$pos = stripos($title);
$title = $this->getTitle();
}
?>
<title><?php echo $title; ?> | test</title>
Here is the working code for above question.
<?php
//set empty title
$title = '';
if ($_product = Mage::registry('current_product'))
{
$title = $_product->getName();
$sku = $_product->getSku();
$pos = stripos($title, $sku);
if($pos === false )
{
//no sku already - append now
$title.= ' - ' . $sku;
}
}
else
{
$title = $this->getTitle();
}
?>
<title><?php echo $title; ?> | test</title>
Related
Dbfiddle: https://dbfiddle.uk/?rdbms=mysql_8.0&fiddle=65b310b4b973a7577d4953e01c09a124
Currently I have a table that displays a total count of my data values for each source. I'm getting this value after comparing 2 tables 1 is crm_leads with all my product information and 1 is crm_sources with what sources are the products related to.
Now this is the output:
Now as you can see the total count is shown under each header next to its source. There are 8 cells for each source as seen in the picture. Now these count values are inside a tags which once clicked go to viewall page.
Now here basically I want to show the data of the item that I had clicked. So for example, if I clicked the 163 under Hot status, it takes me to the viewall page and shows me id, source, enquiry_date for all those under status Hot in a table.
So basically it should detect the data for which source and which status is clicked and then accordingly make a statement like this?
select * from crm_leads where lead_source = '.$source.' and lead_status = '.$status.';
Another thing I'm thinking I can do here is put my table inside a form and pass those values as post in my controller class leadstatus which will pass that value to viewall? Not really sure on how to proceed.
Model Class:
function get_statusreport($fdate='',$tdate='')
{
$this->db->select("l.lead_status,crm_sources.title,count(*) as leadnum,l.enquiry_date,l.sub_status");
$this->db->from($this->table_name." as l");
if($fdate !='')
$this->db->where("date(l.added_date) >=",date('Y-m-d',strtotime($fdate)));
if($tdate !='')
$this->db->where("date(l.added_date) <=",date('Y-m-d',strtotime($tdate)));
$this->db->where("lead_status <>",10);
$this->db->join("crm_sources ","crm_sources.id= l.lead_source","left");
$this->db->group_by("l.lead_status,crm_sources.title");
$this->db->order_by("leadnum DESC, crm_sources.title ASC,l.lead_status ASC");
$query = $this->db->get();
$results = $query->result_array();
return $results;
}
Controller Class(leadstatus holds the view for my current table):
public function leadstatus($slug='')
{
$content='';
$content['groupedleads'] = $this->leads_model->get_statusreport($fdate,$tdate);
$this->load->view('crm/main',$main);
$this->load->view('crm/reports/leadstatus',$content);
}
public function viewall($slug='')
{
$content='';
$this->load->view('crm/main',$main);
$this->load->view('crm/reports/viewall',$content);
}
View class:
<?php
$ls_arr = array(1=>'Open',8=>'Hot',2=>'Closed',3=>'Transacted',4=>'Dead');
foreach($groupedleads as $grplead){
$statuses[] = $status = $ls_arr[$grplead["lead_status"]];
if($grplead["title"] == NULL || $grplead["title"] == '')
$grplead["title"] = "Unknown";
if(isset($grplead["title"]))
$titles[] = $title = $grplead["title"];
$leaddata[$status][$title] = $grplead["leadnum"];
}
if(count($titles) > 0)
$titles = array_unique($titles);
if(count($statuses) > 0)
$statuses = array_unique($statuses);
?>
<table>
<tr">
<th id="status">Source</th>
<?php
if(count($statuses) > 0)
foreach($statuses as $status){
?><th id=<?php echo $status; ?>><?php echo $status; ?></th>
<?php
}
?>
<th>Total</th>
</tr>
<?php
if(is_array($titles))
foreach($titles as $title){
?>
<tr>
<?php
$total = 0;
echo "<td>".$title."</td>";
foreach ($statuses as $status) {
$num = $leaddata[$status][$title];
echo "<td><a target='_blank' href='".site_url('reports/viewall')."'>".$num."</a></td>";
$total += $num;
$sum[$status] += $num;
}
echo "<td>".$total."</td>";
$grandtotal += $total;
?>
</tr>
<?php } ?>
</table>
You can include the source and status in the URL like this:
foreach ($statuses as $status) {
$num = $leaddata[$status][$title];
echo "<td><a target='_blank' href='" . site_url('reports/viewall?source=' . $source . '&status=' . $status) . "'>" . $num . "</a></td>";
$total += $num;
$sum[$status] += $num;
}
Then in your controller:
public function viewall($slug = '')
{
$content = '';
$source = $this->input->get('source');
$status = $this->input->get('status');
// Do what you want with $source and $status
$this->load->view('crm/main', $main);
$this->load->view('crm/reports/viewall', $content);
}
I want to display the page heading of a Joomla menu item if this is filled. I've tryed with this code wothout success:
<h1 class="title">
<?php
if (null === ($this->params->get('page_heading')))
{
$mydoc = JFactory::getDocument();
$mytitle = $mydoc->getTitle();
echo $mytitle;
}
else
{
$active = JFactory::getApplication()->getMenu()->getActive();
echo $active->params->get('page_heading');
}
?>
</h1>
Any suggestion?
I've solved myself this way:
<h1 class="title">
<?php $menu = JFactory::getApplication()->getMenu();
$active = $menu->getActive();
$mydoc = JFactory::getDocument();
$mytitle = $mydoc->getTitle();
$pageHeading = $active->params->get('page_heading');
if($pageHeading != "")
{
echo $pageHeading;
}
else
{
echo $mytitle;
}
?>
</h1>
I had similar need and noticed this code doesn't work in Joomla 4.
Here is my solution:
Joomla 3
$menu = JFactory::getApplication()->getMenu()->getActive();
$title = $menu->title;
$page_heading = $menu->params->get('page_heading');
echo $page_heading ?? $title;
Joomla 4
$menu = JFactory::getApplication()->getMenu()->getActive();
$title = $menu->title;
$page_heading = $menu->getParams()->get('page_heading');
echo $page_heading ?? $title;
The only difference between these 2 is how you get the menu item params, params in J3 vs getParams() in J4.
<?php
include("config.inc.php");
header("Cache-Control: no-cache, must-revalidate");
echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>";
echo "<!DOCTYPE html PUBLIC \"-//WAPFORUM//DTD XHTML Mobile 1.0//EN\"\"http://www.wapforum.org/DTD/xhtml-mobile10.dtd\">";
echo "<html xmlns=\"http://www.w3.org/1999/xhtml\">";
echo "<head>";
echo "<title>$stitle</title>";
echo "<link rel=\"StyleSheet\" type=\"text/css\" href=\"theme/theme.css\" />";
echo "</head>";
?>
<head>
<META HTTP-EQUIV="Refresh" Content="10">
</head>
<?php
echo "<body>";
echo "<p align=\"center\">";
echo "Live Score:
---
";
$feed = "http://www.scorespro.com/rss/live-soccer.xml";
$fp = #fopen($feed,"r");
while(!feof($fp)) $raw .= #fgets($fp, 4096);
fclose($fp);
if( preg_match("/<item>(.*)<\/item>/", $raw, $rawitems ) ) {
$items = explode("<item>", $rawitems[0]);
$p = 5;
if ($npage == "")$npage = "1";
$countfile= count($items);
$countfile=$countfile-2;
$first=($npage*$p)-$p;
$npages = ceil($countfile / $p);
$items = array_reverse($items);
$next_arrays=($first+($p-1));
if($next_arrays>$countfile)$next_arrays=$countfile;
for ($i=($first); $i <= $next_arrays; $i++) {
preg_match("<title>(.*)</title>",$items[$i+1], $title );
preg_match("<link>(.*)</link>",$items[$i+1], $url );
preg_match("<description>(.*)</description>",$items[$i+1], $description);
$title[1] = str_replace("'", "", $title[1]);
$title[1] = str_replace("& ", "&", $title[1]);
echo $title[1].' ';
}
}
// if ($npage <= $npages and $npage>1) $gline_rew = '[url="'.$_SERVER["]Prev[/url] ';
// if ($npages > 1 and $npage<$npages) $gline_next = ' [url="'.$_SERVER["]Next[/url]';
// echo "
// ---
// Page {$npage} of {$npages}
// ".$gline_rew.$gline_next."
// ---
// ";
echo "</small>\n";
echo "</p>";
echo "</body>";
echo "</html>";
?>
<?php
public_static_function getInstance() {
static $instance;
$class = $title;
if ( ! $instance instanceof $class) {
$instance = new $class;
}
return $instance;
}
Hello!
I am making a live-score site using PHP.
But when I use this code and run it, I get a blank page.
I hope that I will find the mistake by myself but for now I can`t.
I would be happy if someone knows where the mistake is and help me.
Thank you in advance !!!
This is wrong
public_static_function getInstance() {
It should be
public static function getInstance() {
Also add error_reporting(E_ALL) when you have blank page(Which means you have errors)
Even when fixed, this will not work:
public static function getInstance() {
static $instance;
$class = $title;
...
}
Furthermore we have simpleXML_load_str() for handling RSS (or other XML) strings.
I think what you want is a decent way to handle an RSS feed.
Have a look at this post about RSS feeds
Good luck!
I have this code but it doesn't work. It show nothing.
<?php
$item = file_get_contents('https://www.googleapis.com/books/v1/volumes?q=Bowling Alone&maxResults=1');
$booktitle = (isset($item->volumeInfo->title) ? $item->volumeInfo->title : false);
$description = (isset($item->volumeInfo->description) ? $item->volumeInfo->description : false);
echo "<b>Title:</b> " . $booktitle;
echo "<b>Description:</b> " . $description;
?>
So, please help me fix it ! Also, this is any way to get content faster ? Thank you very much !
Make it url compatible, so no spaces in it. You also needed to add a foreach loop because incase of more results. And decode the json result into a object
$item = file_get_contents('https://www.googleapis.com/books/v1/volumes?q=Bowling%20Alone&maxResults=1');
$item = json_decode($item);
foreach ($item->items as $item) {
$booktitle = (isset($item->volumesInfo->title) ? $item->volumeInfo->title : false);
$description = (isset($item->volumeInfo->description) ? $item->volumeInfo->description : false);
echo "<b>Title:</b> " . $booktitle;
echo "<b>Description:</b> " . $description;
}
<?php
$item = file_get_contents('https://www.googleapis.com/books/v1/volumes?q=Bowling%20Alone&maxResults=1');
$item = json_decode($item);
$item = reset($item->items);
$booktitle = (isset($item->volumesInfo->title) ? $item->volumeInfo->title : false);
$description = (isset($item->volumeInfo->description) ? $item->volumeInfo->description : false);
echo "<b>Title:</b> " . $booktitle;
echo "<b>Description:</b> " . $description;
?>
My following code is based on
1.Get current URL
2.Go through array and check if in url value = to value in array
do this:
$on_this_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
foreach ($city_array as $sandwich) {
if (strpos($on_this_link, $sandwich) == true) {
$sandwich = trim($sandwich, '/');
$city = $sandwich;
if ($city == 'newyork') {
foreach ($category_array as $double_sandwich) {
if (strpos($on_this_link, $double_sandwich) == true) {
$double_sandwich = trim($double_sandwich, '/');
$category_is = $double_sandwich;
Loader::model('page_list');
$nh = Loader::helper('navigation');
$pl = new PageList();
$pl->filterByAttribute('city', '%' . $city . '%', 'like');
$pl->filterByAttribute('category','%'.$category_is.'%','like');
$pl->sortByDisplayOrder();
$pagelist = $pl->get();
foreach ($pagelist as $p) {
echo '<li> ' .htmlspecialchars($p->getCollectionName()) . ' </li>';
?>
}
}
}
}
So It will show me only pages that have the same attribute with URL
Each of this page has image attribute that I want to show.
How can I pass this Image Attribute??
Check out the comments in the page list block's view template:
https://github.com/concrete5/concrete5/blob/master/web/concrete/blocks/page_list/view.php#L33
You can get image attributes by putting some code like this inside your foreach ($pagelist as $p) loop:
$img = $p->getAttribute('example_image_attribute_handle');
if ($img) {
//you could output the original image at its full size like so:
echo '<img src="' . $img->getRelativePath() . '" width="' . $img->getAttribute('width') . '" height="' . $img->getAttribute('height') . '" alt="" />';
//or you could reduce the size of the original and output that like so:
$thumb = Loader::helper('image')->getThumbnail($img, 200, 100, false); //<--200 is width, 100 is height, and false is for cropping (change to true if you want to crop the image instead of resize proportionally)
echo '<img src="' . $thumb->src . '" width="' . $thumb->width . '" height="' . $thumb->height . '" alt="" />';
}
Thx but I did it already just another way!
I didnt used
Loader::model('page_list');
Instead I used:
$blockType = BlockType::getByHandle('page_list');
And hardcoded the block!
$th = Loader::helper('text');
$ih = Loader::helper('image');
$page_current = Page::getCurrentPage();
$page_2 = $page_current->getCollectionHandle();
$img = $page->getAttribute('product'); $thumb =
$ih->getThumbnail($img, 240,150, false);
And after I changed a little bit my Code above:
$on_this_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
foreach ($city_array as $sandwich) {
if (strpos($on_this_link, $sandwich) == true) {
$sandwich = trim($sandwich, '/');
$city = $sandwich;
if ($city == 'newyork') {
foreach ($category_array as $double_sandwich) {
if (strpos($on_this_link, $double_sandwich) == true) {
$double_sandwich = trim($double_sandwich, '/');
$category_is = $double_sandwich;
$city_att = $page->getAttribute('city', '%' . $city . '%', 'like');
$sub_cat_att = $page->getAttribute('category','%'.$category_is.'%','like'); ?>
<?php if($city == $city_att && $category_is == $sub_cat_att){ ?><li><img src="<?php echo $thumb->src ?>" width="<?php echo $thumb->width ?>" height="<?php echo $thumb->height ?>" alt="" />
<h3> <?php echo $title ?></h3>
<div class="product_description">
<?php echo $description ?>
</div>
Read More...
</li> <?php } ?> <?php
}
}
}
So everything it is working But still thx for respond! Apreciate