Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Basics: Getting catalog data
 
MuschPusch
Member
 
Total Posts:  44
Joined:  2008-04-24
 

Hi,

i’m using a code snippet from “php|architect’s Guide to Programming with Magento” to get all products of a category.

<?PHP

require_once 'magento/app/Mage.php';
umask(0);
//not Mage::run();
Mage::app('default');

//code snipped
$className Mage::getConfig()
->
getBlockClassName('catalog/product_list');
$block = new $className();
$className Mage::getConfig()
->
getBlockClassName('core/template');
$toolbar = new $className();
$block->setChild('toolbar'$toolbar);
//choose whatever category ID you want


$block->setCategoryId(3);
$block->setTemplate('catalog/product/list_xml.phtml');
echo 
$block->renderView();

Now is it possible to access the products array in list_xml.phtml.

My questions
1. How can i access the attributes of an article? Attribute values doesn’t seem to be in the product array....
2. How can i access the categories? What do i need to do to use this functions?

/* Get the categories that are active for the store */
$_main_categories=$this->getStoreCategories();
$_current_category=$this->getCurrentCategory();

3. How can i access associated products?

$_associatedProducts $this->getAssociatedProducts()

Magento is great but the database model and mvc/ zend stuff is quite difficult in the beginning....

regards Volkan

 
Magento Community Magento Community
Magento Community
Magento Community
 
MuschPusch
Member
 
Total Posts:  44
Joined:  2008-04-24
 

add to 1.)
I found some code getting the attributes of a product but my main problem is that i don’t understand how to load the classes to use the functions.

attribute loop:

$attributes $product->getAttributes();
foreach (
$attributes as $attribute{
if ($attribute->getIsVisibleOnFront()
&& 
$attribute->getIsUserDefined()) {
$value 
$attribute->getFrontend()->getValue($product);
if (
strlen($value) && $product->hasData(
$attribute->getAttributeCode())) {
$data[$attribute
->getAttributeCode()= array(
’label’ => $attribute->getFrontend()->getLabel(),
’value’ => $value
)
);
}
}
}

4. Can someone explain me the difference between getModel(’catalog/product’) and $className = Mage::getConfig()
->getBlockClassName(’catalog/product_list’);

I need to get this running as soon as possible and would be really thankful for some help

regards Volkan

 
Magento Community Magento Community
Magento Community
Magento Community
 
Webkrebse
Member
 
Avatar
Total Posts:  40
Joined:  2009-02-15
Germany
 

That’s how I got the categoryId of a product within the product view:

$_product        $this->getProduct();
$_categories    $_product->getCategoryIds();
$_categoryId    $_categories[0];

With kind regards,
Dorothea

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top