If you want to filter a product collection by categories as well, the following code may help. Once the category filter is applied, the collection contains only products from the specified categories, in this example category IDs 123 and 456.…
Setting the size of a collection programmatically (Magento 1)
Use this code to set the page size of a Magento collection programmatically:
|
1 |
$orders = Mage::getResourceModel('sales/order_collection')->setPageSize(100); |
Loading a model without using IDs (Magento 1)
Sometimes there is no id available for loading a model. If thats the case, the following code might help out. It loads a collection by an attribute like name or sku.
|
1 |
$collectionData = Mage::getModel('modelname')->getCollection()->addFieldToFilter('attribute', 'attribute value'); |
Afterwards, it is possible to iterate over the…
Getting the SQL of a collection (Magento 1)
Use the following code to get the underlying SQL of a Magento collection:
|
1 |
$sql = (string)$collection->getSelect(); |
Getting the SQL query of a collection (Magento 1)
This short piece of code returns the SQL query behind a Magento collection.
|
1 |
$select = $collection->getSelect()->__toString(); |