Questions tagged [collection]

Questions related to Magento collections

0
votes
0answers
83 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
451 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
89 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
134 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
25 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
33 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 ...
-1
votes
1answer
19 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
32 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. ...
1
vote
1answer
393 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
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="...
1
vote
1answer
685 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( ...
1
vote
1answer
168 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
47 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
223 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
29 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
205 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
411 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
66 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
115 views

Magento 2: Parsing Item information through block

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 URL - ...
0
votes
3answers
145 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
80 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
148 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
35 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
44 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 ...
1
vote
1answer
22 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
158 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
220 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
189 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)...
1
vote
1answer
98 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
60 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
69 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
116 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
63 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
45 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
372 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
257 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
66 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
51 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
123 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 ...
0
votes
0answers
17 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
1answer
60 views

Mysql FULL JOIN in magento 2

How can i execute something like full join in magento 2 then set query data in my collection. Below i try to do somethig. $joinLeftCustomerSql = $connection ->select() ->from("$...
0
votes
0answers
24 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->...
1
vote
1answer
122 views

Magento2 | MassAction Filter instance none given

I'm getting strange error when I want to use mass action in a grid : AH01071: Got error 'PHP message: PHP Fatal error: Uncaught TypeError: Argument 2 passed to Toto\\Helloworld\\Controller\\...
0
votes
2answers
347 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 ...
2
votes
1answer
514 views

how to retrieve Coupon Code by rule Id on Checkout Success Page?

I have coupon rule collection created at admin side and displaying rule names in the system configuration of the custom module. Actually, I wanted to get coupon code of a cart rule that has been ...
1
vote
0answers
154 views

override getLoadedProductCollection of \Magento\Catalog\Block\Product\ListProduct

I am overriding getLoadedProductCollection() in my block where performing some custom query public function getLoadedProductCollection() { $myCategory = $this->...
1
vote
1answer
356 views

Magento2: How to get product collection by attribute or category id?

How to get product collection by multiple attributes? Magento 2.0
0
votes
2answers
662 views

Magento2 how to modify admin grid collection using ui component

You guys would be knowing that usually, we are using core Magento DataProvider while creating admin grid using UI component. Sometimes, we need to add some filter or modify the basic grid collection ...
0
votes
1answer
156 views

Remove item from category collection in Magento 1.9

I have a category collection in Magento 1.9 This is my code :- $categories = Mage::getModel('catalog/category') ->getCollection() ->addAttributeToSelect('*') ->...