Questions tagged [collection]

Questions related to Magento collections

Filter by
Sorted by
Tagged with
1
vote
3answers
33 views

Magento 2 + custom eav field value store in array

I have a custom eav structure and there is store_id save in array format in the database field. I need to filer collection with addFieldToFilter with store_id. $collection = $this->...
2
votes
0answers
9 views

How to create a pagination on product page for the reviews

I am trying to create pagination on product page just to keep the review down. I have over 50 reviews for product is there anyway I could limit it to 10. Is there anyway I could follow some codes or ...
1
vote
1answer
23 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 "...
2
votes
6answers
439 views

Date Range filter not working in custom Grid Magento 2

I have created the custom sales report using ui component. Grid is loading correctly. I have added the date range filter as like below. <column name="created_at" class="Magento\Ui\Component\...
0
votes
1answer
81 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
38 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-&...
1
vote
2answers
34 views

difference in result of count and getSize()

I am preparing the product collection as follows $visibleProducts = $this->catalogProductVisibility->getVisibleInCatalogIds(); $collection = $this->productCollectionFactory->create(); $...
2
votes
1answer
25 views

Magento catalog price rule

How to get product based on conditions on catalog rule in magento2? By product model products are received but how to apply filter to get only those product based on conditions. Any help will be ...
0
votes
0answers
31 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.
1
vote
1answer
38 views

Magento 2: How to add multilevel AND and OR conditions to searchCriteria?

What i want to achieve is this - attr1 = 'val1' AND attr2 = 'val2' AND ((attr_s1 = 'val_s1' AND attr_d1 = 'val_d1' AND attr_t1 = 'val_t1') OR (attr_s2 = 'val_s2' AND attr_d2 = 'val_d2' AND ...
0
votes
0answers
27 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 `...
3
votes
1answer
57 views

Magento 2 Updating Other Products in catalog_product_save_after event Observer

I had created an Observer of this event:catalog_product_save_after I am trying to update other products and loading them on the basis of their id, but it is giving me an error. I am Sharing my code ...
0
votes
1answer
35 views

Magento 2: How to get sub category and their products in collection?

I want to get the categories and related products in collection using parent category ID. So that i can show the grid like sub category 1 sub category 1's product 1 sub category 1's product 2 sub ...
3
votes
2answers
64 views

collection, get product image

Sorry for my English I have this code $productCollection = Mage::getModel('catalog/product') ->getCollection() ->addAttributeToSelect('short_description') ->...
2
votes
1answer
27 views

Difference between $this->getData() or $this->getResource()

In my Collection.php when i get the collection by $this->getData() is give me collection. But it create some other problem for me . Now i use $this->getResource() then problem solved But it ...
0
votes
2answers
32 views

Magento 1 | how get product attribute data

Sorry for my English. I have this code. $productCollection = Mage::getModel('catalog/product') ->getCollection() ->addAttributeToFilter('attribute_set_id',array(12,4)) ...
0
votes
1answer
14 views

Magento1 | Collection how get all products where qty > 1, build query

I have this code $productCollection = Mage::getModel('catalog/product') ->getCollection() ->addAttributeToFilter('attribute_set_id',array(12,4)) ->setPageSize(...
3
votes
1answer
35 views

Magento 2: Getting unknown category

I am trying to get a level 2 category list. I got all level 2 categories but I am also getting 2 unknown categories which are not in backend. This is weird. Here is my code public function ...
0
votes
0answers
22 views

Difference between Magento Collection ,object , array

Please clear the main difference between Magento Collection , object , array and arraylist also ?
0
votes
0answers
21 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
1answer
79 views

recently viewed product collection is empty in magento 2

I have added a code in Magento_Catalog/layout/catalog_product_view.xml <referenceBlock name="product.info.details"> <block class="Magento\Reports\Block\Product\Widget\Viewed" name="...
1
vote
1answer
29 views

How is a product name retrieved if the query does not return it in the result set?

I'm trying to get data from catalog_product EAV tables with the following code: $productCollection = Mage::getModel('catalog/product')->getCollection() ->addAttributeToFilter('...
0
votes
1answer
25 views

Why magento2 outputs the query while showing data from ResourceModel collection Factory..?

protected $productCollectionFactory; public function __construct( ..... \Custom\MyModule\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory, ... ) { ...
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
61 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
37 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
44 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 ...
2
votes
1answer
86 views

Magento 2 - All products attributes updated after update from collection

I have got collection in $collecction from Magento\Catalog\Model\ResourceModel\Product\CollectionFactory with some certain conditions I am updating a custom attribute viewed_count in foreach loop ...
0
votes
0answers
24 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.
2
votes
1answer
80 views

Magento 2 - Need to filter comma seprated 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
3answers
82 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
18 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() ->...
0
votes
1answer
55 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
28 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 `...
3
votes
1answer
97 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 ...
1
vote
1answer
29 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
20 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 ...
1
vote
0answers
50 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', ...
3
votes
2answers
217 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 ...
2
votes
1answer
66 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
1answer
38 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
25 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\...
0
votes
0answers
71 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
45 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(...
0
votes
1answer
50 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 ...
2
votes
0answers
158 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/...
1
vote
2answers
81 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 $...
0
votes
2answers
73 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 ...
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
189 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) { $...