how can i access directly to magento order history from observer? - magento

How can i get the value ,what i set by addStatusHistoryComment while creating order by php script.
$order = $observer->getEvent()->getOrder();
$dbOrderId = $order->getId();
$MagOrderId = $order->getRealOrderId();
Mage::log('dbOrderId : '. $dbOrderId);
Mage::log('MagOrderId : '. $MagOrderId);
I need to get like something $order->getStatusHistoryComment()
it is not working.
Need help.
The following data is not working as order is not commit yet.
$connection = Mage::getSingleton('core/resource')->getConnection('core_read');
$sql = "SELECT comment FROM sales_flat_order_status_history WHERE parent_id=' $dbOrderId' limit 1 ";
$connection = Mage::getSingleton('core/resource')->getConnection('core_read');
foreach ($connection->fetchAll($sql) as $arr_row) {
$comments=$arr_row['comment'];

Use getStatusHistoryCollection instead of getStatusHistoryComment and it should work. The method is defined in Mage_Sales_Model_Order.
Or you can use getVisibleStatusHistory if you want only the comments visible on frontend.

Related

Codeigniter Call to undefined method CI_DB_mysqli_result::fetch_assoc()

hello i want to update the row by clicking on edit button, but it giving me this error, kindly help
function updateUser()
{
$data = stripslashes(file_get_contents("php://input"));
$mydata = json_decode($data, true);
$id = $mydata['sid'];
//retrieve specific info
$sql = "SELECT * FROM admin WHERE id = {$id}";
$result = $this->db->query($sql);
$row = $result->fetch_assoc();
echo json_encode($row); //returning json formate
}
Use $result->row_array(); instead of $result->fetch_assoc();
To prevent sql injection, you may also want to bind the $id separately instead of concatenating it into the query, like this:
$sql = "SELECT * FROM admin WHERE id = ?";
$result = $this->db->query($sql, array($id));
$row = $result->row_array();
See also: https://codeigniter.com/userguide3/database/queries.html#query-bindings

magento - How to get product meta title?

I use following code to get the current product meta title, but it doesn't work.
$curr_prod = Mage::registry('current_product');
$meta_title = $curr_prod->getMetaTitle();
echo $meta_title;
I can get the correct $curr_prod object, but I don't know which method I should use to get the meta title of current product, anyone can help on this?
Thanks!
$title = $product->getMetaTitle();
if ($title) {
$headBlock->setTitle($title.' - '. $product->getFinalPrice());
}
try the code it might work
Set Meta information(Title, Keyword, Description) on Controller Action. Fetch meta information from product data and set the values for layout head block.
$_product = Mage::getModel('catalog/product')->load($id);
if($_product){
$title = $_product->getMetaTitle();
$keyword = $_product->getMetaKeyword();
$description = $_product->getMetaDescription();
}
$this->loadlayout();
$title = $title!=""?$title:$this->getLayout()->getBlock('head')->getTitle();
$keyword = $keyword!=""?$keyword:$this->getLayout()->getBlock('head')->getKeywords();
$description = $description!=""?$description:$this->getLayout()->getBlock('head')->getDescription();
$this->getLayout()->getBlock('head')->setTitle($title )
->setKeywords($keyword)
->setDescription($description);
$this->renderlayout();

Need to convert to magento MVC structure

I have developed a code that contains a aquery which returns ratings of a product in json format. The code is as follows:
<?php header('content-type: application/json; charset=utf-8');
require_once('/opt/phpapps/magento/app/Mage.php');
umask(0);
Mage::app();
$cid=$_GET['catid'];
$read = Mage::getSingleton('core/resource')->getConnection('core_read');
$query = "SELECT round(t1.rating_summary / 20) AS rating, t2.product_id FROM review_entity_summary AS t1 INNER JOIN catalog_category_product AS t2 ON t1.entity_pk_value = t2.product_id WHERE category_id =" . $cid . " AND store_id = '1'";
$results = $read->fetchAll($query);
$json = json_encode($results);
print_r( $json );
?>
I am instructed to convert this into MVC pattern. I knew that MVC can be done by creating separate folders like blocks, controllers, models,sql,etc, helpers folders. But I am not sure what is the next stepa nd how to execute the developed to get the json data..
Help me in this...
The best way to is create a custom Extension/Model, there's a lot of tutorials out there to do this, however you could use something to generate an example for you to get started:
http://www.silksoftware.com/magento-module-creator/
However, for something this simple you could just create a custom block in the local namespace, for example:
app/code/local/Mage/Catalog/Block/Product/Ratingsjson.php
<?php
/**
* Ratingsjson.php
*/
class Mage_Catalog_Block_Product_Ratingsjson extends Mage_Catalog_Block_Product_Abstract
{
/**
* Get products with special offer attribute set
*
* #return type
*/
public function getRatings()
{
/**
* This will be injected from the tag / XML below
* you can pass what ever variables you want this way.
* getSomeAttribute() will get the value 'some_attribute' from the
* CMS tag or XML config.
*/
$categoryId = $this->getCategoryId();
if($categoryId == NULL) {
$categoryId = 1; // or some default;
}
$resource = Mage::getSingleton('core/resource');
$read = $resource->getConnection('catalog_read');
// Do your stuff here...
$query = "SELECT round(t1.rating_summary / 20) AS rating, t2.product_id FROM review_entity_summary AS t1 INNER JOIN catalog_category_product AS t2 ON t1.entity_pk_value = t2.product_id WHERE category_id =" . $cid . " AND store_id = '1'";
$results = $read->fetchAll($query);
return json_encode($results);
}
}
Create a template to do what you want:
template/mymodeule/mytemplate.phtml
<?php
echo $this->getRatings();
You can then use your new block inside CMS pages:
{{block type="catalog/ratignsjson" category_id="3" temaplte="mymodeule/mytemplate.phtml"}}
Or if you want to load it via XML config:
<block type="catalog/ratignsjson" category_id="3" name="ratignsjson" template="mymodeule/mytemplate.phtml"/>
To do this properly and output strict Json data you would want to set json content type headers etc but I think that's a little too much for this particular case.

How to Get User Group Names in Joomla 2.5

I'm writing a Joomla 2.5 component that I had been developing in Joomla 1.7. I have been using code like this:
$user = JFactory::getUser();
$groups = $user->get('groups');
The $groups array would contain a list of ids with the group name as the index. Joomla 2.5 seems to have scrapped this functionality. I have been unable to find out how to get the group names without directly querying the database. Is there any method for getting a list of the groups a user is a member of without having to resort to querying the database?
The code I generated below gets the names of all the groups the user is a part of and stores them in the variable $groupNames separated by line breaks:
foreach ($user->groups as $groupId => $value){
$db = JFactory::getDbo();
$db->setQuery(
'SELECT `title`' .
' FROM `#__usergroups`' .
' WHERE `id` = '. (int) $groupId
);
$groupNames .= $db->loadResult();
$groupNames .= '<br/>';
}
print $groupNames;
It technically queries the database but is done via the Joomla API. This is working well for me on Joomla 2.5.
Yes, this changed.
But what you should be using instead is:
JFactory::getUser()->getAuthorisedGroups();
or just getUserGroups
Real snippet:
$user = JFactory::getUser();
$db = JFactory::getDBO();
$db->setQuery($db->getQuery(true)
->select('*')
->from("#__usergroups")
);
$groups=$db->loadRowList();
$userGroups = $user->groups;
$return=array();
foreach ($groups as $key=>$g){
if (array_key_exists($g[0],$userGroups)) array_push($return,$g[4]);
}
$groups=$return;
/////printing groupnames for current user/////////////
print_r($groups);
Here it is:
<?php
$user =& JFactory::getUser();
foreach ($user->groups as $key => $value){
echo $key.'<br>';
}
?>
This will print all the user group names to the screen. The user group names are the "keys" of the array $user->groups.

'mysql_num_rows(): supplied argument is not a valid argument' when trying to use JDatabase

$select = "SELECT * FROM `jos_users`";
$connection->setQuery($select);
$rows = $connection->getNumRows();
$rows does not work it throws the 'mysql_num_rows(): supplied argument is not a valid' error but...
$result = $connection->loadObjectList();
$result works fine.
Is this a Joomla bug?? Or what am i doing wrong?
<?
$select = "SELECT * FROM `jos_users`";
$connection->setQuery($select);
//add this:
$connection->query();
$rows = $connection->getNumRows();
?>
You're setting the query but not executing it.
would it need to call query()... $res = $db->query('select * from jos_users'); $db->getNumRows($res);

Resources