Stack Exchange Network

Stack Exchange network consists of 174 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
20 views

Best seller items in category magento 2

I have used below code to filter products by category id. $_objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $catalog_ids = 4; $productCollection = $_objectManager- >create('...
0
votes
2answers
36 views

Filter sales/order collection according to country

I would like to filter out my home country (GB or United Kingdom) from the following sales/order collection. How can this be done? $orders = Mage::getModel('sales/order')->getCollection() ...
0
votes
0answers
8 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
2answers
35 views

Magento2: get latest Best seller collection

I am fetching Bestsellers like this: protected $_collectionFactory; \Magento\Sales\Model\ResourceModel\Report\Bestsellers\CollectionFactory $collectionFactory, $this->_collectionFactory = $...
0
votes
2answers
39 views

Get Product Collecton by category with filters in magento 2

I need to filter category product collection with Instock items and only simple products. I have used below code to implement it.But the out of stock products also fetching with the collection. ...
0
votes
1answer
39 views

AND inside OR in where condition in getCollections() [duplicate]

Need to generate the following query with getCollection() however unable to figure it out. (id_path = '12/xyz') OR (request_path = '/abc' AND store_id = '1') Tried the following but I need it the ...
0
votes
0answers
27 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 $...
1
vote
1answer
47 views

Magento 2 How to get customer collection from website id?

I want to get collection for customer website wise. I have a website id, and now I want all the customers which belong to that particular website id. I am trying here: using \Magento\Customer\Model\...
0
votes
0answers
30 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
30 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
1answer
17 views

Custom attribute saved but not loaded in collection?

I added a custom attribute is_featured to my Magento 1.7 store. Its a yes/no dropdown. I am setting it to yes on storeview level and to no on the standard level. Now I try to load a collection with ...
2
votes
2answers
28 views

addFieldToFilter `OR` condition for customer relationship in Magento 2

I have a custom module to store customer relationship, with database structure like this: |entity_id|first_customer|second_customer| entity_id => the relationship id first_customer => customer ...
0
votes
1answer
13 views

Magento 1.x addFieldToFilter using AND instead of OR (how can I join search using AND)

I am trying to use AND and OR based on user input. OR = success But I an unable to setup AND queries for addFieldToFilter question: how can I add the second (looped filter) using AND to join $...
1
vote
0answers
27 views

Magento 2: Sub category showing product from other sub category

I have a block class that extends \Magento\Catalog\Block\Product\ListProduct and tried to override the list.phtml with exactly the same file (say mylist.phtml), except it is located under my module. ...
0
votes
0answers
15 views

Magento catalog_product_collection_load_before on product list pages only

I have a module using catalog_product_collection_load_before event. And I want to use it on product list pages only. Not sure why but its being used on single product pages too. config.xml <?xml ...
1
vote
1answer
67 views

Magento 2: How to add where clause in grid collection

I am working on a module, where I have 2 custom tables. One is of all customer who have added product to First table(one customer can add multiple tables) and that first table is displayed on grid. ...
0
votes
0answers
20 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
1answer
53 views

Category collection with filter Magento2

I have created custom Drop down attribute for category with attribute_code is "is_homecategory" Used below methods to create it. Setup/InstallData.php public function install( ...
0
votes
0answers
41 views

magento 2 load resource model by multiple custom fields- equivalent to the addFieldToFilter method

i want to load my resource model by multiple customs fields. i am aware that i can load a collection with multiple field with the addFieldToFilter i.e as follows; $this->collection() -&...
1
vote
1answer
34 views

Magento 2, filter product collection by sku while preserving the given array sequence

Using below code, collection is filtered. If $productSkus array is like Array ( [0] => 5714156000153 [1] => 8690604469871 [2] => 6412616365413 ) after filtering I see the collection is in ...
0
votes
0answers
25 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
0answers
60 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 ...
1
vote
1answer
25 views

How can i get products from a remote database in real time by filters in Magento 2

This request is for an auto parts store. The products are filtered by car make, model, year, etc. When a client apply a filter I need to make an API call to manufacturer server, get products and ...
1
vote
0answers
45 views

How to sort a collection after load

I have a store collection. And it has the following fields [0] => Array ( [location_id] => 5 [title] => Los Angeles [description] => [status] => 1 ...
1
vote
2answers
89 views

Magento 2, addAttributeToSelect not working with product collection?

I am applying these fillers: $collection->addAttributeToSelect('name'); $collection->addAttributeToSelect('sku'); but every time getting full record as comes form: $collection->...
1
vote
3answers
35 views

Product collection by category id, gives zero products

The following code, returns an empty collection in most categories, even if the category indeed has products: $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $...
0
votes
1answer
31 views

Magento 2: Parsing Item information through block

Good day, I want to create a phtml file and create a dynamic block with that one to put on CMS pages - Take it as product information blocks where i want to display the product name, the price, the ...
0
votes
3answers
58 views

How to prevent memory consumption during collection enumeration?

In the following script: $pageSize = 1000; $productCollection = Mage::getModel('catalog/product') ->getCollection() ->addWebsiteFilter($website->getId()) ->...
0
votes
1answer
28 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
16 views

Magento 2 Get product collection filter by atributes does not give the exact match

I have created a filter to get product bellow is an examples: $filter = array( array('attribute' => 'color', 'eq' => '2'),//id of option array('attribute' => 'size', 'eq' => '5'),// ...
0
votes
1answer
21 views

What is the role of visibility filter in colections Magento 2?

I am getting Order Items, from order collection by Order ID but as from the attached screen shot (Order 15) I am getting one product data two times. Can any body explain the reason and what will be ...
2
votes
0answers
23 views

Check if 2 dates already exist in collection filtering

i have a custom collection which has database column start_at and end_at in Y-m-d format , i try to do some validation before inserting to database, one of them is make sure the period between ...
0
votes
0answers
23 views

magento 1 custom report collection initselect issue

I created custom report module named Hs/Paymentreport and Collection file extends Mage_Sales_Model_Resource_Report_Collection_Abstract class. In my collection class file, __construct() method looks ...
1
vote
0answers
95 views

Magento 2 : how can i add my custom filter in custom admin grid

i have created custom admin grid which shows the log of login customer, every time customer login successfully the log will be added in that grid even if same customer, what i want to do is add my ...
1
vote
1answer
21 views

Alter getProduct collection

I need to alter the equivalent of native "getProductCollection", but I don't know how and where to do this. I need the getProductCollection to look like this : public function getProductCollection() ...
1
vote
1answer
52 views

Get all guest & customer email id's in single collection Magento 2

I am trying to list all unique email id's (guest & customers) in admin grid to restrict specific email id to place order. For that, I got an id's from customer collection and order collection. ...
2
votes
1answer
89 views

Magento 2.2.6: Product collection does not apply the filter

EDIT: I have seen that in magento 2 the ListProduct page is cached, for this reason once loaded it does not enter. Is there any way to modify the query returned by ListProduct? I extend the class: ...
0
votes
1answer
56 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
28 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)...
1
vote
1answer
42 views

Duplicate entities in collection

I'm trying to extend Products in carts report grid. I needed to separate products for each customer and add a Customer name column. So for example a product with id number equal to 123 may exist in ...
1
vote
1answer
29 views

unable to solve the error in magento2

I need to solve this below error, Fatal error: Method Magento\Ui\TemplateEngine\Xhtml\Result::__toString() must not throw an exception, caught TypeError: Argument 1 passed to Webkul\Pos\Model\...
0
votes
0answers
22 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\...
2
votes
2answers
72 views

Magento 2 Get Product ViewCount Value By Factory

Trying to get most viewed product view count value, I need to use it in another method calculations. E.g.(if most viewed product view count value is 100 then I need this value to be returned) What am ...
1
vote
3answers
40 views

Error in collections

I had an error like below, Fatal error: Uncaught TypeError: Argument 5 passed to Webkul\Pos\Model\ResourceModel\Agent\Collection::__construct() must be an instance of Magento\Framework\App\...
3
votes
1answer
34 views

How to create a addnametoselect function for custom tables

I need to create an addnametoselect function (like in customer collection) for filtering purpose in the custom collection filter by the fields in custom Table on DB in magento2. Please, anyone, help ...
1
vote
1answer
187 views

Magento 1 - Convert Object into an array value

I was trying to get the information of tracking in the UPS. I got on of the method from the core (app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups.php => method name getTracking($trackings)) that ...
2
votes
1answer
134 views

Magento 2: How to get Customer collection filter by Full name like admin grid?

How to get Customer collection filter by Full name or by keyword like admin grid of magento 2?
0
votes
1answer
32 views

SKU Report for null attribute values

I am getting all product sku's that does not have a attribute value 'image_link'. I have written this code in magento : $products = Mage::getModel('catalog/product') ->getCollection() ->...
1
vote
0answers
28 views

How to get collection from database in phtml not from cache when full cache enabled

I have created an extension which I have uploaded in the marketplace but marketplace rejected due to cacheable="false". <block class="Company\Module\Block\Hello" name="information" template="...
2
votes
1answer
50 views

Group Collection to Filter Unique Products Based on a Specific Attribute

Scenario: A store catalog is populated with configurable products each having several children with different sizes and colors. As the goal is to show the different color variations, only the ...