Magento Forum

Best Practice for a Product’s Category at Checkout
 
mc_jesse
Jr. Member
 
Avatar
Total Posts:  14
Joined:  2008-09-08
 

I’m wondering if there’s anything the community would consider as a best practice for pulling a single category to tie a product to at the time of checkout.  I’ve read the option here, but I didn’t really like the “unknown” option. Plus, in my initial testing, iterating over $product->getCategoryCollection() didn’t seem to work.

Just to be clear, here’s what I’m doing and where I’m hitting a wall:

* event observer on “sales_order_place_after”
* basically:

$event $observer->getEvent();
        
$order $event->getOrder();
        foreach (
$order->getAllItems() as $item){
              
//this
                
$category Mage::getModel('catalog/category')->load($product->getCategoryId());
                
$myitem['category_id'$product->getCategoryId();
                
$myitem['category_name'$category->getName();
              
//or this
                
$cats $product->getCategoryCollection();
                
$i 0;
                foreach(
$cats as $cat){
                    
if ($i==0){
                        $myitem[
'category_id'$cat->getId();
                    
}
                    $myitem[
'category_name'$cat->getName()."-".$myitem['category_name'];
                    
$i++;
                
}
        }

Really the only reasonable solutions I’ve thought up are either just picking the 1st category for a product or dropping category support for magento in in my system completely. The other option (that I really would rather stay away from) is building multiple category stuff into my system.

Anyone have thoughts on this situation?

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