Reputation: 2129
I have a PHP website and now the I want to add a shopping cart to my existing php website. So I am using magento for this.
In the directory of my website I have created a new directory with the name of "shop" and put magento in this directory.
My website is working fine. But on website's home page I want to show categories and products from the magento site so it is not possible to use the magento built-in functions for this as my website's home page is out the magento site.
So I think I should query the magento database tables for this but the magento database tables are so complex so any body who can give me some idea about this problem?
Is there any other way to solve my problem and if the only the query is the solution then how will I query the magento database tables to show categories and products.
Thanks in advance.
Upvotes: 1
Views: 3934
Reputation: 10898
You need not to write complex queries to show some categories in homepage. But instead you can add the below in your homepage (Menu > CMS > Pages > Homepage)
{{block type="catalog/product_list" category_id="3" template="catalog/product/list.phtml"}}
where category_id is the id of the category to be shown. See screenshot to get cat id.
Upvotes: -1
Reputation: 1153
I would try something like this:
require 'shop/app/Mage.php';
/* Run magento app */
Mage::app();
function get_categories(){
$category = Mage::getModel(’catalog/category’);
$tree = $category->getTreeModel();
$tree->load();
$ids = $tree->getCollection()->getAllIds();
$arr = array();
if ($ids){
foreach ($ids as $id){
$cat = Mage::getModel(’catalog/category’);
$cat->load($id);
array_push($arr, $cat);
}
}
return $arr;
}
$categories = get_categories();
foreach($categories as $cat) {
echo "<br />Category: " . $cat->getName();
$collection = $cat->getProductCollection();
foreach ($collection as $item) {
$product = Mage::getModel("catalog/product")->load($item->getId());
echo "<br />Product: " . $product->getName();
}
}
Upvotes: 4