0

I'm trying to limit order for admin users by category, I can find the collection of product id by category and collect sales/order but how can I use this with an event observer?

$category_id = 44;
$category = Mage::getModel("catalog/category")->load($category_id);
$products = Mage::getModel("catalog/product")->getCollection()
  ->addCategoryFilter($category);

Next I collect just the product ids so I can use them:

$product_ids = array();
foreach ($products as $product)
  $product_ids[] = $product->getId();

$items = Mage::getModel("sales/order_item")->getCollection()
  ->addFieldToFilter("product_id", array("in" => $product_ids));

1 Answers1

1

You can use SetPageSize and SetCurPage for that

$col = Mage::getModel('YOUR MODEL') ->getCollection() ->setPageSize(17) ->setCurPage(1);

HTH

MageZeus
  • 184
  • 1
  • 6
  • @RatneshKumar: For me, it also works with the sales/order_item Model: $salesItems = Mage::getModel('sales/order_item')->getCollection() ->setPageSize(17); – MageZeus Apr 09 '16 at 14:24
  • yes it is that was my bad, actually when i iterate the collection it iterates through all the items in it. can you tell me why? – Mojo Jojo Apr 10 '16 at 18:24
  • The error must be on your side, I iterate through it and I only get the 17 items...can you show me some code? – MageZeus Apr 11 '16 at 13:36