Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [collection]

Questions related to Magento collections

0
votes
1answer
415 views

Magento 2 : Join 2 tables in Existing collection

I've been trying to join 2 tables with the existing collection of Customers (customer_entity). I've added like below. $items->getSelect()->join('customer_entity_text as second', 'main_table....
1
vote
1answer
2k views

Magento:2 How to Image upload in custom module

Image upload working fine in tmp folder, then store in DB. I want to after saving data image stored in the base folder pub/media/events var_dump($data); " ["events_url"]=> array(1) { [0]=> ...
1
vote
2answers
2k views

Magento 2 - product collection filtered with custom attribute

I would like to filter product collection on category page using custom attribute. For example: On category page, I want to list only products that have custom attribute age set to 10. How to ...
1
vote
0answers
341 views

Magento 2 : Get Customer Collection with it's Attribute

I've managed to get customer collection using class \Magento\Customer\Model\ResourceModel\Customer\CollectionFactory but it returns me default details not with Created Customer Attributes. Any ...
1
vote
2answers
2k 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
97 views

Get collection with promotional products not working

I need to get a collection listing all products with a promotion, but I'm getting this error: Fatal error: Call to a member function getBackend() on boolean I tried those 2 solutions, but still ...
1
vote
1answer
233 views

Use search_criteria to filter custom extension collection in Magento 2

I generated a custom extension with a custom model collection from mage2gen , is it possible to implement the search_criteria like when you retrieve product using rest api? what i know is the product ...
3
votes
1answer
740 views

Magento-2 get all products having product qty less than 5 only

I'm trying to get product collection, only the products which have the qty less than 5 in Magento 2, but I'm failing to load. use Magento\Framework\App\Bootstrap; require DIR . '/../app/bootstrap....
0
votes
2answers
150 views

addFieldtofilter array not reading

I am trying to filter product collection by ids if I use below code, the filter works ok and the product shows. $this->_productCollection ->addFieldToFilter('entity_id',array('in'=&...
1
vote
1answer
243 views

Filter collection with attribute from custom module

I have a custom module which I load data with following code inside list.phtml: foreach ($_productCollection as $_product){ $_id = $_product->getId(); $event = Mage::getModel('aw_eventbooking/...
0
votes
1answer
185 views

Magento 1.9 join table issue

I'm having an issue with Magento 1.9.2.4 trying to make a join on my collection, here's the problem: Actually I've got a custom table named product_banner which I'm getting by: $collection = Mage::...
0
votes
3answers
61 views

Magento 1.9 : Error getting collection Model of Catalogrule

I try to get a collection of Mage::getModel('catalogrule/rule') but when I do Mage::getModel('catalogrule/rule')->getCollection() I have an error because can't call a function of boolean. I do a ...
1
vote
2answers
879 views

Magento 2 : setOrder not working in collection

In my custom collection $career_collection->setOrder('career_id','ASC'); not working. My function is below public function getAllCareers(){ $Careers = $this->_careersFactory->create(); ...
4
votes
1answer
385 views

How to use collection factory model in Unit Test magento 2

I have a custom extension with model with structure like this in database: +----------------------------------+ |entity_id | customer_id | balance | +----------------------------------+ | 1 | ...
1
vote
1answer
108 views

Magento 2.2.3 :: How to check if ProductCollection exists?

Here is my problem: I have a vehicle parts site which lets user select their specific model and be saved via a cookie. Then the whole site will be filtered via my module plugin, where I override “...
2
votes
1answer
131 views

Get collection of recently updated products

I'm trying to create a collection of all products that have been updated in my store the past 24 hours. The following code seems to be ok to me. Although I have tried numerous altering versions of it,...
0
votes
1answer
84 views

How to get collection object when use where in collection

I am trying to add where in collection but it return Varien_Db_Select Object instead of return collection object. $collection = Mage::getModel('orderoutofuk/orderitem')->getCollection()->...
0
votes
1answer
289 views

Magento 1.9 custom collection pagination not working in admin grid?

I have created a custom grid to show a monthly wise report, But the pagination is not working with the Varien_Data_Collection . Please find the code snipet below from Grid.php $rows = $...
1
vote
2answers
168 views

Magento 2.1 - Memory Leak in my getCollection function

So I'm creating a really simple module to read from a custom table. Nothing fancy, table has two rows: +-----------+--------------+ + status_id + status_label + +-----------+--------------+ + 1 ...
1
vote
1answer
201 views

MEQP Gives a Warning : Data load getFirstItem() method detected in loop

I want to get the First item from the collection so I have used following code. But it gives some warning on the usage of getFirstItem() protected $_sampleFactory; public function __construct( \...
2
votes
1answer
230 views

Magento product collection filter not working

I am using magento list file class with override productlist.php.So i can use product collection object and try to filter using type_id but nothing happend. Here is my code. <?php use Magento\...
0
votes
1answer
117 views

Magento 2: toolbar url problems in custom module with custom router

I have the custom module with product collection and custom router. for example i want to have link https://domain.com/gaires/something Router code: namespace UseApp\Gaires\Controller; class Router ...
0
votes
2answers
49 views

Magento 2 How to load product collection, Category collection, Load product by child ID

I have some experience in M1 and M2 but am somewhat struggling to grasp how to load the child category. At the minute it loads the default M2 category with [0] or [1] next category etc. But I just ...
1
vote
1answer
467 views

sql - joinLeft collection sales_flat_order_grid

I have this SQL query: select main_table.*, (select nexway_status from nexway_order where order_id=main_table.entity_id ORDER BY id DESC LIMIT 1) as nexway_status from sales_flat_order_grid as ...
0
votes
2answers
373 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
547 views

Displaying products on the front page does not work

Magento 1.9.3.7 Porto theme I did a fresh install of Magento 1.9.3.7. I installed the Porto theme. The setup is identical to the one I have in Magento 1.9.1 but when I put the following code into the ...
0
votes
1answer
504 views

Magento 1.9 Cache Custom Block Data

I have a custom module that displays products from a given category in a carousel. Now, I was wanting to cache the results, so the database is not queried and duly for speed optimisation. However, I ...
0
votes
1answer
108 views

How to write sub-query with group by in Magento 1.9?

I am new in learning Magento. I need to create query like this, SELECT * FROM YourTable WHERE ARIDNR IN ( SELECT ARIDNR FROM YourTable GROUP BY ARIDNR HAVING COUNT(*) > 1 ) How to write this ...
0
votes
1answer
111 views

Magento 2 Category Collection doesn't show items not in Top Menu

I am trying to display certain categories along with their images on homepage. I've made sure the categories dont appear in the top menu and only in the code that I am trying to use. Below code only ...
1
vote
2answers
23 views

Simple type products collection - wrong count

Here's a collection that should include all simple products in my magento store: $collectionSimple = Mage::getModel('catalog/product')->getCollection() ->addAttributeToFilter('...
1
vote
3answers
397 views

Collection filter date range not working

I tried to find the collection that has a range created between 4 hours, but somehow it doesnt show the right collection size, it always returns '0', here's how i use the filter: $to = date('Y-m-d H:...
3
votes
0answers
75 views

How to handle multiple tables with magento 2 repositories?

As we all know, magento 2 suggests using repositories as an additional layer between resource models/collections and the rest of application. It's all pretty straightforward and simple when you use it ...
0
votes
1answer
475 views

Magento 2: Sort multilevel category collection by both level and position

I am using Magento 2.2 and I want to get a collection of categories that is made up of a number of sublevels of a specific category. How can I get this collection sorted by both level and position so ...
1
vote
2answers
264 views

Magento 2: How to get a customer by Telephone attribute?

I'd like to filter my collection using something like: $collection->setField('telephone') ->setConditionType('eq') ->setValue('(555) 229-3326') But the telephone attribute is an ...
0
votes
1answer
33 views

getCitiesAsOptions() [closed]

I try to get from collection, City ID and City Name, to put in module Meanbee/Shippingrules as new condition All it's good but on multtiple select filed I get city iD-s, I supose to get name as Label ...
3
votes
0answers
103 views

Magento API complex filter value from another key value

I have a custom soap api for my magento 1 website, the problem is i dont know what array value to pass as the filters parameter so the parameter will work like this: $collections = Mage::getModel('...
0
votes
2answers
437 views

How to get All Active Categories in Custom Module Admin Form(UI-component) Dropdown in Magento 2?

I need to get all categories in a dropdown in admin ui form. So Please provide me a solution Form.xml <field name="category_name" sortOrder="10" formElement="select"> <argument ...
0
votes
1answer
484 views

Magento 2: Merge multiple collections

For a configurable product I want to get all related products of the linked simple products. How is it possible to merge multiple collections? At the moment I overwrite the related products on each ...
1
vote
1answer
205 views

How to load filter state for admin grid?

I'm looking for a way to get the state/settings for the order_sales_view grid on a in a php class. I want to load the grid and the filter state to use for selecting previous and next order according ...
1
vote
2answers
515 views

How to add filter to the collection of attributes in magento 2

magento 1 code to get all the attributes collection public function getAttributes() { $collection = Mage::getResourceModel('catalog/product_attribute_collection')->addVisibleFilter()-&...
0
votes
1answer
281 views

How to get all the attributes and show in the dropdown field in a backend form in magento 2

I have created backend form which has one dropdown field. How Do I get all the attributes and show it in a dropdown in magento 2
0
votes
3answers
451 views

Magento 2, preference for Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection does not work

When filters + Ancor is enabled for category, sorting by product name doesn't work. I know the fix as I tested in Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection. So now I'm trying to ...
1
vote
1answer
540 views

Magento 2 product collection not filtering by custom attribute (Type multi-select)?

I am trying to filter product collection with custom attribute "Groups" code "group" which is a multi-select attribute created from Magento admin, but it is giving empty result (this attribute is ...
0
votes
1answer
28 views

Multiselct product attribute is not beign added into collection filtering

I have created a multi select attribute and assigned this to attribute set. Attribute is showing in product search results but I am unable to include this into product collection filtering as well as ...
0
votes
1answer
175 views

Get admin grid's row count Magento 1.9

If I am creating a block which is type 'Mage_Adminhtml_Block_Widget_Grid' in my controller like so... $block = $this->getLayout()->createBlock('mymod/adminhtml_mymod_my_grid'); I can get the ...
1
vote
3answers
306 views

count is not working after filtering the collection

I am getting the correct count using code. $this->getCatalogRuleCollection()->count() But when I am adding the filter to it is not working. Following code is not working. $this->...
2
votes
3answers
1k views

Magento 2 filtering product collection and sorting

Considering below I can display products with true value of my custom attribute in ascending order based on position. How can I have products with false right after these in ascending too? if ($...
0
votes
2answers
958 views

Magento 2 : How to filter customer group collection?

Anybody have idea about how can i filter customer group pragmatically ? I can able to get customer group collection by using below code. $customerGroupsCollection = $objectManager->create('\...
3
votes
2answers
544 views

how to get status of last order id in magento2 sql query?

i want to get last order id along with order status in magneto2, i use this query to extract it but the status is not extracting correct: SELECT max(entity_id) , STATUS FROM sales_order max ...
1
vote
2answers
820 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 (...