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

6
votes
4answers
14k views

Magento 2 how to get order collection

how to get order collection in custom module ? like My Orders collection in customers dashboard (frontend). this collection how to get?
0
votes
1answer
989 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 $...
1
vote
1answer
35 views

Magento 2 - Need to filter comma sperated values in addAttributeToFilter along with category filter

I need to filter comma sperated values in addAttributeToFilter in magento 2 Here is my Code: $comma_separated_values = 26,27,28,29; $categoryProducts = $category->getProductCollection()->...
0
votes
1answer
180 views

Cache a product collection by a key?

I have added a collection to buff out related products with extra "most viewed" products from a products top level category. This is a slow query and takes about 0.2 seconds so was wondering if this ...
0
votes
0answers
20 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
3answers
29 views

custom table left join with catalog/product

I have a custom table called flagged_products which lists flagged products like this: +-----------+------------+---------------------+ | entity_id | product_id | flagged_on | +-----------+---...
1
vote
1answer
15 views

How to get product random collection in magento2?

I want to get the random 10 products from whole product collection in magento2. $productCollection = $this ->productModel ->getProductCollection() ->...
3
votes
1answer
25 views

Custom FilterList incorrectly sets Collection size in Layered Navigation

In order to add a custom filter to the Layered Navigation, I overrode the class Magento\LayeredNavigation\Block\Navigation\Category to load my own FilterList class instead of the one from core. My ...
0
votes
1answer
26 views

array convert into Magento 2 collection

I have 2 collection 1 is $bestsalecollection that show in dashboard . second is product collection. After filter collection when i return it generate error Call to a member function isLoaded() on ...
0
votes
0answers
19 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 `...
1
vote
1answer
904 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
883 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
0answers
21 views

Call to a member function isLoaded() on array

Call to a member function isLoaded() on array in /var/www/html/codility-magento-market-place/vendor/magento/module-backend/Block/Widget/Grid/Extended.php:473 Stack trace $bestsalecollection = $this-&...
1
vote
1answer
20 views

Magento 2 - Recently viewed product collection from Model

Please read description carefully before marking it as duplicate I want to get recently viewed product collection from Model instead of Block I have check similar post but no one answered it ...
0
votes
0answers
16 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
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 ...
3
votes
2answers
47 views

Magento 2.3 - Add product name column in custom ui grid with product name filter

I have added product name column in my custom ui grid. In which data displayed properly but not filtered grid by product name. Note : I set product name with comma separated in ui grid column. Here ...
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]=> ...
0
votes
2answers
27 views

How to get value from sales_flat_order_item table using quote_item_id?

Using the sales_order_place_after event in my custom Observer. I have the quote_item_id value (example 324). How to get the corresponding item_id value from the sales_flat_order_item table? I am ...
5
votes
1answer
2k views

Magento checking order updated_at using Magento date and time

we are trying to filter out orders that were created longer than 60 minutes ago with status pending. We are having some problems with the date/time functions We tried: - date('Y-m-d H:m:s') and ...
2
votes
1answer
26 views

Magento 2 - Multiple collection on same block

I have a block where I want 3 different collections with different category filters. I have created collection object in constructor like this: protected $collection; public function __construct( ...
0
votes
0answers
15 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. ...
3
votes
1answer
17 views

Magento 2 - Multiple categories filter on product collection

I have a product collection $collection which is created by Magento\Catalog\Model\ResourceModel\Product\Collection code is: $collection = $objectManager->create('Magento\Catalog\Model\...
1
vote
2answers
1k views

Magento 2 - Losing data with extension attributes in bundle options collection

I am using Magento 2.1.4 I add a new column required_total on table catalog_product_bundle_option I created the extension_attributes.xmlfile <?xml version="1.0"?> <config xmlns:xsi="...
0
votes
0answers
18 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 ...
1
vote
1answer
22 views

Magento 2 call list.phtml with custom collection

I have custom collection in $collection I want to pass it to list.phtml so that I don't have to create listing UI again. I am trying to do this but it is not working <?php echo $this->getLayout(...
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
27 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 ...
1
vote
1answer
114 views

Magento 2 get special price product collection

I want to get all sale products (which have specila price and special from date and special to date) in a .phtml file. Which i use in any where in store.specially in list page.
0
votes
4answers
2k views

Magento 2.1 UI component form addFieldToFilter() on null

I am trying to make a UI component form for creating products in Magento 2.1 module. However, I stuck with the problem that it throws this error: Fatal error: Method Magento\Ui\TemplateEngine\...
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
4answers
3k 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\...
2
votes
2answers
2k views

Magento 2 Get last and first item from model collections

I want to retrieve the last and first item from model collection in magento 2, in magento 1.9 i can simply retrieve it like this : $lastItem = $collections->getLastItem(); $firstItem = $...
2
votes
0answers
34 views

how to do pagination to display collection at admin panel custom table in magento 2

I'm trying to create a pagination for my collection to display in a .phtml file, but am getting error page Invalid template file: 'Magento_Theme::html/pager.phtml. Here is my code: code/...
0
votes
1answer
561 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 ...
1
vote
2answers
2k views

Issues sorting by two attributes

I'm having problems applying a default sort order to the product collection for the listing page. When some conditions are met I want to sort by 'region' and then by 'price'. I have added the ...
1
vote
2answers
54 views

Get recently viewed product collection Magento 2.3.1

I have tried this but it is not working. I am getting blank array. Suggestions please, i am stuck. I want to display recently viewed product in owl carousel. But getting no products. protected $...
4
votes
3answers
964 views

Incorrect product count in layered navigation after overriding list product collection

I have customized(override) product list collection getProductCollection and filtered collection as required. public function getProductCollection() { if (isset($this->...
4
votes
1answer
1k 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
4answers
3k 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(); ...
2
votes
1answer
3k 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
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
2answers
153 views

Magento 2: get latest Bestseller collection

I am fetching Bestsellers like this: protected $_collectionFactory; \Magento\Sales\Model\ResourceModel\Report\Bestsellers\CollectionFactory $collectionFactory, $this->_collectionFactory = $...
0
votes
1answer
35 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) { $...
1
vote
0answers
22 views

Magento 2 : Need to set custom category collection using plugin

I want to set custom category collection using plugin. I created plugin about Magento\Catalog\Block\Product\ProductList\Toolbar this block and aroundSetCollection(). But, not actual output I received....
6
votes
2answers
119 views

Empty Collection :: CollectionFactory Approach and getCollection approach both give empty result

I have created a table in my database using db_schema.xml and then populated that table with sql insert commands directly in mysql workbench. My model code is <?php namespace Lmap\...
2
votes
2answers
1k 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 ...
4
votes
5answers
2k views

Magento 2 - Bestseller product collection

I am trying to get bestseller products on homepage using product collection in Magento 2. I only got Most Viewed product listing (?) and I am not getting bestseller products. Here is my code: $...
1
vote
0answers
18 views

how to use walk method to join two tables in magento 2

friends, how to use the walk() method to join two tables in Magento 2 I have 2 tables and I want to join them based on some conditioning. my present code looks like this $result = array(); $...
1
vote
2answers
954 views

Magento 2: Invalid customer attribute in collection filtering

I'm getting a strange error after filtering through customerFactory. Exception #0 (Magento\Framework\Exception\LocalizedException): Invalid attribute name: is_active. private function ...