All Questions
30 questions
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
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
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
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 ...
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
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 ...
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 ...
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 ...
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
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
...
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 ...