joomla 2.5 get seo link by article id - joomla

let´s say I have following id´s from articles (#__content)
3,4,5 and I want to know the SEO URLs for these ID´s within my template.
pseudo code:
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$db->setQuery($query);
$query
->select(array('a.seolink'))
->from('#__content AS a')
->where("a.id = '3'" );
Anyone knows a query or function which does the job?
with kind regards,
tony

If you have article slug ("id:alias") and category slug ("catid:catalias"), then you could do
$link = JRoute::_(ContentHelperRoute::getArticleRoute($slug, $catslug));
From #__content you can get id, alias and catid, so you just have to get category alias too (since I think it won't work without it, but you can try)
Offtopic: anyone interested in adding tag synonyms for Joomla, please give your opinion

Related

Sanitize input in joomla

I have code like this in my Joomla plugin:
$some_id = $_GET["someid"];
$db = JFactory::getDBO();
$db->setQuery("SELECT * FROM #__table WHERE id = '$some_id'");
$result = $db->loadRow();
Does Joomla sanitize this automatically, or i need to do something (and what) to sanitize this query ? Using Joomla 2.5.
There is no need to sanitize database queries when using Joomla. The information you are pulling down is the information that has put put there or already there, and thus you don't want to change. I would also recommend using Joomla 2.5 coding standards to make database queries, like so:
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select($db->quoteName('*'))
->from($db->quoteName('#__table'))
->where($db->quoteName('id') . ' = ' . $db->quote($some_id));
$db->setQuery($query);
$rows = $db->loadRow(); //or loadResult()
The only time I have ever needed to sanitize (so to speak) something was when handling files, in which case I used JFile::makeSafe();.
Please take a look at you will get your answer
Secure coding guidelines
http://docs.joomla.org/Secure_coding_guidelines
Take a look at JInput and this corresponding documentation
Filter example:
$jinput = JFactory::getApplication()->input;
$some_id = $jinput->get('someid', '', 'string');

Get all site product ID in magento

Now, i want to get all product ID of my site. IS there a simple way to get all product ID in my site of magento,
To save resources it is better to use:
Mage::getModel('catalog/product')->getCollection()->getAllIds();
foreach(Mage::getModel('catalog/product')->getCollection() as $product)
{
var_dump($product->getId());
}
Or if you have access to command line, run mysql -u your_username -p magento_database and then you can run this query:
SELECT entity_id, sku FROM catalog_product_entity; don't forget that you might need something like LIMIT 0,30 or WHERE sku LIKE '%shirt%'. You can get to this via the command line or from phpmyadmin (if available). phpmyadmin has a query window in it somewhere.
I normally do sneaky things in Magento by creating php scripts in the var/export/ folder. Then you do not need to worry about how to interact with the Magento/Zend/MVC framework.
little variation If you All Product id from particular categories then:
$category_ids = array(11,16); // your category ids
$productIds = array();
foreach($category_ids as $category_id){
$category = Mage::getModel('catalog/category')->load($category_id);
$result = Mage::getResourceModel('catalog/product_collection')->addCategoryFilter($category)->getAllIds();
$productIds = array_merge($productIds,$result);
}
var_dump($productIds);

Echo Specific Category Description on Magento Frontend

I want to create a page in the Magento CMS, then echo specific category descriptions on it. What is the code snippet i will need to accomplish this. I am assuming I will need to reference the categories' unique id within the database to echo their description...
thanks for the help!
john
Using PHP:
$categoryId = 15;
$category = Mage::getModel('catalog/category')->load($categoryId);
if($category->getId()) {
echo $category->getDescription(); // Should escape this, blocks have $this->escapeHtml()
}
I don't know how to do this using magentos email/cms template markup (I don't think its possible) - unless you create a block or widget.

Select only specific fields in Magento

I'm trying to use the MAX function of MySQL to retrieve the latest dates from my table.
$_updates = Mage::getModel('ticket/updates')->getCollection();
$_updates->getSelect()->columns('MAX(created) as max_created')->group(array('status_id'));
This is the resulting query:
SELECT `main_table`.*, MAX(created) AS `max_created` FROM `em_ticket_updates` AS `main_table` GROUP BY `status_id`
The problem with this is that if all the fields are included (main_table.*) it does not function correctly.
Is there a way to remove main_table.* from the query and only use specific fields?
Thanks.
A Zend trick can be used here.
$_updates->getSelect()
->reset(Zend_Db_Select::COLUMNS)
->columns('MAX(created) as max_created')
->group(array('status_id'));
NOTE:
For EAV collection you must re-add the entity_id or you will have an error when the collection is loaded.
$collection = Mage::getModel('catalog/product')
->getCollection();
$collection->getSelect()
->reset(Zend_Db_Select::COLUMNS)
->columns(array('entity_id'));
$collection
->addAttributeToSelect(array('image','small_image','thumbnail'))
->addFieldToFilter('entity_id', array('in' => $simple_ids));
Magento provide addFieldToSelect() fumctionality. Use below code to get specific field.
$Collection = Mage::getModel('showdown/votes')->getCollection();
$Collection->addFieldToSelect('id');
I recognise this is an old post but I thought I'd post an alternative solution.
I had a similar problem myself, I eventually searched through the source until I reached Zend_Db_Select After consulting the Zend Documentation (Example 8).
$select = $db->select()
->from(array('p' => 'products'),
array('product_id', 'product_name'));
Just need to use "getColumnValues"
$_updates = Mage::getModel('ticket/updates')->getCollection();
$columnValues = $_updates->getColumnValues('Your Column Name');

Magento Product Insert Function

I need to add a custom option to all products as they get saved. For that I need to find the function that inserts the products into the database, which I'm not able to find.
Please, any help would be appreciated.
thanx
$client = new SoapClient('http://www.magentolocal.it/api/?wsdl');
$session = $client->login('productloader', '1234567890');
$sku = "123456";
$attrs['name'] = "Template #1";
$attrs['description'] = "This is the first template.";
$attrs['short_description'] = "This is the short description of the template";
$attrs['websites'] = array('1');
$attrs['price'] = "11.53";
$attrs['categories'] = array('35');
$attrs['images'] = array()
$result = $client->call($session, 'catalog_product.create', array('simple', '63', $sku, $attrs));
echo $result;
$client->endSession($session);
Magento's EAV system is pretty strung out among several files, so you won't find a single function that accomplishes what you want. If you did go looking for it, and changed it, you would also be changing the same save method that mostly every other object in Magento uses, which is probably not what you want.
To do what you want, try setting up an observer/listener on the events that catalog products use when saving, namely catalog_product_save_before or catalog_product_save_after. That way, you don't have to hack the framework.
Hope that helps!
Thanks,
Joe
How about http://www.magentocommerce.com/wiki/doc/webservices-api/api/catalog_product#catalog_product.create?

Resources