Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [model]

Models contain most of the business logic in Magento modules

4
votes
2answers
102 views

Magento 2: When should we use a ProductRepository, ProductFactory, Product model?

When should we use a ProductRepository, ProductFactory, Product model? vendor/magento/module-catalog/Model/Product.php vendor/magento/module-catalog/Model/ProductRepository.php generated/code/...
0
votes
1answer
12 views

How to add a pay until date to invoice in Magento2?

Please excuse me if I am asking a dumb question, but I am new to Magento and frankly, my first impression is that it is over-designed and poorly documented. Maybe this is part of their business model, ...
0
votes
1answer
16 views

What to replace deprecated Class 'Zend_Rest_Client' with in Magento 2.3?

A module I'm maintaining is not working on Magento 2.3 since Magento apparently deprecated Class 'Zend_Rest_Client' . I don't see any replacement Client listed in their documentation, so I'm a bit ...
-1
votes
0answers
19 views

add multiple filters in model data in magento 1.9

I want to apply the filters to the model file without collection in model file. Means when I load model like this Mage::getModel('modulename/modelname')->load(id) filter should be apply directly ...
0
votes
2answers
22 views

How to resolve “Model LSD method save() detected in loop” in magento 2?

I am getting a warning as a "Model LSD method save() detected in the loop" when I did MEOP2" The issue is on below the line $model->setData($finalData)->save(); Please anyone can help me to ...
1
vote
1answer
43 views

Magento 2.3. How to add data using model?

I have two variants adding data using Model. Which variant is more rignt ? Especially I want to ask about this $slider->setDataChanges(true);in first variant because I must set up _hasDataChanges ...
2
votes
1answer
21 views

factory class duplicate insert check in magento2

I have created a model class as like below. Vendor\Module\Model/Bulider.php namespace Vendor\Module\Model; use Magento\Framework\Exception\QualificationException; class Builder extends \Magento\...
1
vote
1answer
22 views

Magento 2.2 - Fatal error: Uncaught Error: Call to undefined method Magento\Framework\App\ResourceConnection::load()

Fatal error: Uncaught Error: Call to undefined method Magento\Framework\App\ResourceConnection::load() in /var/www/html/magento2_dev/vendor/magento/framework/Model/AbstractModel.php:536 Just adding ...
3
votes
0answers
38 views

How to load Ui-component form data using another column instead of primary field Magento 2?

I have created a form using Ui-component it is working fine while adding new form & edit form. But I would like to do customization as per my requirement. Default Magento Ui form data is display ...
1
vote
1answer
35 views

How to use resultJsonFactory in Model file magento2

I have used below code to print response from my Model file. <?php class CountrylistManagement implements \Vendor\Module\Api\CountrylistManagementInterface { protected $_storeManager; ...
0
votes
1answer
29 views

Magento 2: Get order ID and Date in DHL Shipping Carrier model

I have a requirement to attach the order ID and order date to the xml request (ShipmentRequest) located in /magento/dhl/model/Carrier.php Is there a way to retrieve the order ID linked to this ...
1
vote
0answers
25 views

How can I change multiple entries in DB?

In DB I have Rows: ID NAME PHONE Example: 1 Steave 33333333 2 Joe 77777 I can add and Edit any row, but I want when I click "save everyone" I rewrote all phones on DB example: 1 Steave 33333333 ...
0
votes
1answer
23 views

Magento 2 : Only dependency assignment operations are allowed in constructor. No other operations are allowed

Magento 2 Coding standard provide me Warning My Code is here namespace Namespace\Modulename\Model; use Magento\Framework\App\Request\DataPersistorInterface; use Magento\Ui\DataProvider\...
1
vote
2answers
60 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
0answers
42 views

di.xml ExtensionPool create/read handlers Conflicts

I am creating extensionpool handlers to save data in multiple tables. There are total 3 tables : 1 : Sliders 2 : SliderItems 3 : SliderSelectedItems When I create/update Slider, list of selected ...
1
vote
1answer
35 views

KnockoutJS Which Model does the Minicart use?

So, i'm very new when it comes to using KnockoutJS but i've been doing some reading around it and to my knowledge each template file has its own corresponding model. However, as i'm looking through ...
2
votes
1answer
67 views

Magento 2 - Difference between Model, ResourceModel. Collection and Repository

I'm studying Magento and I'm confusing about the differences between these four layers. What I have understood is the following: Model Is the entity class with ONLY getters/setters and magic methods....
0
votes
0answers
26 views

Unable to override model class, only this file has problem

I am overriding Worldpay Model class that create xml request file. <?xml version="1.0" encoding="UTF-8"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:...
0
votes
2answers
33 views

Magento 2 Model Classses are not injecting without Factory in custom module

I am developing an module in Magento 2.I have created helper,Model Fatal error:vendorname\modulename\Model\Testclass class is not exist.I have tried each and everything to resolve this issue but ...
0
votes
2answers
28 views

Error on constructor of a class that extends \Magento\CatalogRule\Model\Rule

Im trying to do a model that extends \Magento\CatalogRule\Model\Rule, but in the contructor the context is giving me a warning: Declaration of overridden method should be compatible with parent class....
2
votes
1answer
48 views

Magento 2.3 - The correct way to get custom attribute

I have added the custom attribute referral_code of type static to the customer entity. The attribute showing up correctly, and I can get/set it in easy way with $customer->getReferralCode() and ...
2
votes
2answers
102 views

How to use a Magento 1 model to update multiple rows?

I am processing some records and I need to set a datetime field to the current time for multiple rows. I have all the row IDs. What's the best way to do this with Magento 1? The SQL would be like this:...
1
vote
1answer
95 views

Magento 2 + Fatal error save() must be an instance interface not a model

Trying to save record in admin grid with create API interface but getting fatal Error link below Fatal error: Uncaught TypeError: Argument 1 passed to Mage2\Inquiry\Model\InquiryRepository::save()...
0
votes
1answer
99 views

How to add expression in collection query magento 2?

I want to write this query into Magento 2 formate SELECT vendor_id, vendor_name, ( 6371 * ACOS( COS( RADIANS( 45.4102961 ) ) * COS( RADIANS( vendor_latitude ) ) * COS( RADIANS( vendor_longitude ) ...
1
vote
1answer
74 views

Getting error after adding arguments in constructor

I have added model in my constructor public function __construct( Context $context, PageFactory $resultPageFactory, \Vendor\Module\Model\Productsgrid $model ) { $this->model = $...
3
votes
1answer
89 views

How to fix this “Running schema recurring.Unique constraint violation found”

How to fix this error "Running schema recurring.Unique constraint violation found". This statement occurs when I used upgrade command of Magento 2 model upgradation.
0
votes
1answer
16 views

Can a product's attribute store several values for the same product or do I have to do something else (Magento 1.9)?

I will explain with general terms the situation: I have some products which should have 1-8 values for the same attribute and in the same product. For example: SKU 55720, Name of Attribute: Norm, ...
6
votes
2answers
111 views

Proper way to call a model constant in Magento 1

I have the class below: class Company_Module_Model_Somemodel extends Mage_Core_Model_Abstract { const SOME_CONST = 'constant_text'; } What is the proper and correct way to call the constant ...
0
votes
1answer
53 views

Magento 2 - Add a new product attribute with values from DB

I'm looking for creating a custom attribute for products, already have a CRUD module, with name and descriptions fields, so the names from my DB should be options of that attribute. How do I need to ...
0
votes
0answers
26 views

Magento 2 Query in custom model file not working

I am working on the Magento 2 custom model file, my table name is custom_log, then I have created the following model file in my module directory. Test/Customlog/Model/Log.php namespace Test\...
0
votes
1answer
25 views

Which one is the difference between Product and ProductRepository?

In Magento 2, which one is the difference between Magento\Catalog\Model\Product and Magento\Catalog\Model\ProductRepository? Using both of them, seems they have the same methods, so I don't know when ...
0
votes
1answer
132 views

How to get products from wishlist using customer id

Magento 2.3 PHP 7.1 I trying to get products from customer wishlist in Model but $products array is empty. $products = []; $items = $this->wishlist->loadByCustomerId(1, true)-&...
0
votes
0answers
51 views

I need to create a new module to table exists with another prefix of mam

I need to create a new module and this project have tables with other prefixes, How I omit this default prefix in my file /Model/ModelTable.php this is the code inside: namespace Arkix\Zonas\Model\...
1
vote
2answers
57 views

Magento 2 + How to import the custom city collection from the database into a dropdown (for the city textarea)

I'm a bit confused with creating a city dropdown with my custom cities. I have already imported the cities into a table and also created the Model, ResourceModel, Collection. Now I need to get those ...
2
votes
2answers
142 views

getItemById($itemId) for Magento Quote Model not working as expected in Magento 2

Here is my code, where I'm calling Quote model file and getItemById function. public function __construct( \Magento\Quote\Model\Quote $quote ) { $this->quote = $quote; } ...
1
vote
0answers
17 views

How to save lines of my custom object via API?

I have the next JSON example and I need to save this with a model via POST. The problem is how to save the field lines of this JSON... { "sizeCurves": { "external_key": "...
0
votes
1answer
95 views

Call to a member function beginTransaction() on a non-object when deployed to live

On my laptop everything works fine but when I deploy to our live test server I get: Fatal error: Call to a member function beginTransaction() on a non-object in /var/www/html/magento82/app/code/core/...
0
votes
1answer
94 views

Magento 2 How to use model function in phtml file When override phtml?

I want to override book.phtml file from my module and want to check if my module is enabled or not. if module is enabled then need to hide links and button from that phtml. I have module function as ...
0
votes
0answers
30 views

How can I get rows from the eav_attribute_option_swatch table

How can get some rows from the eav_attribute_option_swatch table ? Is there a model that I can use, if so how do i use it. Maybe there is something like get entity by id. (I have the option_id of ...
2
votes
2answers
32 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 ...
0
votes
1answer
145 views

How to get url parameter in model

How to get url parameter : at this file app/code/Vendor/Module/Model/ResourceModel/Module/Grid/Collection.php My Url is like this http://192.168.2.215/mtheme/admin/vendor_module/index/details/id/1/ ...
0
votes
1answer
32 views

Developer to Production Cashe

I have been using MAGE for about 2 months now and I am a Neophyte to front and back end. I am looking for a little guidance in changing form "developer" to "production" mode. I don't use the CL, I use ...
0
votes
1answer
80 views

invalid create method

I have a model, I call it in a block and when I use the create method I get an error saying: Exception #0 (Magento\Framework\Exception\LocalizedException): Invalid method Vendor\Namespace\Model\...
1
vote
1answer
44 views

How to delete the content of a table

I'm able to fetch the single items, or the whole tables via the $modelFactory->create()->load(ID) or $modelFactory->create()->getCollection() Using the $modelFactory, how can I delete all ...
0
votes
0answers
14 views

M2: Can we use Model class in Block and same Block class in Model for sharing values?

I want to use an instance of a Model into a Block and an instance of same Block into same Model. As namespace Demo\HelloWorld\Block; class Seller extends \Magento\Framework\View\Element\Template { ...
2
votes
0answers
126 views

Magento2: How can I set to a model in “specificcountry” on config.xml file?

I want to set default values with a model from declared class in system.xml. The result of the model is extracted from the database, from a custom table and the result looks like this: AF,AL,DE,BE,FR ...
3
votes
1answer
39 views

How to connect Model / Data Model

Vendor/ModuleName/Model/TestModel.php Vendor/ModuleName/Model/Data/TestModel.php Vendor/ModuleName/Model/TestModelRepository.php Interfaces are already created. The Data Model contains for eg. these ...
2
votes
0answers
41 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
2answers
95 views

Create simple hello world model

I developed a extension. Now I try to add a model which has a function that returns "hello world". I tried it like seen here. app/code/local/Fekete/Newsletter2Go/etc/config.xml ... <global> ...
2
votes
3answers
196 views

magento 2 : model in custom module

i already have a table in database also created model files and all works fine so now added another table successfully so what changes i need to do with model files i mean in model resourcemodel and ...