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

Custom Order Grid
 
joey santiago
Sr. Member
 
Total Posts:  76
Joined:  2009-02-25
 

Hi everybody,

i am trying to get a custom order grid that should help me showing only some orders to a user, especially only the ones that have the products they are allowed to see.
Example:

i have 10 manufacturers. Each one of them can access, modify and create his own products. They should of course see only the orders that contain their products.

I modified /app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php in order to get the logged user role. I should then open all of the orders in my collection getting the ones in which i have the correct products…

how would i get this?

many thanks,

joey

 
Magento Community Magento Community
Magento Community
Magento Community
 
joey santiago
Sr. Member
 
Total Posts:  76
Joined:  2009-02-25
 

//Get logged in user
    $user Mage::getSingleton('admin/session')->getUser();
        
//Get the role id of the user
        
$roleId implode(''$user->getRoles());
        
        
//Get the role name
        
$roleName Mage::getModel('admin/roles')->load($roleId)->getRoleName();
        
        
//Check if the user is 'manufacturer'
        
if ($roleName == 'manufacturer'{
      
//Gets the manufacturers attribute
      
$productFake Mage::getModel('catalog/product');
      
$attributes Mage::getResourceModel('eav/entity_attribute_collection')
        ->
setEntityTypeFilter($productFake->getResource()->getTypeId())
        ->
addFieldToFilter('attribute_code''storeowner'// This can be changed to any attribute code
        
->load(false);
        
$attribute $attributes->getFirstItem()->setEntity($productFake->getResource());
        
/* @var $attribute Mage_Eav_Model_Entity_Attribute */
        
$owner $attribute->getSource()->getAllOptions(false);
        foreach (
$owner as $man{
          
if($user->getUsername()==$man['label']){
        $ownerAttVal 
$man['value'];
          

        } 
        
//print $user->getUsername();//['store_id'];
        //should open all of the orders and select the one with products of this
        //manufacturer
      
foreach($collection as $order){
          
//creare un oggetto ORDER per ogni ordine. Controllare il manufacturer di ogni
          //item contenuto in ORDER.
          
$productIds = array();
echo 
"Ordine N: ".$order->getId()." ";
          foreach (
$order->getAllItems() as $item{
            $productIds[] 
$item->getProductId();
          
}

        $productCollection 
Mage::getModel('catalog/product')->getCollection()
          ->
addIdFilter($productIds)
          ->
addAttributeToSelect('name')
          ->
addAttributeToSelect('storeowner')
          ->
load();
$prodInOrder 0;
        foreach (
$order->getAllItems() as $item{
$prodInOrder
++;
echo 
"prodInOrder: ".$prodInOrder." ";
            
$product $productCollection->getItemById($item->getProductId());
echo 
"prodId:".$product->getId()." ";
echo 
"prodName:".$product->getName()." ";
echo 
"prodOwner:".$product->getStoreowner()." ";
echo 
"userAttValue: ".$ownerAttVal." ";
          if(
$product->getStoreowner()==$ownerAttVal{
        
echo "il prodotto Ã¨ dell'utente, l'ordine va tenuto ";
//         $collection->addAttributeToSelect('entity_id');
        
$collection->addAttributeToFilter'entity_id', array('like'=>$order->getEntityId()));
          
}
        }
      
echo "<br />";    
      
}
    }
I almost did it… just some problems with $collection->addAttributeToFilter( ‘entity_id’, array(’like’=>$order->getEntityId())); ... it doesn’t work!!! Could anyone help me out?
thanks
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top