从Magento中的自定义PHP脚本访问产品和类别信息
问题描述:
What I'm trying to do is gain access to all of my product and category information in a particular store from a custom PHP script in Magento. I have already included Mage.php, and can access the store info, but I'm not sure how to proceed from here
<?php
include '../../../../app/Mage.php';
$allStores = Mage::app()->getStore(6);
var_dump($allStores);
?>
This gives me access to the store information, but if i try to call ->getProduct() it throws an error
答
You are most likely looking for a product collection, which is a Magento data structure that contains a grouping of products:
$collection = Mage::getModel('catalog/product')->getCollection();
$collection->addAttributeToSelect('*');
$collection->addStoreFilter(8);
foreach ($collection as $product) {
Zend_Debug::dump($product->getData());
}
$categories = Mage::getModel('catalog/category')->getCollection();
foreach ($categories as $category) {
Zend_Debug::dump($category)
}
The product object in Magento is fairly complex, given Magento's EAV data structure.