Questions tagged [collection]

Questions related to Magento collections

Filter by
Sorted by
Tagged with
1
vote
1answer
993 views

Magento2 does n't get the order collection from Order\CollectionFactory

I am using the Magento2.2 version . I am using the class Magento\Sales\Model\ResourceModel\Order\CollectionFactory; to get the order collection.But getting the error Fatal error: Uncaught Error: ...
0
votes
0answers
6 views

Magento 2 | Enable filters on collection factory programmatically

In my phtml file that I recalled in a cms page I took the entire collection of products, filtered it and finally recalled it. Everything works fine but I can't get the navigation filters like they are ...
0
votes
0answers
10 views

Magento 2 | Add Filters of Layered Navigation to custom collection

I asked this question because I would like to explain myself better. In my CMS page I have recalled my custom collection in this way: $blockProductColl = $block->getLayout()->createBlock(...
0
votes
0answers
14 views

Add default date from filter to UI Component grid in Magento 2

I have a custom grid created in the backend for a Magento 2.4.1 instance. Everything is working properly (filters, sorting, etc.), but I have one more request that seems to be more complicated. I have ...
2
votes
1answer
27 views

Custom Sorting on category page not working in Magento 2.4.2

I have Magento 2.4.2. I have written a custom code to add A-Z & Z-A filters on category page. I have added dependency injection using below code <preference for="Magento\Catalog\Block\...
83
votes
6answers
82k views

Difference between getSize() and count() on collection

I have heard many times that they both are the same. But I am facing a weird issue, in the product collection of CatalogSearch module, count() is returning correct product count while getSize() is ...
0
votes
1answer
1k views

Get product collection based on entity_id in magento2

How to Create product collection with filter based on entity_id in Magento 2? I tried below: $model = $this->_objectManager->create('Vendor\MOdule\Model\Queue'); $ProductId = $this->...
3
votes
3answers
595 views

How to call save method in collection instance

I was appeared Magento 2 Associate developer certification exam, in that I got the below tricky question, but I don't know the concept and answer of the question. can you have an idea regarding the ...
1
vote
2answers
2k views

Custom column in Magento 1.9 admin grid

I am creating a custom grid in an admin module. This grid represents a table almost column for column, however, I want to add a completely custom column with a bit of logic to this column. Here's my (...
0
votes
0answers
27 views

Magento 2 override resource model collection not working

I want to override Magento Reports module and it's not working. here's my code : di.xml <preference for="Magento\Reports\Model\ResourceModel\Report\Collection" type="SZK\Shamsi\Model\...
0
votes
0answers
32 views

Filtering product collection by custom attribute by overriding $layer->getProductCollection();

I created a module and a new block so that I can overwrite \Magento\Catalog\Block\Product\ListProduct. My catalog consists of configurable products, and I need to filter based on attributes assigned ...
1
vote
1answer
972 views

How to get all products collection for special category

I am looking for function which is similar to getLoadedProductCollection and which retrieves all products from this category with selected filters, not only those I can see on current page like ...
0
votes
0answers
22 views

How to get the updated customer record in magento 2

I am trying to fetch the customer record which is updated. Customer update implies both customer entity as well as customer's address. I am relying on the updated_at column which technically says that ...
4
votes
1answer
1k views

How set order with custom field column magento 2

I want to setOrder with custom field column in get list product. I override toolbar.php but it's not working di.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-...
0
votes
2answers
2k views

How to write inner join query in collection method (magento2)?

How to write this query in magento2 collection method? SELECT o.increment_id , h.status, h.created_at FROM sales_order AS o INNER JOIN sales_order_status_history AS h ON h.parent_id = o.entity_id ...
0
votes
1answer
14 views

Collection DataProvider - Strange behavior

I've been killing for hours and no result. I don't understand this strange behavior, can anyone please explain this to me? It's unbelievable ... Thanks for All!!! $this->collection = $Collection; $...
0
votes
1answer
981 views

how to store custom collection in cache in admin grid?

My collection model is testimonial/record. In database table(testimonial_record) 2,00,000 records so it loads more how to decrease time to fetch collection data in grid.So I think I have to store ...
0
votes
0answers
17 views

Magento 2 - Pagination not refresh cache

I'm on the category page. When I click on the pagination number, for example the number 2 with the link "www.magento2.com/category?p=2", I see that when clicked the page is never completely ...
1
vote
1answer
1k 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\...
0
votes
1answer
36 views

Get the average price for product collection

If there's a way in Magento 2 to get the average price for a product collection. Or should I loop over the collection? Thanks
0
votes
3answers
2k views

Call to undefined method addFieldToFilter() in magento 2

I have a model,resource model,collection file shown below. app/code/Magge/Custom/Model/Categrory.php namespace Magge\Custom\Model; use Magento\Framework\Model\AbstractModel; class Categrory ...
0
votes
2answers
151 views

Magento 2.4.1 Layered navigation with custom product collection

I want to override category product collection on the category product page in front-end. I want to show collection according to attribute set. After customize collection layered navigation product ...
0
votes
1answer
1k views

process collection after load collection

$categoryid = 43; $layer = Mage::getModel("catalog/layer"); $category = Mage::getModel("catalog/category")->load($categoryid); $layer->setCurrentCategory($category); $attributes = $layer ...
17
votes
1answer
25k views

how to add pagination on custom collection in Magento 2

I am working on custom module. How can i use default magento pagination with my custom collection and also set custom limits on that?
6
votes
4answers
2k views

Magento 2 get out of stock products in collection

I am trying to get all the products from the collection(both in stock and out of stock) but with no luck at all. The setting on admin needs to hide the out of stock products from frontend but I want ...
1
vote
1answer
2k views

Magento-2 How to get custom product collection in catalog search result based on particular category

I am working on custom module for catalog access. It requires only logged in customer to access the assigned category products. Right now in catalog search result, product collection displays all the ...
6
votes
2answers
3k views

How can Set filter collection in custom model by product id magento 2

I want to filter collection in my custom model by product id to load the filter data value in admin grid. My Model:- Vender\Modulename\Model\Outofstock namespace Vender\Modulename\Model; class ...
0
votes
1answer
1k views

Getting Notice Notice: Use of undefined constant sales_flat_order_status_history - assumed 'sales_flat_order_status_history'

I have created below collection query in my custom external magento page-- <?php $mageFilename = 'app/Mage.php'; require_once $mageFilename; Mage::setIsDeveloperMode(true); ini_set("...
2
votes
3answers
3k views

Hide out of stock products

I want to hide out of stock products from showing in search or category pages and I do not want to use the built in feature: Admin >> System >> Configuration >> Catalog >> ...
0
votes
1answer
38 views

How can I insert multiple row at once without for loop using collection in Magento 2?

I want insert multiple record without for loop in Magento 2 my data is as follow, Array ( [0] => Array ( [path] => whatsapp_contact/whatsapp_contact_button_settings/...
1
vote
2answers
432 views

Magento 2 - Collection getSize() returns zero

I have read about the difference between collection count() and collection getSize(), but I don't understand what's the reason that gives different numbers in each method. In a custom collection I ...
2
votes
3answers
4k views

How to delete object from collection in magento2

How to remove any object from magento 2 collection. If we have collection of products and we want to delete product which is at first index . how to delete that product without deleting it from ...
0
votes
2answers
26 views

Memory exhaust when using custom module collection

I'm trying to create a custom module with the usual model, resourcemodel and collection. My problem is that whenever I try to use the collection, magento runs out of memory. The collection only has ...
0
votes
1answer
1k views

Magento 2 get custom module data in theme phtml

I have created the custom module and inserted all the required fields detail in the database. Now, I want to list all rows in below file path: I have tried with the $objectManager, but direct call $...
3
votes
2answers
4k 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 <...
0
votes
1answer
2k views

Magento 2 - how to use count and group by clause in collection

i have order collection and want to this query result like `SELECT `created_at`,COUNT(`entity_id`) FROM `sales_order_item` GROUP BY `created_at`; i use this query `$selectCollection=$this->...
0
votes
0answers
35 views

Collection getSize() returns weird data [duplicate]

Well, here is getSize() definition inside AbstractDb class public function getSize() { if ($this->_totalRecords === null) { $sql = $this->getSelectCountSql(); ...
2
votes
2answers
4k views

How to use addFieldToFilter & addFieldToSelect in magento2

I need to known how to use addFieldToFilter & addFieldToSelect in frontend? And can I use like below $searchQuery = $wholeData["searchQuery"] ?? ""; $searchQuery = trim($...
5
votes
1answer
2k views

Grid pagination does not work in magento

Pagination is not working in my grid. All records are being shown on same page. All though Pagination is being shown at the top but all pages shows same records. Here is the code-- protected ...
1
vote
1answer
2k views

Magento 2.2 : Search Functionality/Layered Navigation on a Custom Product Collection?

I use a custom product collection which is used on all category view pages (basically, instead of using Magento's collection, I wrote my own module with the custom collection to implement a cookie-...
0
votes
1answer
27 views

Magento 2 | Exclude duplicate Item ID from a collection before foreach

When I foreach my collection filtered by tier price, qty and customer group I get the error: "Item (Magento \ Catalog \ Model \ Product \ Interceptor) with the same ID already exists". This ...
0
votes
1answer
28 views

Magento 2 | Item with the same ID already exists when join tables

In my class I have filtered my collection by tier price and quantity. If I put the display of only 3 products the code works, while if I set the display for all products I get this problem: Item (...
0
votes
1answer
21 views

Magento 2 | Join table catalog_product_entity_tier_price to collection

I'm trying to filter my product collection by tier price. I currently have this code but it doesn't work and it returns error: protected $_productCollectionFactory; public function ...
1
vote
4answers
6k 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\...
1
vote
2answers
6k views

how to get block data on phtml template in magento 2

what is missing in my code block data not shown in phtml template block page namespace xxxx\Trails\Block; use \Magento\Framework\View\Element\Template; use \Magento\Framework\View\Element\...
0
votes
1answer
21 views

SQL Syntax error when getting collection on listing

I've created my own module for managing leaflets in home page and i wanted to have a listing with existing leaflets. I've created UI_Component for listing (by Magicento) but when I go to listing page ...
0
votes
5answers
9k views

Magento2: Get category product count which is show in admin after the category name

I want to show category product count which is shown in admin after the category name. As of now I write this code but it's not working properly. $category->getProductCollection()->count(); ...
9
votes
5answers
5k views

How to get product collection of out of stock items - opposite of addInStockFilterToCollection()?

I have a requirement to display a category's products in two lists - one for in stock items, the other for out of stock items. I'm using Mage::getSingleton('cataloginventory/stock')->...
3
votes
4answers
23k 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()->...
0
votes
1answer
28 views

Get specific columns from Left Join

I am trying to join two tables like below $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $collection = $objectManager->get('Advance\Module\Model\Method') ->...

1
2 3 4 5
33