Questions tagged [collection]

Questions related to Magento collections

Filter by
Sorted by
Tagged with
1
vote
1answer
86 views

Collection Sort Order in Text Field - Same values are ordered randomly

I am sorting a custom collection by a text field EAV attribute (UMC was originally used to scaffold the module which has been heavily modified since). $myCollection->setOrder('my_name', 'ASC') ...
3
votes
2answers
646 views

How can I get collection result “column headers” or “column names” in Magento 1.9x?

How can I get collection result "column headers" or "column names" from query? Suppose I have $data = Mage::getModel('catalog/product')->getCollection(); and I have some joins with other tables I ...
1
vote
3answers
4k views

Magento2: load attribute using attribute code

I am using the below code to load the attribute using attribute code but it's not working:- protected $_attribute; public function __construct( ... \Magento\Eav\Model\ResourceModel\Entity\...
0
votes
1answer
678 views

Clean way to add media gallery images to product collection

I have to display small images of products loaded by collection. Problem is (I think it is), that products (coming from collection) by default doesn't containt any images within. I have tried ...
0
votes
1answer
172 views

Magento 2.2 error when tried to load product or order in external file

I tried to load a product or an order form an external file using Object Manager but everytime i receive the same err: "PHP message: PHP Fatal error: Uncaught Magento\Framework\Exception\...
1
vote
0answers
389 views

How to Filter Attribute Set, Attribute option value and filter by manufacture in product export

Change into app/code/local/Mage/ImportExport/Model/Export/Entity/Product.php on line 647 in funtion export() $collection = $this->_prepareEntityCollection(Mage::getResourceModel('catalog/...
1
vote
0answers
188 views

Incorrect product count in layered navigation filter while sort using custom collection

I have an issue with layered navigation filter count. I have changed the product collection of sort, everything is working fine except the product count. Can anyone help. Toolbar.php class ...
2
votes
3answers
857 views

Export simple product using script in magento2 [closed]

How we get simple product collection with visibility 4 (catalog/search) with script in Magento 2?
0
votes
1answer
3k views

Convert model collection to json_encode

Currently I'm converting my collection data to json_encode like this: $collections = $this->modelFactory->create()->getCollection() ->addFieldToFilter('status','1'); $...
1
vote
1answer
618 views

How to limit the product reviews shown in product page in magento 2

I have created review form as popup modal, And I have also removed reviews tab in product page. And I have created new section before footer which contains the collection of customer reviews which is ...
6
votes
3answers
5k views

Magento 2 - Layered Navigation for Custom Product Collection

I created a CMS page for products that contain a certain attribute (On Sale Items). I extended the ListProduct class and added filters to the product collection to achieve the desired results. (...
1
vote
0answers
234 views

removeItemByKey not working in product collection - Magento 2

I have a product collection (\Magento\Catalog\Model\ResourceModel\Product\Collection $collection), I try to remove some of the item from the collection by using below code. foreach ($collection->...
3
votes
1answer
1k views

How to get product rating collection in magento 2

I need to get product rating collection in block, and need to display it in template.Please provide me a solution
1
vote
1answer
323 views

Magento 2.2 product collection doesn't return out of stock products

Magento 2.2.* seems to make it very difficult to get out of stock products in a collection! I have the following code which works fine in Magento 2.0 and 2.1: use Magento\Framework\View\Result\...
0
votes
1answer
551 views

Left join on custom collection, to get product name by product ID

There's a collection which contains product ids. I'd like to join it with the magento table that stores paroduct names, in order to add product name to collection. $collection = Mage::getModel("...
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-...
1
vote
0answers
96 views

getCollection()->getSize() not returning correct number of records

getCollection()->getSize() not returning correct number of records. Here is my code : /** @var $collection Mage_Reports_Model_Resource_Report_Collection */ $collection = Mage::...
3
votes
0answers
59 views

Magento 2 : How to get top 10 repeated values in a column using CRUD instead of sql?

I want to get top 10 most repeated values in a column of my table, I can do so using sql but I need to do it using CRUD i.e using collections or model as magento coding standard doesn't allow naked ...
0
votes
3answers
2k views

How to get the all the reviews of the product posted by the customer in magento 2

I have removed review tab and placed my review form as a popup modal in product page.How to get the all the reviews of the product posted by the customer in Product page.Now I need to get all the ...
0
votes
1answer
55 views

Where condition in the collection issue in M1

This is my collection: $blacklist = Mage::getModel('mynamespace_mymodule/customers')->getCollection() ->addFieldToFilter('store_id', $order->getStoreId()) ->...
1
vote
1answer
629 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, $...
6
votes
1answer
1k views

Magento2.2 getCollection from Factory deprecated

I get in my editor (PhPStorm) on getCollection the message that it is deprecated. In my controller i got the function public function __construct( Registry $registry, ...
2
votes
1answer
934 views

Magento 2 Sort Reviews by rating

I want to add sorting in Review Listing. What is the logic to add Sort by ratings? I have override method getReviewsCollection() of Magento/Review/Block/Product/View.php So I have $this->...
0
votes
1answer
137 views

How to replace searchable column “store_id” to “website_id” into Sales/Orders admin grid?

I want to filter the orders by website (rather than store ID) I have tried to remove: $this->addColumn('store_id', array( 'header' => Mage::helper('sales')->__('Purchased ...
2
votes
0answers
1k views

Magento 2 filter not working on custom column

Magento 2 Filter is not working. In the below code column created through layout xml are getting filter, but on column created via column class file filter is not working. I have found that one ...
1
vote
0answers
566 views

Magento 2: Delete duplicate products programatically

I need to search Magento 2 DB for duplicate SKUs and remove duplicate products using a script, i found a very useful script here: Remove duplicated products from catalog. but it's not compatible with ...
2
votes
1answer
288 views

Magento 2 model error after updating on 2.2 verison

I have a CRUD module created on magento 2.1.6 version which was working ok untill i updated magento to version 2.2.1 Now when i compile my code i receive the following err: namespace\module\Model\...
0
votes
1answer
71 views

Magento2 di in ResourceCollection

I have the fallowing collection and I want to pass the ProductFactory so it can be accessible in my collection. class Collection extends AbstractCollection { public $productFactory; ...
2
votes
0answers
275 views

Join table to get the detail of customer, customer ordered item, and the item product

i'm following this tutorial to create the grid for custom report, and to get the collection there's a function which accept the from date and to date like this: public function setDateRange($from, $...
1
vote
0answers
144 views

Magento 2 Add 'Remove out of stock' filter in category page and search results page

I have to add 'Remove out of stock' filter on the category page and search results page. By default i m displaying all products which is in stock or out of stock. Any suggestions please? i m not ...
1
vote
3answers
2k views

can't filter collection by custom attribute

I have a custom attribute called parent_sku, I setted it to yes in Product Listing from the backend menu, and almost all the products have a value in this attribute. I tried: $subCollection = Mage::...
0
votes
1answer
707 views

How to filter product collection using 2 or more category filters in magento2?

How to filter product collection using more than two category. In magento1, we can use ->addAttributeToFilter('category_ids',array('finset'=>'36,37')); but how can i do this in magento2? Also i ...
2
votes
1answer
1k views

Magento 2 : Reset filters in a collection such as addFieldtoFilter, addAttribute to filter etc

I want to deploy following logic ; - Load product collection *start loop* - Extract the value with which I filter collection. - Filter based on above attribute to see if the product is there. ...
3
votes
2answers
4k views

Get product collection by store ID on Magento 2.2

I want to get all products by store ID, so I'm doing it like this return $this->productCollection->addStoreFilter(27); productCollection is Magento\Catalog\Model\ResourceModel\Product\...
0
votes
1answer
290 views

How to get pending products in magento 2

Here I added one product per customer function works well. But if payment is canceled or pending also this works. I need this to work only when order status is pending or canceled but shouldn't work ...
2
votes
0answers
64 views

Magento2 Custom Module Backend - Pass ID FK from GridView Master to GridView Details

I have to pass a FK parameter from GridView Master to GridView Details. GridView Master (GVM): GridView Details (GVD): PROBLEM: After click on 'Questions' on GVM for ID = 22, in GVD is showed all ...
2
votes
0answers
233 views

convert direct sql to collection in magento 2

How we can convert direct SQL query to collection ? SELECT wk_mpauction_winner_data.auction_id, wk_mpauction_winner_data.customer_id, quote_item.created_at AS quote_item_date ,sales_order_item....
1
vote
2answers
920 views

Create customer programatically using setData

i have a dynamic data array which contain customer data, the data inside the array will be variative, thats why i'm using setData function to insert the customer data to customer model like this: $...
0
votes
1answer
483 views

Get collection not working but query does

I don't know why this: $attributeCollection = Mage::getResourceModel('myext/attributelist_collection') //$attributeCollection = Mage::getModel('myext/attributelist')->getCollection() ->...
0
votes
2answers
313 views

Toolbar.php collection filtering using getCollection and addCategoryFilter not working

I am using Magento 1.9.3.6 CE I want to add a select dropdown on the toolbar of product lists on category pages to filter the collection by a subcategory. (sidenote: I can't use the normal catalog ...
0
votes
1answer
304 views

Magento 2: Same collection on listing page

I have some weird problem Here is my code that write in afterGetPrice() function, I am using plugin here to change price of product based on my custom table $customPrice = $this->...
0
votes
1answer
324 views

Magento 2 - AddAttributeToSelect(“customattr”) only returns products where customattr is not null

I have added an extra sort by option to my magento 2 store which uses the price divided by a unit_of_sale attribute to sort the catalog by an each price. The sort works in a lot of categories from ...
6
votes
1answer
6k views

How to get Best Selling Product Collection in Magento 2 using Object Manager

How can I get "Monthly Best selling product" in Magento 2?
1
vote
2answers
1k 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 ...
6
votes
4answers
5k views

How to solve admin grid error?

I am getting this error in admin custom module of Magento 2. Something went wrong with processing the default view and we have restored the filter to its original state. admin grid error.
1
vote
1answer
69 views

List of customers in customer groups

I have around 80 different customer groups, with different prices on. How can I find out how many customers are in any given group? Can I make a list of all customers included in customer group? I ...
5
votes
1answer
4k views

Filter product collection by sku or name

I have a variable which containing value to filter both name or sku, i tried to filter the product collection using this variable like this: $queryName = 'bat'; $category = $this->_categoryFactory-...
3
votes
1answer
103 views

Filter collection value from another value from another index

I create a custom attribute last_sync for customer custom attribute, i need to filter it if this attribute is null OR greater than created_at, right now i'm using code like this: $collections = Mage::...
0
votes
1answer
87 views

Magento 2 - Creating collection triggers print_r or var_dump

Whenever I call the create() method on my custom collection, the page just displays a print_r (or a var_dump, I don't really know) of the entity that is related to the collection. Also it looks like ...
3
votes
2answers
355 views

Magento2 Collection Multiple Columns as OR

I want to do something very simple, have a collection that returns all customers that have a certain string in their name or email. Based on how you can use in, I thought I would be able to do ...