Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options answers only not deleted user 217

Questions related to Magento collections

3 votes

How Do I Create a Derived Collection

To make it correct, you derive a custom collection from the standard one. … If models write to the database, they have a resource model and a collection class. this is defined via the <resourceModel> node. …
Fabian Blechschmidt's user avatar
4 votes

Subquery in a collection

Then you can get the select from the collection and put the one in the other. … $subquery = Mage::getSingleton('core/resource')->getConnection('core_write');->select() $collection->getSelect()->where("myAttribute = $subquery") // example more: https://stackoverflow.com/questions …
Fabian Blechschmidt's user avatar
1 vote

magento setpage show first page even if the page doesn't exist

->addUrlRewrite($subcategory->getId()) This loads the collection, everything after this doesn't do anything about the sql query. …
Fabian Blechschmidt's user avatar
2 votes

How to sort special price collection

Works $collection = Mage::getResourceModel('catalog/product_collection'); Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection); Mage::getSingleton('catalog … /product_visibility')->addVisibleInCatalogFilterToCollection($collection); $collection->addMinimalPrice() ->addFinalPrice() ->addTaxPercents() ->addAttributeToSelect(Mage:: …
Fabian Blechschmidt's user avatar
2 votes

Get Next and Previous item from a collection

Collection itself As Minesh pointed out indirectly: There is no way using the API of the colletion directly. … The problem is, that magento only implements IteratorAggregate, so the Collection itself doesn't offer what you want. …
Fabian Blechschmidt's user avatar
6 votes
Accepted

Getting Customer Collection

And group name, like this: $collection->joinTable('customer/customer_group', 'customer_group_id=group_id', array('customer_group_code'), null, 'left'); Didn't tested it ;-) It is important to set as …
Fabian Blechschmidt's user avatar
4 votes

Magento Error: Item (Mage_Sales_Model_Order) with the same id "1457" already exist

After loading, all the items are added to the collection, if an order id is already set, this error is thrown. What do you want to achieve? …
Fabian Blechschmidt's user avatar
8 votes
Accepted

Reload collection after count()

count() loads the collection, therefore it doesn't matter to reload it. … /lib/Varien/Data/Collection/Db.php:208 /** * Get collection size * * @return int */ public function getSize() { if (is_null($this->_totalRecords)) { $sql = $this->getSelectCountSql(); …
Fabian Blechschmidt's user avatar
10 votes
Accepted

Filter product collection by custom attribute

/app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php:339 /** * Wrapper for compatibility with Varien_Data_Collection_Db * * @param mixed $attribute * @param mixed $condition */ public function … Load the collection and then check echo (string)$collection->getSelect(). After(!) the ->load(). …
Fabian Blechschmidt's user avatar
1 vote
Accepted

Weird issue using addFieldToFilter via a helper method

Because count() calls $collection->count() which does: \Varien_Data_Collection::count public function count() { $this->load(); return count($this->_items); } and after the collection is loaded … So remove the if(count($collection) > 0) and everything is fine :-) Or instead use getSize() which does not load the collection: \Varien_Data_Collection_Db::getSize public function getSize() { if …
Fabian Blechschmidt's user avatar
2 votes

Magento DB Collection generate error on UNION

Did you try: $select = $collection1->getSelect()->union($collection2->getSelect());
Fabian Blechschmidt's user avatar
5 votes

Check which filters have been applied to a collection

You can change the collection to use the protected $_filters = array(); property instead of applying the filters directly, then you can just get the filter, if you have access to this property. …
Fabian Blechschmidt's user avatar
1 vote

Simple query: group by customer & specific product attribute (shirt size) but how?

You can use $collection->getTable('catalog/product') to get a table name, including prefix and everything The information which size the customer chose is encoded in product_options and there is no easy …
Fabian Blechschmidt's user avatar
0 votes

Array of product ids for a given category (ignoring is_anchor)

I think the only alternative is to join catalog_category_product into the product collection
Fabian Blechschmidt's user avatar
14 votes

Difference between getSize() and count() on collection

Both methods load the collection and count the items. UPDATE Oh I see a problem: getSize() caches the _totalRecords, this means it is not recalculated. Check where _totalRecords is set? …
Fabian Blechschmidt's user avatar

15 30 50 per page