All Questions
Tagged with collection model
80 questions
0
votes
1
answer
48
views
Argument 5 passed to Vendor\Module\Model\ResourceModel\PriceResult\Collection\Interceptor::__construct()
I have created a custom module and it's working fine,if I only run php bin/magento setup:upgrade command. However, when I attempt to run php bin/magento s:d:c it raises an exception.
Type Error ...
0
votes
1
answer
56
views
Where should I connect model-data-access?
I am building a custom feature to create lists of favourite products.
For this purpose I have created 2 models: The actual list-entity and a model representing information about a single product.
For ...
0
votes
1
answer
256
views
Extending custom interface and data model
I have successfully created a custom interface.
My model: app/code/Vendor/Samples/Model/Orders.php
class Orders extends \Magento\Framework\Model\AbstractModel implements OrdersInterface
{
...
0
votes
1
answer
76
views
Magento2: How to add data in child table?
I have a custom module with named A and db tab is z ok.
now question is my:
How to add child table? which is already I have done with PK and FK key constrains.
How to add data in created child table ...
0
votes
2
answers
397
views
Magento 2 applying filters to collection reflects in all phtml
I have applied a filter in a PHTML that loads in headers. The filter is below.
In Constructor:
\Magento\Catalog\Model\ResourceModel\Category\Collection $collection
Block Code:
public function ...
0
votes
1
answer
1k
views
Get specific columns from Left Join
I am trying to join two tables like below
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$collection = $objectManager->get('Advance\Module\Model\Method')
->...
0
votes
0
answers
143
views
Not able to add filters on getItemsCollection in admin order page
I am implementing a feature, where I need to filter the order item list in order admin page. I have checked and found the list is getting from method getItemsCollection(). But when I am trying to ...
0
votes
0
answers
93
views
Cannot Assign Param Value in Model Collection. Magento 2
I'm currently Facing a really strange Issue I'm applying filter on my custom table data in grid by adding function
Vendor/Module/Model/ResourceModel/Withdrawal/Grid/Collection.php
protected function ...
0
votes
2
answers
2k
views
Magento 2 - How to properly load quote model by quote id?
I used to load the quote like this:
$quote = $this->quoteModel->load($quoteId);
But now I get a warning in PhpStorm saying that this method is deprecated:
Deprecated:
100.1.0 because entities ...
0
votes
1
answer
386
views
Load Customer Model by Extension Attribute in Magento 2
How can I load the Customer Model and Collection by Extension Attribute in Magento 2?
I've declared an extension attribute in extension_attributes.xml and saved to the Customer Model. Now, How can I ...
0
votes
2
answers
469
views
Magento2.3: How to collect the data by time?
I want to collect the records from 10PM to 5AM of wishlist data. I have already created a module and not sure how to filter the records by this timeframe.
The wishlist table contains a field called ...
0
votes
1
answer
588
views
how to set group by and order by for custom model collection query in magento 2.3.4
$Custommodel=$this->mycustommodelFactory->create();
$collection = $Custommodel->getCollection()->addFieldToFilter("customer_id",$customerid);
$collection->getSelect()->group('...
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\...
0
votes
1
answer
761
views
Magento 2: Ui Component - Magento\Customer\Model\Session can't return current customer
I've got an issue using ui component on front in a large module.
The model I'm using for my grid is used at several other points.
But I discovered my configuration in di.xml is doing some strange ...
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
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 $...
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 ...
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 ...
0
votes
1
answer
669
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()
->...
0
votes
3
answers
3k
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 ...
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
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
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] =...
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 ...
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 ...
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
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 | ...
0
votes
1
answer
6k
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');
$...
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 ...
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\...
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::...
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-...
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/...
0
votes
1
answer
44
views
How to merge two getmodels
I want to merge two Model results in a variable to use it in the register. There's a way to do this?
$commercial = Mage::getModel('thorleif/commercial')->load(1);
$lcat = Mage::getModel('...
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
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 ...
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 ...
1
vote
1
answer
1k
views
Magento 2: How to get shipment collection on phtml?
I'm trying to get the shippment collection on popup.pthml, but not able to get.
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$shipmentCollection = $objectManager->get('...
1
vote
0
answers
883
views
How to load a model with relationships via repository in Magento 2?
Background story:
I was trying to load a model with model_store relationship using this snippet. I failed to do that with my own model. Model is being loaded without store data. Some debuging later I ...
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' => ...
0
votes
1
answer
255
views
Magento: A question about collection LIMIT by the way "Zend Db limit"
There are several ways to limit collection for magento you could find here Magento: Set LIMIT on collection.
I tried the best answer, both ways work well.
But when I am trying, I met a question is ...
0
votes
0
answers
456
views
How to add another model collection data to an array. [Magento 1.9]
I have response collection $customerData, I have to add referral code of selected customers in the same array,
Model and field of referral code is :
$referCustomer = Mage::getModel('...
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\...
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 ...
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()...
1
vote
1
answer
293
views
Magento 2: Guide for All Collections
For now, I'm not able to find any guide for this. If I need to get all collection say for Example all Orders List
so I will go to Vendor Magento Folder, Particular Module's di.xml file & checking ...
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 ...
1
vote
1
answer
529
views
Magento: Which is optimized way to get single record? [duplicate]
load by Id
$data = Mage::getModel('module_name/model)->load($id);
or
//collection by filter
$data = Mage::getModel('module_name/model)->getCollection()->addFieldToFilter('id',$id);
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
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() ...