Questions tagged [model]
Models contain most of the business logic in Magento modules
777
questions
1
vote
1
answer
55
views
Cannot instantiate abstract class Magento\Framework\Data\Collection\AbstractResource
I am getting this error on my homepage after upgrading my Magento version from 2.4.0 to 2.4.6.
Error: Cannot instantiate abstract class
Magento\Framework\Data\Collection\AbstractResource in
/home/...
0
votes
1
answer
190
views
Magento 2 - Best practices - Helper vs Model : Which one to get config values?
I cannot seem to find an official information about what is the recommended way to retrieve configuration values in Magento 2.
I am searching for the recommended way to retrieve values from the ...
0
votes
1
answer
41
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
3
answers
44
views
Preference Module - When to Pass in Parent Dependencies
I am currently creating a preference module to add additional functionality to \Magento\Catalog\Model\Product and in reviewing some of the tutorials, example below, I noted that dependencies weren't ...
0
votes
1
answer
55
views
Magento2: get values to databse
I'm trying to get values from the popup model of radio buttons into the database and I'm not getting that, what am I doing wrong?
BLOCK FILE
<?php
namespace vendor\ThreeYearOrders\Block;
use ...
0
votes
2
answers
64
views
Override Model File Magento 2
I want to override Magento\PageBuilder\Model\Catalog\Sorting\SimpleOption.php file. Please check the code below,
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:...
0
votes
2
answers
260
views
Magento 2 - Is it bad practice to directly use SQL in php?
We are using a third party module. They have their own database tables and read out data from it by using direct SQL statements
app/code/Company/Foo/Model/Calculator.php
...
public function foo($...
1
vote
3
answers
103
views
Help please , Well configured, but i can't get Model in Magento 1.9.4.5
app/code/local/Info/news/Bock/Adminhtml/news/Grid.php
<?php
class Info_News_Block_Adminhtml_News_Grid extends Mage_Adminhtml_Block_Widget_Grid{
public function __construct(){
...
0
votes
1
answer
54
views
Set function not working on Customer\Visitor model for custom column
I am trying to add new custom columns for now online customer grid.
I have added new custom columns in customer_visitor table, but I am not able to save data in custom columns.
Firstly, I have added ...
1
vote
1
answer
99
views
is it possible to extend the block class in model
Is it possible to extend block class in model? if so, how to do it. please provide me with example. I have inherited model a class from model and i want to inherits class in block using the class i ...
0
votes
2
answers
602
views
Magento 2: How to add new method in core interface?
I need to add new method to the core interface so I was checking all the Magento forums and came to know that this can be achieved via extension attributes as like in the post Magento 2 : Override ...
0
votes
1
answer
228
views
how to create customer using custom rest api Magento 2.4.4
I have to create custom rest api for create customer programmatically in Magento-2.4.4.
so anyone have an idea then share with me.
0
votes
1
answer
121
views
Magento Javascript events
How does one discover which Javascript events exist in Magento 2?
I need to run some Javascript code in an adminhtml form for a custom module. The code should run after the fields are displayed (i.e. ...
0
votes
1
answer
336
views
Append "Add New" button in Grid Listing, on a Form
A custom module has Foo and Bar Models. In the Foo element's Form, there exists a grid listing of Bar items which belong to that Foo. This is an excerpt from the view/adminhtml/ui_component/...
0
votes
1
answer
35
views
In Model Edit, display filtered grid of another Model
Consider two models, Foo and Bar. The Bar model has a non-nullable field foo_id which is associated with a Foo object.
<?xml version="1.0" ?>
<schema xmlns:xsi="..." xsi:...
0
votes
1
answer
48
views
PASS DATA FROM MODEL TO BLOCK
Hello guys i get my data from db with API i want to show data in frontend , i can do this
this is function, that return an array of data.
public function getComputerAttr($customerId) {
$...
0
votes
0
answers
112
views
Customer Session Dont work adequately
i want to get customer id in model, but customer session return null in any case. Someone can help me ?
I also try to get customer id in block but doest work !
0
votes
1
answer
50
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
209
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
60
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
0
answers
513
views
Magento 2 GraphQL How to update custom row
Using Magento 2.4.3 Graphql
Able to get, insert and delete a row from the custom table but unable to update(edit) custom row...
custom endpoints -
mutation {
updateCustomMedia(id:7,
input: {
...
0
votes
1
answer
290
views
Magento 2 - Make fields in custom form required
I created a custom controller and model where users can save bank payment data information.
I added a form where users can change data from the model.
Is there a way to reuse the magento code to ...
0
votes
1
answer
140
views
Magento 2 - store bank payment data
We have a debit payment method where the user has to enter some data like his name, IBAN, BIC and the name of the bank.
I need to store these pieces of information in our database and automatically ...
0
votes
1
answer
447
views
How to override Model file ConvertToCsv in custom module
Here am trying to override a vendor file that is
vendor/magento/module-ui/Model/Export/ConvertToCsv.php
etc/di.xml file
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:...
1
vote
2
answers
1k
views
Magento 2 : Custom Module Admin Grid is not Showing
My Custom module is working in Magento 2.4.0 but when I installed in Magento 2.4.3 version it's showing below error in grid section.
Type Error occurred when creating object: Rh\CategoryGallery\Model\...
0
votes
2
answers
1k
views
Magento 2 - Delete from custom Model
I am trying to delete a record in my custom table (custom model).
I can do it like this:
$mymodel = $this->mycustomFactory->create();
$mymodel->load($id);
$mymodel->delete();
But I ...
0
votes
1
answer
312
views
How to override a method of a class where the method itself is defined in its parent class, and only called in the current class?
I would like to extend the OrderSender class, located at Magento\Sales\Model\Order\Email\Sender\ and then override the method prepareTemplate($order), this method is actually defined in the Sender ...
0
votes
1
answer
4k
views
How to override a method in Magento 2
I would like to override a method of a class, but it does not work. The changes added to the method are not used.
File \Magento\Sales\Model\Order\Email\Sender.php
<?php
/**
* Copyright © Magento, ...
0
votes
2
answers
322
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
321
views
Custom Model not updating in catalog_product_save_after event
I ran into weird issue. I am trying to update my custom model/table in catalog_product_save_after event but it always creates new entry in the DB instead of updating older one.
I'm doing this way :
...
0
votes
0
answers
254
views
Overriding model file of third party extension magento2.3.2: Type Error occurred when creating object
I am using amasty store locator extension. and I am customizing one of the model files of the extension.The file which i want to override is located inside Amasty/Storelocator/model/location.php. But ...
0
votes
1
answer
454
views
Magento 2 admin order grid model filters based on conditions
I have overridden Magento's default order grid controller. I'm trying to apply different filters based on the custom cookie I set.
My di.xml
<?xml version="1.0"?>
<config xmlns:xsi=&...
0
votes
4
answers
4k
views
Magento 2: How to get last inserted custom table Id without saving new item?
I want to get the last inserted id to my block without adding new data into the table. I want to use this value to automatically filled in my phtml file. I tried getId and it's not working. I just ...
0
votes
1
answer
924
views
How to pass current value of Ui form field in js file
I want to pass the value of checkbox in custom js file, I am using UI component to create a chechbox.
So I have to pass this value to js file and then use that value in Model.
I am not able to pass ...
0
votes
1
answer
350
views
Url parameter in magento 2 collection filter
I need to filter Magento 2 custom grid model collection by URL parameter. I have used this below code.
protected function _initSelect() {
$objectManager = \Magento\Framework\App\...
0
votes
1
answer
480
views
Magento 2 call url param in Model Collection filter
I'm trying to get some data that matches the id in the URL. I have a param in admin URL like below.
seller/items/index/id/9/
I'm using the admin UI component which is working fine.
My model code ...
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
1
answer
252
views
Override Model from third party vendor in custom theme
I am trying to override a Model from a third Party vendor in a custom-theme. The original file was:
/vendor/3rdpartyompany/3rdpartymodule/Model/Formatter/BaseImage.php
I copied that file over to:
/...
0
votes
0
answers
122
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
1
answer
460
views
Magento 2: Class instance
When i printed this print_r(get_class($this->getOrder()));
I got this class name
Magento\Sales\Model\Order\Interceptor
What does this actually mean ?
Where is this "Magento\Sales\Model\Order\...
0
votes
1
answer
76
views
Need some brief difference about interfaces and model?
As we know save method by using modelfactory is deprecated i just want to know what is the alternative and how it is implemented because i tried API interfaces but at save i got stuck so kindly anyone ...
0
votes
2
answers
2k
views
Magento 2 :How to override Magento\Sales\Model\Order\Email\Sender.php model?
Is their any way we can override Magento\Sales\Model\Order\Email\Sender.php model in magento 2 module ?
I have created below files
di.xml
<?xml version="1.0"?>
<config xmlns:xsi=&...
1
vote
1
answer
395
views
How to change model data via plugin
How to make a plugin for a model and turn one of its fields into a different value.
For example, in the documentation, they make an after plugin for the model and return a different value.
public ...
0
votes
1
answer
372
views
ResourceModel->delete() not deleting row in custom table
I am writing a module which imports additional product information into a custom table with SKU as the PK.
If there is already a row in the custom table regarding the SKU, i have to delete the old row ...
0
votes
0
answers
57
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
0
answers
447
views
How to get custom table from data fetch by form id in magento 2.3.1
How to get custom table form table by form_id for custom table in magento 2.3.1?
try this but it's not working
custom table screen short:
Vendor\Module\Block\Form.php
<?php
namespace Vendor\...
1
vote
1
answer
2k
views
Magento 2 Category Tree With Multiselect and Text box in Custom Page
I am looking solution to get a Category tree on a custom page and parallel a text box, where the admin user could add some text and in parallel, he can select multiple categories. After adding text ...
0
votes
1
answer
62
views
Getting current page type in model?
Magento 2.3.4
Is it somehow possible to get the current page in a model? I am using some sort of page speed optimizer and want to disable some of its features on the product page. I checked the code ...
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 ...
1
vote
4
answers
4k
views
Magento 2 - Check if record with certain value already exist in table before creating it
I created a new table company_shipping_quote.
I am writing data into it like this:
$quoteId = $quote->getId();
$html = $this->_generateNote($expressRule);
$quoteModel = $this->...