Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
6 votes
1 answer
2k 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 ...
Marius's user avatar
  • 199k
9 votes
2 answers
13k views

Magento 2: Walk through collection and delete

I was wondering if there was a way of walking through a collection on Magento 2 and deleting entries from the database. In Magento 1, this could be done by doing something like the following: Mage::...
Richard Cripps's user avatar
5 votes
1 answer
4k views

Magento Case Sensitive addFieldToFilter search result

How to get case sensitive search result using addFieldToFilter() of collection object in magento. I want to get search result based on case sensitive search results. Like ABCDE12 is not equal to ...
Rakesh Jesadiya's user avatar
0 votes
1 answer
737 views

Large Collection Exhausting Memory

I am writing an admin module. I created a collection and if the number of rows in the table are small it loads fine. Ultimately the table will have 250k rows in it and when I attempt to load the ...
Michael Sole's user avatar
6 votes
4 answers
11k views

Magento 2: how to use the collection walk iterator?

Back in Magento 1, it was possible to use the collection iterator to walk through the results and avoid looping through them. It was a huge improvement in terms of performance when dealing with ...
Raphael at Digital Pianism's user avatar
3 votes
1 answer
4k views

Custom Sort order for magento product collection (Sort collection by an array values)

I have product collection as below, Array ( [0] => Array ( [entity_id] => 1995 [type_id] => configurable [sku] => WSH06 [has_options] => 1 ...
Narayan S's user avatar
  • 594
1 vote
4 answers
8k views

Magento 2: How to set visibility and status to product using collection?

I'm creating a cron to pass through all the products and set them visible and active. This is my execute of the cron who runs well: public function execute(){ /** * @var $item \Magento\...
ntzz's user avatar
  • 534
1 vote
1 answer
257 views

contain text in collection - Magento2

I am trying to filter the collection based on contain string It is working $collection = $this->_chennaidbFactory->create()->getCollection() ->addFilter('event_date',['like'=&...
Bilal Usean's user avatar
  • 10.1k
2 votes
1 answer
1k views

Mysql query to Model, Resource Model, Collection - Magento 2

I can easily get or set value using ORM. I felt difficult to convert mysql query logic to Model, Resource Model, Collection(ORM). for example I am getting last one hour data using the below query ...
Bilal Usean's user avatar
  • 10.1k
2 votes
2 answers
5k views

Magento 2 - Check if category exists or not

I need to check if category exist or not by category name. I have try this with category name test but it does not work at the same time it does not throw any error $category = $this->...
Bilal Usean's user avatar
  • 10.1k
6 votes
6 answers
35k views

How to use getFirstItem() in collection into magento 2

How to get first item of collection in magento 2 I am trying $infoColl = $this->_customFactory->create()->getCollection(); $infoColl->addFieldToFilter('session_id', $id); $...
Newbie's user avatar
  • 1,614
3 votes
2 answers
5k views

How to add collection filter to gridContainer in Magento 2?

I need to add a collection filter to my grid. I do few search on Internet but unfortunately it can't resolve my case. I'm using gridContainer instead of usual way. Here is my files: layout.xml <...
Toan Nguyen's user avatar
  • 3,069
4 votes
1 answer
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 ...
Neeraj Garg's user avatar
9 votes
1 answer
15k views

Magento 2 use group by in collection

I've got a collection from the factory method getCollection(). The problem is that when I use get_class_methods($class) to list all the methods that the collection possesses I can't seem to find one ...
Lachezar Raychev's user avatar
7 votes
4 answers
12k views

which are best method to get collection in magento 2

I am creating a custom module. which is preferred method to get collection. i need to know the advantage and disadvantage these method? objectManager $objectManager = \Magento\Framework\App\...
Qaisar Satti's user avatar
  • 32.5k
6 votes
2 answers
26k views

Magento 2: How to get product collection by category?

We are trying to get product collection by category id. Block: protected $_categoryFactory; public function __construct( \Magento\Backend\Block\Template\Context $context, \Magento\...
PolyakovAO's user avatar
1 vote
1 answer
2k views

Magento 2 custom module gives list page blank

I have custom module the news_index_index file is as bellow. <?xml version="1.0"?> <!-- /** * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ --&...
Denish Vachhani's user avatar
19 votes
3 answers
59k views

Magento2 Order by clause in collection

I have a custom collection to which I add filters. For example, I have this: $giftColletion = $this->_giftFactory->getCollection(); $giftColletion->addFieldToFilter('store_id', 1); What ...
Lachezar Raychev's user avatar
3 votes
4 answers
26k views

Get category collection from product ID

How can I get category collection data from product ID? I have tried using the following way but it's not working for me. $product = $this->_productFactory->create()->getCollection()->...
Pratik's user avatar
  • 3,805
10 votes
2 answers
11k views

Whats the best way to check if a custom attribute exists in Magento2

In being careful, I want to check if my custom attribute exists before I attempt to utilize it in any way. I need to check against all attributes collection, not just the product collection. My ...
CarComp's user avatar
  • 1,256
0 votes
1 answer
5k views

How to get orders collection in magento 2

Magento 2 get order collection to update customers id using csv. For example we can take magento 1 we can update using test.php file like that how we can update in magento 2. I am creating new ...
Pawankumar's user avatar
4 votes
1 answer
2k views

Magento 2 product repository

In Magento2, I understood we have to use repositories instead of collections. What I do not understand is how to add custom attributes to repository. If I do something like this: $searchCriteria ...
Phoenix128_RiccardoT's user avatar
4 votes
1 answer
2k views

Magento2 - addAttributeToFilter wrong pagination

I'm creating an extension that filters the product collection. The filter works perfect, but it looks like pagination is not updated. I see 6 pages, but on page 2 the page is already empty. Here's my ...
Silvan's user avatar
  • 1,357
3 votes
1 answer
7k views

Magento2 - Custom product attribute in product collection

I've created a new product attribute 'brand'. This attribute is within my default attribute set. Now I'm trying to get all brands from a product collection within a category. I'm fetching the product ...
Silvan's user avatar
  • 1,357
4 votes
1 answer
3k 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 ...
Silvan's user avatar
  • 1,357
1 vote
2 answers
3k views

How can I get custom module collection on form page magento 2

I want to set categories in dropdown field of form of subcategory module in magento2 . How can I get category collection on subcategory form page and set values in dropdown field. I am trying to do ...
Arun Pal's user avatar
  • 523
3 votes
1 answer
2k views

Why does the Product\Collection not respect the page-number and page-size attributes?

I'm trying to get a list of all the products in the store using the product-collections but it doesn't respect the page and page-size params. I'm using the sample data and have 174 products in my ...
Mridang Agarwalla's user avatar
3 votes
1 answer
2k views

Magento2 how to override collection

I want to build a grid that show information from "directory_country_region" table but show only for "country_id" with id = "TH". I'm using UI component & Magento\...
HungDQ's user avatar
  • 812
2 votes
4 answers
3k views

Magento 2: add fields to products collection

Ok so I'm trying to implement a simple export to CSV massaction on the Magento 2 Catalog products grid. I've successfully created the mass action item, as well as the admin controller. I am able to ...
Raphael at Digital Pianism's user avatar
0 votes
1 answer
1k views

Unrecognized method 'isLoaded()' in Magento 2

I'm trying to join product and my custom table but it's returning error Unrecognized method 'isLoaded()' my code is: /** * @param \Magento\Backend\Block\Template\Context $context * @param \...
Bojjaiah's user avatar
  • 3,782
2 votes
1 answer
3k views

Magento 2 Cms block collection

What code would be required to get a complete list of cms blocks in Magento 2. What I mean is block collection like in Magento 1 I would try to keep to repository interfaces like this following: $...
Marty Wallace's user avatar
14 votes
5 answers
25k views

To add default filter to grid in Magento2?

I have created one custom module with title & status field attribute in admin grid. Grid collections in module_test_grid_block.xml <arguments> <argument name="id" ...
DRAJI's user avatar
  • 855
2 votes
2 answers
2k views

How to implement custom collection properly in Magento2?

I am trying to inject a CollectionFactory object into a Plugin like this: /** * PopulateCustomerCards constructor. * @param CardCollectionFactory $cardCollectionFactory */ public function ...
awavi's user avatar
  • 989
6 votes
4 answers
44k views

Magento 2 Get product collection in a custom template block

I have defined a featured product template in a cms static page as below: {{block class="Magento\Catalog\Block\Product\ListProduct" template="Magento_Catalog::product/featured.phtml"}} Now I want to ...
Vicky Dev's user avatar
  • 1,992
1 vote
2 answers
3k views

Get all products that has special price and special price < price

I want to get all products that has special price and special price < price. Can anyone show me how can i achieve that ?
Huan Dao's user avatar
  • 607
12 votes
4 answers
38k views

Magento 2: How to Filter a Product Collection By Store ID

Using a product factory object, I'm able to create a product, grab a product collection, and fetch the first item of that collection /* var $productFactory \Magento\Catalog\Model\ProductFactory */ $...
Alana Storm's user avatar
  • 44.4k
0 votes
1 answer
462 views

Magento 2 - Calling the SearchCriteriaBuilder in a Collection gives an error

I am experimenting with Magento 2 and trying to add some filtering in my collection. Hence i am calling the SearchCriteriaBuilder in the constructor. namespace MyCode\MyBlog\Model\Resource\Post; use ...
Sakis's user avatar
  • 421
4 votes
4 answers
9k 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
sandeep sharma's user avatar
1 vote
1 answer
2k views

Magento 2 Get Attribute collection?

I have Custom category attribute id for ex 200. I want to get Attribute Option label from Value in magento 2 if any clue is also much appreciate.
Pratik's user avatar
  • 3,805
3 votes
1 answer
426 views

Magento2 PHPUnit internal method getCollectionMock. Bug or Feature?

When I was writing unit tests for one magento collection I faced with the following strange thing: Magento allows create mock for collection with it's internal phpunit method: \Magento\Framework\...
zhartaunik's user avatar
  • 3,846

1
7 8 9 10
11