Questions tagged [collection]

Questions related to Magento collections

282 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
1
vote
1answer
20 views

How add new item in existing collection in magento 2

i have 2 collections 1 Orders 0 date "2019-07-05" count "2" 1 date "2019-06-20" count "2" 2 date "2019-06-18" count "2" 3 date "2019-06-17" count "2" 4 date "...
0
votes
0answers
16 views

Magento 2 custom module select query doesn't work

I have the following query: SELECT `main_table`.*, `secondTable`.* FROM `table_one` AS `main_table` LEFT JOIN `table_two` AS `secondTable` ON main_table.blog_id = secondTable.blog_id WHERE (...
0
votes
0answers
13 views

magento 2 how to add search box to fronted for a custom table contents

How to add a frontend search box for a custom table contents. When the user enters three letters of a name then get data in pop up. Anyone Can help? Thank you in advance.
0
votes
1answer
26 views

Magento 2: How to filter orders by order items

In magento 1, I was able to filter orders by the following: $orderitem = Mage::getModel('sales/order_item')->getCollection(); $orderitem->addFieldToFilter('name',array('like'=>'%'.$value.'%')...
0
votes
0answers
14 views

Magento 2 collection filters for GRID are not working

I'm developing a module for Magento 2, but when trying to create a GRID, my filters are not working. I have some settings in other class and load it to the collection, using it inside the ...
0
votes
1answer
13 views

magento 1.9 | how setStockData on collection

i have this code $productCollection = Mage::getModel('catalog/product')->getCollection(); $productCollection->addAttributeToSelect('SKU') ->addAttributeToFilter('...
0
votes
1answer
30 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
2answers
29 views

Set order for product Collection in magento2

I am filtering product collection like below. $productSkuString = 'O, C, D, A, F, S'; $productSkus = explode(', ', $productSkuString); $collection = $this->collectionFactory-&...
0
votes
0answers
23 views

Magento 2 create new tab and add customer grid collection on product add/edit page in admin

I am using magento 2.3 and i want add custom tab in Product edit page on admin and add grid collection of customer in custom tab. So any one know How i can do that. Thank you.
0
votes
0answers
17 views

Magento 2 product collection getSelect Order by Case unException Unknown column 'name' in 'order clause'

I need to use ORDER BY CASE name which is product name Query: SELECT `e`.*, `cat_index`.`position` AS `cat_index_position`, `stock_status_index`.`stock_status` AS `is_salable` FROM `...
0
votes
0answers
16 views

Difference between Magento Collection ,object , array

Please clear the main difference between Magento Collection , object , array and arraylist also ?
0
votes
0answers
17 views

How to get magento2 bundle products in list page

How to get magento2 bundle products in category list page. I assigned to category but not visible in frontend. Thanks
0
votes
0answers
11 views

Collection array attribute value change on run time

i have a collection [0] => Array ( [entity_id] => 93 [state] => complete [subtotal_invoiced] => 3445.0000 [total_invoiced] => ...
0
votes
2answers
39 views

I need to filter product collection by category id and color attribute

I need to get product collection by category id and color attribute. But It's not working. Here is my code: $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $categoryFactory = $...
0
votes
1answer
26 views

Sort product collection on stock status in magento2.3

I want to sort my list.phtml and catalogsearch by availability. Mean that when category page or search result page loads, first show "in stock" product and at the end show out of stock items. Don't ...
0
votes
1answer
23 views

Magento2 admin grid: SQL error when sorting by specific field

Database table columns are displayed in custom grid in adminhtml. One of the field has name 'precision' and this causes SQL error when I sort the grid by this field (as this is mysql reserved word and ...
0
votes
0answers
23 views

Set a default filter for Order Grid

How can I set a default filter for Order Grid programmatically? I read many different answer but they don't work properly.
0
votes
0answers
24 views

Why product collection query not showing “color” attribute in select?

Case 1: $collection = $this->product->getCollection() ->addAttributeToSelect('color'); echo $collection->getSelect()->__toString(); Output: SELECT `e`.* FROM `...
0
votes
0answers
13 views

Incorrect product sorting for numerical attributes (Magento 2.2.8)

I've got a shop with an attribute "capacity" created via Magento Backend: Shops -> Attribute -> Product It has "Text Field" as input type and "Decimal" as validation. So for new products therefore ...
0
votes
0answers
25 views

Set custom Record Count to Collection pagination in Report Grid

How we can set count of collection size before setting for the grid. Main Sales collection: $collection=Mage::getModel('sales/order')->getCollection() ->addAttributeToFilter('created_at', ...
0
votes
0answers
20 views

Magento 1.9.3.1 Sales Order Grid limit records

I have a Magento store running with over 18,000 order records all the other pages within admin load within 1 - 2 seconds apart from Sales>Orders this can take anything between 5 - 20 seconds to load. ...
0
votes
0answers
28 views

Magento 2.3 custom conditions for attribute filter using addAttributeToFilter

In Magento 2.3 I need to filter the collection as per below scenario. I have L, W and H attributes for products And user input is "X, Y and Z" then the following condition will give the desired ...
0
votes
1answer
39 views

How to use Magento 2 cache?

I have a requirement where, I have huge custom data(around 5000) to display in a page. Currently, I have displayed them in a table and it takes time when I load the page. I want to save the collection ...
0
votes
0answers
21 views

Magento 2 how to match one item from one collection to another item in another collection if both are same then add to an array

I'm trying to compare two values from collection to another two values from another collection if they both are same then add that row to a array. How to achieve it. Can I get help? Thank you in ...
0
votes
1answer
47 views

how to update data in database table

I am sending data to the database by checking duplicate data. But I can't be inserting/updating data in the database. protected function saveEntityFinish(array $entityData, $table) { $...
0
votes
1answer
40 views

Magento 2 : AddAttributeToFilter with AND Condition

In product collection, I want to do like : $productCollection = $this->productCollectionFactory->create(); $productCollection->addCategoriesFilter(['in' => $catalog_id])->...
0
votes
2answers
54 views

How to pass added custom “key=>value” into getCollection()?

On product lisitng page i want to get one more parameter "latitude" for all product,how can i achieve? Here is my code:- public function setCollection($collection) { $this->...
0
votes
1answer
30 views

How can get custom table columns on product listing page using product_id of the custom table

On product listing page, I need to show visitor nearest product first. I've a marketplace site and each product have different seller and there is a custom table having seller_id and product_id ...
0
votes
1answer
45 views

Magento2: unable to get Actual result by using getSize()?

Collection protected function _getProductCollection() { $tagModel = $this->tagTagFactory->create(); $this->_productCollection = $this->_productCollection ->...
0
votes
0answers
410 views

Magento merge two collections with different sorting orders

I have one store in Magento 1.9 , There is a listing page with AJAX scroll loading, on first page I am showing 24 products. We are showing products with label In-Stock and Sold Out, In-stock products ...
0
votes
1answer
71 views

Could not filter product collection in Mage_Catalog_Block_Product_List by a custom attribute in magento 1.9

I have an issue similar to this question , and i checked the 'Already answered link' too. But my issue is bit different. The error is similar in the above link but with my custom attribute : ...
0
votes
1answer
36 views

Model Collection.php magento 2

I cant seem to find any information why we need to create a Collection.php file inside ResourceModel and what is the purpose of collection.
0
votes
0answers
22 views

How to get all categories and products in one collection in magento 2

How to get all categories(with levels) and it's products in one collection in magento 2
0
votes
0answers
118 views

Magento 2.3 collection factory not exist

I use magento 2.3 and I can't see collectionFactory created in generated folder or inject to any class. ModelFactory can create normally. There are my code: Model file: <?php namespace Lights\...
0
votes
0answers
26 views

Set a permanent limit on returned rows in grid

I have created a grid extending Mage_Adminhtml_Block_Widget_Grid. Within _prepareCollection I'm doing this: $collection->getSelect()->limit(10); But as soon the reset filter button is clicked ...
0
votes
0answers
86 views

Best seller collection filter magento2

I am trying to filter Best seller product collection like below. Seems the setOrder is not working. class BestSeller extends \Magento\Framework\View\Element\Template { protected $...
0
votes
0answers
92 views

Magento 1.9.4 add custom dropdown field to inventory tab

Currently in magento when you manually change the quantity of a stock managed product in the admin there is no reason assigned to this. So, what I would like to do is add a dropdown field below the ...
0
votes
1answer
161 views

Magento 2 custom module Collection join table _initSelect

My Collection.php .... public function __construct( \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory, \Psr\Log\LoggerInterface $logger, ...
0
votes
0answers
23 views

How can I use 0 instead of null magento 2 collection?

I have created module to show report in grid. But in collection some fields contains null value how can I change null to 0. <block class="Magento\Backend\Block\Widget\Grid\Column" name="...
0
votes
0answers
49 views

Magento 2 - Apply filter on Product collection

Is there any common event or plugin to apply the filter to product collection which includes product list page, related products list as well as upsell and cross-sell product list? If no, then how ...
0
votes
1answer
87 views

Retrieve Compare Items Collection returning zero Items Magento 2

While I am trying to return compare items in custom module phtml file, it is returning zero items but in database table catalog_compare_item showing all the added items to compare. Class Used : ...
0
votes
1answer
198 views

Magento 2 Join Product Collection with Custom CollectionFactory

In Magento 2.2.5, I have Custom Model Collection (followed this tutorial). In that I want to add the Product Collection into this custom collection by default. How to achieve this.
0
votes
1answer
31 views

RewardspointsFactory class does not exist

Please anyone review my code. Facing this error. Exception #0 (ReflectionException): Class Sugarcode\Test\Model\ResourceModel\Test\RewardspointsFactory does not exist Exception #1 (ReflectionException)...
0
votes
0answers
72 views

How to get a Array Response from collection with getfieldset

I'm trying to get a Array Response from collection with getfieldset like below, still got this error and unable to resolve this. Uncaught Error: Cannot instantiate interface Magento\Framework\DB\...
0
votes
0answers
18 views

Display content between set products on magento 2 category page

I was wondering if there would be a solution to display blocks, with content i can enter in the backend, between or after a set amount of products. I know i can display some static content at the top ...
0
votes
0answers
27 views

Magento 2 filter datetime which already pass 24 hour

I have created a custome model and this model has created_at attribute, i need to find the model collection which created_at is greater than now in 24 hour: for example : $transaction = $this->...
0
votes
2answers
394 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
0answers
13 views

Cache management on collection

I am creating a custom magento 2 module of a blog. I have a block : <?php namespace Formation\Blog\Block; class Posts extends \Magento\Framework\View\Element\Template { public function ...
0
votes
0answers
39 views

Repository collection join processor doesn't work when called twice

I have a repository that has to join a table for certain filters when using getList. I noticed that Magento does this using a JoinProcessor. Everything works fine except when calling getList a second ...
0
votes
0answers
14 views

Join tables in collection

I have a collection of products filtered in layered navigation. $productCollection = Mage::getSingleton('catalog/layer') ->getProductCollection() ->addAttributeToSelect('*'); I ...