Questions tagged [collection]

Questions related to Magento collections

Filter by
Sorted by
Tagged with
1
vote
0answers
15 views

Missing required argument $mainTable on Collection

I have a custom grid, where it gets some data from the shipment table. This is the error message received: Missing required argument $mainTable of Vendor\Module\Model\ResourceModel\Order\Shipment\...
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-...
1
vote
0answers
30 views

Filter Magento2 Fulltext\Collection by OR condition

How can i filter the Magento2 Fulltext\Collection (Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection) by an OR condition between 2 product attributes, with respecting also the ...
1
vote
1answer
930 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
5answers
1k views

How to limit the results from a Left Join in Magento?

I have a collection that I need to join with another collection... the problem is the table contains 125k rows and so it times out. //Fields $this->addFieldToSelect('id'); $...
1
vote
3answers
2k views

Magento 2 - Add Custom Attribute to Product Collection without Flat Catalog EAV?

I have the below collection: $this->_collection->getSelect() ->order(new \Zend_Db_Expr('price_index.min_price / IF(e.unit_of_sale = NULL, 1, e.unit_of_sale) DESC')); This ...
2
votes
4answers
2k 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 ...
0
votes
3answers
28 views

Magento 2 : Get Product Collection based on Attribute

I want to get product collection based on attribute. For ex : If "Size" attribute exist in "Bag","Bottom" attribute set then, All Product's of Bag and Bottom return in ...
1
vote
1answer
17 views

I am facing this error while fetching data to admin grid in Magento

I am facing this error while fetching data from custom table in Magento 2.3.5 the error is: Argument 1 passed to Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider::...
0
votes
1answer
21 views

How to join a custom table and show its attribute on Magento 2 rest Api getList() function?

Im creating a custom product Api with searchCriteria from \Magento\Catalog\Model\ResourceModel\Product\Collection And I joined other table to this collection; public function getList(\Magento\...
5
votes
3answers
5k 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 ...
10
votes
4answers
12k views

How to get product collections by set of ids in magento 2?

I wanna something like "IN CLAUSE" in MYSQL using by magento2 ORM, something like this: select * from product where id in (...) but by using collection in magento 2? for example something like this:...
1
vote
1answer
745 views

How to check the category collection is empty or not in magento 2?

I am getting the subcategories of a main category like this(this file is in root folder) use \Magento\Framework\App\Bootstrap; include('app/bootstrap.php'); $bootstrap = Bootstrap::create(BP, $...
0
votes
2answers
1k 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
1answer
20 views

convert sql query to magento addFieldToFilter combine OR and AND

You can convert me this sql I did not arrive at combined OR and AND at the same time SELECT * FROM sales_order AS main_table, sales_order_payment AS sop WHERE ((status = 'processing') Or ((status = '...
0
votes
1answer
998 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 ...
1
vote
1answer
33 views

Category CollectionFactory issue

Can anyone see what I am doing wrong here. It displays All categories instead of only showing the specific website/store categories. $collection = $this->_categoryCollectionFactory->create(); $...
1
vote
1answer
18 views

Magento 2 print phtml product collection

When I try to get product list in a controller for a ajax module like this : echo $this->layoutFactory->create() ->createBlock('\Magento\Catalog\Block\Product\ListProduct') ...
0
votes
1answer
16 views

Magento 2 Filter Orders Based On shipping Country

I want to Filter Orders based on Shipping country I have filtered using other attributes like grand_base_total and store_id but struck at shipping country as there is no any attribute for that in ...
16
votes
6answers
41k views

How to print collection mysql query in magento 2?

There is getSelect()->__toString(); is available in Magento 1 for print query of collection. like below example $products = Mage::getModel(‘catalog/product’) ->addAttributeToFilter(‘status’, ...
0
votes
2answers
13 views

Magento2 addFieldToFilter, Need 'and' and 'Or' in sql

I need magento sql collection. Query need like that. select * from custom_table where customer_id=xx or (customer_group=1 and custom_field=1) I can add or operator like below select * from ...
0
votes
1answer
986 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("...
1
vote
1answer
1k 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 ...
1
vote
0answers
10 views

SearchCriteria vs Collection - Query Performance Difference

I am trying to refactor get category data method. Initially, it was written with Collection filter. Later I refactored with the search builder interface. When I tried to compare the querying time, I ...
0
votes
1answer
15 views

Pagination in Custom Collection magento 2

I am retrieving data from third party as an object, I am forcefully converting an object into array and collection. I want to apply pagination with the data, I tried using core pagination logic and ...
0
votes
0answers
26 views

I am getting incorrect count of products for layered navigation in magento 2.3

In layered navigation filter i am getting incorrect product count, i can't get the solution for this problem. Example : The products under Shorts category in 49 but in the filter for me showing as ...
0
votes
0answers
27 views

Get current product details in price phtml file in magento 2

I want to get current product details in /Magento_Catalog/templates/product/price/amount/default.phtml file. I want to display custom price as per my requirements. so i need to get product collection ...
0
votes
0answers
15 views

Magento 2 Get Request Param Always Null

I can't seem to get request params from a Data Provider. I've modified Magento\Review\Ui\DataProvider\Product\ReviewDataProvider.php to log (also tried var_dump) the information, but it always returns ...
0
votes
0answers
24 views

Magento 2 - How to use mysql find_in_set?

In Magento 2, I try to use find_in_set mysql function but without success. I try this : $result->getSelect()->order("find_in_set(e.entity_id,'".implode(',',$sort_order)."')"); But it give me ...
0
votes
0answers
10 views

customer custom filter is not working in customer grid admin

I added filter with custom table.i'm getting the all customers even i pass filter parameter. backendurl/backend/customer/index/index/practitioner/22 protected function _initSelect() { ...
1
vote
1answer
23 views

In magento 2 on product collection both addFieldToFilter and addCategoryFilter is not working

I am trying to get the product based on the 3 rules. 1st rule -> the product should have been created within a month 2nd rule -> it should be belonging to a particular category 3rd rule ->it should ...
1
vote
1answer
21 views

Out of stock products: why do they appear in Collection::getAllIds and not in Collection::getItems

Im trying to get all products in a collection: out of stock and products in stock. So what I did is: /** @var $collection \Magentp\Catalog\Model\ResourceModel\Product\Collection */ $collection = $...
5
votes
2answers
2k 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
32 views

How to get list of orders filtering by payment method

I would like to get a list of orders which have been made by a specific payment method using the search criteria. Is there any way we can achieve this? The only thing I've found is this thread: ...
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 $...
0
votes
0answers
13 views

Apply filters or mass actions on grids with fake collection (or wirhout ui components)

I a admin grid with a change on _prepareCollection() function to get the collection from a response of api call, its working fine. But I do not have the filters or mass functions, how can I do that ...
0
votes
1answer
901 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
15 views

How do I get all products in a category?

Consider my 'shorts' category below. It has 149 products in. 13 are configurable, the rest are simple products that have a visibility of 'Not visible individually'. I have the following: $category = ...
0
votes
0answers
6 views

Megento 2 Left joining two tables, if null default to 0

Title self esplicative, but when I perform the join, then add field to select then make the expression I get an error. $this->getCollection()->getSelect() ->joinLeft( [ ...
1
vote
1answer
1k views

Magento2 how to override collection

I've just been working with Magento2 for 1 week. There are many things that made me confuse. I want to build a grid that show information from "directory_country_region" table but show only for "...
1
vote
1answer
1k 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-...
6
votes
3answers
5k views

Get Website ID from Website Name

As the title says. I don't want the ID of the current website, I want the ID of any website by supplying only that websites name. I have this code: $siteModel = Mage::getResourceModel( 'core/...
0
votes
1answer
46 views

Show products with zero quantity last in Magento 1.9

I want to show products with zero quantity last in all site categories, search results, etc. But the sort order should be as follows: the products with a non-zero quantity (not in decreasing, default (...
13
votes
3answers
29k 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 ...
0
votes
1answer
747 views

load customer collection by email and mobile but not general group

I want to load customer collection by email and mobile but not general group for email load $customer = Mage::getModel("customer/customer")->loadByEmail($customerEmail); for mobile $customer ...
0
votes
0answers
16 views

Magento2 : Join Another Table in Existing Collection

Lets say, Third party collection class is as below: namespace Vendor\ShipRule\Model\ResourceModel\Rule; class Collection extends Magento\Framework\Model\ResourceModel\Db\Collection\...
1
vote
1answer
26 views

For each Loop Not Print Proper Data

On product listing page I have $_productCollection = $block->getLoadedProductCollection(); if I call getData on $_productCollection I get different array than I get in foreach loop. Does anyone ...
1
vote
2answers
5k 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
0answers
25 views

How to display collection data in grid ui admin?

I create controller to get data from database as code below. The query in controller: $orderCollection = $this->_salesOrderCollectionFactory->create() ->addFieldToFilter( ...
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
2 3 4 5
32