Questions tagged [collection]

Questions related to Magento collections

Filter by
Sorted by
Tagged with
4
votes
3answers
9k views

How to get last created product id?

I have overridden the Mage_ImportExport_Model_Import_Entity_Abstract class and in the function _saveValidatedBunches() I want to get the last created product Id. I've tried the following, but it ...
4
votes
2answers
399 views

Where is setDoNotUseCategoryId() declared and what does it mean?

While getting related products, cross sells and upsells and collections, the function setDoNotUseCategoryId() is used. Where is it declared and can you explain the usage? foreach ($this->...
4
votes
2answers
4k views

How to get disable product collection whenever flat enable at frontend

In my system flat setting has been enable for products and as per as magento system magento exclude disable products from product collection whenever flat table is creating. That why we can not get ...
4
votes
3answers
3k views

How to join a calculated column from a table to collection

I have a table name stat_customer look like this: I want to add a column page_view to customer collection to show at grid page. page_view is total page view of product page for each customer. My SQL ...
4
votes
3answers
7k views

How to Get Distinct Entries from Joined Tables Through Join()

This doubt aroused when I am answering one of the question that posted here. But this question is not a continuation of that question, rather a general doubt. Basically I need to get log-customer ...
4
votes
3answers
6k views

How to get visitor log (customer) collection

I'm looking to load the log/customer collection and am running into some issues. When using Mage::getModel('log/customer')->load(1); the appropriate data is returned but if I try to load the ...
4
votes
2answers
3k views

Joining to a Resource Model that doesn't have a Select?

So I have this resource model that I pulled from some admin code on the dashboard. It works, but I can't seem to join to it. Doing ->getSelect()->__toString(); shows nothing? So is this not a ...
4
votes
2answers
8k views

Filter Category Collection by Enabled, Visible Products

I want a list of category IDs, which have products that have... visibility: Catalog or Catalog and Search status: enabled (for the given store) I can't find a built-in way to do this that is fast. ...
4
votes
3answers
10k views

how can we get category by name and parant category id?

How can I check category have any child category with specific name ? $category = Mage::getModel('catalog/category')->load($name, 'name'); but I want sub category from specific parent category.
4
votes
3answers
5k views

How to update category page with custom filters, and also layered navigation, Magento 2.1

I need to update category page collection by filtering restricted SKUs. As like $collection->getSelect()->where("`e`.`sku` IN('24-MB04', '24-MB03', '24-MB02')"); Above query gives collection ...
4
votes
1answer
765 views

How to properly use getCollectionMock

TL;DR: I would love an example of how Magento\Framework\TestFramework\Unit\Helper\ObjectManager::getCollectionMock() can be used for unit tests that involve collections and/or collection factories and ...
4
votes
4answers
8k views

How to call category collection on home page in magento 2?

I want to show all the category on the left sidebar on home page. Please let me know how to get all the categories by collection, or there is another way to call all the category. please let me know
4
votes
2answers
13k views

Category collection: addAttributeToFilter on parents

I have a category structure like this with a total of around 5000 categories: A is_active=1 A1 is_active=1 A1-1 is_active=1 A1-2 is_active=1 A1-... A2 A3 B is_active=0 B1 is_active=1 B1-... ...
4
votes
3answers
3k views

Apply an extra filter in view

I am trying to add additional filters to a collection after the collection seems to of been generated. In catalogue product list.phtml there is the following line of code: $_productCollection = $this-...
4
votes
5answers
2k views

Magento 2 - Bestseller product collection

I am trying to get bestseller products on homepage using product collection in Magento 2. I only got Most Viewed product listing (?) and I am not getting bestseller products. Here is my code: $...
4
votes
3answers
1k views

What is faster - getting raw attribute value or use collection?

I need to load one attribute value(weight) for many product IDs. Say list of the product ids is in array $productIDs. In general case, which approach is faster, Loading raw attribute value for ...
4
votes
1answer
373 views

Exclude Category when showing product collection

I am showing Most popular products and I want to be able to exclude certain products from showing. I thought the best way would be to exclude a category and when I want to exclude a product I can put ...
4
votes
2answers
11k views

how to filter product collection by category?

My products are in multiple categories. As such, using ->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left') returns ...
4
votes
2answers
2k views

Add all flat-attributes to product collection?

How can I get a catalog/product collection with all attributes which are selected to be "used in product listing", i.e. are in the flat table?
4
votes
2answers
1k views

How to get list of all users?

As in title, how can I get a list of all users in Magento ? Found already some examples but none of those works. All I managed to get was either only one user (myself) or nothing while I was expecting ...
4
votes
1answer
2k views

Load additional product attributes in Wishlist

I want to show some additional product attributes in the wishlist template, but they are not loaded. On the category page it is working, so it is not an index problem. When I call $item->...
4
votes
2answers
3k views

Load visible and invisible products at once?

This is my code: $visibility = array( Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH, Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG, ...
4
votes
2answers
3k views

Magento aggregate collections?

I need to get customer life time sales data. Both Qty and Amount. I have tried below Mysql Query it's worked fine. How can i change this Mysql query in Magento collection format. Because this data ...
4
votes
1answer
3k views

Getting Customer Collection

How do I add company and group name to this collection $collection = Mage::getResourceModel('customer/customer_collection') ->addAttributeToSelect('*') ...
4
votes
2answers
10k views

Product Attributes and filtering mechanics

TL;DR: How to filter multiple select/dropdown attributes (multi-selects would be cumbersome)? Or use a different method? Consider a product select/dropdown attribute whose values correspond to each ...
4
votes
2answers
6k views

Magento 2: What is a Resource Model and how can I use it?

In Magento 1, using a resource model we are getting collections of data: $products = Mage::getResourceModel('catalog/product_collection'); $category = Mage::getResourceModel('catalog/...
4
votes
2answers
4k views

Why is setPageSize() and setCurPag‌​e( ) functions not working with the collection created with \Magento\Framework\Data\CollectionFactory?

This is my block file, everything is working fine except setPageSize() and setCurPage() functions at last. Regardless of these two filters it is allowing all the rows to be fetched. What could be the ...
4
votes
2answers
942 views

Magento 2 and filtered collections

I have a collection of users and I want to create a backend grid to show only some user depending on a filter. For example I want to show all the users in my table whith age greater than 18. I ...
4
votes
2answers
377 views

Saving category from collection resets include_in_menu

Sometimes it is convenient to save a category directly from the collection it was loaded. For instance, for all categories of which the name attribute starts with foo, I want to update the meta_title ...
4
votes
1answer
2k views

Magento2 - How to filter product collection on category view

I'm trying to add filters to a product collection on the category page. I wanted to create an observer that listens to catalog_product_collection_load_before, but I found out that the even is not ...
4
votes
2answers
3k views

How to get configurable attribute label and value in magento 2?

To use Object Manager is not a proper way but this code is for testing purpose only. I want to get attribute value which is available in configurable products. I have tried with below code, but I get ...
4
votes
4answers
6k views

Get quote item collection by using quote item id in Magento 2

I get the quote_item_id like this: $orderItems = $order->getAllItems(); foreach($orderItems as $orderItem){ $qouteItemId = $orderItem->getQuoteItemId(); } I need to load quote item ...
4
votes
1answer
983 views

_afterLoad() on models when loading collection

I've defined some logic in the _afterLoad() for one of my models. When loading one model using Mage::getModel('foo/bar)->load(1) _afterLoad() is triggered and the extra data values are set. When ...
4
votes
1answer
7k views

Magento 2 module Object DOMDocument should be created?

I am working on Magento 2.0.4 . I need to get collection of my custom table. For this I created the function getAreaCollection() in my block file but I got following error when I add constructor in ...
4
votes
1answer
8k views

Add filter to getLoadedProductCollection()

In my magento store (ce-1.9.0) I have setup a custom product attribute: custom_depth_check And the attribute has the setting of Used in Product Listing : Yes Used for Sorting in Product Listing : ...
4
votes
3answers
11k views

Get Products list with all product attributes in Magento

I have a statement $collection = Mage::getResourceModel('catalog/product_collection'); in file app/code/core/Mage/Catalog/Block/Product/New.php in protected function _getProductCollection(). It ...
4
votes
1answer
3k views

How to join a collection with a query

I have a table represented in backend with two rendered fields, but when I try to make a CSV export from this grid, those two fields are not included. So I tried to make a join from the initial ...
4
votes
2answers
2k views

How to addFieldToFilter for attribute special_price with flat product tables?

In a class which extends Mage_Catalog_Model_Layer I have the following code: $collection = Mage::getModel('catalog/category') ->load($rootCategoryId) ->getProductCollection() ->...
4
votes
1answer
5k views

How do I get a collection of attribute values and products that use them?

I would like to run a report of attribute values used by a drop-down select attribute, e.g. colour, and the quantity of products that actually use them. I can get the list of actually used attributes ...
4
votes
2answers
467 views

Call to Magento load() to load a model is slow the first time, fast in subsequent calls?

We have a program where we are trying to import Customers and Orders using php into Magento from a non-Magento system via csv files. In a loop we call this function to get a customer model of ...
4
votes
1answer
572 views

Is there any way to get where condition from the collection?

I want to get the where condition from a collection.I'm using it in my sales order grid. $collection = $this->getCollection(); echo $this->getCollection()->getSelect(); When i apply ...
4
votes
1answer
530 views

When setting a product attribute programmatically, can't retrieve it from a collection

I've got a simple varchar product attribute, let's call it "badge". If I set values for it programmatically for a set of products like this: Mage::getModel('catalog/product_action') ->...
4
votes
1answer
577 views

Collection with custom data not filtering

Hi guys i have a collection in which i add custom data to. I am then trying to filter the collection by one of the original fields but it doesn't seem to work. Here is my collection building code: $...
4
votes
1answer
775 views

Zend > DB > Query > quote column

I've got a query which returns the orders by considering a condition on the column "maxvalue": Mage::getModel('sales/order')->getCollection()->addFieldToFilter('maxvalue', 'bla') It generates ...
4
votes
1answer
2k views

How to set filter_index for a column which is not in the database table?

My code is as follows. Everything works fine except the filteration of new column which shows abandoned cart item names comma separately. I have overridden the block ...