Stack Exchange Network

Stack Exchange network consists of 174 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

0
votes
1answer
15 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
15 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
23 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
18 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
72 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
47 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
30 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
13 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
28 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
35 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
29 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
21 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
42 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
10 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
41 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
33 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
24 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
52 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
155 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
15 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
26 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
68 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
36 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
1answer
24 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
27 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
8 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
233 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
102 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
47 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
0answers
54 views

Getting model data

I have started working with Magento 1.9 a week ago. Whenever I wish to make a module I need to know the field names for different models to fetch them from an observable I've been doing something ...
0
votes
2answers
188 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
34 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
14 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
10 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
344 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
90 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
42 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\...
0
votes
2answers
56 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
68 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 ...
0
votes
1answer
80 views

Magetno 2 custom module how to Update DB Table row with model

How do I update instead of inserting new row on save using model My code: $question = $this->_objectManager->create('Vendor\HelloWorld\Model\Question'); $question->setTitle('Simple Question'...
0
votes
3answers
645 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] =...
1
vote
1answer
108 views

Magento 2 - Not able to override CouponManagement Model

I am trying to override Magento\Quote\Model\CouponManagement core vendor file. What I am trying to achieve is change the default error message when the wrong coupon code is added. My di.xml <?...
0
votes
0answers
55 views

How to override ProductRepository model file in Magento2?

I need to override processMediaGallery method from \vendor\magento\module-catalog\Model\ProductRepository.php I used below code in my custom module etc/di.xml. < preference for="\Magento\...
4
votes
1answer
327 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 ...
2
votes
4answers
1k 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 ...
3
votes
3answers
462 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() ->...
0
votes
0answers
43 views

Model for sales_flat_order_payment table

I want to fetch the data from sales_flat_order_payment table and display in my admin panel grid. Is there any model through which I can fetch the data? If not, what is the work around to fetch the ...
0
votes
0answers
17 views

Total number of transaction not equal to total number of orders

I fetched all the transaction details using modelclass: sales/order_payment_transaction but my number of transactions are not close to Magento orders. What can be the problem or am I fetching it using ...
1
vote
1answer
48 views

Magento 2 : injecting models, interfaces in constructor magento

I'm new to magento 2 and I'm trying to understand how exactly injections work in magento. I understand that injecting a model and interfaces is the right approach in magento 2. But for some reason ...