All Questions
Tagged with collection model
80 questions
16
votes
2
answers
7k
views
Why magento use resource and mysql4 model collection?
What is the purpose of using these two models collection.
Resource
Mysql4
why can't we use resource model for all collections.
Why we are using MySql4 collection for simple module
Some one explain....
15
votes
4
answers
26k
views
Magento - custom (non eav) model, load by multiple fields
I have a custom model and resource model. I want to load a single instance of the model using more than 1 field.
The model has the following fields:
id
tag_name
custom_name
group_name
I want to ...
15
votes
3
answers
2k
views
Efficient Collection Calling, Filtering, and Loading
Right now im reusing a lot of collections that are nested within foreach loops. Is it possible to move these things up a few levels?
Currently Im forced to reload collections that have 51k + entities ...
7
votes
1
answer
45k
views
Custom Sort Order For Collection
I need to sort a collection based on "sort_order" field instead of "id" as shown in the image.
$collection=Mage::getResourceModel('banners/manage_collection');
$collection->getSelect()->order('...
7
votes
3
answers
4k
views
magento 1.9: How to load customers by mobile number [duplicate]
I want to load customer and get his data from telephone number
we have load() methods, to load customer by id as well as we have loadByEmail() to load customer by Email but i want to load customer by ...
7
votes
2
answers
5k
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 ...
6
votes
4
answers
44k
views
Magento 2 Get product collection in a custom template block
I have defined a featured product template in a cms static page as below:
{{block class="Magento\Catalog\Block\Product\ListProduct" template="Magento_Catalog::product/featured.phtml"}}
Now I want to ...
5
votes
5
answers
28k
views
Get quote item collection by using quote item id in Magento 2
I get the quote_item_id like this:
$orderItems = $order->getAllItems();
foreach($orderItems as $orderItem){
$qouteItemId = $orderItem->getQuoteItemId();
}
I need to load quote item ...
5
votes
2
answers
5k
views
Get a Magento product collection without sub-products of configurable products
I want to get a list of all products available in my Magento installation. Currently I am using the following call to filter out enabled products and limit the result set to those products which are ...
5
votes
1
answer
2k
views
FishPig Attribute Splash Pages Extension Bugs [closed]
I'm evaluating the FishPig Attribute Splash Pages extension for a client, and I've run into a few bugs. I've got support requests into the extension vendor, but since it's a free extension I figured ...
4
votes
3
answers
5k
views
Magento 2 addFieldToFilter equal today for datetime field
I have a model with field in datetime format, i want to filter the field with equal today date like this:
$collections = $this->customFactory->create()->getCollection()
->...
4
votes
2
answers
13k
views
Magento 2: What is a Resource Model and how can I use it?
In Magento 1, using a resource model we are getting collections of data:
$products = Mage::getResourceModel('catalog/product_collection');
$category = Mage::getResourceModel('catalog/...
4
votes
2
answers
3k
views
Joining to a Resource Model that doesn't have a Select?
So I have this resource model that I pulled from some admin code on the dashboard. It works, but I can't seem to join to it. Doing ->getSelect()->__toString(); shows nothing? So is this not a ...
4
votes
1
answer
1k
views
_afterLoad() on models when loading collection
I've defined some logic in the _afterLoad() for one of my models. When loading one model using Mage::getModel('foo/bar)->load(1) _afterLoad() is triggered and the extra data values are set. When ...
4
votes
2
answers
500
views
Call to Magento load() to load a model is slow the first time, fast in subsequent calls?
We have a program where we are trying to import Customers and Orders using php into Magento from a non-Magento system via csv files.
In a loop we call this function to get a customer model of ...
4
votes
1
answer
1k
views
One to many relationship in M2
I am working on a module where I have to implement one to many relationship. I have one table for series with id and name field and one table series_product where I have id, series_id, product_id and ...
4
votes
2
answers
1k
views
getCollection return null on custom model collection Magento 2.3.4
I'm creating a custom module to make a model by using mage2gen, I named this model critic:
app/code/Vendor/Module/Model/Critic.php
namespace Vendor\Module\Model;
use Vendor\Module\Api\Data\...
4
votes
2
answers
2k
views
How to use collection factory model in Unit Test magento 2
I have a custom extension with model with structure like this in database:
+----------------------------------+
|entity_id | customer_id | balance |
+----------------------------------+
| 1 | ...
3
votes
3
answers
20k
views
Magento 2 How to get only one field data in collection
I want to get only one field data in my custom module collection. For ex:
getting following data in collection:
Array
(
[0] => Array
(
[banner_id] => 1
[banner_title] =...
3
votes
2
answers
4k
views
addAttributeToSelect Call to undefined method M2
I have two custom modules and am calling one collectionfactory in other module and getting `
Call to undefined method addAttributeToSelect
Collection file look like
class Collection extends \...
3
votes
2
answers
2k
views
Call to undefined method Collection::getData()
I use (Manthan_Marketplace) extension in my Magento store
I want to add a table to this extension
so create a custom table (photos) in Magento database with name:(manthan_marketplace_photos)
Table ...
3
votes
3
answers
4k
views
load method vs getCollection method which is better and faster
Let assume we have 1 record in database and id is 1
we can get record using 2 method load by id and getCollection.
$model = Mage::getModel('stackexchange/questions')
->getCollection()...
3
votes
1
answer
3k
views
Filtering error when using custom Varien object collection in admin grid
I have created a custom Varien object collection for my admin module (because the data is not from a db) and have got it successfully to show in an admin grid. I built the collection by using the ...
3
votes
2
answers
944
views
load customer object update issue in magento 2?
I have used below code in my controller
use Magento\Customer\Api\Data\CustomerInterfaceFactory;
class editPost extends \Magento\Framework\App\Action\Action
{
protected $_customer;
protected $...
3
votes
2
answers
2k
views
What is different between getCollection(); and $product->getData();
What is different between getCollection(); and $product->getData();
$products_collection = Mage::getModel('catalog/product')
**getCollection();
->addAttributeToSelect('*')
->addFieldToFilter('...
3
votes
2
answers
3k
views
Magento Collection Loading Prematurely
I am pretty new to Magento, and am creating a module to integrate third party reviews with a website I am developing.
It's all going well, but I've hit a snag, and I'm at a bit of a loose end with ...
3
votes
1
answer
2k
views
Workaround for Mage::getModel('catalog/product') and foreach loop
Currently used code for retrieving filtered product collection:
$products = Mage::getModel('catalog/product')
->setStoreId($storeId)
->getCollection()
->...
3
votes
3
answers
3k
views
Magento resource Collection override
I have been trying to override Magento resource collection class. I have found few solutions but it seems can't get it to work.
The class is located in:
App/code/core/Mage/Reports/Model/Resource/...
3
votes
2
answers
3k
views
Magento collection classes confusion
I confused by following collection classes
$orders = Mage::getResourceModel('sales/order_item_collection');
$orders = Mage::getResourceModel('sales/order');
$orders = Mage::getResourceModel('sales/...
3
votes
1
answer
148
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::...
3
votes
0
answers
120
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 ...
3
votes
0
answers
5k
views
Magento 2: Duplicate key-sequence unique identity-constraint 'uniqueVirtualType' fatal error while di:compile
When i run php bin/magento setup:di:compile it gives me below error
[Magento\Framework\Exception\LocalizedException] Invalid Document
Element 'virtualType': Duplicate key-sequence
['Custom\...
2
votes
1
answer
8k
views
how to join three tables on every time when model load
I want to join three tables on every time when model load (for example on edit from page, on grid page in admin and detail page in front-end etc... ) in my custom module. can you please let me know ...
2
votes
1
answer
485
views
Convert normal mysql query with math functions into magento model format
I have the following query in MySQL. I need to convert it for magento.
My query is,
SELECT latitude, longitude, SQRT(
POW(69.1 * (latitude - [startlat]), 2) +
POW(69.1 * ([startlng] - ...
2
votes
2
answers
7k
views
Invalid method addFieldToSelect
I have this code
$collection = Mage::getModel("news/views");
->addFieldToSelect('post_id', array('eq' => $this->getRequest()->getParam("id")));
And when i'm trying to save my post i get ...
2
votes
2
answers
186
views
What methods typically go in Model, Resource and Collection
I'm fairly new to Magento, coming from a Symfony/Laravel background. Magento's ORM implementation seems a bit confusing at first. Most resource/collection classes only seem to have a _construct() ...
2
votes
1
answer
1k
views
Mysql query to Model, Resource Model, Collection - Magento 2
I can easily get or set value using ORM. I felt difficult to convert mysql query logic to Model, Resource Model, Collection(ORM).
for example I am getting last one hour data using the below query
...
2
votes
2
answers
2k
views
Parent/child relationship in custom module [duplicate]
I am adding a custom "category" model with children items in my module.
To add children I need to fetch collection from this "mycategories" module. How do I get a collection of categories when adding ...
2
votes
0
answers
169
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 ...
2
votes
1
answer
393
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\...
2
votes
2
answers
98
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
vote
1
answer
2k
views
Magento 2: How many options do I have to use with addFieldToFilter? [closed]
What out-of-the-box logical conditions can I use with the addFieldToFilter method?
$this->addFieldToFilter();
Thanks
1
vote
2
answers
397
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 $...
1
vote
2
answers
2k
views
Get product by name in magento 1.9
How to get product by name? I have the name of the product in my code and iIwant to get product so I use this code :
$model = Mage::getModel('catalog/product');
$product = $model->load('name-of-...
1
vote
2
answers
2k
views
how to merge two collection in magento 1.9
$collection = Mage::getModel("manager/campus")->getCollection()
->addFieldToFilter('regionalmanager',array('finset' => $arr))
->addFieldToFilter('status', array('eq' => ...
1
vote
1
answer
4k
views
Magento 2 - Collection on custom table problem
I created my custom table on magento, with the InstallSchema and InstallData and It works fine, then I created my Model class, initially it seemed to work, because I used the collection in one Block ...
1
vote
5
answers
1k
views
Product Collection won't get all products
I am using a pretty basic product collection but it isn't returning all products in my store. Please find the code below:
$collection = Mage::getModel('catalog/product')->getCollection()->...
1
vote
1
answer
15k
views
Get custom data in item collection array
This is somewhat confusing.. I hope my explanation is clear.
As we all know magento converts a php object(I don't know what it is exactly) to an Array by using:
$item->getData(); // Where $...
1
vote
2
answers
52
views
How to output and filter collection using "->where" filter?
I trying to get output from collection using 'where'
filter but no result.
This is my code:
$collection = Mage::getModel('my_work/datanews')
->getCollection()
->...
1
vote
1
answer
2k
views
How to get sum of particular column (custom model)?
I have custom model with 4 fields(a,b,c,d).
I need sum of "d" field.
So my solution using collection loop the d values and make the sum.For this is any simple solution?
Thanks in advance.
$...