How to call a joomla module in virtuemart shop.browse page - joomla

How can a joomla module be called inside the virtuemart shop.browse page. I tried the following code inside the browse_layouttable.tpl.php but it is not working for me. I am using joomla1.5.23 and the virtuemart version is 1.1.8. Any suggestion?
<?php
$modules =& JModuleHelper::getModules('logo');
foreach ($modules as $module)
{
echo JModuleHelper::renderModule($module)
}
?>

Try this
$document = &JFactory::getDocument();
$renderer = $document->loadRenderer('module');
$Module = &JModuleHelper::getModule('mod_fmDataGrid');
$Params = "param1=bruno\n\rparam2=chris"; //if you want to pass params
$Module->params = $Params;
echo $renderer->render($Module);

I would suggest you use "Modules Anywhere" from NoNumber:
http://extensions.joomla.org/extensions/core-enhancements/coding-a-scripts-integration/embed-a-include/6402
After you install this plugin you can add module positions directly in your browse page PHP using this example:
{modulepos mynewposition}
This is a must have plugin for all Joomla users, because you can use it throughout your site.

Related

add product to wishlist in magento API

I have checked in magento soap API but I can not find API for add product to wish list so I am developing own API but I don't know what is the problem with my code so please help me to find solution.
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
require_once '../app/Mage.php';
Mage::app();
$customer_id = $_GET['customer_id'];
$product_id = $_GET['product_id'];
$customer = Mage::getModel('customer/customer');
$wishlist = Mage::getModel('wishlist/wishlist');
$product = Mage::getModel('catalog/product');
$customer->load($customer_id);
$wishlist->loadByCustomer($customer_id);
$res = $wishlist->addNewItem($product->load($product_id));
if($res)
{
$status =1;
$message = "your product has been added in wishlist";
}
else
{
$status =0;
$message = "wrong data send";
}
$result = array("status" =>$status,"message"=>$message);
header('Content-type: application/json; charset=utf-8');
echo json_encode($result);
?>
There is a similar question you might want to check.
In your code you are not extending Magento API in any way but creating a standalone hackish script that inserts items to wishlist. I suggest that you take a look on how to develop a magento extension or if you need to create a backend (CLI) script, at least use the same structure as in shell/abstract.php and extend the shell base class - you will save yourself loads of headaches.
Moreover, your code is not secure, maintainable and removes all the benefits of using Magento as an ecommerce platform/framework (security, authorization & authentication etc)
Inchoo have quite some blog posts that could give you an idea where to begin
http://inchoo.net/magento/magento-api-v2/
http://inchoo.net/magento/extending-the-magento-api/
/* error_reporting(E_ALL);
ini_set("display_errors", 1);*/
You Have Comment This line And Write this
require_once './app/Mage.php';

Add SKU to end of Magento URL

I have searched for days trying to find a way of doing this but cannot find an answer, hopefully someone here can help me.
Essentially we want to insert the SKU into the product page url
Example
SKU = ST500DM002
So
domain.co.uk/seagate-barracuda-500gb-sata3.html
Would become
domain.co.uk/seagate-barracuda-500gb-sata3-ST500DM002.html
I had a look at this How to customize product URL?
It kind of works but it creates a path like this http://www.domain. co.uk/catalog/product/ST500DM002/seagate-barracuda-500gb-sata3.html rather than add it onto the end
Also we have a lot of SKUs with # in them which causes problems and throws 404
Is there a way to programmatically add the SKU and strip out #
Thanks
Copy the code and paste it to the file "script.php" and move it to magento root folder and try to run it in browser by using the following url,
http://localhost.com/script.php
<?php
require 'app/Mage.php';
Mage::app();
$amount = 0;
$model = Mage::getModel('catalog/product');
$products = $model->getCollection();
foreach ($products as $product) {
$model->load($product->getId());
$urlkey = $product->getUrlKey();
$sku = $product->getSku();
$product->setUrlKey($urlkey."/".$sku)->save();
set_time_limit();
$amount++;
}
When you run the file, All the urls will be rewritten with the new url keys.
You can find updated keys everywhere.
Create observer to catch event catalog_product_save_after_handler
$product = $observer->getProduct();
$urlkey = $product->getUrlKey();
$sku = $product->getSku();
if(substr($urlkey, strlen($sku) * (-1)) != $sku){
$product->setUrlKey($urlkey."/".$sku)->save();
}

Call function inside Joomla articles

I am facing a problem. I have created a article in Joomla administrator and i have created a function in a php file. I have to call that function in that article . I don't know how do i call function in article.
Here is the code:
class modVodesbalanceHelper {
function deductBalance()
{
$db = JFactory::getDBO();
$result = null;
$user = JFactory::getUser();
if ($user->guest) {
return false;
}
$query = 'SELECT credit' .
' FROM #__vodes_credits' .
' WHERE userid = ' . (int) $user->id
;
$db->setQuery($query);
$result = $db->loadResult();
$result_final=$result-10;
$query = 'update #__vodes_credits SET credit='.$result_final.
' WHERE userid = ' . (int) $user->id
;
//echo $query;
$db->setQuery($query);
$result = $db->loadResult();
}
}
In admin panel, in article i have write this code:
<script>
window.onload=function()
{
var a=confirm("do you want to purchase this credit");
if(a)
{
document.location.href ="index.php?option=com_content&view=featured";
}
else
{
document.location.href="index.php?option=com_content&view=article&id=3";
}
}
</script>
I have to call deductBalance when user click on the "OK" of comfirm box.
Please tell me to sought it .
You can't add PHP to Joomla article by default. For this you need to use a 3rd party plugin. Personally, I would recommend using Sourcerer. Once installed and enabled, you can use the following in your article:
{source}
<?php
// All your PHP code
?>
{/source}
Don't include PHP files inside your article
I would use Sourcerer to add php code inside joomla article.
Check the sourcerer plugin to be enabled (check plugin enabled status here: extensions->plugin manager->sourcerer).
Then, use the "Insert Code" button at the bottom of your WYSIWYG editor when adding your PHP scripts. Your code should be wrapped with
{source}
//php code wrapped by <?php ?>
{/source}
If you need to use code directly within Joomla article then use Sourcerer as in above questions. If you feel to keep the PHP code in seperate module. Use Blank Module
Or mod_php module. Then in your Joomla Article you can place the code like this,
{loadposition}*Your Custom Module Position*{/loadposition}

Displaying list of logged in users in Front side using Joomla 2.5 component

I would like to display all login user list in Front side using Joomla 2.5 component.
Can any body tell me how do do this?
I would also want to develop change password and news subscription module.
Try this,
$db =JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('*')
->from('#__users');
$db->setQuery($query);
$rows = $db->loadObjectList();
foreach ($rows as $row) {
$user = JFactory::getUser($row->id);
$status = $user->guest;
if(!$status){
echo $row->name.'---Email'.$row->email;
}
}
Use this extension to implement its in your site if you need quick solution.
Hope it helps..

Code to display articles from category ID?

What would be the code to display articles from category (specified by ID)?
In Wordpress this is fairly easy by doing:
<?php
query_posts('cat=1');
while (have_posts()) : the_post();
the_title();
endwhile;
?>
I'm looking for similar code for Joomla.
$db = JFactory::getDbo();
$id = 50;//example
$query = $db->getQuery(true);
$query->select('*');
$query->from('#__content');
$query->where('catid="'.$id.'"');
$db->setQuery((string)$query);
$res = $db->loadObjectList();
foreach($res as $r){
echo '<h3>'.$r->title.'</h3>';
echo $r->introtext;
}
You can use next code template:
$categoryId = $[category id];
require_once("components/com_content/models/category.php");
$category = new ContentModelCategory();
$category->hit($categoryId);
$articles = $category->getItems();
print_r($articles);
There is no direct code for getting this in joomla like word press.
If you want to check the code you can check the code for achieving this by following path.
components/com_content/view/category/view.html.php
and
components/com_content/view/category/tmpl/blog.php
According to my Guess your requirement is to display the articles from same category.
then in joomla you dont need to edit in any code.
for achieving this you can simply create a menu.
and menu layout type should be category blog and Choose your category from the right side category options.
This will get the complete article from that category.
If you want to manage it in your style you can add style based on blog.php file .
Hope this will help you..
Try this:
$articles = JFactory::getDBO()->setQuery("SELECT * FROM #__content WHERE catid = '21'")->loadObjectList();
Of course replace '21' with id of your category.
This is quite easy in Joomla. You can find the code in /components/com_content/models/category.php under getItems()
Below is an example
$model = JModelLegacy::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
$model->setState('params', JFactory::getApplication()->getParams());
$model->setState('filter.category_id', $category_id);
$articles = $model->getItems();

Resources