Questions tagged [collection]

Questions related to Magento collections

Filter by
Sorted by
Tagged with
4
votes
1answer
82 views

Magento 2 Updating Other Products in catalog_product_save_after event Observer

I had created an Observer of this event:catalog_product_save_after I am trying to update other products and loading them on the basis of their id, but it is giving me an error. I am Sharing my code ...
4
votes
1answer
568 views

One to many relationship in M2

I am working on a module where I have to implement one to many relationship. I have one table for series with id and name field and one table series_product where I have id, series_id, product_id and ...
4
votes
1answer
4k views

Magento 2 - Customize Customer Grid Collection Data

I want to add a where clause in customer grid collection. e.g. $currentCollection->getSelect()->where('custom condition'); I tried to google it but got no success. I have also tried to ...
4
votes
2answers
1k views

Programatically get subcategories of several root categories with collection

I am working on a collection query of categories: $categories_check = Mage::getModel('catalog/category') ->getCollection() ->setStoreId($storeId) ->...
4
votes
2answers
428 views

Not getting NULL value or empty value when the filter fails.Why?

I am using the code below to get the orders when filtering using email address of the logged in user. $order = Mage::getResourceModel('sales/order_collection') ->addFieldToSelect('*') ...
4
votes
1answer
1k views

Hide configurable product with child product availability out of stock from product listing page

I want to hide all the configurable products from product listing page for which even a single associated simple product is out of stock. For it first of all I'm trying to filter all configurable ...
4
votes
4answers
5k views

Filter collection by yes/no attribute

I'm using the following to filter my collection: $collection = Mage::getModel('catalog/product') ->getCollection() ->setStoreId($storeId) ...
4
votes
2answers
1k views

grid joinTable alias problem in order by

I made in customers admin grid a join with sales_flat_order table: protected function _preparePage() { $this->getCollection()->joinTable('sales_flat_order', ...
4
votes
1answer
2k views

Manual eav join best way?

If i have a product collection in a multi store environment and i wish to also retrieve a specific attributes value from another store with my collection result, how is the best way to do this? For ...
4
votes
1answer
3k views

difference between collection and collectionFactory

I need the list of all the admin users. And, both the below set of codes, provide the same result. Code 1 public function __construct( \Magento\User\Model\ResourceModel\User\Collection $...
4
votes
1answer
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 ...
4
votes
1answer
1k views

Subselect as main_table on magento collection

I'm trying to do a query with subselect in magento collection. Example The original query: $collection = Mage::getModel('salesrule/rule') ->getCollection() ->addFieldToFilter('rule_type', 2)...
4
votes
1answer
623 views

Apply Saved Filters to Custom Collection

I have created a custom grid and collection. Now, I am saving the filters to session for future use using: $this->setSaveParametersInSession(true); and retrieving this in another controller. How ...
4
votes
1answer
807 views

List Least Sold Products

My Boss has asked my to provide a list of all products that have not sold in the last 3 months listed in order of most stock I have hunted for some code I can hack already but found very little, I am ...
4
votes
3answers
433 views

Associating Categories with Additional Collections Other Than Products

I've got a decent understanding of the basics of eav and adding additional attributes to categories, products and other entities however I'd like to be able to form a one to many relationship between ...
4
votes
1answer
44 views

How to select image from categories collection?

I have entity \Magento\Catalog\Model\ResourceModel\Category\Collection $categoryCollection And I'm trying following $categoryCollection->addAttributeToSelect('image'); but this doesn't work ...
4
votes
1answer
281 views

loop through 2 collections with in one phtml

I am working on a custom module that is pulling in 2 different collections. When I try to use a for-each to loop through either of the collections the page displays the collection correctly. However,...
4
votes
1answer
511 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 | ...
4
votes
0answers
88 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 ...
4
votes
0answers
149 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('...
4
votes
0answers
380 views

Magento 2 : How to Return the Collection from afterload

I have implemented this jquerytokenizer in Ui Component form shown in the below image. It works well , the data is saved accurately- but when I go to edit a saved record this field is empty ...
4
votes
1answer
994 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-...
4
votes
0answers
161 views

Magento 2 addProductsFilter to Stock Item collection

In Magento 1 you were able to add a product filter to a Stock Item collection in the Mage_CatalogInventory_Model_Resource_Stock_Item_Collection class. This functionality appears to be missing along ...
4
votes
2answers
388 views

Magento getting store bestsellers: configurable products, only from current store

Magento getting store bestsellers: configurable products, only from current store We have tested some bestseller codes like from here and here and here. They all work fine if you only sell simple ...
3
votes
3answers
28k views

Filter product collection by custom attribute

I'm filtering a product collection by the custom attribute ean with the following code $collection = Mage::getModel('catalog/product')->getCollection(); $collection->addAttributeToSelect('name')...
3
votes
3answers
10k views

Product image url as part of collection load

Is it possible to have the product image url loaded as part of the product collection? for examples: Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*'); This doesnt ...
3
votes
5answers
15k 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); $...
3
votes
2answers
3k views

Magento 2 how to get sum of a column?

I have created a custom collection factory. Now I want the sum of a column,how can I achieve it. Here is my code $collection = $this->customFactory->create()->addFieldToFilter('status',2) -&...
3
votes
1answer
6k views

Remove existing WHERE clauses from $collection->getSelect()

I am trying to modify the Lifetime Sales figure on the admin landing page to include pending_payment orders. I have set up a module as follows: class Steamdesk_Dashboard_Block_Dashboard_Sales extends ...
3
votes
4answers
16k views

fatal error: Call to a member function getCollection() on a non-object in magento

I am trying to get a collection of objects of a table of our database. Unfortunately the following code was leading to an error. my code is <?php class Ics_EasyLife_Block_Template extends ...
3
votes
4answers
9k views

Subquery in a collection

I am trying to do a query of the form: SELECT TableA.id, ( SELECT MAX(TableB.qty) FROM TableB WHERE TableB.parent_id=TableA.id ) FROM TableA the important thing being that the select ...
3
votes
1answer
11k views

Magento 2: How to get customer collection [closed]

I got customer collection with help of objectManager but I don't know how to get customer collection via injecting a class in constructor(Dependency Injection). So how we get customer collection ...
3
votes
2answers
981 views

Call to undefined method Collection::getData()

I use (Manthan_Marketplace) extension in my Magento store I want to add a table to this extension so create a custom table (photos) in Magento database with name:(manthan_marketplace_photos) Table ...
3
votes
2answers
7k views

addAttributeToSelect in magento2

addAttributeToSelect is not working in magento 2. i tried below but it is loading all item. $groupCollection = $this->_productloader->create(); $groupCollection->addAttributeToFilter('sku','...
3
votes
3answers
2k views

Magento 2 addFieldToFilter equal today for datetime field

I have a model with field in datetime format, i want to filter the field with equal today date like this: $collections = $this->customFactory->create()->getCollection() ->...
3
votes
2answers
2k views

Magento 1: admin product grid column value disappear on name search

I'm facing an interesting problem regarding a custom modification to the backend Catalog Product grid. NB: I'm currently using a module adding columns to this grid via an observer. Nevertheless, the ...
3
votes
2answers
17k views

Get product collection filter by if attribute exists?

Goal: Retrieve a collection of products that have a certain attribute Here's what I'm trying: public function Hydrate($attribute) { $this->id = Mage::helper('myHelper')->CamelCase($...
3
votes
2answers
5k views

filter check current date between two dates

I have custom collection and I want to check current date available or not between start_date and end_date. $currentDate = date("Y-m-d 00:00:00"); $collection = Mage::getModel('test/validity')->...
3
votes
2answers
9k views

Loading a product collection by a specific attribute drop-down value

I am trying to load a specific virtual products with its custom options, but instead I keep getting an empty array. My attribute is 'part_identifier' in the attribute set 'boat_part' It is a drop-...
3
votes
1answer
3k views

Filtering error when using custom Varien object collection in admin grid

I have created a custom Varien object collection for my admin module (because the data is not from a db) and have got it successfully to show in an admin grid. I built the collection by using the ...
3
votes
2answers
323 views

load customer object update issue in magento 2?

I have used below code in my controller use Magento\Customer\Api\Data\CustomerInterfaceFactory; class editPost extends \Magento\Framework\App\Action\Action { protected $_customer; protected $...
3
votes
1answer
3k views

Magento 2 Custom Collection

How can I create custom collection to show data in grid in back-end. Example, I want to show a list of log files or show cron job tasks, The did not come from Database, just an array I collect. ...
3
votes
3answers
645 views

Get first and last inovice # in every date

I am trying to show invoices for every single day, so for that purpose I used group by on created date and sum on subtotal. This is how I done it : $orders = Mage::getModel("sales/order_invoice")->...
3
votes
1answer
2k views

How to retrieve a customer by phone number?

I need to retrieve the customer object belonging to a certain (mobile) phone number. How can I do this in Magento? And how can I get a customer by phone number when a phone number was entered by end ...
3
votes
1answer
16k views

Product collection filter by stores

How do I filter a product collection so that it includes only products in store 2 that are not in store 3. It can include any other stores as long it is in store 2 but not in store 3. product->...
3
votes
3answers
633 views

Is It Possible to Print the Current Collection's ORDER BY information?

I've created a custom sort module that I'm attempting to debug. I'm curious if it is possible to display this information somewhere in my catalog pages (e.g. app/code/design/package/theme/template/...