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

2
votes
1answer
31 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 ...
-1
votes
0answers
9 views

Magento2 how to overtire Model for Checkout cart page and also cart quantity increase by ajax cart + and - button click events [on hold]

Magento2 how to overtire Model for Checkout cart page and also cart quantity increase by ajax cart + and - button click events so give me suggestion for plugin available for free Help Me
2
votes
2answers
40 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
35 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
71 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
32 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
40 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, ...
0
votes
2answers
60 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
32 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
17 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
23 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
44 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
39 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
33 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
88 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
14 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
62 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
48 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
20 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
29 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
52 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
31 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
41 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
43 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
11 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
75 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
36 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
30 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
65 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
166 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 ...
1
vote
1answer
18 views

GridFactory getting generated into wrong location

I have a custom module with backend management. I have an observer on config save that uses the file upload to read submitted file to update the collection however this fails due to below; class \My\...
1
vote
0answers
29 views

Magento 2: Migration using models

I would like to migrate products from magento 1 to magento 2 using core models instead of the migration toolkit provided by magento. The reason is that the products need A LOT of modification in the ...
4
votes
3answers
104 views

How to get config data from model in magento 2?

I have code file in model.How to get config data ? I have error with AbstractMethod and getConfigData() in PHP storm .ERROR Class AbstractMethod is deprecated Method getConfigData is ...
0
votes
1answer
48 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
0answers
25 views

Prevent a model from being saved

I'm trying to prevent a model from being saved by setting Mage_Core_Model_Abstract's _dataSaveAllowed property. This is going to happen inside an overriding Abstract.php file within local pool. app/...
0
votes
0answers
50 views

magento 2 - Overriding Abstract class in model is not working in custom module

I am trying to override the fontsize value for pdfslip file in my module. The pdfslip files can be found in admin under sales->invoices->actions. The function that I am interested in is ...
0
votes
0answers
9 views

What class should I extend for creating data source model of the database field?

I have some a custom entity model that has the some field in a database. I want to use some data source for it for validation and modification value of data. What model can I use for the database ...
2
votes
1answer
332 views

Custom Module data save gives array to string exception in Magento 2

I've made a custom module with a ui component in the admin. It's a grid that is filled with block data. When adding a block, and saving it in Controller/Adminhtml/Content/Save.php, exception "Array ...
0
votes
2answers
208 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 ...
0
votes
1answer
74 views

Magento 1.9 add attribute to Credit memo item

I am trying to add a quantity to return to stock data to the credit memo item. I have made 2 install scripts. One adds a column to the database <?php $installer = $this; $installer->...
0
votes
2answers
365 views

Magento 2 Override Model using Plugin

I have to override magento 2 code model file in the custom module. I have to override below method from Magento\Quote\Model\Quote\Address to my custom module and I have to change value of $amount. ...
0
votes
1answer
38 views

Magento 2 model for adding images to media folder (not for products)?

When not working with products, is there a magento2 model/function that can be used for reading/writing images to the media folder? (like addImageToMediaGallery / getMediaGalleryProcessor()->...
1
vote
1answer
15 views

Module with cron job to fetch all products where custom attribute is true

I am brand new to Magento module development, and I need some help getting started. My goal is relatively simple: I'd like to create a module which fetches all products with a custom attribute '...
0
votes
0answers
13 views

Create a detail listing page of a record on admin side

I want to create a page like an edit page of an model where user cannot change any content. He can only see the content. How can i achieve it?
2
votes
2answers
454 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 \...
2
votes
2answers
121 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 $...
0
votes
2answers
58 views

Magento2 Model not loading complete data using Factory

Below is my construct function of controller - public function __construct( \Magento\Framework\App\Action\Context $context, \Magento\Framework\Registry $coreRegistry, \Vendor\...
1
vote
2answers
67 views

Magento 1.9 Override Model Problem

Path File i want Override app\code\community\OtherCompany\core\Model\Api\Rest\Client.php Path my file override app\code\local\MyCompany\MyModule\Model\Api\Rest\Client.php app\etc\modules\...
1
vote
0answers
87 views

get join table's all rows with collection magento2

I am fetching a collection (of user table), that is retrieving correctly. Now I have one more table (ex.- address) that has multiple row related collection table primary key. I want to fetch them all ...